From ae43f7f6a7f4b43479c9f60b6ece58a595b0039e Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 19 Feb 2021 19:28:13 -0300 Subject: [PATCH 1/5] Remove user commands --- internal/auth0/user.go | 13 ---- internal/auth0/user_mock.go | 150 ------------------------------------ internal/cli/users.go | 113 --------------------------- internal/display/users.go | 39 ---------- 4 files changed, 315 deletions(-) delete mode 100644 internal/auth0/user.go delete mode 100644 internal/auth0/user_mock.go delete mode 100644 internal/cli/users.go delete mode 100644 internal/display/users.go 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) -} From 5b7cfa7583e91b61a57d887a12f595c505558e84 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 19 Feb 2021 19:38:45 -0300 Subject: [PATCH 2/5] Remove rules commands --- internal/auth/auth.go | 1 - internal/auth/auth_test.go | 1 - internal/auth0/auth0.go | 4 - internal/auth0/rule.go | 25 -- internal/auth0/rule_mock.go | 130 --------- internal/cli/root.go | 2 - internal/cli/rules.go | 513 ------------------------------------ internal/display/rules.go | 47 ---- internal/rules/rules.go | 1 - 9 files changed, 724 deletions(-) delete mode 100644 internal/auth0/rule.go delete mode 100644 internal/auth0/rule_mock.go delete mode 100644 internal/cli/rules.go delete mode 100644 internal/display/rules.go delete mode 100644 internal/rules/rules.go diff --git a/internal/auth/auth.go b/internal/auth/auth.go index d960f07d7..cf7478044 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -40,7 +40,6 @@ var requiredScopes = []string{ "create:actions", "delete:actions", "read:actions", "update:actions", "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:client_keys", "read:logs", } diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index fd1e2f1df..8dee1524a 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -8,7 +8,6 @@ func TestRequiredScopes(t *testing.T) { "actions", "clients", "resource_servers", - "rules", } crudPrefixes := []string{"create:", "delete:", "read:", "update:"} diff --git a/internal/auth0/auth0.go b/internal/auth0/auth0.go index 19135dd29..e8a9eb15a 100644 --- a/internal/auth0/auth0.go +++ b/internal/auth0/auth0.go @@ -15,11 +15,9 @@ type API struct { Client ClientAPI Connection ConnectionAPI Log LogAPI - Rule RuleAPI ResourceServer ResourceServerAPI Role RoleAPI CustomDomain CustomDomainAPI - User UserAPI } func NewAPI(m *management.Management) *API { @@ -32,10 +30,8 @@ func NewAPI(m *management.Management) *API { Connection: m.Connection, Log: m.Log, ResourceServer: m.ResourceServer, - Rule: m.Rule, Role: m.Role, CustomDomain: m.CustomDomain, - User: m.User, } } diff --git a/internal/auth0/rule.go b/internal/auth0/rule.go deleted file mode 100644 index de0b48621..000000000 --- a/internal/auth0/rule.go +++ /dev/null @@ -1,25 +0,0 @@ -//go:generate mockgen -source=rule.go -destination=rule_mock.go -package=auth0 - -package auth0 - -import "gopkg.in/auth0.v5/management" - -type RuleAPI interface { - // Create a new rule. - // - // Note: Changing a rule's stage of execution from the default `login_success` - // can change the rule's function signature to have user omitted. - Create(r *management.Rule, opts ...management.RequestOption) error - - // Retrieve rule details. Accepts a list of fields to include or exclude in the result. - Read(id string, opts ...management.RequestOption) (r *management.Rule, err error) - - // Update an existing rule. - Update(id string, r *management.Rule, opts ...management.RequestOption) error - - // Delete a rule. - Delete(id string, opts ...management.RequestOption) error - - // List all rules. - List(opts ...management.RequestOption) (r *management.RuleList, err error) -} diff --git a/internal/auth0/rule_mock.go b/internal/auth0/rule_mock.go deleted file mode 100644 index cdcaa3cc2..000000000 --- a/internal/auth0/rule_mock.go +++ /dev/null @@ -1,130 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: rule.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" -) - -// MockRuleAPI is a mock of RuleAPI interface -type MockRuleAPI struct { - ctrl *gomock.Controller - recorder *MockRuleAPIMockRecorder -} - -// MockRuleAPIMockRecorder is the mock recorder for MockRuleAPI -type MockRuleAPIMockRecorder struct { - mock *MockRuleAPI -} - -// NewMockRuleAPI creates a new mock instance -func NewMockRuleAPI(ctrl *gomock.Controller) *MockRuleAPI { - mock := &MockRuleAPI{ctrl: ctrl} - mock.recorder = &MockRuleAPIMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockRuleAPI) EXPECT() *MockRuleAPIMockRecorder { - return m.recorder -} - -// Create mocks base method -func (m *MockRuleAPI) Create(r *management.Rule, opts ...management.RequestOption) error { - m.ctrl.T.Helper() - varargs := []interface{}{r} - 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 *MockRuleAPIMockRecorder) Create(r interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{r}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockRuleAPI)(nil).Create), varargs...) -} - -// Read mocks base method -func (m *MockRuleAPI) Read(id string, opts ...management.RequestOption) (*management.Rule, 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.Rule) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Read indicates an expected call of Read -func (mr *MockRuleAPIMockRecorder) 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((*MockRuleAPI)(nil).Read), varargs...) -} - -// Update mocks base method -func (m *MockRuleAPI) Update(id string, r *management.Rule, opts ...management.RequestOption) error { - m.ctrl.T.Helper() - varargs := []interface{}{id, r} - 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 *MockRuleAPIMockRecorder) Update(id, r interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{id, r}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockRuleAPI)(nil).Update), varargs...) -} - -// Delete mocks base method -func (m *MockRuleAPI) Delete(id string, opts ...management.RequestOption) 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 *MockRuleAPIMockRecorder) 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((*MockRuleAPI)(nil).Delete), varargs...) -} - -// List mocks base method -func (m *MockRuleAPI) List(opts ...management.RequestOption) (*management.RuleList, 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.RuleList) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// List indicates an expected call of List -func (mr *MockRuleAPIMockRecorder) List(opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockRuleAPI)(nil).List), opts...) -} diff --git a/internal/cli/root.go b/internal/cli/root.go index 6772d7d47..ef9c79cd8 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -64,13 +64,11 @@ func Execute() { rootCmd.AddCommand(apisCmd(cli)) rootCmd.AddCommand(tryLoginCmd(cli)) rootCmd.AddCommand(logsCmd(cli)) - rootCmd.AddCommand(rulesCmd(cli)) rootCmd.AddCommand(actionsCmd(cli)) rootCmd.AddCommand(connectionsCmd(cli)) rootCmd.AddCommand(rolesCmd(cli)) rootCmd.AddCommand(customDomainsCmd(cli)) rootCmd.AddCommand(getTokenCmd(cli)) - rootCmd.AddCommand(usersCmd(cli)) // keep completion at the bottom: rootCmd.AddCommand(completionCmd(cli)) diff --git a/internal/cli/rules.go b/internal/cli/rules.go deleted file mode 100644 index 05e22e3a1..000000000 --- a/internal/cli/rules.go +++ /dev/null @@ -1,513 +0,0 @@ -package cli - -import ( - "fmt" - "io/ioutil" - "os/user" - "regexp" - "strings" - - "github.com/auth0/auth0-cli/internal/ansi" - "github.com/auth0/auth0-cli/internal/auth0" - "github.com/auth0/auth0-cli/internal/prompt" - "github.com/spf13/cobra" - "gopkg.in/auth0.v5/management" -) - -const ( - ruleID = "id" - ruleName = "name" - ruleScript = "script" - ruleOrder = "order" - ruleEnabled = "enabled" -) - -func rulesCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "rules", - Short: "Manage rules for clients", - } - - cmd.SetUsageTemplate(resourceUsageTemplate()) - cmd.AddCommand(listRulesCmd(cli)) - cmd.AddCommand(enableRuleCmd(cli)) - cmd.AddCommand(disableRuleCmd(cli)) - cmd.AddCommand(createRulesCmd(cli)) - cmd.AddCommand(deleteRulesCmd(cli)) - cmd.AddCommand(updateRulesCmd(cli)) - - return cmd -} - -func listRulesCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "list", - Short: "List your rules", - Long: `List the rules in your current tenant.`, - RunE: func(cmd *cobra.Command, args []string) error { - var rules *management.RuleList - err := ansi.Spinner("Loading rules", func() error { - var err error - rules, err = getRules(cli) - return err - }) - - if err != nil { - return err - } - - cli.renderer.RulesList(rules) - return nil - }, - } - - return cmd -} - -func enableRuleCmd(cli *cli) *cobra.Command { - var flags struct { - Name string - } - - cmd := &cobra.Command{ - Use: "enable", - Short: "Enable a rule", - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if shouldPrompt(cmd, ruleName) { - input := prompt.TextInput(ruleName, "Name:", "Name of the rule.", true) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - err := ansi.Spinner("Enabling rule", func() error { - var err error - data, err := getRules(cli) - if err != nil { - return err - } - - rule := findRuleByName(flags.Name, data.Rules) - if rule != nil { - err := enableRule(rule, cli) - if err != nil { - return err - } - } else { - return fmt.Errorf("No rule found with name: %q", flags.Name) - } - return nil - }) - - if err != nil { - return err - } - - // @TODO Only display modified rules - rules, err := getRules(cli) - - if err != nil { - return err - } - - cli.renderer.RulesList(rules) - - return nil - }, - } - - cmd.Flags().StringVarP(&flags.Name, ruleName, "n", "", "Name of the rule.") - mustRequireFlags(cmd, ruleName) - - return cmd -} - -func disableRuleCmd(cli *cli) *cobra.Command { - var flags struct { - Name string - } - - cmd := &cobra.Command{ - Use: "disable", - Short: "Disable a rule", - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if shouldPrompt(cmd, ruleName) { - input := prompt.TextInput(ruleName, "Name:", "Name of the rule.", true) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - err := ansi.Spinner("Disabling rule", func() error { - var err error - data, err := getRules(cli) - if err != nil { - return err - } - - rule := findRuleByName(flags.Name, data.Rules) - if rule != nil { - if err := disableRule(rule, cli); err != nil { - return err - } - } else { - return fmt.Errorf("No rule found with name: %q", flags.Name) - } - return nil - }) - - if err != nil { - return err - } - - // @TODO Only display modified rules - rules, err := getRules(cli) - - if err != nil { - return err - } - - cli.renderer.RulesList(rules) - - return nil - }, - } - - cmd.Flags().StringVarP(&flags.Name, ruleName, "n", "", "rule name") - mustRequireFlags(cmd, ruleName) - - return cmd -} - -func createRulesCmd(cli *cli) *cobra.Command { - var flags struct { - Name string - Script string - Order int - Enabled bool - } - - cmd := &cobra.Command{ - Use: "create", - Short: "Create a new rule", - Long: `Create a new rule: - - auth0 rules create --name "My Rule" --script "function (user, context, callback) { console.log( 'Hello, world!' ); return callback(null, user, context); }" - `, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if shouldPrompt(cmd, ruleName) { - input := prompt.TextInput( - "name", "Name:", - "Name of the rule. You can change the rule name later in the rule settings.", - true) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, ruleScript) { - input := prompt.TextInput(ruleScript, "Script:", "Script of the rule.", true) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, ruleOrder) { - input := prompt.TextInputDefault(ruleOrder, "Order:", "Order of the rule.", "0", false) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, ruleEnabled) { - input := prompt.BoolInput(ruleEnabled, "Enabled:", "Enable the rule.", false) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if strings.Contains(flags.Script, ".js") { - content, err := parseFileByName(flags.Script) - - if err != nil { - return err - } - - flags.Script = content - } - - r := &management.Rule{ - Name: &flags.Name, - Script: &flags.Script, - Order: &flags.Order, - Enabled: &flags.Enabled, - } - - err := ansi.Spinner("Creating rule", func() error { - return cli.api.Rule.Create(r) - }) - - if err != nil { - return err - } - - cli.renderer.Infof("Your rule `%s` was successfully created.", flags.Name) - return nil - }, - } - - cmd.Flags().StringVarP(&flags.Name, ruleName, "n", "", "Name of this rule (required)") - cmd.Flags().StringVarP(&flags.Script, ruleScript, "s", "", "Code to be executed when this rule runs (required)") - cmd.Flags().IntVarP(&flags.Order, ruleOrder, "o", 0, "Order that this rule should execute in relative to other rules. Lower-valued rules execute first.") - cmd.Flags().BoolVarP(&flags.Enabled, ruleEnabled, "e", false, "Whether the rule is enabled (true), or disabled (false).") - mustRequireFlags(cmd, ruleName, ruleScript) - - return cmd -} - -func deleteRulesCmd(cli *cli) *cobra.Command { - var flags struct { - ID string - Name string - } - - cmd := &cobra.Command{ - Use: "delete", - Short: "Delete a rule", - Long: `Delete a rule: - - auth0 rules delete --id "12345"`, - PreRunE: func(cmd *cobra.Command, args []string) error { - if flags.ID != "" && flags.Name != "" { - return fmt.Errorf("TMI! 🤯 use either --name or --id") - } - - prepareInteractivity(cmd) - return nil - }, - RunE: func(cmd *cobra.Command, args []string) error { - if shouldPrompt(cmd, ruleID) && flags.Name == "" { - input := prompt.TextInput(ruleID, "Id:", "Id of the rule to delete.", false) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, ruleName) && flags.ID == "" { - input := prompt.TextInput(ruleName, "Name:", "Name of the rule to delete.", false) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if !cli.force && canPrompt(cmd) { - if confirmed := prompt.Confirm("Are you sure you want to proceed?"); !confirmed { - return nil - } - } - - var r *management.Rule - ruleIDPattern := "^rul_[A-Za-z0-9]{16}$" - re := regexp.MustCompile(ruleIDPattern) - - if flags.ID != "" { - if !re.Match([]byte(flags.ID)) { - return fmt.Errorf("Rule with id %q does not match pattern %s", flags.ID, ruleIDPattern) - } - - rule, err := cli.api.Rule.Read(flags.ID) - if err != nil { - return err - } - r = rule - } else { - data, err := getRules(cli) - if err != nil { - return err - } - if rule := findRuleByName(flags.Name, data.Rules); rule != nil { - r = rule - } else { - return fmt.Errorf("No rule found with name: %q", flags.Name) - } - } - - err := ansi.Spinner("Deleting rule", func() error { - return cli.api.Rule.Delete(*r.ID) - }) - - if err != nil { - return err - } - - return nil - }, - } - - cmd.Flags().StringVarP(&flags.ID, ruleID, "i", "", "ID of the rule to delete.") - cmd.Flags().StringVarP(&flags.Name, ruleName, "n", "", "Name of the rule to delete.") - - return cmd -} - -func updateRulesCmd(cli *cli) *cobra.Command { - var flags struct { - ID string - Name string - Script string - Order int - Enabled bool - } - - cmd := &cobra.Command{ - Use: "update", - Short: "update a rule", - Long: `Update a rule: - - auth0 rules update --id "12345" --name "My Updated Rule" --script "function (user, context, callback) { console.log( 'Hello, world!' ); return callback(null, user, context); }" --order 1 --enabled true - `, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if shouldPrompt(cmd, ruleID) { - input := prompt.TextInput(ruleID, "Id:", "Id of the rule.", true) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, ruleName) { - input := prompt.TextInput( - "name", "Name:", - "Name of the rule. You can change the rule name later in the rule settings.", - true) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, ruleScript) { - input := prompt.TextInput(ruleScript, "Script:", "Script of the rule.", true) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, ruleOrder) { - input := prompt.TextInputDefault(ruleOrder, "Order:", "Order of the rule.", "0", false) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, ruleEnabled) { - input := prompt.BoolInput(ruleEnabled, "Enabled:", "Enable the rule.", false) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if strings.Contains(flags.Script, ".js") { - content, err := parseFileByName(flags.Script) - - if err != nil { - return err - } - - flags.Script = content - } - - r := &management.Rule{ - Name: &flags.Name, - Script: &flags.Script, - Order: &flags.Order, - Enabled: &flags.Enabled, - } - - err := ansi.Spinner("Updating rule", func() error { - return cli.api.Rule.Update(flags.ID, r) - }) - - if err != nil { - return err - } - - cli.renderer.Infof("Your rule `%s` was successfully updated.", flags.Name) - return nil - }, - } - - cmd.Flags().StringVarP(&flags.ID, ruleID, "i", "", "ID of the rule to update (required)") - cmd.Flags().StringVarP(&flags.Name, ruleName, "n", "", "Name of this rule") - cmd.Flags().StringVarP(&flags.Script, ruleScript, "s", "", "Code to be executed when this rule runs") - cmd.Flags().IntVarP(&flags.Order, ruleOrder, "o", 0, "Order that this rule should execute in relative to other rules. Lower-valued rules execute first.") - cmd.Flags().BoolVarP(&flags.Enabled, ruleEnabled, "e", false, "Whether the rule is enabled (true), or disabled (false).") - mustRequireFlags(cmd, ruleID) - - return cmd -} - -// @TODO move to rules package -func getRules(cli *cli) (list *management.RuleList, err error) { - return cli.api.Rule.List() -} - -func findRuleByName(name string, rules []*management.Rule) *management.Rule { - for _, r := range rules { - if auth0.StringValue(r.Name) == name { - return r - } - } - return nil -} - -func enableRule(rule *management.Rule, cli *cli) error { - return cli.api.Rule.Update(rule.GetID(), &management.Rule{Enabled: auth0.Bool(true)}) -} - -func disableRule(rule *management.Rule, cli *cli) error { - return cli.api.Rule.Update(rule.GetID(), &management.Rule{Enabled: auth0.Bool(false)}) -} - -func parseFileByName(inputFile string) (string, error) { - usr, _ := user.Current() - inputFile = strings.Replace(inputFile, "~/", usr.HomeDir+"/", -1) - f, err := ioutil.ReadFile(inputFile) - - if err != nil { - return "", fmt.Errorf("Error reading file: %s", err) - } - - if err != nil { - return "", fmt.Errorf("Cannot parse file %s: %w", f, err) - } - - if err != nil { - return "", err - } - - return string(f), nil -} diff --git a/internal/display/rules.go b/internal/display/rules.go deleted file mode 100644 index 31bebf4e1..000000000 --- a/internal/display/rules.go +++ /dev/null @@ -1,47 +0,0 @@ -package display - -import ( - "fmt" - "sort" - "strconv" - - "github.com/auth0/auth0-cli/internal/ansi" - "gopkg.in/auth0.v5/management" -) - -type ruleView struct { - Name string - Enabled bool - ID string - Order int -} - -func (v *ruleView) AsTableHeader() []string { - return []string{"Id", "Name", "Enabled", "Order"} -} - -func (v *ruleView) AsTableRow() []string { - return []string{v.ID, v.Name, strconv.FormatBool(v.Enabled), fmt.Sprintf("%d", v.Order)} -} - -func (r *Renderer) RulesList(ruleList *management.RuleList) { - r.Heading(ansi.Bold(r.Tenant), "rules\n") - var res []View - - //@TODO Provide sort options via flags - sort.Slice(ruleList.Rules, func(i, j int) bool { - return ruleList.Rules[i].GetOrder() < ruleList.Rules[j].GetOrder() - }) - - for _, rule := range ruleList.Rules { - res = append(res, &ruleView{ - Name: *rule.Name, - ID: *rule.ID, - Enabled: *rule.Enabled, - Order: *rule.Order, - }) - } - - r.Results(res) - -} diff --git a/internal/rules/rules.go b/internal/rules/rules.go deleted file mode 100644 index 1e8c7fa08..000000000 --- a/internal/rules/rules.go +++ /dev/null @@ -1 +0,0 @@ -package rules From 723aebbc3294e01b555039691f21aa0684a36500 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 19 Feb 2021 19:41:20 -0300 Subject: [PATCH 3/5] Remove roles commands --- internal/auth0/auth0.go | 2 - internal/auth0/role.go | 22 --- internal/cli/roles.go | 272 -------------------------------------- internal/cli/root.go | 1 - internal/display/roles.go | 62 --------- 5 files changed, 359 deletions(-) delete mode 100644 internal/auth0/role.go delete mode 100644 internal/cli/roles.go delete mode 100644 internal/display/roles.go diff --git a/internal/auth0/auth0.go b/internal/auth0/auth0.go index e8a9eb15a..e7fe8fd38 100644 --- a/internal/auth0/auth0.go +++ b/internal/auth0/auth0.go @@ -16,7 +16,6 @@ type API struct { Connection ConnectionAPI Log LogAPI ResourceServer ResourceServerAPI - Role RoleAPI CustomDomain CustomDomainAPI } @@ -30,7 +29,6 @@ func NewAPI(m *management.Management) *API { Connection: m.Connection, Log: m.Log, ResourceServer: m.ResourceServer, - Role: m.Role, CustomDomain: m.CustomDomain, } } diff --git a/internal/auth0/role.go b/internal/auth0/role.go deleted file mode 100644 index 5f6f4b1a8..000000000 --- a/internal/auth0/role.go +++ /dev/null @@ -1,22 +0,0 @@ -//go:generate mockgen -source=role.go -destination=role_mock.go -package=auth0 - -package auth0 - -import "gopkg.in/auth0.v5/management" - -type RoleAPI interface { - // Create a new role. - Create(r *management.Role, opts ...management.RequestOption) (err error) - - // Retrieve a role. - Read(id string, opts ...management.RequestOption) (r *management.Role, err error) - - // List all roles that can be assigned to users or groups. - List(opts ...management.RequestOption) (r *management.RoleList, err error) - - // Update a role. - Update(id string, r *management.Role, opts ...management.RequestOption) (err error) - - // Delete a role. - Delete(id string, opts ...management.RequestOption) (err error) -} diff --git a/internal/cli/roles.go b/internal/cli/roles.go deleted file mode 100644 index d73f4e778..000000000 --- a/internal/cli/roles.go +++ /dev/null @@ -1,272 +0,0 @@ -package cli - -import ( - "github.com/AlecAivazis/survey/v2" - "github.com/auth0/auth0-cli/internal/ansi" - "github.com/auth0/auth0-cli/internal/auth0" - "github.com/spf13/cobra" - "gopkg.in/auth0.v5/management" -) - -func rolesCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "roles", - Short: "Manage resources for roles", - } - - cmd.SetUsageTemplate(resourceUsageTemplate()) - cmd.AddCommand(rolesListCmd(cli)) - cmd.AddCommand(rolesGetCmd(cli)) - cmd.AddCommand(rolesDeleteCmd(cli)) - cmd.AddCommand(rolesUpdateCmd(cli)) - cmd.AddCommand(rolesCreateCmd(cli)) - - return cmd -} - -func rolesListCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "list", - Short: "List all roles", - Long: `auth0 roles list -Retrieve filtered list of roles that can be assigned to users or groups - -`, - RunE: func(cmd *cobra.Command, args []string) error { - var list *management.RoleList - err := ansi.Spinner("Getting roles", func() error { - var err error - list, err = cli.api.Role.List() - return err - }) - - if err != nil { - return err - } - - cli.renderer.RoleList(list.Roles) - return nil - }, - } - - return cmd -} - -func rolesGetCmd(cli *cli) *cobra.Command { - var flags struct { - RoleID string - } - cmd := &cobra.Command{ - Use: "get", - Short: "Get a role", - Long: `auth0 roles get --role-id myRoleID -Get a role - -`, - RunE: func(cmd *cobra.Command, args []string) error { - - if !cmd.Flags().Changed("role-id") { - qs := []*survey.Question{ - { - Name: "RoleID", - Prompt: &survey.Input{ - Message: "RoleID:", - Help: "ID of the role to get.", - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { - return err - } - } - - var role *management.Role - err := ansi.Spinner("Getting role", func() error { - var err error - role, err = cli.api.Role.Read(flags.RoleID) - return err - }) - - if err != nil { - return err - } - - cli.renderer.RoleGet(role) - return nil - }, - } - - cmd.Flags().StringVarP(&flags.RoleID, "role-id", "i", "", "ID of the role to get.") - - return cmd -} - -func rolesDeleteCmd(cli *cli) *cobra.Command { - var flags struct { - RoleID string - } - cmd := &cobra.Command{ - Use: "delete", - Short: "Delete a role", - Long: `auth0 roles delete --role-id myRoleID -Delete a role. - -`, - RunE: func(cmd *cobra.Command, args []string) error { - - if !cmd.Flags().Changed("role-id") { - qs := []*survey.Question{ - { - Name: "RoleID", - Prompt: &survey.Input{ - Message: "RoleID:", - Help: "ID of the role to delete.", - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { - return err - } - } - - return ansi.Spinner("Deleting role", func() error { - return cli.api.Role.Delete(flags.RoleID) - }) - }, - } - - cmd.Flags().StringVarP(&flags.RoleID, "role-id", "i", "", "ID of the role to delete.") - - return cmd -} - -func rolesUpdateCmd(cli *cli) *cobra.Command { - var flags struct { - RoleID string - Name string - Description string - } - cmd := &cobra.Command{ - Use: "update", - Short: "Update a role", - Long: `auth0 roles update --role-id myRoleID --name myName --description myDescription -Update a role. - -`, - RunE: func(cmd *cobra.Command, args []string) error { - - if !cmd.Flags().Changed("role-id") { - qs := []*survey.Question{ - { - Name: "RoleID", - Prompt: &survey.Input{ - Message: "RoleID:", - Help: "ID of the role to update.", - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { - return err - } - } - - role := &management.Role{} - - if cmd.Flags().Changed("name") { - role.Name = auth0.String(flags.Name) - } - - if cmd.Flags().Changed("description") { - role.Description = auth0.String(flags.Description) - } - - err := ansi.Spinner("Updating role", func() error { - return cli.api.Role.Update(flags.RoleID, role) - }) - if err != nil { - return err - } - - cli.renderer.RoleUpdate(role) - return nil - }, - } - - cmd.Flags().StringVarP(&flags.RoleID, "role-id", "i", "", "ID of the role to update.") - cmd.Flags().StringVarP(&flags.Name, "name", "n", "", "Name of this role.") - cmd.Flags().StringVarP(&flags.Description, "description", "d", "", "Description of this role.") - - return cmd -} - -func rolesCreateCmd(cli *cli) *cobra.Command { - var flags struct { - Name string - Description string - } - cmd := &cobra.Command{ - Use: "create", - Short: "Create a role", - Long: `auth0 roles create --name myName --description myDescription -Create a new role. - -`, - RunE: func(cmd *cobra.Command, args []string) error { - - if !cmd.Flags().Changed("name") { - qs := []*survey.Question{ - { - Name: "Name", - Prompt: &survey.Input{ - Message: "Name:", - Help: "Name of the role.", - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { - return err - } - } - - if !cmd.Flags().Changed("description") { - qs := []*survey.Question{ - { - Name: "Description", - Prompt: &survey.Input{ - Message: "Description:", - Help: "Description of the role.", - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { - return err - } - } - - role := &management.Role{ - Name: auth0.String(flags.Name), - Description: auth0.String(flags.Description), - } - - err := ansi.Spinner("Creating role", func() error { - return cli.api.Role.Create(role) - }) - if err != nil { - return err - } - - cli.renderer.RoleCreate(role) - return nil - }, - } - - cmd.Flags().StringVarP(&flags.Name, "name", "n", "", "Name of the role.") - cmd.Flags().StringVarP(&flags.Description, "description", "d", "", "Description of the role.") - - return cmd -} diff --git a/internal/cli/root.go b/internal/cli/root.go index ef9c79cd8..f918457c8 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -66,7 +66,6 @@ func Execute() { rootCmd.AddCommand(logsCmd(cli)) rootCmd.AddCommand(actionsCmd(cli)) rootCmd.AddCommand(connectionsCmd(cli)) - rootCmd.AddCommand(rolesCmd(cli)) rootCmd.AddCommand(customDomainsCmd(cli)) rootCmd.AddCommand(getTokenCmd(cli)) diff --git a/internal/display/roles.go b/internal/display/roles.go deleted file mode 100644 index 8252bde1b..000000000 --- a/internal/display/roles.go +++ /dev/null @@ -1,62 +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 roleView struct { - Name string - ID string - Description string -} - -func (v *roleView) AsTableHeader() []string { - return []string{"Name", "Role ID", "Description"} -} - -func (v *roleView) AsTableRow() []string { - return []string{v.Name, v.ID, v.Description} -} - -func (r *Renderer) RoleList(roles []*management.Role) { - r.Heading(ansi.Bold(r.Tenant), "roles\n") - var res []View - for _, r := range roles { - res = append(res, &roleView{ - Name: auth0.StringValue(r.Name), - ID: auth0.StringValue(r.ID), - Description: auth0.StringValue(r.Description), - }) - } - - r.Results(res) -} - -func (r *Renderer) RoleGet(role *management.Role) { - r.Heading(ansi.Bold(r.Tenant), "role\n") - r.Results([]View{&roleView{ - Name: auth0.StringValue(role.Name), - ID: auth0.StringValue(role.ID), - Description: auth0.StringValue(role.Description), - }}) -} - -func (r *Renderer) RoleUpdate(role *management.Role) { - r.Heading(ansi.Bold(r.Tenant), "role\n") - r.Results([]View{&roleView{ - Name: auth0.StringValue(role.Name), - ID: auth0.StringValue(role.ID), - Description: auth0.StringValue(role.Description), - }}) -} - -func (r *Renderer) RoleCreate(role *management.Role) { - r.Heading(ansi.Bold(r.Tenant), "role\n") - r.Results([]View{&roleView{ - Name: auth0.StringValue(role.Name), - ID: auth0.StringValue(role.ID), - Description: auth0.StringValue(role.Description), - }}) -} From 41d3ac8163ed6d758a48f046cafa0cc0917cb768 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 19 Feb 2021 19:43:51 -0300 Subject: [PATCH 4/5] Remove custom domaains commands --- internal/auth0/auth0.go | 2 - internal/auth0/custom_domain.go | 22 --- internal/auth0/custom_domain_mock.go | 131 ------------- internal/cli/custom_domains.go | 266 --------------------------- internal/cli/custom_domains_test.go | 130 ------------- internal/cli/root.go | 1 - internal/display/custom_domains.go | 83 --------- 7 files changed, 635 deletions(-) delete mode 100644 internal/auth0/custom_domain.go delete mode 100644 internal/auth0/custom_domain_mock.go delete mode 100644 internal/cli/custom_domains.go delete mode 100644 internal/cli/custom_domains_test.go delete mode 100644 internal/display/custom_domains.go diff --git a/internal/auth0/auth0.go b/internal/auth0/auth0.go index e7fe8fd38..ca0f44d07 100644 --- a/internal/auth0/auth0.go +++ b/internal/auth0/auth0.go @@ -16,7 +16,6 @@ type API struct { Connection ConnectionAPI Log LogAPI ResourceServer ResourceServerAPI - CustomDomain CustomDomainAPI } func NewAPI(m *management.Management) *API { @@ -29,7 +28,6 @@ func NewAPI(m *management.Management) *API { Connection: m.Connection, Log: m.Log, ResourceServer: m.ResourceServer, - CustomDomain: m.CustomDomain, } } diff --git a/internal/auth0/custom_domain.go b/internal/auth0/custom_domain.go deleted file mode 100644 index 970618476..000000000 --- a/internal/auth0/custom_domain.go +++ /dev/null @@ -1,22 +0,0 @@ -//go:generate mockgen -source=custom_domain.go -destination=custom_domain_mock.go -package=auth0 - -package auth0 - -import "gopkg.in/auth0.v5/management" - -type CustomDomainAPI interface { - // Create a new custom domain. - Create(r *management.CustomDomain, opts ...management.RequestOption) (err error) - - // Retrieve a custom domain configuration and status. - Read(id string, opts ...management.RequestOption) (c *management.CustomDomain, err error) - - // Run the verification process on a custom domain. - Verify(id string, opts ...management.RequestOption) (c *management.CustomDomain, err error) - - // Delete a custom domain and stop serving requests for it. - Delete(id string, opts ...management.RequestOption) (err error) - - // List all custom domains. - List(opts ...management.RequestOption) (c []*management.CustomDomain, err error) -} diff --git a/internal/auth0/custom_domain_mock.go b/internal/auth0/custom_domain_mock.go deleted file mode 100644 index 1d551aab1..000000000 --- a/internal/auth0/custom_domain_mock.go +++ /dev/null @@ -1,131 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: custom_domain.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" -) - -// MockCustomDomainAPI is a mock of CustomDomainAPI interface -type MockCustomDomainAPI struct { - ctrl *gomock.Controller - recorder *MockCustomDomainAPIMockRecorder -} - -// MockCustomDomainAPIMockRecorder is the mock recorder for MockCustomDomainAPI -type MockCustomDomainAPIMockRecorder struct { - mock *MockCustomDomainAPI -} - -// NewMockCustomDomainAPI creates a new mock instance -func NewMockCustomDomainAPI(ctrl *gomock.Controller) *MockCustomDomainAPI { - mock := &MockCustomDomainAPI{ctrl: ctrl} - mock.recorder = &MockCustomDomainAPIMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockCustomDomainAPI) EXPECT() *MockCustomDomainAPIMockRecorder { - return m.recorder -} - -// Create mocks base method -func (m *MockCustomDomainAPI) Create(r *management.CustomDomain, opts ...management.RequestOption) error { - m.ctrl.T.Helper() - varargs := []interface{}{r} - 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 *MockCustomDomainAPIMockRecorder) Create(r interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{r}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockCustomDomainAPI)(nil).Create), varargs...) -} - -// Read mocks base method -func (m *MockCustomDomainAPI) Read(id string, opts ...management.RequestOption) (*management.CustomDomain, 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.CustomDomain) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Read indicates an expected call of Read -func (mr *MockCustomDomainAPIMockRecorder) 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((*MockCustomDomainAPI)(nil).Read), varargs...) -} - -// Verify mocks base method -func (m *MockCustomDomainAPI) Verify(id string, opts ...management.RequestOption) (*management.CustomDomain, error) { - m.ctrl.T.Helper() - varargs := []interface{}{id} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Verify", varargs...) - ret0, _ := ret[0].(*management.CustomDomain) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Verify indicates an expected call of Verify -func (mr *MockCustomDomainAPIMockRecorder) Verify(id interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{id}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Verify", reflect.TypeOf((*MockCustomDomainAPI)(nil).Verify), varargs...) -} - -// Delete mocks base method -func (m *MockCustomDomainAPI) Delete(id string, opts ...management.RequestOption) 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 *MockCustomDomainAPIMockRecorder) 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((*MockCustomDomainAPI)(nil).Delete), varargs...) -} - -// List mocks base method -func (m *MockCustomDomainAPI) List(opts ...management.RequestOption) ([]*management.CustomDomain, 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.CustomDomain) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// List indicates an expected call of List -func (mr *MockCustomDomainAPIMockRecorder) List(opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockCustomDomainAPI)(nil).List), opts...) -} diff --git a/internal/cli/custom_domains.go b/internal/cli/custom_domains.go deleted file mode 100644 index 32881ffd6..000000000 --- a/internal/cli/custom_domains.go +++ /dev/null @@ -1,266 +0,0 @@ -package cli - -import ( - "github.com/AlecAivazis/survey/v2" - "github.com/auth0/auth0-cli/internal/ansi" - "github.com/auth0/auth0-cli/internal/auth0" - "github.com/spf13/cobra" - "gopkg.in/auth0.v5/management" -) - -func customDomainsCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "custom-domains", - Short: "Manage resources for custom-domains", - } - - cmd.SetUsageTemplate(resourceUsageTemplate()) - cmd.AddCommand(customDomainsListCmd(cli)) - cmd.AddCommand(customDomainsCreateCmd(cli)) - cmd.AddCommand(customDomainsDeleteCmd(cli)) - cmd.AddCommand(customDomainsGetCmd(cli)) - cmd.AddCommand(customDomainsVerifyCmd(cli)) - - return cmd -} - -func customDomainsListCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "list", - Short: "List custom domains configurations", - Long: ` -Retrieve details on custom domains. - - auth0 custom-domains list - -`, - RunE: func(cmd *cobra.Command, args []string) error { - var customDomains []*management.CustomDomain - err := ansi.Spinner("Getting custom domains", func() error { - var err error - customDomains, err = cli.api.CustomDomain.List() - return err - }) - - if err != nil { - return err - } - - cli.renderer.CustomDomainList(customDomains) - return nil - }, - } - - return cmd -} - -func customDomainsCreateCmd(cli *cli) *cobra.Command { - var flags struct { - Domain string - Type string - VerificationMethod string - } - cmd := &cobra.Command{ - Use: "create", - Short: "Configure a new custom domain", - Long: ` -Create a new custom domain. - -Note: The custom domain will need to be verified before it will accept requests. - - auth0 custom-domain create --domain example.org --type auth0_managed_certs --type txt - -`, - RunE: func(cmd *cobra.Command, args []string) error { - - if !cmd.Flags().Changed("domain") { - qs := []*survey.Question{ - { - Name: "Domain", - Prompt: &survey.Input{ - Message: "Domain:", - Help: "Domain name.", - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { - return err - } - } - - customDomain := &management.CustomDomain{ - Domain: auth0.String(flags.Domain), - Type: auth0.String(flags.Type), - VerificationMethod: auth0.String(flags.VerificationMethod), - } - - err := ansi.Spinner("Creating custom domain", func() error { - return cli.api.CustomDomain.Create(customDomain) - }) - if err != nil { - return err - } - - cli.renderer.CustomDomainCreate(customDomain) - return nil - }, - } - - cmd.Flags().StringVarP(&flags.Domain, "domain", "d", "", "Domain name.") - cmd.Flags().StringVarP(&flags.Type, "type", "t", "auth0_managed_certs", "Custom domain provisioning type. Must be auth0_managed_certs or self_managed_certs. Defaults to auth0_managed_certs") - cmd.Flags().StringVarP(&flags.VerificationMethod, "verification-method", "v", "txt", "Custom domain verification method. Must be txt.") - - return cmd -} - -func customDomainsDeleteCmd(cli *cli) *cobra.Command { - var flags struct { - CustomDomainID string - } - cmd := &cobra.Command{ - Use: "delete", - Short: "Delete a custom domain configuration", - Long: ` -Delete a custom domain and stop serving requests for it. - - auth0 custom-domains delete --custom-domain-id myCustomDomainID -`, - RunE: func(cmd *cobra.Command, args []string) error { - - if !cmd.Flags().Changed("custom-domain-id") { - qs := []*survey.Question{ - { - Name: "CustomDomainID", - Prompt: &survey.Input{ - Message: "CustomDomainID:", - Help: "ID of the custom domain to delete.", - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { - return err - } - } - - return ansi.Spinner("Deleting custom domain", func() error { - return cli.api.CustomDomain.Delete(flags.CustomDomainID) - }) - }, - } - - cmd.Flags().StringVarP(&flags.CustomDomainID, "custom-domain-id", "i", "", "ID of the custom domain to delete.") - - return cmd -} - -func customDomainsGetCmd(cli *cli) *cobra.Command { - var flags struct { - CustomDomainID string - } - cmd := &cobra.Command{ - Use: "get", - Short: "Get custom domain configuration", - Long: ` -Retrieve a custom domain configuration and status. - - auth0 custom-domain get --custom-domain-id myCustomDomainID -`, - RunE: func(cmd *cobra.Command, args []string) error { - - if !cmd.Flags().Changed("custom-domain-id") { - qs := []*survey.Question{ - { - Name: "CustomDomainID", - Prompt: &survey.Input{ - Message: "CustomDomainID:", - Help: "ID of the custom domain to retrieve.", - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { - return err - } - } - - var customDomain *management.CustomDomain - err := ansi.Spinner("Getting custom domain", func() error { - var err error - customDomain, err = cli.api.CustomDomain.Read(flags.CustomDomainID) - return err - }) - if err != nil { - return err - } - - cli.renderer.CustomDomainGet(customDomain) - return nil - }, - } - - cmd.Flags().StringVarP(&flags.CustomDomainID, "custom-domain-id", "i", "", "ID of the custom domain to retrieve.") - - return cmd -} - -func customDomainsVerifyCmd(cli *cli) *cobra.Command { - var flags struct { - CustomDomainID string - } - cmd := &cobra.Command{ - Use: "verify", - Short: "Verify a custom domain", - Long: ` -Run the verification process on a custom domain. - -Note: Check the status field to see its verification status. Once verification is complete, it may take up to 10 minutes before the custom domain can start accepting requests. - -For self_managed_certs, when the custom domain is verified for the first time, the response will also include the cname_api_key which you will need to configure your proxy. This key must be kept secret, and is used to validate the proxy requests. - -Learn more about verifying custom domains that use Auth0 Managed certificates: - - https://auth0.com/docs/custom-domains#step-2-verify-ownership - -Learn more about verifying custom domains that use Self Managed certificates: - - https://auth0.com/docs/custom-domains/self-managed-certificates#step-2-verify-ownership - - auth0 custom-domain verify --custom-domain-id myCustomDomainID -`, - RunE: func(cmd *cobra.Command, args []string) error { - - if !cmd.Flags().Changed("custom-domain-id") { - qs := []*survey.Question{ - { - Name: "CustomDomainID", - Prompt: &survey.Input{ - Message: "CustomDomainID:", - Help: "ID of the custom domain to verify.", - }, - }, - } - err := survey.Ask(qs, &flags) - if err != nil { - return err - } - } - - var customDomain *management.CustomDomain - err := ansi.Spinner("Verifying custom domain", func() error { - var err error - customDomain, err = cli.api.CustomDomain.Verify(flags.CustomDomainID) - return err - }) - if err != nil { - return err - } - - cli.renderer.CustomDomainVerify(customDomain) - return nil - }, - } - - cmd.Flags().StringVarP(&flags.CustomDomainID, "custom-domain-id", "i", "", "ID of the custom domain to retrieve.") - - return cmd -} diff --git a/internal/cli/custom_domains_test.go b/internal/cli/custom_domains_test.go deleted file mode 100644 index b18afda5f..000000000 --- a/internal/cli/custom_domains_test.go +++ /dev/null @@ -1,130 +0,0 @@ -package cli - -import ( - "bytes" - "io/ioutil" - "testing" - - "github.com/auth0/auth0-cli/internal/auth0" - "github.com/auth0/auth0-cli/internal/display" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/assert" - "gopkg.in/auth0.v5/management" -) - -func TestCustomDomainsCmd(t *testing.T) { - t.Run("List", func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - m := auth0.NewMockCustomDomainAPI(ctrl) - m.EXPECT().List().MaxTimes(1).Return([]*management.CustomDomain{{ID: auth0.String("testID"), Domain: auth0.String("testDomain"), Type: auth0.String("testType")}}, nil) - stdout := &bytes.Buffer{} - cli := &cli{ - renderer: &display.Renderer{ - MessageWriter: ioutil.Discard, - ResultWriter: stdout, - Format: display.OutputFormat("json"), - }, - api: &auth0.API{CustomDomain: m}, - } - - cmd := customDomainsListCmd(cli) - if err := cmd.Execute(); err != nil { - t.Fatal(err) - } - - assert.JSONEq(t, `[{"ID": "testID", "Domain": "testDomain", "Type": "testType", "Primary": false, "Status": "", "VerificationMethod": "","Verification": {"Methods": null}}]`, stdout.String()) - }) - - t.Run("Create", func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - m := auth0.NewMockCustomDomainAPI(ctrl) - m.EXPECT().Create(gomock.Any()).MaxTimes(1).Return(nil) - stdout := &bytes.Buffer{} - cli := &cli{ - renderer: &display.Renderer{ - MessageWriter: ioutil.Discard, - ResultWriter: stdout, - Format: display.OutputFormat("json"), - }, - api: &auth0.API{CustomDomain: m}, - } - - cmd := customDomainsCreateCmd(cli) - cmd.SetArgs([]string{"--domain=testDomain", "--type=testType", "--verification-method=testVerificationMethod"}) - if err := cmd.Execute(); err != nil { - t.Fatal(err) - } - - assert.JSONEq(t, `[{"ID": "", "Domain": "testDomain", "Type": "testType", "Primary": false, "Status": "", "VerificationMethod": "testVerificationMethod", "Verification": {"Methods": null}}]`, stdout.String()) - }) - - t.Run("Delete", func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - m := auth0.NewMockCustomDomainAPI(ctrl) - m.EXPECT().Delete(gomock.Any()).MaxTimes(1).Return(nil) - stdout := &bytes.Buffer{} - cli := &cli{ - renderer: &display.Renderer{ - MessageWriter: ioutil.Discard, - ResultWriter: stdout, - Format: display.OutputFormat("json"), - }, - api: &auth0.API{CustomDomain: m}, - } - - cmd := customDomainsDeleteCmd(cli) - cmd.SetArgs([]string{"--custom-domain-id=testCustomDomainID"}) - if err := cmd.Execute(); err != nil { - t.Fatal(err) - } - }) - - t.Run("Get", func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - m := auth0.NewMockCustomDomainAPI(ctrl) - m.EXPECT().Read(gomock.Any()).MaxTimes(1).Return(&management.CustomDomain{ID: auth0.String("testID"), Domain: auth0.String("testDomain"), Type: auth0.String("testType")}, nil) - stdout := &bytes.Buffer{} - cli := &cli{ - renderer: &display.Renderer{ - MessageWriter: ioutil.Discard, - ResultWriter: stdout, - Format: display.OutputFormat("json"), - }, - api: &auth0.API{CustomDomain: m}, - } - - cmd := customDomainsGetCmd(cli) - cmd.SetArgs([]string{"--custom-domain-id=testCustomDomainID"}) - if err := cmd.Execute(); err != nil { - t.Fatal(err) - } - assert.JSONEq(t, `[{"ID": "testID", "Domain": "testDomain", "Type": "testType", "Primary": false, "Status": "", "VerificationMethod": "", "Verification": {"Methods": null}}]`, stdout.String()) - }) - - t.Run("Verify", func(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - m := auth0.NewMockCustomDomainAPI(ctrl) - m.EXPECT().Verify(gomock.Any()).MaxTimes(1).Return(&management.CustomDomain{ID: auth0.String("testID"), Domain: auth0.String("testDomain"), Type: auth0.String("testType")}, nil) - stdout := &bytes.Buffer{} - cli := &cli{ - renderer: &display.Renderer{ - MessageWriter: ioutil.Discard, - ResultWriter: stdout, - Format: display.OutputFormat("json"), - }, - api: &auth0.API{CustomDomain: m}, - } - - cmd := customDomainsVerifyCmd(cli) - cmd.SetArgs([]string{"--custom-domain-id=testCustomDomainID"}) - if err := cmd.Execute(); err != nil { - t.Fatal(err) - } - assert.JSONEq(t, `[{"ID": "testID", "Domain": "testDomain", "Type": "testType", "Primary": false, "Status": "", "VerificationMethod": "", "Verification": {"Methods": null}}]`, stdout.String()) - }) -} diff --git a/internal/cli/root.go b/internal/cli/root.go index f918457c8..f50b60919 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -66,7 +66,6 @@ func Execute() { rootCmd.AddCommand(logsCmd(cli)) rootCmd.AddCommand(actionsCmd(cli)) rootCmd.AddCommand(connectionsCmd(cli)) - rootCmd.AddCommand(customDomainsCmd(cli)) rootCmd.AddCommand(getTokenCmd(cli)) // keep completion at the bottom: diff --git a/internal/display/custom_domains.go b/internal/display/custom_domains.go deleted file mode 100644 index f97534753..000000000 --- a/internal/display/custom_domains.go +++ /dev/null @@ -1,83 +0,0 @@ -package display - -import ( - "strconv" - - "github.com/auth0/auth0-cli/internal/ansi" - "github.com/auth0/auth0-cli/internal/auth0" - "gopkg.in/auth0.v5/management" -) - -type customDomainView struct { - ID string - Domain string - Type string - Primary bool - Status string - VerificationMethod string - Verification customDomainVerificationView -} - -type customDomainVerificationView struct { - Methods []map[string]interface{} -} - -func (v *customDomainView) AsTableHeader() []string { - return []string{"Domain", "Custom Domain ID", "Type", "Primary", "Status", "Verification Method"} -} - -func (v *customDomainView) AsTableRow() []string { - return []string{v.Domain, v.ID, v.Type, strconv.FormatBool(v.Primary), v.Status, v.VerificationMethod} -} - -func (r *Renderer) CustomDomainList(customDomains []*management.CustomDomain) { - r.Heading(ansi.Bold(r.Tenant), "custom-domains\n") - var res []View - for _, c := range customDomains { - res = append(res, &customDomainView{ - ID: auth0.StringValue(c.ID), - Domain: auth0.StringValue(c.Domain), - Type: auth0.StringValue(c.Type), - Primary: auth0.BoolValue(c.Primary), - Status: auth0.StringValue(c.Status), - VerificationMethod: auth0.StringValue(c.VerificationMethod), - }) - } - r.Results(res) -} - -func (r *Renderer) CustomDomainCreate(customDomain *management.CustomDomain) { - r.Heading(ansi.Bold(r.Tenant), "custom-domain created\n") - r.Results([]View{&customDomainView{ - Domain: auth0.StringValue(customDomain.Domain), - Type: auth0.StringValue(customDomain.Type), - ID: auth0.StringValue(customDomain.ID), - Primary: auth0.BoolValue(customDomain.Primary), - Status: auth0.StringValue(customDomain.Status), - VerificationMethod: auth0.StringValue(customDomain.VerificationMethod), - }}) -} - -func (r *Renderer) CustomDomainGet(customDomain *management.CustomDomain) { - r.Heading(ansi.Bold(r.Tenant), "custom-domain\n") - r.Results([]View{&customDomainView{ - Domain: auth0.StringValue(customDomain.Domain), - Type: auth0.StringValue(customDomain.Type), - ID: auth0.StringValue(customDomain.ID), - Primary: auth0.BoolValue(customDomain.Primary), - Status: auth0.StringValue(customDomain.Status), - VerificationMethod: auth0.StringValue(customDomain.VerificationMethod), - }}) -} - -func (r *Renderer) CustomDomainVerify(customDomain *management.CustomDomain) { - r.Heading(ansi.Bold(r.Tenant), "custom-domain verified\n") - r.Results([]View{&customDomainView{ - Domain: auth0.StringValue(customDomain.Domain), - Type: auth0.StringValue(customDomain.Type), - ID: auth0.StringValue(customDomain.ID), - Primary: auth0.BoolValue(customDomain.Primary), - Status: auth0.StringValue(customDomain.Status), - VerificationMethod: auth0.StringValue(customDomain.VerificationMethod), - }}) -} From eaf0c3be16f0114d49f71572623893dab8e5a87c Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 19 Feb 2021 19:46:49 -0300 Subject: [PATCH 5/5] Remove connections commands --- internal/auth0/auth0.go | 2 - internal/auth0/connection.go | 26 ------ internal/auth0/connection_mock.go | 150 ------------------------------ internal/cli/connections.go | 48 ---------- internal/cli/root.go | 1 - internal/display/connections.go | 37 -------- 6 files changed, 264 deletions(-) delete mode 100644 internal/auth0/connection.go delete mode 100644 internal/auth0/connection_mock.go delete mode 100644 internal/cli/connections.go delete mode 100644 internal/display/connections.go diff --git a/internal/auth0/auth0.go b/internal/auth0/auth0.go index ca0f44d07..4c69d64d3 100644 --- a/internal/auth0/auth0.go +++ b/internal/auth0/auth0.go @@ -13,7 +13,6 @@ type API struct { ActionExecution ActionExecutionAPI ActionBinding ActionBindingAPI Client ClientAPI - Connection ConnectionAPI Log LogAPI ResourceServer ResourceServerAPI } @@ -25,7 +24,6 @@ func NewAPI(m *management.Management) *API { ActionExecution: m.ActionExecution, ActionBinding: m.ActionBinding, Client: m.Client, - Connection: m.Connection, Log: m.Log, ResourceServer: m.ResourceServer, } diff --git a/internal/auth0/connection.go b/internal/auth0/connection.go deleted file mode 100644 index 80a611551..000000000 --- a/internal/auth0/connection.go +++ /dev/null @@ -1,26 +0,0 @@ -//go:generate mockgen -source=connection.go -destination=connection_mock.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) error - - // Read retrieves a connection by its id. - Read(id string, opts ...management.RequestOption) (c *management.Connection, err error) - - // List all connections. - List(opts ...management.RequestOption) (c *management.ConnectionList, err error) - - // Update a connection. - Update(id string, c *management.Connection, opts ...management.RequestOption) (err error) - - // Delete a connection and all its users. - Delete(id string, opts ...management.RequestOption) (err error) - - // ReadByName retrieves a connection by its name. This is a helper method when a - // connection id is not readily available. - ReadByName(name string, opts ...management.RequestOption) (*management.Connection, error) -} diff --git a/internal/auth0/connection_mock.go b/internal/auth0/connection_mock.go deleted file mode 100644 index d369a5c14..000000000 --- a/internal/auth0/connection_mock.go +++ /dev/null @@ -1,150 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: connection.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" -) - -// MockConnectionAPI is a mock of ConnectionAPI interface -type MockConnectionAPI struct { - ctrl *gomock.Controller - recorder *MockConnectionAPIMockRecorder -} - -// MockConnectionAPIMockRecorder is the mock recorder for MockConnectionAPI -type MockConnectionAPIMockRecorder struct { - mock *MockConnectionAPI -} - -// NewMockConnectionAPI creates a new mock instance -func NewMockConnectionAPI(ctrl *gomock.Controller) *MockConnectionAPI { - mock := &MockConnectionAPI{ctrl: ctrl} - mock.recorder = &MockConnectionAPIMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockConnectionAPI) EXPECT() *MockConnectionAPIMockRecorder { - return m.recorder -} - -// Create mocks base method -func (m *MockConnectionAPI) Create(c *management.Connection, 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 *MockConnectionAPIMockRecorder) 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((*MockConnectionAPI)(nil).Create), varargs...) -} - -// Read mocks base method -func (m *MockConnectionAPI) Read(id string, opts ...management.RequestOption) (*management.Connection, 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.Connection) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Read indicates an expected call of Read -func (mr *MockConnectionAPIMockRecorder) 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((*MockConnectionAPI)(nil).Read), varargs...) -} - -// List mocks base method -func (m *MockConnectionAPI) List(opts ...management.RequestOption) (*management.ConnectionList, 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.ConnectionList) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// List indicates an expected call of List -func (mr *MockConnectionAPIMockRecorder) List(opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockConnectionAPI)(nil).List), opts...) -} - -// Update mocks base method -func (m *MockConnectionAPI) Update(id string, c *management.Connection, 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 *MockConnectionAPIMockRecorder) 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((*MockConnectionAPI)(nil).Update), varargs...) -} - -// Delete mocks base method -func (m *MockConnectionAPI) Delete(id string, opts ...management.RequestOption) 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 *MockConnectionAPIMockRecorder) 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((*MockConnectionAPI)(nil).Delete), varargs...) -} - -// ReadByName mocks base method -func (m *MockConnectionAPI) ReadByName(name string, opts ...management.RequestOption) (*management.Connection, error) { - m.ctrl.T.Helper() - varargs := []interface{}{name} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "ReadByName", varargs...) - ret0, _ := ret[0].(*management.Connection) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ReadByName indicates an expected call of ReadByName -func (mr *MockConnectionAPIMockRecorder) ReadByName(name interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{name}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadByName", reflect.TypeOf((*MockConnectionAPI)(nil).ReadByName), varargs...) -} diff --git a/internal/cli/connections.go b/internal/cli/connections.go deleted file mode 100644 index fe44dd34f..000000000 --- a/internal/cli/connections.go +++ /dev/null @@ -1,48 +0,0 @@ -package cli - -import ( - "github.com/auth0/auth0-cli/internal/ansi" - "github.com/spf13/cobra" - "gopkg.in/auth0.v5/management" -) - -func connectionsCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "connections", - Short: "Manage resources for connections", - } - - cmd.SetUsageTemplate(resourceUsageTemplate()) - cmd.AddCommand(listConnectionsCmd(cli)) - - return cmd -} - -func listConnectionsCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "list", - Short: "List existing connections", - Long: `auth0 connections list -Lists your existing connections. To create one try: - - auth0 connections create -`, - RunE: func(cmd *cobra.Command, args []string) error { - var list *management.ConnectionList - err := ansi.Spinner("Loading connections", func() error { - var err error - list, err = cli.api.Connection.List() - return err - }) - - if err != nil { - return err - } - - cli.renderer.ConnectionList(list.Connections) - return nil - }, - } - - return cmd -} diff --git a/internal/cli/root.go b/internal/cli/root.go index f50b60919..9a9e113de 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -65,7 +65,6 @@ func Execute() { rootCmd.AddCommand(tryLoginCmd(cli)) rootCmd.AddCommand(logsCmd(cli)) rootCmd.AddCommand(actionsCmd(cli)) - rootCmd.AddCommand(connectionsCmd(cli)) rootCmd.AddCommand(getTokenCmd(cli)) // keep completion at the bottom: diff --git a/internal/display/connections.go b/internal/display/connections.go deleted file mode 100644 index f2125f8e4..000000000 --- a/internal/display/connections.go +++ /dev/null @@ -1,37 +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 connectionView struct { - Name string - Strategy string - ConnectionID string -} - -func (v *connectionView) AsTableHeader() []string { - return []string{"Name", "Type", "Connection ID"} -} - -func (v *connectionView) AsTableRow() []string { - return []string{v.Name, v.Strategy, ansi.Faint(v.ConnectionID)} -} - -func (r *Renderer) ConnectionList(connections []*management.Connection) { - r.Heading(ansi.Bold(r.Tenant), "connections\n") - - var res []View - for _, c := range connections { - res = append(res, &connectionView{ - Name: auth0.StringValue(c.Name), - Strategy: auth0.StringValue(c.Strategy), - ConnectionID: auth0.StringValue(c.ID), - }) - - } - - r.Results(res) -}