Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions docs/commands/rhoas_connector.md

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

41 changes: 41 additions & 0 deletions docs/commands/rhoas_connector_start.md

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

41 changes: 41 additions & 0 deletions docs/commands/rhoas_connector_stop.md

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

4 changes: 4 additions & 0 deletions pkg/cmd/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/cmd/connector/describe"
"github.com/redhat-developer/app-services-cli/pkg/cmd/connector/list"
"github.com/redhat-developer/app-services-cli/pkg/cmd/connector/namespace"
"github.com/redhat-developer/app-services-cli/pkg/cmd/connector/start"
"github.com/redhat-developer/app-services-cli/pkg/cmd/connector/stop"
"github.com/redhat-developer/app-services-cli/pkg/cmd/connector/update"
"github.com/redhat-developer/app-services-cli/pkg/cmd/connector/use"

Expand All @@ -32,6 +34,8 @@ func NewConnectorsCommand(f *factory.Factory) *cobra.Command {
cluster.NewConnectorClusterCommand(f),
namespace.NewNameSpaceCommand(f),
use.NewUseCommand(f),
start.NewStartCommand(f),
stop.NewStopCommand(f),
// Hidden for the users and docs at the moment
create.NewCreateCommand(f),
delete.NewDeleteCommand(f),
Expand Down
92 changes: 92 additions & 0 deletions pkg/cmd/connector/start/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package start

import (
"github.com/redhat-developer/app-services-cli/pkg/cmd/connector/connectorcmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
connectormgmtclient "github.com/redhat-developer/app-services-sdk-go/connectormgmt/apiv1/client"
"github.com/spf13/cobra"
)

type options struct {
outputFormat string
f *factory.Factory
connectorID string
}

// NewStartCommand creates a new command to start a connector
func NewStartCommand(f *factory.Factory) *cobra.Command {

opts := &options{
f: f,
}

cmd := &cobra.Command{
Use: "start",
Short: f.Localizer.MustLocalize("connector.start.cmd.shortDescription"),
Long: f.Localizer.MustLocalize("connector.start.cmd.longDescription"),
Example: f.Localizer.MustLocalize("connector.start.cmd.example"),
Hidden: false,
RunE: func(cmd *cobra.Command, args []string) error {

validOutputFormats := flagutil.ValidOutputFormats
if opts.outputFormat != "" && !flagutil.IsValidInput(opts.outputFormat, validOutputFormats...) {
return flagutil.InvalidValueError("output", opts.outputFormat, validOutputFormats...)
}

return runUpdateCommand(opts)
},
}

flags := connectorcmdutil.NewFlagSet(cmd, f)
flags.AddConnectorID(&opts.connectorID)
flags.AddOutput(&opts.outputFormat)

return cmd

}

func runUpdateCommand(opts *options) error {
f := opts.f

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

if opts.connectorID == "" {
connectorInstance, instance_err := contextutil.GetCurrentConnectorInstance(&conn, f)
if instance_err != nil {
return instance_err
}

opts.connectorID = *connectorInstance.Id
}

api := conn.API()

patch := make(map[string]interface{})
patch["desired_state"] = connectormgmtclient.CONNECTORDESIREDSTATE_READY
a := api.ConnectorsMgmt().ConnectorsApi.PatchConnector(f.Context, opts.connectorID).Body(patch)

response, httpRes, err := a.Execute()
if httpRes != nil {
defer httpRes.Body.Close()
}

if err != nil {
return err
}

if err = dump.Formatted(f.IOStreams.Out, opts.outputFormat, response); err != nil {
return err
}

f.Logger.Info(f.Localizer.MustLocalize("connector.update.info.success"))

return nil
}
92 changes: 92 additions & 0 deletions pkg/cmd/connector/stop/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package stop

import (
"github.com/redhat-developer/app-services-cli/pkg/cmd/connector/connectorcmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
connectormgmtclient "github.com/redhat-developer/app-services-sdk-go/connectormgmt/apiv1/client"
"github.com/spf13/cobra"
)

type options struct {
outputFormat string
f *factory.Factory
connectorID string
}

// NewStopCommand creates a new command to start a connector
func NewStopCommand(f *factory.Factory) *cobra.Command {

opts := &options{
f: f,
}

cmd := &cobra.Command{
Use: "stop",
Short: f.Localizer.MustLocalize("connector.stop.cmd.shortDescription"),
Long: f.Localizer.MustLocalize("connector.stop.cmd.longDescription"),
Example: f.Localizer.MustLocalize("connector.stop.cmd.example"),
Hidden: false,
RunE: func(cmd *cobra.Command, args []string) error {

validOutputFormats := flagutil.ValidOutputFormats
if opts.outputFormat != "" && !flagutil.IsValidInput(opts.outputFormat, validOutputFormats...) {
return flagutil.InvalidValueError("output", opts.outputFormat, validOutputFormats...)
}

return runUpdateCommand(opts)
},
}

flags := connectorcmdutil.NewFlagSet(cmd, f)
flags.AddConnectorID(&opts.connectorID)
flags.AddOutput(&opts.outputFormat)

return cmd

}

func runUpdateCommand(opts *options) error {
f := opts.f

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

if opts.connectorID == "" {
connectorInstance, instance_err := contextutil.GetCurrentConnectorInstance(&conn, f)
if instance_err != nil {
return instance_err
}

opts.connectorID = *connectorInstance.Id
}

api := conn.API()

patch := make(map[string]interface{})
patch["desired_state"] = connectormgmtclient.CONNECTORDESIREDSTATE_STOPPED
a := api.ConnectorsMgmt().ConnectorsApi.PatchConnector(f.Context, opts.connectorID).Body(patch)

response, httpRes, err := a.Execute()
if httpRes != nil {
defer httpRes.Body.Close()
}

if err != nil {
return err
}

if err = dump.Formatted(f.IOStreams.Out, opts.outputFormat, response); err != nil {
return err
}

f.Logger.Info(f.Localizer.MustLocalize("connector.update.info.success"))

return nil
}
36 changes: 36 additions & 0 deletions pkg/core/localize/locales/en/cmd/connectors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ cat myconnector.json | rhoas connector update

# Delete a Connectors instance with ID c9b71ucotd37bufoamkg
rhoas connector delete --id=c9b71ucotd37bufoamkg

# Start a Connectors instance with ID c9b71ucotd37bufoamkg
rhoas connector start --id=c9b71ucotd37bufoamkg

# Start the Connectors instance in the current context
rhoas connector stop
'''

[connector.create.cmd.shortDescription]
Expand All @@ -143,6 +149,36 @@ rhoas connector create --file=myconnector.json
cat myconnector.json | rhoas connector create
'''

[connector.stop.cmd.shortDescription]
one = 'Stop a connector instance'

[connector.stop.cmd.longDescription]
one = 'Stop a connectorc instance, pass an id or use the instance in the current context'

[connector.stop.cmd.example]
one = '''
# Stop a connector instance
rhoas connector stop

# Stop a connector instance
rhoas connector stop --id=IJD76DUH675234
'''

[connector.start.cmd.shortDescription]
one = 'Start a connector instance'

[connector.start.cmd.longDescription]
one = 'Start a Connectors instance, pass an id or use the instance in the current context'

[connector.start.cmd.example]
one = '''
# Start a connector instance
rhoas connector start

# Start a connector instance
rhoas connector start --id=IJD76DUH675234
'''

[connector.create.info.success]
one = 'Successfully created the Connectors instance'

Expand Down
2 changes: 1 addition & 1 deletion pkg/shared/contextutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func GetCurrentConnectorInstance(conn *connection.Connection, f *factory.Factory
func GetConnectorForServiceConfig(currCtx *servicecontext.ServiceConfig, conn *connection.Connection, f *factory.Factory) (*connectormgmtclient.Connector, error) {

if currCtx.ConnectorID == "" {
return nil, f.Localizer.MustLocalizeError("context.common.error.noConnecterID")
return nil, f.Localizer.MustLocalizeError("context.common.error.noConnectorID")
}

connectorInstance, _, err := (*conn).API().ConnectorsMgmt().ConnectorsApi.GetConnector(f.Context, currCtx.ConnectorID).Execute()
Expand Down