Skip to content

Commit ddd600f

Browse files
fix(connector update): populate kafka url (#1786)
1 parent 152c36e commit ddd600f

File tree

4 files changed

+60
-22
lines changed

4 files changed

+60
-22
lines changed

docs/commands/rhoas_connector_update.md

+7-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cmd/connector/create/create.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,21 @@ func createServiceAccount(opts *factory.Factory, shortDescription string) (*svca
164164
}
165165

166166
func setDefaultValuesFromFlags(connector *connectormgmtclient.ConnectorRequest, opts *options) error {
167+
168+
conn, err := opts.f.Connection()
169+
if err != nil {
170+
return err
171+
}
172+
167173
if opts.kafkaId != "" {
174+
kafkaInstance, _, kafkaErr := kafkautil.GetKafkaByID(opts.f.Context, conn.API().KafkaMgmt(), opts.kafkaId)
175+
if kafkaErr != nil {
176+
return kafkaErr
177+
}
178+
168179
connector.Kafka = connectormgmtclient.KafkaConnectionSettings{
169-
Id: opts.kafkaId,
180+
Id: opts.kafkaId,
181+
Url: kafkaInstance.GetBootstrapServerHost(),
170182
}
171183
}
172184

pkg/cmd/connector/update/update.go

+33-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package update
22

33
import (
44
"encoding/json"
5+
56
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
67
"github.com/redhat-developer/app-services-cli/pkg/shared/connectorutil"
78
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
9+
"github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
810
"github.com/spf13/cobra"
911

1012
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
@@ -20,6 +22,7 @@ type options struct {
2022
namespaceID string
2123
kafkaID string
2224
name string
25+
id string
2326

2427
outputFormat string
2528
f *factory.Factory
@@ -43,13 +46,30 @@ func NewUpdateCommand(f *factory.Factory) *cobra.Command {
4346
return flagutil.InvalidValueError("output", opts.outputFormat, validOutputFormats...)
4447
}
4548

49+
if opts.id != "" {
50+
return runUpdate(opts)
51+
}
52+
53+
conn, err := opts.f.Connection()
54+
if err != nil {
55+
return err
56+
}
57+
58+
connector, err := contextutil.GetCurrentConnectorInstance(&conn, opts.f)
59+
if err != nil {
60+
return err
61+
}
62+
63+
opts.id = connector.GetId()
64+
4665
return runUpdate(opts)
4766
},
4867
}
4968
flags := flagutil.NewFlagSet(cmd, f.Localizer)
69+
flags.StringVar(&opts.id, "id", "", f.Localizer.MustLocalize("connector.flag.id.description"))
5070
flags.StringVar(&opts.name, "name", "", f.Localizer.MustLocalize("connector.flag.name.description"))
51-
flags.StringVar(&opts.namespaceID, "namespace-id", "", f.Localizer.MustLocalize("connector.flag.kafkaID.description"))
52-
flags.StringVar(&opts.kafkaID, "kafka-id", "", f.Localizer.MustLocalize("connector.flag.namespaceID.description"))
71+
flags.StringVar(&opts.namespaceID, "namespace-id", "", f.Localizer.MustLocalize("connector.flag.namespaceID.description"))
72+
flags.StringVar(&opts.kafkaID, "kafka-id", "", f.Localizer.MustLocalize("connector.flag.kafkaID.description"))
5373
flags.AddOutput(&opts.outputFormat)
5474

5575
return cmd
@@ -63,13 +83,10 @@ func runUpdate(opts *options) error {
6383
return err
6484
}
6585

66-
api := conn.API()
67-
68-
connector, err := contextutil.GetCurrentConnectorInstance(&conn, opts.f)
69-
if err != nil || connector == nil {
70-
if connector, err = connectorutil.InteractiveSelect(conn, opts.f); err != nil {
71-
return err
72-
}
86+
connectorsApi := conn.API().ConnectorsMgmt()
87+
connector, err := connectorutil.GetConnectorByID(&connectorsApi, opts.id, opts.f)
88+
if err != nil {
89+
return err
7390
}
7491

7592
connectorChanged := false
@@ -82,7 +99,12 @@ func runUpdate(opts *options) error {
8299
connectorChanged = true
83100
}
84101
if opts.kafkaID != "" {
85-
connector.Kafka.SetId(opts.kafkaID)
102+
kafkaInstance, _, kafkaErr := kafkautil.GetKafkaByID(opts.f.Context, conn.API().KafkaMgmt(), opts.kafkaID)
103+
if kafkaErr != nil {
104+
return kafkaErr
105+
}
106+
connector.Kafka.SetId(kafkaInstance.GetId())
107+
connector.Kafka.SetUrl(kafkaInstance.GetBootstrapServerHost())
86108
connectorChanged = true
87109
}
88110

@@ -105,7 +127,7 @@ func runUpdate(opts *options) error {
105127
return err
106128
}
107129

108-
a := api.ConnectorsMgmt().ConnectorsApi.PatchConnector(opts.f.Context, connector.GetId())
130+
a := conn.API().ConnectorsMgmt().ConnectorsApi.PatchConnector(opts.f.Context, connector.GetId())
109131
a = a.Body(patchData)
110132
updated, httpRes, err := a.Execute()
111133
if httpRes != nil {

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ After you edit the configuration file, use the "connector update" command to upd
399399

400400
[connector.update.cmd.example]
401401
one = '''
402-
# Update a Connectors instance
403-
rhoas connector update --id=my-connector --file=myconnector.json
402+
# Update name of the current Connectors instance
403+
rhoas connector update --name=my-connector
404404
405-
# Update a Connectors instance from stdin
406-
cat myconnector.json | rhoas connector update
405+
# Update Kafka Instance of a Connectors instance by ID
406+
rhoas connector update --kafka-id ce6pg07k09f3rs6us7sg --id ce6tgb1mk0orirpo5i70
407407
'''
408408

409409
[connector.update.info.success]
@@ -424,6 +424,9 @@ one = 'ID of of the Kafka instance that you want the Connectors instance to use'
424424
[connector.flag.namespace.description]
425425
one = 'ID of the namespace for the Connectors instance (the default is the namespace for the current context)'
426426

427+
[connector.flag.id.description]
428+
one = 'ID of the Connectors instance to be updated (the default is the instance in current context)'
429+
427430
[connector.flag.name.description]
428431
one = 'Override the name of the Connectors instance (the default name is the name specified in the connector configuration file)'
429432

0 commit comments

Comments
 (0)