Skip to content

Commit

Permalink
fix(connector update): populate kafka url (#1786)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkpattnaik780 authored Jan 12, 2023
1 parent 152c36e commit ddd600f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
13 changes: 7 additions & 6 deletions docs/commands/rhoas_connector_update.md

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

14 changes: 13 additions & 1 deletion pkg/cmd/connector/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,21 @@ func createServiceAccount(opts *factory.Factory, shortDescription string) (*svca
}

func setDefaultValuesFromFlags(connector *connectormgmtclient.ConnectorRequest, opts *options) error {

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

if opts.kafkaId != "" {
kafkaInstance, _, kafkaErr := kafkautil.GetKafkaByID(opts.f.Context, conn.API().KafkaMgmt(), opts.kafkaId)
if kafkaErr != nil {
return kafkaErr
}

connector.Kafka = connectormgmtclient.KafkaConnectionSettings{
Id: opts.kafkaId,
Id: opts.kafkaId,
Url: kafkaInstance.GetBootstrapServerHost(),
}
}

Expand Down
44 changes: 33 additions & 11 deletions pkg/cmd/connector/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package update

import (
"encoding/json"

"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/connectorutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
"github.com/spf13/cobra"

"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
Expand All @@ -20,6 +22,7 @@ type options struct {
namespaceID string
kafkaID string
name string
id string

outputFormat string
f *factory.Factory
Expand All @@ -43,13 +46,30 @@ 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.kafkaID.description"))
flags.StringVar(&opts.kafkaID, "kafka-id", "", f.Localizer.MustLocalize("connector.flag.namespaceID.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"))
flags.AddOutput(&opts.outputFormat)

return cmd
Expand All @@ -63,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 @@ -82,7 +99,12 @@ func runUpdate(opts *options) error {
connectorChanged = true
}
if opts.kafkaID != "" {
connector.Kafka.SetId(opts.kafkaID)
kafkaInstance, _, kafkaErr := kafkautil.GetKafkaByID(opts.f.Context, conn.API().KafkaMgmt(), opts.kafkaID)
if kafkaErr != nil {
return kafkaErr
}
connector.Kafka.SetId(kafkaInstance.GetId())
connector.Kafka.SetUrl(kafkaInstance.GetBootstrapServerHost())
connectorChanged = true
}

Expand All @@ -105,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
11 changes: 7 additions & 4 deletions pkg/core/localize/locales/en/cmd/connectors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,11 @@ After you edit the configuration file, use the "connector update" command to upd

[connector.update.cmd.example]
one = '''
# Update a Connectors instance
rhoas connector update --id=my-connector --file=myconnector.json
# Update name of the current Connectors instance
rhoas connector update --name=my-connector
# Update a Connectors instance from stdin
cat myconnector.json | rhoas connector update
# Update Kafka Instance of a Connectors instance by ID
rhoas connector update --kafka-id ce6pg07k09f3rs6us7sg --id ce6tgb1mk0orirpo5i70
'''

[connector.update.info.success]
Expand All @@ -424,6 +424,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 ddd600f

Please sign in to comment.