コード例 #1
0
ファイル: accounts.go プロジェクト: devx/kumoru-sdk-go
//Show displays the details of an Account.
func Show(cmd *cli.Cmd) {
	email := cmd.String(cli.StringArg{
		Name:      "EMAIL",
		Desc:      "email address",
		HideValue: true,
	})

	cmd.Action = func() {
		a := authorization.Account{
			Email: *email,
		}

		account, resp, errs := a.ShowAcct()

		if len(errs) > 0 {
			log.Fatalf("Could not retrieve account: %s", errs[0])
		}

		if resp.StatusCode != 200 {
			log.Fatalf("Could not retrieve account: %s", resp.Status)
		}

		printAccountDetail(account)
	}
}
コード例 #2
0
ファイル: accounts.go プロジェクト: devx/kumoru-sdk-go
//ResetPassword requests the password reset operation to start.
func ResetPassword(cmd *cli.Cmd) {
	email := cmd.String(cli.StringArg{
		Name:      "EMAIL",
		Desc:      "email address",
		HideValue: true,
	})

	cmd.Action = func() {
		a := authorization.Account{
			Email: *email,
		}

		account, resp, errs := a.ResetPassword()

		if len(errs) > 0 {
			log.Fatalf("Could not retrieve account: %s", errs[0])
		}

		if resp.StatusCode != 204 {
			log.Fatalf("Could not reset account password: %s", resp.Status)
		}

		fmt.Println("Password reset instructions sent to:", account.Email)
	}
}
コード例 #3
0
ファイル: accounts.go プロジェクト: devx/kumoru-sdk-go
//Create an Account.
func Create(cmd *cli.Cmd) {
	email := cmd.String(cli.StringArg{
		Name:      "EMAIL",
		Desc:      "email address",
		HideValue: true,
	})

	fName := cmd.String(cli.StringOpt{
		Name:      "f first-name",
		Desc:      "Given Name",
		HideValue: true,
	})

	lName := cmd.String(cli.StringOpt{
		Name:      "l last-name",
		Desc:      "Last Name",
		HideValue: true,
	})

	password := cmd.String(cli.StringOpt{
		Name:      "p password",
		Desc:      "Password",
		HideValue: true,
	})

	cmd.Action = func() {

		if *password == "" {
			*password = passwordPrompt()
			fmt.Println("\n")
		}

		l := authorization.Account{
			Email:     *email,
			GivenName: *fName,
			Surname:   *lName,
		}

		account, resp, errs := l.CreateAcct(*password)

		if len(errs) > 0 {
			log.Fatalf("Could not create account: %s", errs[0])
		}

		if resp.StatusCode != 201 {
			log.Fatalf("Could not create account: %s", resp.Status)
		}

		printAccountDetail(account)
	}
}
コード例 #4
0
ファイル: tokens.go プロジェクト: kumoru/kumoru-sdk-go
func Create(cmd *cli.Cmd) {
	force := cmd.Bool(cli.BoolOpt{
		Name:      "f force",
		Desc:      "If a set of tokens already exist in ~/.kumoru/config, overwrite them.",
		Value:     false,
		HideValue: true,
	})
	dontSave := cmd.Bool(cli.BoolOpt{
		Name:      "d dont_save",
		Desc:      "Output tokens to screen instead of saving to configuration",
		Value:     false,
		HideValue: true,
	})

	cmd.Action = func() {
		usrHome := os.Getenv("HOME")
		directory := usrHome + "/.kumoru/"
		filename := "config"
		kfile := directory + filename

		if *dontSave == false {
			if kumoru.HasTokens(kfile, "tokens") == true && *force == false {
				fmt.Println(kfile, "configuration file already exists, or tokens already exist.")
				fmt.Println("Please see help for additonal options.")
				os.Exit(1)
			}
		}

		username, password := credentials()
		token, resp, body, errs := authorization.GetTokens(username, password)

		if errs != nil {
			log.Fatalf("Could not retrieve new tokens: %s", errs)
		}

		if resp.StatusCode != 201 {
			log.Fatalf("Could not retrieve tokens: %s", resp.Status)
			os.Exit(1)
		}

		switch *dontSave {
		default:
			errs := kumoru.SaveTokens(directory, filename, "tokens", kumoru.Ktokens{
				Public:  token,
				Private: body,
			})

			if errs != nil {
				log.Fatalf("Could not save tokens to file: %s", errs)
			}
		case true:
			fmt.Printf("\n[tokens]\n")
			fmt.Printf("kumoru_token_public=%s\n", token)
			fmt.Printf("kumoru_token_private=%s\n", body)
		}

		a := authorization.Account{
			Email: username,
		}

		account, _, errs := a.Show()

		if errs != nil {
			log.Fatalf("Could not retrieve new tokens: %s", errs)
		}

		switch *dontSave {
		default:
			errs := kumoru.SaveRole(directory, filename, "auth", account.RoleUUID)

			if errs != nil {
				log.Fatalf("Could not save Role to file: %s", errs)
			}

			fmt.Printf("\nTokens saved to %s\n", kfile)
		case true:
			fmt.Printf("\n[auth]\n")
			fmt.Printf("active_role=%s\n", account.RoleUUID)
		}

	}

}