From 33407fad16fbbfb6341ea7153e0e2c2beb0cad97 Mon Sep 17 00:00:00 2001 From: Steve Munene Date: Fri, 10 Jan 2025 14:49:38 +0300 Subject: [PATCH] NOISSUE - Update CLI (#2642) Signed-off-by: nyagamunene --- cli/clients.go | 31 +++++++++++++++++++++++-------- cli/clients_test.go | 15 +++++++++++++-- cli/config.go | 18 ++++++++++++++++-- cmd/invitations/main.go | 2 +- config.toml | 8 +++++--- 5 files changed, 58 insertions(+), 16 deletions(-) diff --git a/cli/clients.go b/cli/clients.go index d59489eef5..6220bb8bd1 100644 --- a/cli/clients.go +++ b/cli/clients.go @@ -198,22 +198,29 @@ var cmdClients = []cobra.Command{ }, }, { - Use: "connect ", + Use: "connect ", Short: "Connect client", Long: "Connect client to the channel\n" + "Usage:\n" + - "\tsupermq-cli clients connect $DOMAINID $USERTOKEN\n", + "\tsupermq-cli clients connect $DOMAINID $USERTOKEN\n", Run: func(cmd *cobra.Command, args []string) { - if len(args) != 4 { + if len(args) != 5 { logUsageCmd(*cmd, cmd.Use) return } + var conn_types []string + err := json.Unmarshal([]byte(args[2]), &conn_types) + if err != nil { + logErrorCmd(*cmd, err) + return + } connIDs := smqsdk.Connection{ ChannelIDs: []string{args[1]}, ClientIDs: []string{args[0]}, + Types: conn_types, } - if err := sdk.Connect(connIDs, args[2], args[3]); err != nil { + if err := sdk.Connect(connIDs, args[3], args[4]); err != nil { logErrorCmd(*cmd, err) return } @@ -222,22 +229,30 @@ var cmdClients = []cobra.Command{ }, }, { - Use: "disconnect ", + Use: "disconnect ", Short: "Disconnect client", Long: "Disconnect client to the channel\n" + "Usage:\n" + - "\tsupermq-cli clients disconnect $DOMAINID $USERTOKEN\n", + "\tsupermq-cli clients disconnect $DOMAINID $USERTOKEN\n", Run: func(cmd *cobra.Command, args []string) { - if len(args) != 4 { + if len(args) != 5 { logUsageCmd(*cmd, cmd.Use) return } + var conn_types []string + err := json.Unmarshal([]byte(args[2]), &conn_types) + if err != nil { + logErrorCmd(*cmd, err) + return + } + connIDs := smqsdk.Connection{ ClientIDs: []string{args[0]}, ChannelIDs: []string{args[1]}, + Types: conn_types, } - if err := sdk.Disconnect(connIDs, args[2], args[3]); err != nil { + if err := sdk.Disconnect(connIDs, args[3], args[4]); err != nil { logErrorCmd(*cmd, err) return } diff --git a/cli/clients_test.go b/cli/clients_test.go index ffbfe447f5..e535290859 100644 --- a/cli/clients_test.go +++ b/cli/clients_test.go @@ -28,6 +28,7 @@ var ( tokenWithoutDomain = "valid" relation = "administrator" all = "all" + conntype = `["publish","subscribe"]` ) var client = sdk.Client{ @@ -817,6 +818,7 @@ func TestConnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, domainID, token, }, @@ -827,6 +829,7 @@ func TestConnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, domainID, token, extraArg, @@ -838,6 +841,7 @@ func TestConnectClientCmd(t *testing.T) { args: []string{ invalidID, channel.ID, + conntype, domainID, token, }, @@ -850,6 +854,7 @@ func TestConnectClientCmd(t *testing.T) { args: []string{ client.ID, invalidID, + conntype, domainID, token, }, @@ -862,6 +867,7 @@ func TestConnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, invalidID, token, }, @@ -873,7 +879,7 @@ func TestConnectClientCmd(t *testing.T) { for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { - sdkCall := sdkMock.On("Connect", mock.Anything, tc.args[2], tc.args[3]).Return(tc.sdkErr) + sdkCall := sdkMock.On("Connect", mock.Anything, tc.args[3], tc.args[4]).Return(tc.sdkErr) out := executeCommand(t, rootCmd, append([]string{connCmd}, tc.args...)...) switch tc.logType { @@ -907,6 +913,7 @@ func TestDisconnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, domainID, token, }, @@ -917,6 +924,7 @@ func TestDisconnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, domainID, token, extraArg, @@ -928,6 +936,7 @@ func TestDisconnectClientCmd(t *testing.T) { args: []string{ invalidID, channel.ID, + conntype, domainID, token, }, @@ -940,6 +949,7 @@ func TestDisconnectClientCmd(t *testing.T) { args: []string{ client.ID, invalidID, + conntype, domainID, token, }, @@ -952,6 +962,7 @@ func TestDisconnectClientCmd(t *testing.T) { args: []string{ client.ID, channel.ID, + conntype, invalidID, token, }, @@ -963,7 +974,7 @@ func TestDisconnectClientCmd(t *testing.T) { for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { - sdkCall := sdkMock.On("Disconnect", mock.Anything, tc.args[2], tc.args[3]).Return(tc.sdkErr) + sdkCall := sdkMock.On("Disconnect", mock.Anything, tc.args[3], tc.args[4]).Return(tc.sdkErr) out := executeCommand(t, rootCmd, append([]string{disconnCmd}, tc.args...)...) switch tc.logType { diff --git a/cli/config.go b/cli/config.go index cc91b2e0c0..d92849963e 100644 --- a/cli/config.go +++ b/cli/config.go @@ -20,8 +20,10 @@ import ( const ( defURL string = "http://localhost" defUsersURL string = defURL + ":9002" - defCLientsURL string = defURL + ":9000" - defDomainsURL string = defURL + ":8189" + defCLientsURL string = defURL + ":9006" + defDomainsURL string = defURL + ":9003" + defChannelsURL string = defURL + ":9005" + defGroupsURL string = defURL + ":9004" defCertsURL string = defURL + ":9019" defInvitationsURL string = defURL + ":9020" defHTTPURL string = defURL + ":8008" @@ -37,6 +39,8 @@ type remotes struct { ClientsURL string `toml:"clients_url"` UsersURL string `toml:"users_url"` DomainsURL string `toml:"domains_url"` + ChannelsURL string `toml:"channels_url"` + GroupsURL string `toml:"groups_url"` HTTPAdapterURL string `toml:"http_adapter_url"` CertsURL string `toml:"certs_url"` InvitationsURL string `toml:"invitations_url"` @@ -106,6 +110,8 @@ func ParseConfig(sdkConf smqsdk.Config) (smqsdk.Config, error) { ClientsURL: defCLientsURL, UsersURL: defUsersURL, DomainsURL: defDomainsURL, + ChannelsURL: defChannelsURL, + GroupsURL: defGroupsURL, HTTPAdapterURL: defHTTPURL, CertsURL: defCertsURL, InvitationsURL: defInvitationsURL, @@ -177,6 +183,14 @@ func ParseConfig(sdkConf smqsdk.Config) (smqsdk.Config, error) { sdkConf.DomainsURL = config.Remotes.DomainsURL } + if sdkConf.ChannelsURL == "" && config.Remotes.ChannelsURL != "" { + sdkConf.ChannelsURL = config.Remotes.ChannelsURL + } + + if sdkConf.GroupsURL == "" && config.Remotes.GroupsURL != "" { + sdkConf.GroupsURL = config.Remotes.GroupsURL + } + if sdkConf.HTTPAdapterURL == "" && config.Remotes.HTTPAdapterURL != "" { sdkConf.HTTPAdapterURL = config.Remotes.HTTPAdapterURL } diff --git a/cmd/invitations/main.go b/cmd/invitations/main.go index 58a137d240..f0b6e02bb1 100644 --- a/cmd/invitations/main.go +++ b/cmd/invitations/main.go @@ -52,7 +52,7 @@ const ( type config struct { LogLevel string `env:"SMQ_INVITATIONS_LOG_LEVEL" envDefault:"info"` UsersURL string `env:"SMQ_USERS_URL" envDefault:"http://localhost:9002"` - DomainsURL string `env:"SMQ_DOMAINS_URL" envDefault:"http://localhost:8189"` + DomainsURL string `env:"SMQ_DOMAINS_URL" envDefault:"http://localhost:9003"` InstanceID string `env:"SMQ_INVITATIONS_INSTANCE_ID" envDefault:""` JaegerURL url.URL `env:"SMQ_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"` TraceRatio float64 `env:"SMQ_JAEGER_TRACE_RATIO" envDefault:"1.0"` diff --git a/config.toml b/config.toml index 299b3db2e1..387e459d86 100644 --- a/config.toml +++ b/config.toml @@ -10,12 +10,14 @@ user_token = "" topic = "" [remotes] - journal_url = "http://localhost:9021" certs_url = "http://localhost:9019" - domains_url = "http://localhost:8189" + channels_url = "http://localhost:9005" + clients_url = "http://localhost:9006" + domains_url = "http://localhost:9003" + groups_url = "http://localhost:9004" host_url = "http://localhost" http_adapter_url = "http://localhost:8008" invitations_url = "http://localhost:9020" - clients_url = "http://localhost:9000" + journal_url = "http://localhost:9021" tls_verification = false users_url = "http://localhost:9002"