Skip to content

Commit

Permalink
NOISSUE - Update CLI (#2642)
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene authored Jan 10, 2025
1 parent a916927 commit 33407fa
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
31 changes: 23 additions & 8 deletions cli/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,29 @@ var cmdClients = []cobra.Command{
},
},
{
Use: "connect <client_id> <channel_id> <domain_id> <user_auth_token>",
Use: "connect <client_id> <channel_id> <conn_types_json_list> <domain_id> <user_auth_token>",
Short: "Connect client",
Long: "Connect client to the channel\n" +
"Usage:\n" +
"\tsupermq-cli clients connect <client_id> <channel_id> $DOMAINID $USERTOKEN\n",
"\tsupermq-cli clients connect <client_id> <channel_id> <conn_types_json_list> $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
}
Expand All @@ -222,22 +229,30 @@ var cmdClients = []cobra.Command{
},
},
{
Use: "disconnect <client_id> <channel_id> <domain_id> <user_auth_token>",
Use: "disconnect <client_id> <channel_id> <conn_types_json_list> <domain_id> <user_auth_token>",
Short: "Disconnect client",
Long: "Disconnect client to the channel\n" +
"Usage:\n" +
"\tsupermq-cli clients disconnect <client_id> <channel_id> $DOMAINID $USERTOKEN\n",
"\tsupermq-cli clients disconnect <client_id> <channel_id> <conn_types_json_list> $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
}
Expand Down
15 changes: 13 additions & 2 deletions cli/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
tokenWithoutDomain = "valid"
relation = "administrator"
all = "all"
conntype = `["publish","subscribe"]`
)

var client = sdk.Client{
Expand Down Expand Up @@ -817,6 +818,7 @@ func TestConnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
domainID,
token,
},
Expand All @@ -827,6 +829,7 @@ func TestConnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
domainID,
token,
extraArg,
Expand All @@ -838,6 +841,7 @@ func TestConnectClientCmd(t *testing.T) {
args: []string{
invalidID,
channel.ID,
conntype,
domainID,
token,
},
Expand All @@ -850,6 +854,7 @@ func TestConnectClientCmd(t *testing.T) {
args: []string{
client.ID,
invalidID,
conntype,
domainID,
token,
},
Expand All @@ -862,6 +867,7 @@ func TestConnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
invalidID,
token,
},
Expand All @@ -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 {
Expand Down Expand Up @@ -907,6 +913,7 @@ func TestDisconnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
domainID,
token,
},
Expand All @@ -917,6 +924,7 @@ func TestDisconnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
domainID,
token,
extraArg,
Expand All @@ -928,6 +936,7 @@ func TestDisconnectClientCmd(t *testing.T) {
args: []string{
invalidID,
channel.ID,
conntype,
domainID,
token,
},
Expand All @@ -940,6 +949,7 @@ func TestDisconnectClientCmd(t *testing.T) {
args: []string{
client.ID,
invalidID,
conntype,
domainID,
token,
},
Expand All @@ -952,6 +962,7 @@ func TestDisconnectClientCmd(t *testing.T) {
args: []string{
client.ID,
channel.ID,
conntype,
invalidID,
token,
},
Expand All @@ -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 {
Expand Down
18 changes: 16 additions & 2 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/invitations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
8 changes: 5 additions & 3 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 33407fa

Please sign in to comment.