-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
fa0ef03
commit 4090eb5
Showing
5 changed files
with
30 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
|
@@ -30,9 +30,11 @@ var createUserCmd = &cobra.Command{ | |
Long: "Create a User and optionally define the role (options `User`|`Admin`).", | ||
Example: ` | ||
opslevel create user "[email protected]" "John Doe" | ||
opslevel create user "[email protected]" "Jane Doe" Admin --skip-send-invite | ||
opslevel create user "[email protected]" "Jane Doe" Admin --skip-welcome-email | ||
opslevel create user "[email protected]" "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 "[email protected]" "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,[email protected],Admin,platform | ||
Edgar Ochoa,[email protected],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) | ||
|
Submodule opslevel-go
updated
17 files
+3 −0 | .changes/unreleased/Dependency-20240923-111450.yaml | |
+3 −0 | .changes/unreleased/Refactor-20240905-144928.yaml | |
+3 −0 | .changes/v2024.9.18.md | |
+13 −0 | .github/workflows/security.yml | |
+4 −0 | CHANGELOG.md | |
+3 −3 | document_test.go | |
+2 −2 | enum.go | |
+3 −3 | go.mod | |
+4 −4 | go.sum | |
+1 −1 | input.go | |
+19 −0 | service.go | |
+57 −26 | service_test.go | |
+2 −2 | system_test.go | |
+52 −0 | testdata/templates/service/service.tpl | |
+5 −4 | user.go | |
+29 −5 | user_test.go | |
+1 −1 | version.go |