Skip to content

Commit

Permalink
fix(kafka create): skip quota fetch with bypass checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rkpattnaik780 authored and wtrocki committed Jul 19, 2022
1 parent 840d16f commit ae75576
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions pkg/cmd/kafka/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,6 @@ func runCreate(opts *options) error {
f.Logger.Info(f.Localizer.MustLocalize("service.info.termsCheck", localize.NewEntry("TermsURL", termsURL)))
return nil
}

err = ValidateBillingModel(opts.billingModel)
if err != nil {
return err
}
}

var payload *kafkamgmtclient.KafkaRequestPayload
Expand All @@ -230,26 +225,6 @@ func runCreate(opts *options) error {
}
} else {

orgQuota, newErr := accountmgmtutil.GetOrgQuotas(f, &constants.Kafka.Ams)
if newErr != nil {
return newErr
}

marketplaceInfo := accountmgmtutil.MarketplaceInfo{
BillingModel: opts.billingModel,
Provider: opts.marketplace,
CloudAccountID: opts.marketplaceAcctId,
}

userQuota, err = accountmgmtutil.SelectQuotaForUser(f, orgQuota, marketplaceInfo)
if err != nil {
return err
}

userQuotaJSON, _ := json.MarshalIndent(userQuota, "", " ")
f.Logger.Debug("Selected Quota object:")
f.Logger.Debug(string(userQuotaJSON))

if opts.provider == "" {
opts.provider = defaultProvider
}
Expand All @@ -264,20 +239,45 @@ func runCreate(opts *options) error {
CloudProvider: &opts.provider,
}

if userQuota.BillingModel == accountmgmtutil.QuotaMarketplaceType && userQuota.CloudAccounts != nil {
if !opts.bypassChecks {

payload.Marketplace = kafkamgmtclient.NullableString{}
payload.Marketplace.Set((*userQuota.CloudAccounts)[0].CloudProviderId)
payload.BillingCloudAccountId = kafkamgmtclient.NullableString{}
payload.BillingCloudAccountId.Set((*userQuota.CloudAccounts)[0].CloudAccountId)
}
err = ValidateBillingModel(opts.billingModel)
if err != nil {
return err
}

if opts.billingModel != "" {
payload.BillingModel = kafkamgmtclient.NullableString{}
payload.BillingModel.Set(&opts.billingModel)
}
orgQuotas, newErr := accountmgmtutil.GetOrgQuotas(f, &constants.Kafka.Ams)
if newErr != nil {
return newErr
}

marketplaceInfo := accountmgmtutil.MarketplaceInfo{
BillingModel: opts.billingModel,
Provider: opts.marketplace,
CloudAccountID: opts.marketplaceAcctId,
}

userQuota, err = accountmgmtutil.SelectQuotaForUser(f, orgQuotas, marketplaceInfo)
if err != nil {
return err
}

userQuotaJSON, _ := json.MarshalIndent(userQuota, "", " ")
f.Logger.Debug("Selected Quota object:")
f.Logger.Debug(string(userQuotaJSON))

if userQuota.BillingModel == accountmgmtutil.QuotaMarketplaceType && userQuota.CloudAccounts != nil {
payload.Marketplace = kafkamgmtclient.NullableString{}
payload.Marketplace.Set((*userQuota.CloudAccounts)[0].CloudProviderId)
payload.BillingCloudAccountId = kafkamgmtclient.NullableString{}
payload.BillingCloudAccountId.Set((*userQuota.CloudAccounts)[0].CloudAccountId)
}

if opts.billingModel != "" {
payload.BillingModel = kafkamgmtclient.NullableString{}
payload.BillingModel.Set(&opts.billingModel)
}

if !opts.bypassChecks {
validator := ValidatorInput{
provider: opts.provider,
region: opts.region,
Expand Down

0 comments on commit ae75576

Please sign in to comment.