コード例 #1
0
ファイル: ondemand.go プロジェクト: nmcclain/goair
func authenticate(force bool) (client *govcloudair.Client, err error) {
	client, err = govcloudair.NewClient()
	if err != nil {
		return client, fmt.Errorf("error with NewClient: %s", err)
	}

	getValue := clue.GetValue{}
	if err := clue.DecodeGobFile("goair_client", &getValue); err != nil {
		return &govcloudair.Client{}, fmt.Errorf("Problem with client decodeGobFile: %v", err)
	}

	if force || (getValue.VarMap["VAToken"] == nil && getValue.VarMap["VCDToken"] == nil) {
		err = client.AuthenticateOD("", "")
		if err != nil {
			return client, fmt.Errorf("error Authenticating: %s", err)
		}

		err = clue.EncodeGobFile("goair_client", clue.UseValue{
			VarMap: map[string]string{
				"VAToken": client.VAToken,
			},
		})
	} else {
		if getValue.VarMap["VAToken"] != nil {
			client.VAToken = *getValue.VarMap["VAToken"]
		}
	}

	return client, err
}
コード例 #2
0
ファイル: vcd.go プロジェクト: nmcclain/goair
func authenticatevcd(force bool) (client *govcloudair.Client, err error) {
	client, err = govcloudair.NewClient()
	if err != nil {
		return client, fmt.Errorf("error with NewClient: %s", err)
	}

	getValue := clue.GetValue{}
	if err := clue.DecodeGobFile("goair_client", &getValue); err != nil {
		return &govcloudair.Client{}, fmt.Errorf("Problem with client decodeGobFile: %v", err)
	}

	var (
		orgname    = viper.GetString("orgname")
		sessionuri = viper.GetString("sessionuri")
	)

	if force || getValue.VarMap["VCDToken"] == nil {
		instanceAttributes := vcatypes.InstanceAttributes{OrgName: orgname, SessionURI: sessionuri}
		err = client.GetBackendAuthOD(instanceAttributes)
		if err != nil {
			return client, fmt.Errorf("error Authenticating: %s", err)
		}

		err = clue.EncodeGobFile("goair_client", clue.UseValue{
			VarMap: map[string]string{
				"VCDToken":      client.VCDToken,
				"VCDORGHREF":    client.VCDORGHREF.String(),
				"VCDAuthHeader": client.VCDAuthHeader,
			},
		})
	} else {
		client.VCDToken = *getValue.VarMap["VCDToken"]

		orgUri, err := url.ParseRequestURI(*getValue.VarMap["VCDORGHREF"])
		if err != nil {
			return client, fmt.Errorf("cannot parse endpoint coming from VCDORGHREF")
		}

		client.VCDORGHREF = *orgUri
		client.VCDAuthHeader = *getValue.VarMap["VCDAuthHeader"]
	}

	return client, err
}