From d6e8ef6a4f58bd3fad928e604abc6fd0b905b114 Mon Sep 17 00:00:00 2001 From: Wojciech Trocki Date: Thu, 21 Jul 2022 13:54:01 +0200 Subject: [PATCH] fix: service registry create not handling errors properly (#1668) --- go.mod | 6 ++--- go.sum | 12 +++++----- pkg/cmd/registry/artifact/crud/list/list.go | 2 +- pkg/cmd/registry/create/create.go | 22 +++++++++++++++++-- pkg/cmd/registry/rule/describe/describe.go | 2 +- pkg/cmd/registry/rule/disable/disable.go | 4 ++-- pkg/cmd/registry/rule/enable/enable.go | 2 +- pkg/cmd/registry/rule/list/list.go | 2 +- pkg/cmd/registry/rule/update/update.go | 2 +- .../locales/en/cmd/registry_crud.en.toml | 11 ++++++++++ 10 files changed, 47 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index a9e3d084d..27634119c 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index fc00b97a0..df6eac0e5 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/cmd/registry/artifact/crud/list/list.go b/pkg/cmd/registry/artifact/crud/list/list.go index 4243c6f49..7acb5053a 100644 --- a/pkg/cmd/registry/artifact/crud/list/list.go +++ b/pkg/cmd/registry/artifact/crud/list/list.go @@ -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) diff --git a/pkg/cmd/registry/create/create.go b/pkg/cmd/registry/create/create.go index 85eec5151..0ce686159 100644 --- a/pkg/cmd/registry/create/create.go +++ b/pkg/cmd/registry/create/create.go @@ -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 } @@ -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 { diff --git a/pkg/cmd/registry/rule/describe/describe.go b/pkg/cmd/registry/rule/describe/describe.go index c4f0cc6d3..86b2c3230 100644 --- a/pkg/cmd/registry/rule/describe/describe.go +++ b/pkg/cmd/registry/rule/describe/describe.go @@ -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 { diff --git a/pkg/cmd/registry/rule/disable/disable.go b/pkg/cmd/registry/rule/disable/disable.go index 2f968ffed..45baf19c7 100644 --- a/pkg/cmd/registry/rule/disable/disable.go +++ b/pkg/cmd/registry/rule/disable/disable.go @@ -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() } diff --git a/pkg/cmd/registry/rule/enable/enable.go b/pkg/cmd/registry/rule/enable/enable.go index 53e497ab0..5f6af0af6 100644 --- a/pkg/cmd/registry/rule/enable/enable.go +++ b/pkg/cmd/registry/rule/enable/enable.go @@ -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) diff --git a/pkg/cmd/registry/rule/list/list.go b/pkg/cmd/registry/rule/list/list.go index bf2e24cb9..a0397a4af 100644 --- a/pkg/cmd/registry/rule/list/list.go +++ b/pkg/cmd/registry/rule/list/list.go @@ -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 { diff --git a/pkg/cmd/registry/rule/update/update.go b/pkg/cmd/registry/rule/update/update.go index 2883f916d..04aa7d067 100644 --- a/pkg/cmd/registry/rule/update/update.go +++ b/pkg/cmd/registry/rule/update/update.go @@ -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), diff --git a/pkg/core/localize/locales/en/cmd/registry_crud.en.toml b/pkg/core/localize/locales/en/cmd/registry_crud.en.toml index b519cc8e4..9cf1a42e3 100644 --- a/pkg/core/localize/locales/en/cmd/registry_crud.en.toml +++ b/pkg/core/localize/locales/en/cmd/registry_crud.en.toml @@ -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'