Skip to content

Commit

Permalink
fix: service registry create not handling errors properly (#1668)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki authored Jul 21, 2022
1 parent fd382b6 commit d6e8ef6
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 18 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ require (
github.com/redhat-developer/app-services-sdk-go/accountmgmt v0.2.0
github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.8.0
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.8.0
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.3
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.8.0
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.13.0
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.4.0
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.9.0
github.com/redhat-developer/service-binding-operator v0.9.0
github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3 // indirect
github.com/spf13/cobra v1.5.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,12 @@ github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.8.0 h1:6lVgDiJT
github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.8.0/go.mod h1:t3IV0eKUPgCQjoInv2l8B/NMm2OVemCxGFO/z91wsCU=
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.8.0 h1:NdtvHSoIQs0Lv4+VAcIHFIfBFgEpXDiscjR1UI7Ylts=
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.8.0/go.mod h1:yazwUm4IHuIWrQ0CCsqN0h7rHZx51nlFbYWKnUn7B84=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.3 h1:rJ7C/Z/piT686Bsl75jojSeCpSS6fGPzgMaUBC++Jjc=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.3/go.mod h1:ILvcakLEXMLZyRdO//WJZNk9fdFbnU+cM3XrBvubE64=
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.8.0 h1:eYOowsTl716BzDXQUR8N3Sz3HRC4e4LfJTKNsM/txvM=
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.8.0/go.mod h1:UoxuqkUN+g5Ni8zgsCA7zidR5s774m9fqhZ5o4eOSIM=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.13.0 h1:aSuONBf3znnotUX7ywLh6xvOVVFsPRIUCfsEBWTWEM0=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.13.0/go.mod h1:ILvcakLEXMLZyRdO//WJZNk9fdFbnU+cM3XrBvubE64=
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.4.0 h1:NhRpkA65wutg4AcxyQf1cMxTIqvKThDmJZkW79dCPZM=
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.4.0/go.mod h1:HkNzOWHTW/SomobQ4343+yR4oTmiyvm85BIWlsh0qbA=
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.9.0 h1:Kru+Z+a4yRn0aFsyKahrbibB9vD0JkvwVw7uPwbWfdA=
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.9.0/go.mod h1:UoxuqkUN+g5Ni8zgsCA7zidR5s774m9fqhZ5o4eOSIM=
github.com/redhat-developer/service-binding-operator v0.9.0 h1:CS+eEtzu/PtWuyvYQFQpZXd6ukSuFtN+U0EKKtTsvlA=
github.com/redhat-developer/service-binding-operator v0.9.0/go.mod h1:D415gZQiz5Q8zyRbmrNrlieb6Xp73oFtCb+nCuTL6GA=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/registry/artifact/crud/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func runList(opts *options) error {
if err != nil {
return err
}
request := a.ArtifactsApi.SearchArtifacts(opts.Context)
request := a.SearchApi.SearchArtifacts(opts.Context)

request = request.Group(opts.group)
request = request.Offset((opts.page - 1) * opts.limit)
Expand Down
22 changes: 20 additions & 2 deletions pkg/cmd/registry/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ func runCreate(opts *options) error {
RegistryCreate(*payload).
Execute()

if srsmgmtv1errors.IsAPIError(err, srsmgmtv1errors.ERROR_7) {
return opts.localizer.MustLocalizeError("registry.cmd.create.error.limitreached")
err = handleErrors(err, opts)
if err != nil {
return err
}

opts.Logger.Info(icon.SuccessPrefix(), opts.localizer.MustLocalize("registry.cmd.create.info.successMessage"))

registry, _, err := serviceregistryutil.GetServiceRegistryByID(opts.Context, conn.API().ServiceRegistryMgmt(), response.GetId())

if err != nil {
return err
}
Expand Down Expand Up @@ -191,6 +193,22 @@ func runCreate(opts *options) error {
return nil
}

func handleErrors(err error, opts *options) error {
if srsmgmtv1errors.IsAPIError(err, srsmgmtv1errors.ERROR_7) {
return opts.localizer.MustLocalizeError("registry.cmd.create.error.limitreached")
}
if srsmgmtv1errors.IsAPIError(err, srsmgmtv1errors.ERROR_13) {
return opts.localizer.MustLocalizeError("registry.cmd.create.error.trial.limitreached")
}
if srsmgmtv1errors.IsAPIError(err, srsmgmtv1errors.ERROR_14) {
return opts.localizer.MustLocalizeError("registry.cmd.create.error.global.limitreached")
}
if err != nil {
return err
}
return nil
}

// Show a prompt to allow the user to interactively insert the data
func promptPayload(opts *options) (payload *srsmgmtv1.RegistryCreate, err error) {
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/registry/rule/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func runDescribe(opts *options) error {

opts.Logger.Info(opts.localizer.MustLocalize("registry.rule.describe.log.info.fetching.globalRule", localize.NewEntry("Type", opts.ruleType), localize.NewEntry("ID", opts.registryID)))

req := dataAPI.AdminApi.GetGlobalRuleConfig(opts.Context, *rulecmdutil.GetMappedRuleType(opts.ruleType))
req := dataAPI.GlobalRulesApi.GetGlobalRuleConfig(opts.Context, *rulecmdutil.GetMappedRuleType(opts.ruleType))

rule, httpRes, err = req.Execute()
if httpRes != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/registry/rule/disable/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ func disableGlobalRule(opts *options, dataAPI *registryinstanceclient.APIClient)

opts.Logger.Info(opts.localizer.MustLocalize("registry.rule.disable.log.info.disabling.globalRule", localize.NewEntry("RuleType", opts.ruleType), localize.NewEntry("ID", opts.registryID)))

req := dataAPI.AdminApi.DeleteGlobalRule(opts.Context, *rulecmdutil.GetMappedRuleType(opts.ruleType))
req := dataAPI.GlobalRulesApi.DeleteGlobalRule(opts.Context, *rulecmdutil.GetMappedRuleType(opts.ruleType))

httpRes, err = req.Execute()
} else {

opts.Logger.Info(opts.localizer.MustLocalize("registry.rule.disable.log.info.disabling.globalRules", localize.NewEntry("ID", opts.registryID)))

req := dataAPI.AdminApi.DeleteAllGlobalRules(opts.Context)
req := dataAPI.GlobalRulesApi.DeleteAllGlobalRules(opts.Context)

httpRes, err = req.Execute()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/registry/rule/enable/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func runEnable(opts *options) error {
),
)

req := dataAPI.AdminApi.CreateGlobalRule(opts.Context)
req := dataAPI.GlobalRulesApi.CreateGlobalRule(opts.Context)

req = req.Rule(rule)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/registry/rule/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func runList(opts *options) error {

opts.Logger.Info(opts.localizer.MustLocalize("registry.rule.list.log.info.fetching.globalRules"))

req := dataAPI.AdminApi.ListGlobalRules(opts.Context)
req := dataAPI.GlobalRulesApi.ListGlobalRules(opts.Context)

enabledRules, httpRes, newErr = req.Execute()
if httpRes != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/registry/rule/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func updateGlobalRule(opts *options, dataAPI *registryinstanceclient.APIClient)
),
)

req := dataAPI.AdminApi.UpdateGlobalRuleConfig(opts.Context, *rulecmdutil.GetMappedRuleType(opts.ruleType))
req := dataAPI.GlobalRulesApi.UpdateGlobalRuleConfig(opts.Context, *rulecmdutil.GetMappedRuleType(opts.ruleType))

rule := registryinstanceclient.Rule{
Config: rulecmdutil.GetMappedConfigValue(opts.config),
Expand Down
11 changes: 11 additions & 0 deletions pkg/core/localize/locales/en/cmd/registry_crud.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ Instance cannot be created. You have reached the limit of service registry insta
Please contact your administrator to increase the limit or remove one of the existing instances.
'''

[registry.cmd.create.error.trial.limitreached]
one = '''
Instance cannot be created. You have reached the limit of service registry instances per user.
Pleare review your existing instances before creating a new one.
'''

[registry.cmd.create.error.global.limitreached]
one = '''
Instance cannot be created. We have reached global the limit of service registry instances.
'''


[registry.cmd.create.flag.use.description]
one = 'Set the new Service Registry instance to the current instance'
Expand Down

0 comments on commit d6e8ef6

Please sign in to comment.