Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20241112-102508.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: Added count flag for services list. Added user delete on import csv
time: 2024-11-12T10:25:08.084783-05:00
5 changes: 5 additions & 0 deletions src/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ var listServiceCmd = &cobra.Command{
client := getClientGQL()
resp, err := client.ListServices(nil)
cobra.CheckErr(err)
if ok, _ := cmd.Flags().GetBool("count"); ok {
fmt.Println(len(resp.Nodes))
return
}
for _, service := range resp.Nodes {
if !isJsonOutput() {
list = append(list, service)
Expand Down Expand Up @@ -249,6 +253,7 @@ func init() {
listServiceCmd.PersistentFlags().Bool("dependencies", false, "Include dependencies of each service")
listServiceCmd.PersistentFlags().Bool("dependents", false, "Include dependents of each service")
listServiceCmd.PersistentFlags().Bool("properties", false, "Include properties of each service")
listServiceCmd.PersistentFlags().Bool("count", false, "Print the service count")

importCmd.AddCommand(importServicesCmd)
}
Expand Down
36 changes: 36 additions & 0 deletions src/cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,41 @@ EOF
},
}

var bulkDeleteUsersCmd = &cobra.Command{
Use: "delete users",
Aliases: []string{"bulk delete users"},
Short: "Deletes users from a CSV",
Long: `Deletes a list of users from a CSV file with the column headers:
Email`,
Example: `
cat << EOF | opslevel import delete users -f -
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tozach - so I think the where we want to put this is in the normal delete users command but add a --bulk or --csv. Thats a bit more of a surgery so do you mind if I checkout this branch and muck with the code to get that to work?

I definitely don't want it under the import command

Email
[email protected]
[email protected]
[email protected]
EOF
`,
Run: func(cmd *cobra.Command, args []string) {
reader, err := readImportFilepathAsCSV()
cobra.CheckErr(err)
for reader.Rows() {
email := reader.Text("Email")
if email == "" {
log.Error().Msgf("user has invalid email '%s'", email)
continue
} else {
err := getClientGQL().DeleteUser(email)
if err != nil {
log.Error().Err(err).Msgf("error deleting user '%s'", email)
continue
} else {
log.Info().Msgf("deleted user '%s'", email)
}
}
}
},
}

func init() {
createUserCmd.Flags().Bool("skip-welcome-email", false, "If this flag is set the welcome e-mail will be skipped from being sent")
listUserCmd.Flags().Bool("ignore-deactivated", false, "If this flag is set only return active users")
Expand All @@ -226,4 +261,5 @@ func init() {
listCmd.AddCommand(listUserCmd)
deleteCmd.AddCommand(deleteUserCmd)
importCmd.AddCommand(importUsersCmd)
importCmd.AddCommand(bulkDeleteUsersCmd)
}
Loading