Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connector update): populate kafka url #1786

Merged
merged 5 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -358,11 +358,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 @@ -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