-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MG-2426 - Replace generic Clients in Users service (#2436)
Signed-off-by: Musilah <[email protected]> Signed-off-by: Arvindh <[email protected]> Signed-off-by: Felix Gateru <[email protected]> Signed-off-by: Dusan Borovcanin <[email protected]> Co-authored-by: Arvindh <[email protected]> Co-authored-by: Felix Gateru <[email protected]> Co-authored-by: Dusan Borovcanin <[email protected]>
- Loading branch information
1 parent
077882f
commit 0019f71
Showing
75 changed files
with
6,202 additions
and
4,553 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,9 +135,10 @@ var cmdProvision = []cobra.Command{ | |
// Create test user | ||
name := namesgenerator.Generate() | ||
user := mgxsdk.User{ | ||
Name: name, | ||
FirstName: name, | ||
Email: fmt.Sprintf("%[email protected]", name), | ||
Credentials: mgxsdk.Credentials{ | ||
Identity: fmt.Sprintf("%[email protected]", name), | ||
Username: name, | ||
Secret: "12345678", | ||
}, | ||
Status: mgxsdk.EnabledStatus, | ||
|
@@ -148,8 +149,7 @@ var cmdProvision = []cobra.Command{ | |
return | ||
} | ||
|
||
user.Credentials.Secret = "12345678" | ||
ut, err := sdk.CreateToken(mgxsdk.Login{Identity: user.Credentials.Identity, Secret: user.Credentials.Secret}) | ||
ut, err := sdk.CreateToken(mgxsdk.Login{Username: user.Username, Secret: user.Credentials.Secret}) | ||
if err != nil { | ||
logErrorCmd(*cmd, err) | ||
return | ||
|
@@ -166,7 +166,7 @@ var cmdProvision = []cobra.Command{ | |
return | ||
} | ||
|
||
ut, err = sdk.CreateToken(mgxsdk.Login{Identity: user.Credentials.Identity, Secret: user.Credentials.Secret}) | ||
ut, err = sdk.CreateToken(mgxsdk.Login{Email: user.Email, Secret: user.Credentials.Secret}) | ||
if err != nil { | ||
logErrorCmd(*cmd, err) | ||
return | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,36 +9,38 @@ import ( | |
"net/url" | ||
"strconv" | ||
|
||
mgclients "github.com/absmach/magistrala/pkg/clients" | ||
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go" | ||
"github.com/absmach/magistrala/users" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var cmdUsers = []cobra.Command{ | ||
{ | ||
Use: "create <name> <username> <password> <user_auth_token>", | ||
Use: "create <first_name> <last_name> <email> <username> <password> <user_auth_token>", | ||
Short: "Create user", | ||
Long: "Create user with provided name, username and password. Token is optional\n" + | ||
Long: "Create user with provided firstname, lastname, email, username and password. Token is optional\n" + | ||
"For example:\n" + | ||
"\tmagistrala-cli users create user user@example.com 12345678 $USER_AUTH_TOKEN\n", | ||
"\tmagistrala-cli users create jane doe janedoe@example.com jane_doe 12345678 $USER_AUTH_TOKEN\n", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) < 3 || len(args) > 4 { | ||
if len(args) < 5 || len(args) > 6 { | ||
logUsageCmd(*cmd, cmd.Use) | ||
return | ||
} | ||
if len(args) == 3 { | ||
if len(args) == 5 { | ||
args = append(args, "") | ||
} | ||
|
||
user := mgxsdk.User{ | ||
Name: args[0], | ||
FirstName: args[0], | ||
LastName: args[1], | ||
Email: args[2], | ||
Credentials: mgxsdk.Credentials{ | ||
Identity: args[1], | ||
Secret: args[2], | ||
Username: args[3], | ||
Secret: args[4], | ||
}, | ||
Status: mgclients.EnabledStatus.String(), | ||
Status: users.EnabledStatus.String(), | ||
} | ||
user, err := sdk.CreateUser(user, args[3]) | ||
user, err := sdk.CreateUser(user, args[5]) | ||
if err != nil { | ||
logErrorCmd(*cmd, err) | ||
return | ||
|
@@ -66,6 +68,7 @@ var cmdUsers = []cobra.Command{ | |
return | ||
} | ||
pageMetadata := mgxsdk.PageMetadata{ | ||
Username: Username, | ||
Identity: Identity, | ||
Offset: Offset, | ||
Limit: Limit, | ||
|
@@ -93,21 +96,21 @@ var cmdUsers = []cobra.Command{ | |
{ | ||
Use: "token <username> <password>", | ||
Short: "Get token", | ||
Long: "Generate new token from username and password\n" + | ||
Long: "Generate a new token with username and password\n" + | ||
"For example:\n" + | ||
"\tmagistrala-cli users token [email protected] 12345678\n", | ||
"\tmagistrala-cli users token jane.doe 12345678\n", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 2 { | ||
logUsageCmd(*cmd, cmd.Use) | ||
return | ||
} | ||
|
||
lg := mgxsdk.Login{ | ||
Identity: args[0], | ||
loginReq := mgxsdk.Login{ | ||
Username: args[0], | ||
Secret: args[1], | ||
} | ||
|
||
token, err := sdk.CreateToken(lg) | ||
token, err := sdk.CreateToken(loginReq) | ||
if err != nil { | ||
logErrorCmd(*cmd, err) | ||
return | ||
|
@@ -116,6 +119,7 @@ var cmdUsers = []cobra.Command{ | |
logJSONCmd(*cmd, token) | ||
}, | ||
}, | ||
|
||
{ | ||
Use: "refreshtoken <token>", | ||
Short: "Get token", | ||
|
@@ -138,13 +142,15 @@ var cmdUsers = []cobra.Command{ | |
}, | ||
}, | ||
{ | ||
Use: "update [<user_id> <JSON_string> | tags <user_id> <tags> | identity <user_id> <identity> ] <user_auth_token>", | ||
Use: "update [<user_id> <JSON_string> | tags <user_id> <tags> | username <user_id> <username> | email <user_id> <email>] <user_auth_token>", | ||
Short: "Update user", | ||
Long: "Updates either user name and metadata or user tags or user identity\n" + | ||
Long: "Updates either user name and metadata or user tags or user email\n" + | ||
"Usage:\n" + | ||
"\tmagistrala-cli users update <user_id> '{\"name\":\"new name\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN - updates user name and metadata\n" + | ||
"\tmagistrala-cli users update <user_id> '{\"first_name\":\"new first_name\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN - updates user first and lastname and metadata\n" + | ||
"\tmagistrala-cli users update tags <user_id> '[\"tag1\", \"tag2\"]' $USERTOKEN - updates user tags\n" + | ||
"\tmagistrala-cli users update identity <user_id> [email protected] $USERTOKEN - updates user identity\n", | ||
"\tmagistrala-cli users update username <user_id> newusername $USERTOKEN - updates user name\n" + | ||
"\tmagistrala-cli users update email <user_id> [email protected] $USERTOKEN - updates user email\n", | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 4 && len(args) != 3 { | ||
logUsageCmd(*cmd, cmd.Use) | ||
|
@@ -168,10 +174,22 @@ var cmdUsers = []cobra.Command{ | |
return | ||
} | ||
|
||
if args[0] == "identity" { | ||
if args[0] == "email" { | ||
user.ID = args[1] | ||
user.Email = args[2] | ||
user, err := sdk.UpdateUserEmail(user, args[3]) | ||
if err != nil { | ||
logErrorCmd(*cmd, err) | ||
return | ||
} | ||
logJSONCmd(*cmd, user) | ||
return | ||
} | ||
|
||
if args[0] == "username" { | ||
user.ID = args[1] | ||
user.Credentials.Identity = args[2] | ||
user, err := sdk.UpdateUserIdentity(user, args[3]) | ||
user.Credentials.Username = args[2] | ||
user, err := sdk.UpdateUser(user, args[3]) | ||
if err != nil { | ||
logErrorCmd(*cmd, err) | ||
return | ||
|
Oops, something went wrong.