Skip to content

Commit

Permalink
feat(kafka create): add billing model flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rkpattnaik780 committed Jun 23, 2022
1 parent 3e8e7a1 commit 136e35d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/commands/rhoas_kafka_create.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/redhat-developer/app-services-sdk-go/accountmgmt v0.2.0
github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.5.0
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.6.0
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.0
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.1
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.6.1
github.com/redhat-developer/service-binding-operator v0.9.0
Expand All @@ -39,7 +39,7 @@ require (
gitlab.com/c0b/go-ordered-json v0.0.0-20201030195603-febf46534d5a
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b // indirect
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb
golang.org/x/text v0.3.7
golang.org/x/tools v0.1.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.5.0 h1:cf+K96kW
github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.5.0/go.mod h1:JAedrXf/qLHd7lpOS+bOFh8nrOpp2j0sg4/VG/1um6c=
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.6.0 h1:ExEHQaihnPNxN2nKXB0q5nrmSv4p8b3Idzt7TChxv+Q=
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.6.0/go.mod h1:hMpejngP3BFnifCDH1gKRG9cU9Q4lr0WiQaW7A1LYo4=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.0 h1:63UhOYB8TozKdnkkws2pXc0D1lEB+K3qX63/OxkjDas=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.0/go.mod h1:m+m7d6xkC9WbSxemslyhjv0jVhquWLysRfdh+RQ5hH0=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.1 h1:Gcyn2kLlslsVT6T8qoiCJpJFPrnD2i2KIFeKQJrXkTY=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.1/go.mod h1:RoPo3tyHjv8apStFNVjChwWYdlWhg6hMzi1IrH3yQX8=
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1 h1:xRq5XJzRDs/Z7e/9SDt6zbNRIyesC4LTqN9ajHKwjHo=
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1/go.mod h1:Z/gr/snlpsqYg4vftmcx97vCR3qMQJhALGelDHx4pMA=
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.6.1 h1:3sUmQ3nAawsYWg7ZCO2Q8HF2J7MW6YA38h/YFL3ao6o=
Expand Down Expand Up @@ -932,8 +932,9 @@ golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401 h1:zwrSfklXn0gxyLRX/aR+q6cgHbV/ItVyzbPlbA+dkAw=
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb h1:8tDJ3aechhddbdPAxpycgXHJRMLpk/Ab+aa4OgdN5/g=
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb/go.mod h1:jaDAt6Dkxork7LmZnYtzbRWj0W47D86a3TGe0YHBvmE=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
24 changes: 24 additions & 0 deletions pkg/cmd/kafka/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type options struct {

marketplaceAcctId string
marketplace string
billingModel string

outputFormat string
autoUse bool
Expand Down Expand Up @@ -147,6 +148,7 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command {
flags.BoolVar(&opts.autoUse, "use", true, f.Localizer.MustLocalize("kafka.create.flag.autoUse.description"))
flags.BoolVarP(&opts.wait, "wait", "w", false, f.Localizer.MustLocalize("kafka.create.flag.wait.description"))
flags.BoolVarP(&opts.dryRun, "dry-run", "", false, f.Localizer.MustLocalize("kafka.create.flag.dryrun.description"))
flags.StringVar(&opts.billingModel, "billing-model", "", f.Localizer.MustLocalize("kafka.create.flag.billingModel.description"))
flags.AddBypassTermsCheck(&opts.bypassChecks)

_ = cmd.RegisterFlagCompletionFunc(FlagProvider, func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
Expand Down Expand Up @@ -249,6 +251,8 @@ func runCreate(opts *options) error {
payload.Marketplace.Set(&opts.marketplace)
payload.BillingCloudAccountId = kafkamgmtclient.NullableString{}
payload.BillingCloudAccountId.Set(&opts.marketplaceAcctId)
payload.BillingModel = kafkamgmtclient.NullableString{}
payload.BillingModel.Set(&opts.billingModel)
}

if !opts.bypassChecks {
Expand Down Expand Up @@ -480,6 +484,11 @@ func promptKafkaPayload(opts *options, userQuotaType accountmgmtutil.QuotaSpec)
}

if !opts.bypassChecks && len(marketplaces) > 0 {

if err = promptBillingModelSelect(f.Localizer, answers); err != nil {
return nil, err
}

if err = promptMarketplaceSelect(f.Localizer, marketplaces, answers); err != nil {
return nil, err
}
Expand Down Expand Up @@ -512,6 +521,21 @@ func promptKafkaPayload(opts *options, userQuotaType accountmgmtutil.QuotaSpec)
return payload, nil
}

func promptBillingModelSelect(localizer localize.Localizer, answers *promptAnswers) error {

billingModelPrompt := &survey.Select{
Message: "Billing model:",
Options: kafkacmdutil.ValidBillingModels,
Help: localizer.MustLocalize("kafka.create.flag.billingModel.description"),
}

if err := survey.AskOne(billingModelPrompt, &answers.Marketplace); err != nil {
return err
}

return nil
}

func promptMarketplaceSelect(localizer localize.Localizer, marketplaceAcctIDs []string, answers *promptAnswers) error {

marketplacePrompt := &survey.Select{
Expand Down
7 changes: 7 additions & 0 deletions pkg/cmd/kafka/kafkacmdutil/kafka_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import (
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
)

var (
billingModelMarketplace = "marketplace"
billingModelStandard = "standard"
)

var ValidBillingModels = []string{billingModelMarketplace, billingModelStandard}

var (
validNameRegexp = regexp.MustCompile(`^[a-z]([-a-z0-9]*[a-z0-9])?$`)
validSearchRegexp = regexp.MustCompile(`^([a-zA-Z0-9-_%]*[a-zA-Z0-9-_%])?$`)
Expand Down
3 changes: 3 additions & 0 deletions pkg/core/localize/locales/en/cmd/kafka.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ one = 'Wait until the Kafka instance is created'
[kafka.create.flag.dryrun.description]
one = 'Validate all user provided arguments without creating the Kafka instance'

[kafka.create.flag.billingModel.description]
one = 'Billing model to be used'

[kafka.create.flag.marketplaceId.description]
one = 'Cloud Account ID for the marketplace'

Expand Down

0 comments on commit 136e35d

Please sign in to comment.