From b367d1f1567abb4f59a9cb8c31de4ccd437632c6 Mon Sep 17 00:00:00 2001 From: Taimoor Ahmad Date: Sat, 20 Jan 2024 16:08:52 -0500 Subject: [PATCH] wip --- src/cmd/alias.go | 3 ++- src/cmd/system.go | 5 ++--- src/cmd/user.go | 15 +++------------ 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/cmd/alias.go b/src/cmd/alias.go index 4c54b2fe..b88181c9 100644 --- a/src/cmd/alias.go +++ b/src/cmd/alias.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/opslevel/cli/common" "os" + "slices" "strings" "github.com/opslevel/opslevel-go/v2023" @@ -59,7 +60,7 @@ opslevel delete alias -t infrastructure-resource my-infra-alias`, Run: func(cmd *cobra.Command, args []string) { alias := args[0] aliasType := cmd.Flags().Lookup("type").Value.String() - if !Contains(opslevel.AllAliasOwnerTypeEnum, aliasType) { + if !slices.Contains(opslevel.AllAliasOwnerTypeEnum, aliasType) { log.Error().Msgf("invalid alias type '%s'", aliasType) os.Exit(1) } diff --git a/src/cmd/system.go b/src/cmd/system.go index 54170c9a..a6164087 100644 --- a/src/cmd/system.go +++ b/src/cmd/system.go @@ -31,7 +31,7 @@ var createSystemCmd = &cobra.Command{ cat << EOF | opslevel create system -f - name: "My System" description: "Hello World System" - owner: "Z2lkOi8vb3BzbGV2ZWwvVGVhbS83NjY" + ownerId: "Z2lkOi8vb3BzbGV2ZWwvVGVhbS83NjY" parent: alias: "alias of domain" note: "Additional system details" @@ -97,7 +97,6 @@ var listSystemCmd = &cobra.Command{ }, } -// TODO: bug in API prevents use of alias in this function. Adding full functionality for now. var updateSystemCmd = &cobra.Command{ Use: "system ID|ALIAS", Aliases: common.GetAliases("System"), @@ -107,7 +106,7 @@ var updateSystemCmd = &cobra.Command{ cat << EOF | opslevel update system my-system-alias-or-id -f - name: "My Updated System" description: "Hello Updated System" - owner: "Z2lkOi8vb3BzbGV2ZWwvVGVhbS83NjY" + ownerId: "Z2lkOi8vb3BzbGV2ZWwvVGVhbS83NjY" parent: alias: "my_domain" note: "Additional system details for my updated system" diff --git a/src/cmd/user.go b/src/cmd/user.go index 6feb3e71..5ba5282c 100644 --- a/src/cmd/user.go +++ b/src/cmd/user.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "os" + "slices" "sort" "strings" @@ -40,7 +41,7 @@ opslevel create user "jane@example.com" "Jane Doe" Admin --skip-welcome-email role := opslevel.UserRoleUser if len(args) > 2 { desiredRole := strings.ToLower(args[2]) - if Contains(opslevel.AllUserRole, desiredRole) { + if slices.Contains(opslevel.AllUserRole, desiredRole) { role = opslevel.UserRole(desiredRole) } } @@ -144,16 +145,6 @@ var deleteUserCmd = &cobra.Command{ }, } -// TODO: move this to opslevel_common -func Contains[T comparable](s []T, e T) bool { - for _, v := range s { - if v == e { - return true - } - } - return false -} - var importUsersCmd = &cobra.Command{ Use: "user", Aliases: common.GetAliases("User"), @@ -180,7 +171,7 @@ EOF continue } userRole := opslevel.UserRoleUser - if Contains(opslevel.AllUserRole, role) { + if slices.Contains(opslevel.AllUserRole, role) { userRole = opslevel.UserRole(role) } input := opslevel.UserInput{