constellation/coordinator/cloudprovider/azure/serviceaccounturi.go

30 lines
948 B
Go
Raw Normal View History

package azure
import (
"fmt"
"net/url"
"github.com/edgelesssys/constellation/cli/azure/client"
)
// getApplicationCredentials converts a cloudServiceAccountURI into Azure ApplicationCredentials.
func getApplicationCredentials(cloudServiceAccountURI string) (client.ApplicationCredentials, error) {
uri, err := url.Parse(cloudServiceAccountURI)
if err != nil {
return client.ApplicationCredentials{}, err
}
if uri.Scheme != "serviceaccount" {
return client.ApplicationCredentials{}, fmt.Errorf("invalid service account URI: invalid scheme: %s", uri.Scheme)
}
if uri.Host != "azure" {
return client.ApplicationCredentials{}, fmt.Errorf("invalid service account URI: invalid host: %s", uri.Host)
}
query := uri.Query()
return client.ApplicationCredentials{
TenantID: query.Get("tenant_id"),
ClientID: query.Get("client_id"),
ClientSecret: query.Get("client_secret"),
Location: query.Get("location"),
}, nil
}