-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added update-user-group subcommand to repos command (#36)
* Added add-user subcommand to repos * Fixed review comments
- Loading branch information
Jesper Lindstrøm Nielsen
authored
Sep 1, 2020
1 parent
1c26c41
commit 50cd7f0
Showing
3 changed files
with
87 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/humio/cli/api" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newReposUpdateUserGroupCmd() *cobra.Command { | ||
var groups []string | ||
cmd := cobra.Command{ | ||
Use: "update-user-group [flags] <repo> <username>", | ||
Short: "Updates the users permissions to a repository based on default groups", | ||
Args: cobra.ExactArgs(2), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
repoName := args[0] | ||
userName := args[1] | ||
|
||
var defaultGroups []api.DefaultGroupEnum | ||
for _, group := range groups { | ||
var defaultGroup api.DefaultGroupEnum | ||
if !defaultGroup.ParseString(group) { | ||
cmd.Println("the group '%s' was not valid (must be either 'Member', 'Admin' or 'Eliminator')") | ||
os.Exit(1) | ||
} | ||
defaultGroups = append(defaultGroups, defaultGroup) | ||
} | ||
|
||
client := NewApiClient(cmd) | ||
apiErr := client.Repositories().UpdateUserGroup(repoName, userName, defaultGroups...) | ||
exitOnError(cmd, apiErr, "error adding user") | ||
}, | ||
} | ||
cmd.Flags().StringSliceVarP(&groups, "groups", "g", []string{api.DefaultGroupEnumMember.String()}, "the groups that the user should be added in") | ||
|
||
return &cmd | ||
} |