cmd

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ExportCommand set the profile enabled
	ExportCommand = &cli.Command{
		Name:  "export",
		Usage: "return the shell command to export AWS environment variables. e.g) awscred export [PROFILE]",
		Flags: []cli.Flag{
			&cli.IntFlag{
				Name:    "port",
				Aliases: []string{"p"},
				Value:   defaultPort,
				Usage:   "the port of server.",
			},
			&cli.BoolFlag{
				Name:    "debug",
				Aliases: []string{"d"},
				Value:   false,
				Usage:   "debug mode.",
			},
		},
		Action: func(c *cli.Context) error {
			var (
				address string
				profile string
			)
			if c.Bool("debug") {
				setDebugMode()
			}

			address = "localhost:" + strconv.Itoa(c.Int("port"))
			profile = c.Args().Get(0)

			return export(address, profile)
		},
	}
)
View Source
var (
	// GenCommand generate a new session token.
	GenCommand = &cli.Command{
		Name:  "gen",
		Usage: "generate a new session token and cache the token in the config file. e.g) awscred gen --code CODE PROFILE",
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:     "code",
				Aliases:  []string{"c"},
				Value:    "",
				Usage:    "The  value  provided  by  the MFA device.",
				Required: true,
			},
			&cli.IntFlag{
				Name:    "port",
				Aliases: []string{"p"},
				Value:   defaultPort,
				Usage:   "the port of server.",
			},
			&cli.BoolFlag{
				Name:    "debug",
				Aliases: []string{"d"},
				Value:   false,
				Usage:   "debug mode.",
			},
		},
		Action: func(c *cli.Context) error {
			var (
				address string
				profile string
				code    string
			)
			if c.Bool("debug") {
				setDebugMode()
			}

			address = "localhost:" + strconv.Itoa(c.Int("port"))
			profile = c.Args().Get(0)
			code = c.String("code")

			return gen(address, profile, code)
		},
	}
)
View Source
var (
	// InfoCommand generate a new session token.
	InfoCommand = &cli.Command{
		Name:  "info",
		Usage: "show the information for each profile.",
		Flags: []cli.Flag{
			&cli.IntFlag{
				Name:    "port",
				Aliases: []string{"p"},
				Value:   defaultPort,
				Usage:   "the port of server.",
			},
			&cli.BoolFlag{
				Name:    "debug",
				Aliases: []string{"d"},
				Value:   false,
				Usage:   "debug mode.",
			},
		},
		Action: func(c *cli.Context) error {
			var (
				address string
			)
			if c.Bool("debug") {
				setDebugMode()
			}

			address = "localhost:" + strconv.Itoa(c.Int("port"))
			return info(address)
		},
	}
)
View Source
var (
	// OffCommand set the profile disabled
	OffCommand = &cli.Command{
		Name:  "off",
		Usage: "set disabled the session token of profile to be reflected on the awscred credentials. e.g) awscred off PROFILE",
		Flags: []cli.Flag{
			&cli.IntFlag{
				Name:    "port",
				Aliases: []string{"p"},
				Value:   defaultPort,
				Usage:   "the port of server.",
			},
			&cli.BoolFlag{
				Name:    "debug",
				Aliases: []string{"d"},
				Value:   false,
				Usage:   "debug mode.",
			},
		},
		Action: func(c *cli.Context) error {
			var (
				address string
				profile string
			)
			if c.Bool("debug") {
				setDebugMode()
			}

			address = "localhost:" + strconv.Itoa(c.Int("port"))
			profile = c.Args().Get(0)

			return off(address, profile)
		},
	}
)
View Source
var (
	// OnCommand set the profile enabled
	OnCommand = &cli.Command{
		Name:  "on",
		Usage: "set enabled the session token of profile to be reflected on the awscred credentials. e.g) awscred on PROFILE",
		Flags: []cli.Flag{
			&cli.IntFlag{
				Name:    "port",
				Aliases: []string{"p"},
				Value:   defaultPort,
				Usage:   "the port of server.",
			},
			&cli.BoolFlag{
				Name:    "debug",
				Aliases: []string{"d"},
				Value:   false,
				Usage:   "debug mode.",
			},
		},
		Action: func(c *cli.Context) error {
			var (
				address string
				profile string
			)
			if c.Bool("debug") {
				setDebugMode()
			}

			address = "localhost:" + strconv.Itoa(c.Int("port"))
			profile = c.Args().Get(0)

			return on(address, profile)
		},
	}
)
View Source
var (
	// PingCommand send the ping to server
	PingCommand = &cli.Command{
		Name:  "ping",
		Usage: "send the ping to daemon",
		Flags: []cli.Flag{
			&cli.IntFlag{
				Name:    "port",
				Aliases: []string{"p"},
				Value:   defaultPort,
				Usage:   "the port of server.",
			},
			&cli.BoolFlag{
				Name:    "debug",
				Aliases: []string{"d"},
				Value:   false,
				Usage:   "debug mode.",
			},
		},
		Action: func(c *cli.Context) error {
			var (
				address string
			)
			if c.Bool("debug") {
				setDebugMode()
			}

			address = "localhost:" + strconv.Itoa(c.Int("port"))

			return ping(address)
		},
	}
)
View Source
var (
	// RunCommand run a Daemon.
	RunCommand = &cli.Command{
		Name:  "run",
		Usage: "start a daemon to reflect session tokens on a new credentials.",
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:    "credentials",
				Aliases: []string{"c"},
				Value:   filepath.Join(homeDir, ".aws", "credentials"),
				Usage:   "the path of aws credentials file.",
			},
			&cli.StringFlag{
				Name:    "homedir",
				Aliases: []string{"dir"},
				Value:   filepath.Join(homeDir, ".awscred"),
				Usage:   "the path of awscred home directory.",
			},
			&cli.IntFlag{
				Name:    "port",
				Aliases: []string{"p"},
				Value:   defaultPort,
				Usage:   "the port of server.",
			},
			&cli.BoolFlag{
				Name:    "server-mode",
				Aliases: []string{"s"},
				Value:   false,
				Usage:   "run as the gRPC server, not daemon.",
			},
			&cli.BoolFlag{
				Name:    "debug",
				Aliases: []string{"d"},
				Value:   false,
				Usage:   "debug mode.",
			},
		},
		Action: func(c *cli.Context) error {
			var (
				err      error
				origCred string
				cred     string
				conf     string
				port     string
			)
			if c.Bool("debug") {
				setDebugMode()
			}

			if origCred, err = filepath.Abs(c.String("credentials")); err != nil {
				return fmt.Errorf("failed to the abs path of aws credentials: %s", err)
			}

			homedir := c.String("homedir")
			if _, err := os.Stat(homedir); os.IsNotExist(err) {
				os.Mkdir(homedir, 0755)
			}

			if cred, err = filepath.Abs(filepath.Join(homedir, "credentials")); err != nil {
				return fmt.Errorf("failed to the abs path of awscred credentials: %s", err)
			}

			if conf, err = filepath.Abs(filepath.Join(homedir, "config")); err != nil {
				return fmt.Errorf("failed to the abs path of awscred config: %s", err)
			}

			port = ":" + strconv.Itoa(c.Int("port"))

			if c.Bool("server-mode") {
				return runServer(origCred, cred, conf, port)
			}

			return runDaemon(homedir, origCred, cred, conf, port)
		},
	}
)
View Source
var (
	// SetCommand set the configuration of profile..
	SetCommand = &cli.Command{
		Name:  "set",
		Usage: "set the configuration which is related with the session token generation. e.g) awscred set --serial SERIAL PROFILE",
		Flags: []cli.Flag{
			&cli.BoolFlag{
				Name:  "on",
				Value: false,
				Usage: "set enalbed after setting.",
			},
			&cli.StringFlag{
				Name:     "serial",
				Aliases:  []string{"s"},
				Value:    "",
				Usage:    "the identification number of the MFA device that is associated with the IAM user.",
				Required: true,
			},
			&cli.IntFlag{
				Name:    "duration",
				Aliases: []string{"c"},
				Value:   43200,
				Usage:   "the  duration, in seconds, that the credentials should remain valid.",
			},
			&cli.IntFlag{
				Name:    "port",
				Aliases: []string{"p"},
				Value:   defaultPort,
				Usage:   "the port of server.",
			},
			&cli.BoolFlag{
				Name:    "debug",
				Aliases: []string{"d"},
				Value:   false,
				Usage:   "debug mode.",
			},
		},
		Action: func(c *cli.Context) error {
			var (
				address  string
				profile  string
				serial   string
				duration int64
			)
			if c.Bool("debug") {
				setDebugMode()
			}

			address = "localhost:" + strconv.Itoa(c.Int("port"))
			profile = c.Args().Get(0)
			serial = c.String("serial")
			duration = c.Int64("duration")

			if err := set(address, profile, serial, duration); err != nil {
				return err
			}

			if c.Bool("on") {
				return on(address, profile)
			}
			return nil
		},
	}
)
View Source
var (
	// TerminateCommand terminate the daemon
	TerminateCommand = &cli.Command{
		Name:  "terminate",
		Usage: "terminate the daemon if the daemon is running.",
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:    "homedir",
				Aliases: []string{"dir"},
				Value:   filepath.Join(homeDir, ".awscred"),
				Usage:   "the path of awscred home directory.",
			},
			&cli.BoolFlag{
				Name:    "debug",
				Aliases: []string{"d"},
				Value:   false,
				Usage:   "debug mode.",
			},
		},
		Action: func(c *cli.Context) error {
			if c.Bool("debug") {
				setDebugMode()
			}

			homedir := c.String("homedir")
			if _, err := os.Stat(homedir); os.IsNotExist(err) {
				return fmt.Errorf("there's no dir: %s", homedir)
			}

			return terminate(homedir)
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL