diff --git a/internal/auth0/user.go b/internal/auth0/user.go deleted file mode 100644 index 003e84f9f..000000000 --- a/internal/auth0/user.go +++ /dev/null @@ -1,13 +0,0 @@ -//go:generate mockgen -source=user.go -destination=user_mock.go -package=auth0 - -package auth0 - -import "gopkg.in/auth0.v5/management" - -type UserAPI interface { - // Read a user by its id. - Read(id string, opts ...management.RequestOption) (u *management.User, err error) - - // List users by email. - ListByEmail(email string, opts ...management.RequestOption) (us []*management.User, err error) -} diff --git a/internal/auth0/user_mock.go b/internal/auth0/user_mock.go deleted file mode 100644 index 86b2ef4f4..000000000 --- a/internal/auth0/user_mock.go +++ /dev/null @@ -1,150 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: user.go - -// Package auth0 is a generated GoMock package. -package auth0 - -import ( - gomock "github.com/golang/mock/gomock" - management "gopkg.in/auth0.v5/management" - reflect "reflect" -) - -// MockUserAPI is a mock of UserAPI interface -type MockUserAPI struct { - ctrl *gomock.Controller - recorder *MockUserAPIMockRecorder -} - -// MockUserAPIMockRecorder is the mock recorder for MockUserAPI -type MockUserAPIMockRecorder struct { - mock *MockUserAPI -} - -// NewMockUserAPI creates a new mock instance -func NewMockUserAPI(ctrl *gomock.Controller) *MockUserAPI { - mock := &MockUserAPI{ctrl: ctrl} - mock.recorder = &MockUserAPIMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockUserAPI) EXPECT() *MockUserAPIMockRecorder { - return m.recorder -} - -// Create mocks base method -func (m *MockUserAPI) Create(c *management.User, opts ...management.RequestOption) error { - m.ctrl.T.Helper() - varargs := []interface{}{c} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Create", varargs...) - ret0, _ := ret[0].(error) - return ret0 -} - -// Create indicates an expected call of Create -func (mr *MockUserAPIMockRecorder) Create(c interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{c}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockUserAPI)(nil).Create), varargs...) -} - -// Read mocks base method -func (m *MockUserAPI) Read(id string, opts ...management.RequestOption) (*management.UserManager, error) { - m.ctrl.T.Helper() - varargs := []interface{}{id} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Read", varargs...) - ret0, _ := ret[0].(*management.UserManager) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Read indicates an expected call of Read -func (mr *MockUserAPIMockRecorder) Read(id interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{id}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockUserAPI)(nil).Read), varargs...) -} - -// List mocks base method -func (m *MockUserAPI) List(opts ...management.RequestOption) (*management.UserManager, error) { - m.ctrl.T.Helper() - varargs := []interface{}{} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "List", varargs...) - ret0, _ := ret[0].(*management.UserManager) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// List indicates an expected call of List -func (mr *MockUserAPIMockRecorder) List(opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockUserAPI)(nil).List), opts...) -} - -// ListByEmail mocks base method -func (m *MockUserAPI) ListByEmail(email string, opts ...management.RequestOption) (*management.UserManager, error) { - m.ctrl.T.Helper() - varargs := []interface{}{email} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "ListByEmail", varargs...) - ret0, _ := ret[0].(*management.UserManager) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ListByEmail indicates an expected call of ListByEmail -func (mr *MockUserAPIMockRecorder) ListByEmail(email interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{email}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListByEmail", reflect.TypeOf((*MockUserAPI)(nil).ListByEmail), varargs...) -} - -// Update mocks base method -func (m *MockUserAPI) Update(id string, c *management.UserManager, opts ...management.RequestOption) error { - m.ctrl.T.Helper() - varargs := []interface{}{id, c} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Update", varargs...) - ret0, _ := ret[0].(error) - return ret0 -} - -// Update indicates an expected call of Update -func (mr *MockUserAPIMockRecorder) Update(id, c interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{id, c}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockUserAPI)(nil).Update), varargs...) -} - -// Delete mocks base method -func (m *MockUserAPI) Delete(id string, opts ...management.User) error { - m.ctrl.T.Helper() - varargs := []interface{}{id} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Delete", varargs...) - ret0, _ := ret[0].(error) - return ret0 -} - -// Delete indicates an expected call of Delete -func (mr *MockUserAPIMockRecorder) Delete(id interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{id}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockUserAPI)(nil).Delete), varargs...) -} diff --git a/internal/cli/users.go b/internal/cli/users.go deleted file mode 100644 index cc8ad9a76..000000000 --- a/internal/cli/users.go +++ /dev/null @@ -1,113 +0,0 @@ -package cli - -import ( - "errors" - - "github.com/auth0/auth0-cli/internal/ansi" - "github.com/auth0/auth0-cli/internal/prompt" - "github.com/spf13/cobra" - "gopkg.in/auth0.v5/management" -) - -const ( - userID = "id" - userEmail = "email" -) - -func usersCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "users", - Short: "Manage users", - } - - cmd.SetUsageTemplate(resourceUsageTemplate()) - cmd.AddCommand(showUserCmd(cli)) - - return cmd -} - -func showUserCmd(cli *cli) *cobra.Command { - var flags struct { - ID string - Email string - Fields string - } - - cmd := &cobra.Command{ - Use: "show", - Short: "Show a user's details", - Long: `$ auth0 users show --id id --email email -Get a user -`, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if shouldPrompt(cmd, userID) && flags.Email == "" { - input := prompt.TextInput(userID, "Id:", "ID of the user to show.", false) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, userEmail) && flags.ID == "" { - input := prompt.TextInput(userEmail, "Email:", "Email of the user to show.", false) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if flags.ID == "" && flags.Email == "" { - return errors.New("User id or email flag must be specified") - } - - if flags.ID != "" && flags.Email != "" { - return errors.New("User id and email flags cannot be combined") - } - - var users []*management.User - var user *management.User - - if flags.ID != "" { - err := ansi.Spinner("Getting user", func() error { - var err error - user, err = cli.api.User.Read(flags.ID) - return err - }) - - if err != nil { - return err - } - - users = append(users, user) - - cli.renderer.UserList(users) - return nil - } - - if flags.Email != "" { - err := ansi.Spinner("Getting user(s)", func() error { - var err error - users, err = cli.api.User.ListByEmail(flags.Email) - return err - }) - - if err != nil { - return err - } - - cli.renderer.UserList(users) - return nil - } - - return nil - }, - } - - cmd.Flags().StringVarP(&flags.ID, userID, "i", "", "ID of the user to show.") - cmd.Flags().StringVarP(&flags.Email, userEmail, "e", "", "Email of the user to show.") - - return cmd -} diff --git a/internal/display/users.go b/internal/display/users.go deleted file mode 100644 index 7ba43623f..000000000 --- a/internal/display/users.go +++ /dev/null @@ -1,39 +0,0 @@ -package display - -import ( - "github.com/auth0/auth0-cli/internal/ansi" - "github.com/auth0/auth0-cli/internal/auth0" - "gopkg.in/auth0.v5/management" -) - -type userView struct { - UserID string - Connection string - Name string - Email string - LatestLogin string -} - -func (v *userView) AsTableHeader() []string { - return []string{"User ID", "Name", "Email", "Latest Login"} -} - -func (v *userView) AsTableRow() []string { - return []string{ansi.Faint(v.UserID), v.Name, v.Email, v.LatestLogin} -} - -func (r *Renderer) UserList(users []*management.User) { - r.Heading(ansi.Bold(r.Tenant), "users\n") - - var res []View - for _, u := range users { - res = append(res, &userView{ - UserID: auth0.StringValue(u.ID), - Name: auth0.StringValue(u.Name), - Email: auth0.StringValue(u.Email), - LatestLogin: u.LastLogin.String(), - }) - } - - r.Results(res) -}