Skip to content

Commit

Permalink
feat(connector update): add id flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rkpattnaik780 committed Dec 5, 2022
1 parent acc14f8 commit 69ce2de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/commands/rhoas_connector_update.md

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

33 changes: 24 additions & 9 deletions pkg/cmd/connector/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type options struct {
namespaceID string
kafkaID string
name string
id string

outputFormat string
f *factory.Factory
Expand All @@ -45,10 +46,27 @@ func NewUpdateCommand(f *factory.Factory) *cobra.Command {
return flagutil.InvalidValueError("output", opts.outputFormat, validOutputFormats...)
}

if opts.id != "" {
return runUpdate(opts)
}

conn, err := opts.f.Connection()
if err != nil {
return err
}

connector, err := contextutil.GetCurrentConnectorInstance(&conn, opts.f)
if err != nil {
return err
}

opts.id = connector.GetId()

return runUpdate(opts)
},
}
flags := flagutil.NewFlagSet(cmd, f.Localizer)
flags.StringVar(&opts.id, "id", "", f.Localizer.MustLocalize("connector.flag.id.description"))
flags.StringVar(&opts.name, "name", "", f.Localizer.MustLocalize("connector.flag.name.description"))
flags.StringVar(&opts.namespaceID, "namespace-id", "", f.Localizer.MustLocalize("connector.flag.namespaceID.description"))
flags.StringVar(&opts.kafkaID, "kafka-id", "", f.Localizer.MustLocalize("connector.flag.kafkaID.description"))
Expand All @@ -65,13 +83,10 @@ func runUpdate(opts *options) error {
return err
}

api := conn.API()

connector, err := contextutil.GetCurrentConnectorInstance(&conn, opts.f)
if err != nil || connector == nil {
if connector, err = connectorutil.InteractiveSelect(conn, opts.f); err != nil {
return err
}
connectorsApi := conn.API().ConnectorsMgmt()
connector, err := connectorutil.GetConnectorByID(&connectorsApi, opts.id, opts.f)
if err != nil {
return err
}

connectorChanged := false
Expand All @@ -84,7 +99,7 @@ func runUpdate(opts *options) error {
connectorChanged = true
}
if opts.kafkaID != "" {
kafkaInstance, _, kafkaErr := kafkautil.GetKafkaByID(opts.f.Context, api.KafkaMgmt(), opts.kafkaID)
kafkaInstance, _, kafkaErr := kafkautil.GetKafkaByID(opts.f.Context, conn.API().KafkaMgmt(), opts.kafkaID)
if kafkaErr != nil {
return kafkaErr
}
Expand Down Expand Up @@ -112,7 +127,7 @@ func runUpdate(opts *options) error {
return err
}

a := api.ConnectorsMgmt().ConnectorsApi.PatchConnector(opts.f.Context, connector.GetId())
a := conn.API().ConnectorsMgmt().ConnectorsApi.PatchConnector(opts.f.Context, connector.GetId())
a = a.Body(patchData)
updated, httpRes, err := a.Execute()
if httpRes != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/core/localize/locales/en/cmd/connectors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ one = 'ID of of the Kafka instance that you want the Connectors instance to use'
[connector.flag.namespace.description]
one = 'ID of the namespace for the Connectors instance (the default is the namespace for the current context)'

[connector.flag.id.description]
one = 'ID of the Connectors instance to be updated (the default is the instance in current context)'

[connector.flag.name.description]
one = 'Override the name of the Connectors instance (the default name is the name specified in the connector configuration file)'

Expand Down

0 comments on commit 69ce2de

Please sign in to comment.