-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: local user credentials - login with an infra user via the cli - create a user in the infra cli - update a users password in the the cli - CLI user create, edit, and delete - identities list users and machines - use provider ID for user and group look up - email not required on list users request, do not validate - move CLI errors to a single file - split up login to separate functions - do not bind env vars for identity commands - don't update user info for local users on token create
- Loading branch information
Showing
12 changed files
with
606 additions
and
248 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
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,10 @@ | ||
package cmd | ||
|
||
import "errors" | ||
|
||
var ( | ||
//lint:ignore ST1005, user facing error | ||
ErrConfigNotFound = errors.New(`Could not read local credentials. Are you logged in? Use "infra login" to login`) | ||
ErrProviderNotUnique = errors.New(`more than one provider exists with this name`) | ||
ErrUserNotFound = errors.New(`no users found with this name`) | ||
) |
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 |
---|---|---|
|
@@ -100,22 +100,17 @@ $ infra grants add -u [email protected] -r admin infra | |
return err | ||
} | ||
|
||
var providers []api.Provider | ||
var provider *api.Provider | ||
|
||
if options.Machine == "" { | ||
providers, err = client.ListProviders(options.Provider) | ||
provider, err = GetProviderByName(client, options.Provider) | ||
if err != nil { | ||
if errors.Is(err, ErrProviderNotUnique) { | ||
return fmt.Errorf("specify provider with -p or --provider: %w", err) | ||
} | ||
return err | ||
} | ||
|
||
if len(providers) == 0 { | ||
return errors.New("no identity providers connected") | ||
} | ||
|
||
if len(providers) > 1 { | ||
return errors.New("specify provider with -p or --provider") | ||
} | ||
|
||
if options.User != "" && options.Group != "" { | ||
return errors.New("only allowed one of --user or --group") | ||
} | ||
|
@@ -131,15 +126,15 @@ $ infra grants add -u [email protected] -r admin infra | |
|
||
if options.User != "" { | ||
// create user if they don't exist | ||
users, err := client.ListUsers(api.ListUsersRequest{Email: options.User}) | ||
users, err := client.ListUsers(api.ListUsersRequest{Email: options.User, ProviderID: provider.ID}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(users) == 0 { | ||
newUser, err := client.CreateUser(&api.CreateUserRequest{ | ||
Email: options.User, | ||
ProviderID: providers[0].ID, | ||
ProviderID: provider.ID, | ||
}) | ||
if err != nil { | ||
return err | ||
|
@@ -153,15 +148,15 @@ $ infra grants add -u [email protected] -r admin infra | |
|
||
if options.Group != "" { | ||
// create group if they don't exist | ||
groups, err := client.ListGroups(api.ListGroupsRequest{Name: options.Group}) | ||
groups, err := client.ListGroups(api.ListGroupsRequest{Name: options.Group, ProviderID: provider.ID}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(groups) == 0 { | ||
newGroup, err := client.CreateGroup(&api.CreateGroupRequest{ | ||
Name: options.Group, | ||
ProviderID: providers[0].ID, | ||
ProviderID: provider.ID, | ||
}) | ||
if err != nil { | ||
return err | ||
|
@@ -234,22 +229,17 @@ func newGrantRemoveCmd() *cobra.Command { | |
return err | ||
} | ||
|
||
var providers []api.Provider | ||
var provider *api.Provider | ||
|
||
if options.Machine == "" { | ||
providers, err = client.ListProviders(options.Provider) | ||
provider, err = GetProviderByName(client, options.Provider) | ||
if err != nil { | ||
if errors.Is(err, ErrProviderNotUnique) { | ||
return fmt.Errorf("specify provider with -p or --provider: %w", err) | ||
} | ||
return err | ||
} | ||
|
||
if len(providers) == 0 { | ||
return errors.New("No identity providers connected") | ||
} | ||
|
||
if len(providers) > 1 { | ||
return errors.New("Specify provider with -p or --provider") | ||
} | ||
|
||
if options.User != "" && options.Group != "" { | ||
return errors.New("only allowed one of --user or --group") | ||
} | ||
|
@@ -260,7 +250,7 @@ func newGrantRemoveCmd() *cobra.Command { | |
var id uid.PolymorphicID | ||
|
||
if options.User != "" { | ||
users, err := client.ListUsers(api.ListUsersRequest{Email: options.User}) | ||
users, err := client.ListUsers(api.ListUsersRequest{Email: options.User, ProviderID: provider.ID}) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -273,7 +263,7 @@ func newGrantRemoveCmd() *cobra.Command { | |
} | ||
|
||
if options.Group != "" { | ||
groups, err := client.ListGroups(api.ListGroupsRequest{Name: options.Group}) | ||
groups, err := client.ListGroups(api.ListGroupsRequest{Name: options.Group, ProviderID: provider.ID}) | ||
if err != nil { | ||
return err | ||
} | ||
|
Oops, something went wrong.