Skip to content

Commit

Permalink
Cli 148 (#280)
Browse files Browse the repository at this point in the history
* [CLI-148] initial commit: user show, create, list

* [CLI-148] refactor: users command

* [CLI-148] refactor users command: add error return value

* Update internal/cli/users.go

Co-authored-by: Rita Zerrizuela <[email protected]>

* [CLI-148] refactor: add suggestions from review

* [CLI-148] refactor: run gofmt on users files

* [CLI-148] refactor: cleanup whitespaces

* [CLI-148] refactored getconnrequusername function

* [CLI-148] refactor: run gofmt on project user files

* [CLI-148] refactor: added code review suggestions

* [CLI-148] refactor: add users open command

* [CLI-148] refactor: gofmt to cleanup

* Apply suggestions from code review

* [CLI-148] refactor: password input

* [CLI-148] refactor: cleanup spaces

* [CLI-148] refactor: sort imports

* [CLI-148] refactor: sync with master

* [CLI-148] refactor: updated set of scopes

* [CLI-148] refactor: updated order  of scopes

* [CLI-148] refactor: updated scopes in auth file

* [CLi-148] refactor: clean up comments

* [CLi-148] refactor: updated scopes to match main branch

* [CLi-148] refactor: cleanup

* workflow test

* workflow add back integration

* workflow comment out integration

* [CLI-148]  updated scopes in config generator

* Update internal/cli/users.go

* Fix 400 error

Co-authored-by: Rita Zerrizuela <[email protected]>
  • Loading branch information
bright-poku and Widcket authored May 14, 2021
1 parent 8b7d93f commit 83f9ea5
Show file tree
Hide file tree
Showing 11 changed files with 690 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ tags
# misc
.vscode
.DS_Store
.idea
3 changes: 2 additions & 1 deletion internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ var requiredScopes = []string{
"create:clients", "delete:clients", "read:clients", "update:clients",
"create:resource_servers", "delete:resource_servers", "read:resource_servers", "update:resource_servers",
"create:rules", "delete:rules", "read:rules", "update:rules",
"read:users", "update:users",
"read:client_keys", "read:logs", "read:connections", "update:connections",
"create:users", "delete:users", "read:users", "update:users",
"read:branding", "update:branding",
"read:client_keys", "read:logs", "read:tenant_settings", "read:custom_domains",
}
Expand Down
2 changes: 2 additions & 0 deletions internal/auth0/auth0.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type API struct {
Rule RuleAPI
Tenant TenantAPI
User UserAPI
Connection ConnectionAPI
}

func NewAPI(m *management.Management) *API {
Expand All @@ -36,6 +37,7 @@ func NewAPI(m *management.Management) *API {
Rule: m.Rule,
Tenant: m.Tenant,
User: m.User,
Connection: m.Connection,
}
}

Expand Down
26 changes: 26 additions & 0 deletions internal/auth0/connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//go:generate mockgen -source=connection.go -destination=connection.go -package=auth0

package auth0

import "gopkg.in/auth0.v5/management"

type ConnectionAPI interface {

// Create a new connection.
Create(c *management.Connection, opts ...management.RequestOption) (err error)

// Read retrieves a connection by its id.
Read(id string, opts ...management.RequestOption) (c *management.Connection, err error)

// ReadByName retrieves a connection by its name.
ReadByName(id string, opts ...management.RequestOption) (c *management.Connection, err error)

// Update a connection.
Update(id string, c *management.Connection, opts ...management.RequestOption) (err error)

// Delete a connection.
Delete(id string, opts ...management.RequestOption) (err error)

// List all connections.
List(opts ...management.RequestOption) (ul *management.ConnectionList, err error)
}
18 changes: 18 additions & 0 deletions internal/auth0/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,22 @@ type UserAPI interface {
// Unblock a user that was blocked due to an excessive amount of incorrectly
// provided credentials.
Unblock(id string, opts ...management.RequestOption) error

// Create a new user.
Create(u *management.User, opts ...management.RequestOption) (err error)

// Read user details for a given user.
Read(id string, opts ...management.RequestOption) (u *management.User, err error)

// Update user.
Update(id string, u *management.User, opts ...management.RequestOption) (err error)

// Delete a user.
Delete(id string, opts ...management.RequestOption) (err error)

// List all users.
List(opts ...management.RequestOption) (ul *management.UserList, err error)

// Search for users
Search(opts ...management.RequestOption) (us *management.UserList, err error)
}
18 changes: 18 additions & 0 deletions internal/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ func (f *Flag) EditorPromptU(cmd *cobra.Command, value *string, initialValue, fi
return nil
}

func (f *Flag) AskPassword(cmd *cobra.Command, value *string, defaultValue *string) error {
return askPasswordFlag(cmd, f, value, defaultValue, false)
}

func (f *Flag) AskPasswordU(cmd *cobra.Command, value *string, defaultValue *string) error {
return askPasswordFlag(cmd, f, value, defaultValue, true)
}

func (f *Flag) RegisterString(cmd *cobra.Command, value *string, defaultValue string) {
registerString(cmd, f, value, defaultValue, false)
}
Expand Down Expand Up @@ -206,6 +214,16 @@ func selectFlag(cmd *cobra.Command, f *Flag, value interface{}, options []string
return nil
}

func askPasswordFlag(cmd *cobra.Command, f *Flag, value *string, defaultValue *string, isUpdate bool) error {
if shouldAsk(cmd, f, isUpdate) {
if err := askPassword(cmd, f, value, defaultValue, isUpdate); err != nil {
return err
}
}

return nil
}

func registerString(cmd *cobra.Command, f *Flag, value *string, defaultValue string, isUpdate bool) {
cmd.Flags().StringVarP(value, f.LongForm, f.ShortForm, defaultValue, f.Help)

Expand Down
11 changes: 11 additions & 0 deletions internal/cli/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ func askBool(cmd *cobra.Command, i commandInput, value *bool, defaultValue *bool
return nil
}

func askPassword(cmd *cobra.Command, i commandInput, value interface{}, defaultValue *string, isUpdate bool) error {
isRequired := !isUpdate && i.GetIsRequired()
input := prompt.Password("", i.GetLabel(), auth0.StringValue(defaultValue), isRequired)

if err := prompt.AskOne(input, value); err != nil {
return handleInputError(err)
}

return nil
}

func _select(cmd *cobra.Command, i commandInput, value interface{}, options []string, defaultValue *string, isUpdate bool) error {
isRequired := !isUpdate && i.GetIsRequired()

Expand Down
Loading

0 comments on commit 83f9ea5

Please sign in to comment.