2023-08-11 09:18:59 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cloudcmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/azureshared"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/gcpshared"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/openstack"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/config"
|
2023-12-11 09:55:44 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/constellation"
|
2023-08-11 09:18:59 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/file"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetMarshaledServiceAccountURI returns the service account URI for the given cloud provider.
|
2023-10-24 09:39:18 -04:00
|
|
|
func GetMarshaledServiceAccountURI(config *config.Config, fileHandler file.Handler) (string, error) {
|
2023-12-11 09:55:44 -05:00
|
|
|
payload := constellation.ServiceAccountPayload{}
|
2023-10-24 09:39:18 -04:00
|
|
|
switch config.GetProvider() {
|
2023-08-11 09:18:59 -04:00
|
|
|
case cloudprovider.GCP:
|
|
|
|
var key gcpshared.ServiceAccountKey
|
|
|
|
if err := fileHandler.ReadJSON(config.Provider.GCP.ServiceAccountKeyPath, &key); err != nil {
|
2023-10-24 09:39:18 -04:00
|
|
|
return "", fmt.Errorf("reading service account key: %w", err)
|
2023-08-11 09:18:59 -04:00
|
|
|
}
|
2023-12-11 09:55:44 -05:00
|
|
|
payload.GCP = key
|
2023-08-11 09:18:59 -04:00
|
|
|
|
2023-10-24 09:39:18 -04:00
|
|
|
case cloudprovider.Azure:
|
2023-12-11 09:55:44 -05:00
|
|
|
payload.Azure = azureshared.ApplicationCredentials{
|
2023-08-11 09:18:59 -04:00
|
|
|
TenantID: config.Provider.Azure.TenantID,
|
|
|
|
Location: config.Provider.Azure.Location,
|
2023-12-11 09:55:44 -05:00
|
|
|
PreferredAuthMethod: azureshared.AuthMethodUserAssignedIdentity,
|
2023-08-11 09:18:59 -04:00
|
|
|
UamiResourceID: config.Provider.Azure.UserAssignedIdentity,
|
|
|
|
}
|
|
|
|
|
|
|
|
case cloudprovider.OpenStack:
|
2023-12-11 09:55:44 -05:00
|
|
|
payload.OpenStack = openstack.AccountKey{
|
2023-08-11 09:18:59 -04:00
|
|
|
AuthURL: config.Provider.OpenStack.AuthURL,
|
|
|
|
Username: config.Provider.OpenStack.Username,
|
|
|
|
Password: config.Provider.OpenStack.Password,
|
|
|
|
ProjectID: config.Provider.OpenStack.ProjectID,
|
|
|
|
ProjectName: config.Provider.OpenStack.ProjectName,
|
|
|
|
UserDomainName: config.Provider.OpenStack.UserDomainName,
|
|
|
|
ProjectDomainName: config.Provider.OpenStack.ProjectDomainName,
|
|
|
|
RegionName: config.Provider.OpenStack.RegionName,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-12-11 09:55:44 -05:00
|
|
|
return constellation.MarshalServiceAccountURI(config.GetProvider(), payload)
|
2023-08-11 09:18:59 -04:00
|
|
|
}
|