Example #1
0
func (c *loginCmd) Main() {
	schemes := NewSchemeMap()

	if c.url == "" {
		Usage(c, "--url is required")
	}
	if c.user == "" {
		Usage(c, "--user is required")
	}
	if c.homeDir == "" {
		c.homeDir = path.Join(os.Getenv("HOME"), ".affinity")
	}

	serverUrl, err := url.Parse(c.url)
	if err != nil {
		die(err)
	}
	schemes.Register(usso.NewOauthCli(fmt.Sprintf("affinity@%s", serverUrl.Host),
		&PasswordPrompter{}))

	user, err := ParseUser(c.user)
	if err != nil {
		die(err)
	}

	scheme := schemes.Token(user.Scheme)
	if scheme == nil {
		die(fmt.Errorf("Scheme '%s' is not supported", user.Scheme))
	}

	token, err := scheme.Authorize(user)
	if err != nil {
		die(err)
	}

	authStore, err := client.NewFileAuthStore(c.homeDir)
	if err != nil {
		die(err)
	}

	err = authStore.Set(token, serverUrl.Host)
	if err != nil {
		die(err)
	}
}
Example #2
0
func (c *groupCmd) Main(h cmdHandler) {
	if c.url == "" {
		Usage(h, "--url is required")
	}
	if c.group == "" {
		Usage(h, "--group is required")
	}
	if c.homeDir == "" {
		c.homeDir = path.Join(os.Getenv("HOME"), ".affinity")
	}

	serverUrl, err := url.Parse(c.url)
	if err != nil {
		die(err)
	}

	authStore, err := client.NewFileAuthStore(c.homeDir)
	if err != nil {
		die(err)
	}
	c.client = group.NewGroupClient(serverUrl, authStore)
}