mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-08 06:52:26 -04:00
AB#2523 Refactor GCP metadata/cloud API (#387)
* Refactor GCP metadata/cloud API * Remove cloud controller manager from metadata package * Remove PublicIP * Move shared cloud packages * Remove dead code Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
e9fecec0bc
commit
c9873f2bfb
54 changed files with 1587 additions and 3791 deletions
57
internal/cloud/azureshared/appcredentials.go
Normal file
57
internal/cloud/azureshared/appcredentials.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package azureshared
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// ApplicationCredentials is a set of Azure AD application credentials.
|
||||
// It is the equivalent of a service account key in other cloud providers.
|
||||
type ApplicationCredentials struct {
|
||||
TenantID string
|
||||
AppClientID string
|
||||
ClientSecretValue string
|
||||
Location string
|
||||
}
|
||||
|
||||
// ApplicationCredentialsFromURI converts a cloudServiceAccountURI into Azure ApplicationCredentials.
|
||||
func ApplicationCredentialsFromURI(cloudServiceAccountURI string) (ApplicationCredentials, error) {
|
||||
uri, err := url.Parse(cloudServiceAccountURI)
|
||||
if err != nil {
|
||||
return ApplicationCredentials{}, err
|
||||
}
|
||||
if uri.Scheme != "serviceaccount" {
|
||||
return ApplicationCredentials{}, fmt.Errorf("invalid service account URI: invalid scheme: %s", uri.Scheme)
|
||||
}
|
||||
if uri.Host != "azure" {
|
||||
return ApplicationCredentials{}, fmt.Errorf("invalid service account URI: invalid host: %s", uri.Host)
|
||||
}
|
||||
query := uri.Query()
|
||||
return ApplicationCredentials{
|
||||
TenantID: query.Get("tenant_id"),
|
||||
AppClientID: query.Get("client_id"),
|
||||
ClientSecretValue: query.Get("client_secret"),
|
||||
Location: query.Get("location"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ToCloudServiceAccountURI converts the ApplicationCredentials into a cloud service account URI.
|
||||
func (c ApplicationCredentials) ToCloudServiceAccountURI() string {
|
||||
query := url.Values{}
|
||||
query.Add("tenant_id", c.TenantID)
|
||||
query.Add("client_id", c.AppClientID)
|
||||
query.Add("client_secret", c.ClientSecretValue)
|
||||
query.Add("location", c.Location)
|
||||
uri := url.URL{
|
||||
Scheme: "serviceaccount",
|
||||
Host: "azure",
|
||||
RawQuery: query.Encode(),
|
||||
}
|
||||
return uri.String()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue