github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/client/cli/auth/cli.go (about)

     1  package cli
     2  
     3  import (
     4  	"github.com/tickoalcantara12/micro/v3/cmd"
     5  	"github.com/tickoalcantara12/micro/v3/util/helper"
     6  	"github.com/urfave/cli/v2"
     7  	// imported specifically for signup
     8  )
     9  
    10  var (
    11  	// ruleFlags are provided to commands which create or delete rules
    12  	ruleFlags = []cli.Flag{
    13  		&cli.StringFlag{
    14  			Name:  "scope",
    15  			Usage: "the scope to amend, e.g. 'user' or '*', leave blank to make public",
    16  		},
    17  		&cli.StringFlag{
    18  			Name:  "resource",
    19  			Usage: "The resource to amend in the format type:name:endpoint, e.g. service:auth:*",
    20  		},
    21  		&cli.StringFlag{
    22  			Name:  "access",
    23  			Usage: "The access level, must be granted or denied",
    24  			Value: "granted",
    25  		},
    26  		&cli.IntFlag{
    27  			Name:  "priority",
    28  			Usage: "The priority level, default is 0, the greater the number the higher the priority",
    29  			Value: 0,
    30  		},
    31  	}
    32  	// accountFlags are provided to the create account command
    33  	accountFlags = []cli.Flag{
    34  		&cli.StringFlag{
    35  			Name:  "secret",
    36  			Usage: "The account secret (password)",
    37  		},
    38  		&cli.StringSliceFlag{
    39  			Name:  "scopes",
    40  			Usage: "Comma separated list of scopes to give the account",
    41  		},
    42  	}
    43  )
    44  
    45  func init() {
    46  	cmd.Register(
    47  		&cli.Command{
    48  			Name:   "auth",
    49  			Usage:  "Manage authentication, accounts and rules",
    50  			Action: helper.UnexpectedSubcommand,
    51  			Subcommands: []*cli.Command{
    52  				{
    53  					Name:  "list",
    54  					Usage: "List auth resources",
    55  					Subcommands: []*cli.Command{
    56  						{
    57  							Name:   "rules",
    58  							Usage:  "List auth rules",
    59  							Action: listRules,
    60  						},
    61  						{
    62  							Name:   "accounts",
    63  							Usage:  "List auth accounts",
    64  							Action: listAccounts,
    65  						},
    66  					},
    67  				},
    68  				{
    69  					Name:  "create",
    70  					Usage: "Create an auth resource",
    71  					Subcommands: []*cli.Command{
    72  						{
    73  							Name:   "rule",
    74  							Usage:  "Create an auth rule",
    75  							Flags:  ruleFlags,
    76  							Action: createRule,
    77  						},
    78  						{
    79  							Name:  "account",
    80  							Usage: "Create an auth account",
    81  							Flags: append(accountFlags, &cli.StringFlag{
    82  								Name:  "namespace",
    83  								Usage: "Namespace to use when creating the account",
    84  							}),
    85  							Action: createAccount,
    86  						},
    87  					},
    88  				},
    89  				{
    90  					Name:  "delete",
    91  					Usage: "Delete a auth resource",
    92  					Subcommands: []*cli.Command{
    93  						{
    94  							Name:   "rule",
    95  							Usage:  "Delete an auth rule",
    96  							Flags:  ruleFlags,
    97  							Action: deleteRule,
    98  						},
    99  						{
   100  							Name:   "account",
   101  							Usage:  "Delete an auth account",
   102  							Flags:  accountFlags,
   103  							Action: deleteAccount,
   104  						},
   105  					},
   106  				},
   107  				{
   108  					Name:  "update",
   109  					Usage: "Update an auth resource",
   110  					Subcommands: []*cli.Command{
   111  						{
   112  							Name:  "secret",
   113  							Usage: "Update an auth account secret",
   114  							Flags: append(accountFlags,
   115  								&cli.StringFlag{
   116  									Name:  "namespace",
   117  									Usage: "Namespace to use when updating the account",
   118  								},
   119  								&cli.StringFlag{
   120  									Name:  "old_secret",
   121  									Usage: "The old account secret (password)",
   122  								},
   123  								&cli.StringFlag{
   124  									Name:  "new_secret",
   125  									Usage: "The new account secret (password)",
   126  								},
   127  							),
   128  							Action: updateAccount,
   129  						},
   130  					},
   131  				},
   132  			},
   133  		},
   134  		&cli.Command{
   135  			Name:        "login",
   136  			Usage:       `Interactive login flow.`,
   137  			Description: "Run 'micro login' for the server",
   138  			Action:      login,
   139  			Flags: []cli.Flag{
   140  				&cli.StringFlag{
   141  					Name:  "password",
   142  					Usage: "Password to use for login. If not provided, will be asked for during login. Useful for automated scripts",
   143  				},
   144  				&cli.StringFlag{
   145  					Name:    "username",
   146  					Usage:   "Username to use for login",
   147  					Aliases: []string{"email"},
   148  				},
   149  			},
   150  		},
   151  		&cli.Command{
   152  			Name:        "logout",
   153  			Usage:       `Logout.`,
   154  			Description: "Use 'micro logout' to delete your token in your current environment.",
   155  			Action:      logout,
   156  		},
   157  	)
   158  }