login

package
v1.0.48-rc Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LoginCmd = &cobra.Command{
		Use:     "login",
		Short:   short,
		Long:    long,
		Example: example,
		PreRunE: internal.CheckAPIAndCLIVersion,
		RunE: func(cmd *cobra.Command, args []string) error {
			org, err := cmd.Flags().GetString("org")
			if err != nil {
				return errors.Wrap(err, "unable to get org flag")
			}
			email, err := cmd.Flags().GetString("email")
			if err != nil {
				return errors.Wrap(err, "unable to get email flag")
			}
			password, err := cmd.Flags().GetString("password")
			if err != nil {
				return errors.Wrap(err, "unable to get password flag")
			}

			api := common.NewAPI()
			m := middleware.NewMiddleware(api)

			session, err := m.Login(email, password)
			if err != nil {
				return errors.Wrapf(err, "unable to log user: %s", email)
			}

			conf, _ := config.ReadConfig()

			conf.Token = *session.Token
			if err := config.WriteConfig(conf); err != nil {
				return errors.Wrap(err, "unable to save config")
			}

			if len(org) != 0 {
				orgSession, err := m.LoginOrg(org, email, password)
				if err != nil {
					return errors.Wrapf(err, "unable to log user: %s", email)
				}

				conf, err := config.ReadConfig()
				if err != nil {
					return errors.Wrap(err, "unable to read config: %s")
				}
				conf.Organizations[org] = config.Organization{
					Token: *orgSession.Token,
				}
				if err := config.WriteConfig(conf); err != nil {
					return errors.Wrap(err, "unable to save config")
				}
			}
			return nil
		},
	}
)

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