From 4090eb5403742286fcd6b4daee73f9ba9da3c651 Mon Sep 17 00:00:00 2001 From: David Bloss Date: Mon, 30 Sep 2024 15:07:06 -0500 Subject: [PATCH] added --skip-send-invite flag to "create user" cmd (#333) * added --skip-send-invite flag to "create user" cmd * fix arg range for create user cmd * fix bool flag, double negative fixin * add skip-welcome-email and skip-invite options to bulk import user cmd * Update .changes/unreleased/Feature-20240930-150305.yaml --------- Co-authored-by: Kyle --- .../unreleased/Feature-20240930-130549.yaml | 3 ++ .../unreleased/Feature-20240930-150305.yaml | 3 ++ Taskfile.yml | 2 +- src/cmd/user.go | 30 ++++++++++++++----- src/submodules/opslevel-go | 2 +- 5 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 .changes/unreleased/Feature-20240930-130549.yaml create mode 100644 .changes/unreleased/Feature-20240930-150305.yaml diff --git a/.changes/unreleased/Feature-20240930-130549.yaml b/.changes/unreleased/Feature-20240930-130549.yaml new file mode 100644 index 00000000..329e9b24 --- /dev/null +++ b/.changes/unreleased/Feature-20240930-130549.yaml @@ -0,0 +1,3 @@ +kind: Feature +body: added --skip-send-invite flag to "create user" cmd +time: 2024-09-30T13:05:49.15243-05:00 diff --git a/.changes/unreleased/Feature-20240930-150305.yaml b/.changes/unreleased/Feature-20240930-150305.yaml new file mode 100644 index 00000000..bdfec3d1 --- /dev/null +++ b/.changes/unreleased/Feature-20240930-150305.yaml @@ -0,0 +1,3 @@ +kind: Feature +body: add --skip-welcome-email and --skip-invite options to bulk import user cmd +time: 2024-09-30T15:03:05.541886-05:00 diff --git a/Taskfile.yml b/Taskfile.yml index 0754339d..4ff35cbd 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -93,7 +93,7 @@ tasks: echo "Using latest version of opslevel-go - {{.LATEST_OPSLEVEL_GO_VERSION}}"; else echo "WARNING: current version of opslevel-go is behind '{{.LATEST_OPSLEVEL_GO_VERSION}}'" - echo "Run 'task lintfix' to get latest version" + echo "Run 'task fix' to get latest version" exit 1 fi diff --git a/src/cmd/user.go b/src/cmd/user.go index 452135d6..811a9f24 100644 --- a/src/cmd/user.go +++ b/src/cmd/user.go @@ -30,9 +30,11 @@ var createUserCmd = &cobra.Command{ Long: "Create a User and optionally define the role (options `User`|`Admin`).", Example: ` opslevel create user "john@example.com" "John Doe" +opslevel create user "jane@example.com" "Jane Doe" Admin --skip-send-invite opslevel create user "jane@example.com" "Jane Doe" Admin --skip-welcome-email +opslevel create user "jane@example.com" "Jane Doe" Admin --skip-send-invite --skip-welcome-email `, - Args: cobra.MinimumNArgs(2), + Args: cobra.RangeArgs(2, 3), Run: func(cmd *cobra.Command, args []string) { email := args[0] name := args[1] @@ -44,14 +46,17 @@ opslevel create user "jane@example.com" "Jane Doe" Admin --skip-welcome-email } } + skipSendInvite, err := cmd.Flags().GetBool("skip-send-invite") + cobra.CheckErr(err) skipEmail, err := cmd.Flags().GetBool("skip-welcome-email") cobra.CheckErr(err) - resource, err := getClientGQL().InviteUser(email, opslevel.UserInput{ + userInput := opslevel.UserInput{ Name: opslevel.RefOf(name), Role: opslevel.RefOf(role), SkipWelcomeEmail: opslevel.RefOf(skipEmail), - }) + } + resource, err := getClientGQL().InviteUser(email, userInput, !skipSendInvite) cobra.CheckErr(err) fmt.Println(resource.Id) }, @@ -160,7 +165,7 @@ var importUsersCmd = &cobra.Command{ Long: `Imports a list of users from a CSV file with the column headers: Name,Email,Role,Team`, Example: ` -cat << EOF | opslevel import user -f - +cat << EOF | opslevel import user --skip-send-invite --skip-welcome-email -f - Name,Email,Role,Team Kyle Rockman,kyle@opslevel.com,Admin,platform Edgar Ochoa,edgar@opslevel.com,Admin,platform @@ -170,6 +175,11 @@ EOF Run: func(cmd *cobra.Command, args []string) { reader, err := readImportFilepathAsCSV() cobra.CheckErr(err) + skipSendInvite, err := cmd.Flags().GetBool("skip-send-invite") + cobra.CheckErr(err) + skipWelcomeEmail, err := cmd.Flags().GetBool("skip-welcome-email") + cobra.CheckErr(err) + for reader.Rows() { name := reader.Text("Name") email := reader.Text("Email") @@ -183,10 +193,11 @@ EOF userRole = opslevel.UserRole(role) } input := opslevel.UserInput{ - Name: opslevel.RefOf(name), - Role: opslevel.RefOf(userRole), + Name: opslevel.RefOf(name), + Role: opslevel.RefOf(userRole), + SkipWelcomeEmail: opslevel.RefOf(skipWelcomeEmail), } - user, err := getClientGQL().InviteUser(email, input) + user, err := getClientGQL().InviteUser(email, input, !skipSendInvite) if err != nil { log.Error().Err(err).Msgf("error inviting user '%s' with email '%s'", name, email) continue @@ -216,7 +227,10 @@ EOF } func init() { - createUserCmd.Flags().Bool("skip-welcome-email", false, "If this flag is set the welcome e-mail will be skipped from being sent") + createUserCmd.Flags().Bool("skip-send-invite", false, "If this flag is set the welcome e-mail will be not be sent") + createUserCmd.Flags().Bool("skip-welcome-email", false, "If this flag is set send an invite email even if notifications are disabled for the account") + importUsersCmd.Flags().Bool("skip-send-invite", false, "If this flag is set the welcome e-mail will be not be sent") + importUsersCmd.Flags().Bool("skip-welcome-email", false, "If this flag is set send an invite email even if notifications are disabled for the account") listUserCmd.Flags().Bool("ignore-deactivated", false, "If this flag is set only return active users") exampleCmd.AddCommand(exampleUserCmd) diff --git a/src/submodules/opslevel-go b/src/submodules/opslevel-go index f1283d61..a05d27a2 160000 --- a/src/submodules/opslevel-go +++ b/src/submodules/opslevel-go @@ -1 +1 @@ -Subproject commit f1283d6150ec3c85b7d00c7a8576bacb1c365f49 +Subproject commit a05d27a21d24d397ae28789b9b05a384bfa1f821