Skip to content

Commit

Permalink
Merge 0c1ca84 into bd5b6f1
Browse files Browse the repository at this point in the history
  • Loading branch information
simon0191 committed Mar 31, 2017
2 parents bd5b6f1 + 0c1ca84 commit 5c2e670
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions cmd/platform/user.go
Expand Up @@ -40,7 +40,7 @@ var userCreateCmd = &cobra.Command{
Use: "create",
Short: "Create a user",
Long: "Create a user",
Example: ` user create --email user@example.com --username userexample --password Password1
Example: ` user create --email user@example.com --username userexample --password Password1
user create --firstname Joe --system_admin --email joe@example.com --username joe --password Password1`,
RunE: userCreateCmdF,
}
Expand All @@ -67,7 +67,7 @@ var resetUserPasswordCmd = &cobra.Command{
var resetUserMfaCmd = &cobra.Command{
Use: "resetmfa [users]",
Short: "Turn off MFA",
Long: `Turn off multi-factor authentication for a user.
Long: `Turn off multi-factor authentication for a user.
If MFA enforcement is enabled, the user will be forced to re-enable MFA as soon as they login.`,
Example: " user resetmfa user@example.com",
RunE: resetUserMfaCmdF,
Expand All @@ -94,13 +94,13 @@ var migrateAuthCmd = &cobra.Command{
Short: "Mass migrate user accounts authentication type",
Long: `Migrates accounts from one authentication provider to another. For example, you can upgrade your authentication provider from email to ldap.
from_auth:
from_auth:
The authentication service to migrate users accounts from.
Supported options: email, gitlab, saml.
Supported options: email, gitlab, saml.
to_auth:
The authentication service to migrate users to.
Supported options: ldap.
Supported options: ldap.
match_field:
The field that is guaranteed to be the same in both authentication services. For example, if the users emails are consistent set to email.
Expand All @@ -119,6 +119,14 @@ var verifyUserCmd = &cobra.Command{
RunE: verifyUserCmdF,
}

var searchUserCmd = &cobra.Command{
Use: "search [users]",
Short: "Search for users",
Long: "Search for users based on username, email, or user ID.",
Example: " user search user1@mail.com user2@mail.com",
RunE: searchUserCmdF,
}

func init() {
userCreateCmd.Flags().String("username", "", "Username")
userCreateCmd.Flags().String("email", "", "Email")
Expand All @@ -144,6 +152,7 @@ func init() {
deleteAllUsersCmd,
migrateAuthCmd,
verifyUserCmd,
searchUserCmd,
)
}

Expand Down Expand Up @@ -431,3 +440,33 @@ func verifyUserCmdF(cmd *cobra.Command, args []string) error {

return nil
}

func searchUserCmdF(cmd *cobra.Command, args []string) error {
initDBCommandContextCobra(cmd)
if len(args) < 1 {
return errors.New("Enter at least one query.")
}

users := getUsersFromUserArgs(args)

for i, user := range users {
if i > 0 {
CommandPrettyPrintln("------------------------------")
}
if user == nil {
CommandPrintErrorln("Unable to find user '" + args[i] + "'")
continue
}

CommandPrettyPrintln("id: " + user.Id)
CommandPrettyPrintln("username: " + user.Username)
CommandPrettyPrintln("nickname: " + user.Nickname)
CommandPrettyPrintln("position: " + user.Position)
CommandPrettyPrintln("first_name: " + user.FirstName)
CommandPrettyPrintln("last_name: " + user.LastName)
CommandPrettyPrintln("email: " + user.Email)
CommandPrettyPrintln("auth_service: " + user.AuthService)
}

return nil
}

0 comments on commit 5c2e670

Please sign in to comment.