Skip to content

Commit d6e8ef6

Browse files
authored
fix: service registry create not handling errors properly (#1668)
1 parent fd382b6 commit d6e8ef6

File tree

10 files changed

+47
-18
lines changed

10 files changed

+47
-18
lines changed

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ require (
2626
github.com/redhat-developer/app-services-sdk-go/accountmgmt v0.2.0
2727
github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.8.0
2828
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.8.0
29-
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.3
30-
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1
31-
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.8.0
29+
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.13.0
30+
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.4.0
31+
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.9.0
3232
github.com/redhat-developer/service-binding-operator v0.9.0
3333
github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3 // indirect
3434
github.com/spf13/cobra v1.5.0

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -683,12 +683,12 @@ github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.8.0 h1:6lVgDiJT
683683
github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.8.0/go.mod h1:t3IV0eKUPgCQjoInv2l8B/NMm2OVemCxGFO/z91wsCU=
684684
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.8.0 h1:NdtvHSoIQs0Lv4+VAcIHFIfBFgEpXDiscjR1UI7Ylts=
685685
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.8.0/go.mod h1:yazwUm4IHuIWrQ0CCsqN0h7rHZx51nlFbYWKnUn7B84=
686-
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.3 h1:rJ7C/Z/piT686Bsl75jojSeCpSS6fGPzgMaUBC++Jjc=
687-
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.12.3/go.mod h1:ILvcakLEXMLZyRdO//WJZNk9fdFbnU+cM3XrBvubE64=
688-
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1 h1:xRq5XJzRDs/Z7e/9SDt6zbNRIyesC4LTqN9ajHKwjHo=
689-
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1/go.mod h1:Z/gr/snlpsqYg4vftmcx97vCR3qMQJhALGelDHx4pMA=
690-
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.8.0 h1:eYOowsTl716BzDXQUR8N3Sz3HRC4e4LfJTKNsM/txvM=
691-
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.8.0/go.mod h1:UoxuqkUN+g5Ni8zgsCA7zidR5s774m9fqhZ5o4eOSIM=
686+
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.13.0 h1:aSuONBf3znnotUX7ywLh6xvOVVFsPRIUCfsEBWTWEM0=
687+
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.13.0/go.mod h1:ILvcakLEXMLZyRdO//WJZNk9fdFbnU+cM3XrBvubE64=
688+
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.4.0 h1:NhRpkA65wutg4AcxyQf1cMxTIqvKThDmJZkW79dCPZM=
689+
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.4.0/go.mod h1:HkNzOWHTW/SomobQ4343+yR4oTmiyvm85BIWlsh0qbA=
690+
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.9.0 h1:Kru+Z+a4yRn0aFsyKahrbibB9vD0JkvwVw7uPwbWfdA=
691+
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.9.0/go.mod h1:UoxuqkUN+g5Ni8zgsCA7zidR5s774m9fqhZ5o4eOSIM=
692692
github.com/redhat-developer/service-binding-operator v0.9.0 h1:CS+eEtzu/PtWuyvYQFQpZXd6ukSuFtN+U0EKKtTsvlA=
693693
github.com/redhat-developer/service-binding-operator v0.9.0/go.mod h1:D415gZQiz5Q8zyRbmrNrlieb6Xp73oFtCb+nCuTL6GA=
694694
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=

pkg/cmd/registry/artifact/crud/list/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func runList(opts *options) error {
127127
if err != nil {
128128
return err
129129
}
130-
request := a.ArtifactsApi.SearchArtifacts(opts.Context)
130+
request := a.SearchApi.SearchArtifacts(opts.Context)
131131

132132
request = request.Group(opts.group)
133133
request = request.Offset((opts.page - 1) * opts.limit)

pkg/cmd/registry/create/create.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,15 @@ func runCreate(opts *options) error {
148148
RegistryCreate(*payload).
149149
Execute()
150150

151-
if srsmgmtv1errors.IsAPIError(err, srsmgmtv1errors.ERROR_7) {
152-
return opts.localizer.MustLocalizeError("registry.cmd.create.error.limitreached")
151+
err = handleErrors(err, opts)
152+
if err != nil {
153+
return err
153154
}
154155

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

157158
registry, _, err := serviceregistryutil.GetServiceRegistryByID(opts.Context, conn.API().ServiceRegistryMgmt(), response.GetId())
159+
158160
if err != nil {
159161
return err
160162
}
@@ -191,6 +193,22 @@ func runCreate(opts *options) error {
191193
return nil
192194
}
193195

196+
func handleErrors(err error, opts *options) error {
197+
if srsmgmtv1errors.IsAPIError(err, srsmgmtv1errors.ERROR_7) {
198+
return opts.localizer.MustLocalizeError("registry.cmd.create.error.limitreached")
199+
}
200+
if srsmgmtv1errors.IsAPIError(err, srsmgmtv1errors.ERROR_13) {
201+
return opts.localizer.MustLocalizeError("registry.cmd.create.error.trial.limitreached")
202+
}
203+
if srsmgmtv1errors.IsAPIError(err, srsmgmtv1errors.ERROR_14) {
204+
return opts.localizer.MustLocalizeError("registry.cmd.create.error.global.limitreached")
205+
}
206+
if err != nil {
207+
return err
208+
}
209+
return nil
210+
}
211+
194212
// Show a prompt to allow the user to interactively insert the data
195213
func promptPayload(opts *options) (payload *srsmgmtv1.RegistryCreate, err error) {
196214
if err != nil {

pkg/cmd/registry/rule/describe/describe.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func runDescribe(opts *options) error {
119119

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

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

124124
rule, httpRes, err = req.Execute()
125125
if httpRes != nil {

pkg/cmd/registry/rule/disable/disable.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ func disableGlobalRule(opts *options, dataAPI *registryinstanceclient.APIClient)
167167

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

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

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

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

177-
req := dataAPI.AdminApi.DeleteAllGlobalRules(opts.Context)
177+
req := dataAPI.GlobalRulesApi.DeleteAllGlobalRules(opts.Context)
178178

179179
httpRes, err = req.Execute()
180180
}

pkg/cmd/registry/rule/enable/enable.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func runEnable(opts *options) error {
152152
),
153153
)
154154

155-
req := dataAPI.AdminApi.CreateGlobalRule(opts.Context)
155+
req := dataAPI.GlobalRulesApi.CreateGlobalRule(opts.Context)
156156

157157
req = req.Rule(rule)
158158

pkg/cmd/registry/rule/list/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func runList(opts *options) error {
117117

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

120-
req := dataAPI.AdminApi.ListGlobalRules(opts.Context)
120+
req := dataAPI.GlobalRulesApi.ListGlobalRules(opts.Context)
121121

122122
enabledRules, httpRes, newErr = req.Execute()
123123
if httpRes != nil {

pkg/cmd/registry/rule/update/update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func updateGlobalRule(opts *options, dataAPI *registryinstanceclient.APIClient)
171171
),
172172
)
173173

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

176176
rule := registryinstanceclient.Rule{
177177
Config: rulecmdutil.GetMappedConfigValue(opts.config),

pkg/core/localize/locales/en/cmd/registry_crud.en.toml

+11
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ Instance cannot be created. You have reached the limit of service registry insta
135135
Please contact your administrator to increase the limit or remove one of the existing instances.
136136
'''
137137

138+
[registry.cmd.create.error.trial.limitreached]
139+
one = '''
140+
Instance cannot be created. You have reached the limit of service registry instances per user.
141+
Pleare review your existing instances before creating a new one.
142+
'''
143+
144+
[registry.cmd.create.error.global.limitreached]
145+
one = '''
146+
Instance cannot be created. We have reached global the limit of service registry instances.
147+
'''
148+
138149

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

0 commit comments

Comments
 (0)