Skip to content

Commit

Permalink
[wip] Use common 'apply' backend for init and upgrades
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Weiße <[email protected]>
  • Loading branch information
daniel-weisse committed Oct 12, 2023
1 parent 6171376 commit d4c0e19
Show file tree
Hide file tree
Showing 7 changed files with 893 additions and 20 deletions.
1 change: 0 additions & 1 deletion cli/internal/cloudcmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ go_library(
importpath = "github.com/edgelesssys/constellation/v2/cli/internal/cloudcmd",
visibility = ["//cli:__subpackages__"],
deps = [
"//cli/internal/cmd/pathprefix",
"//cli/internal/libvirt",
"//cli/internal/state",
"//cli/internal/terraform",
Expand Down
20 changes: 5 additions & 15 deletions cli/internal/cloudcmd/serviceaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package cloudcmd
import (
"fmt"

"github.com/edgelesssys/constellation/v2/cli/internal/cmd/pathprefix"
"github.com/edgelesssys/constellation/v2/internal/cloud/azureshared"
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/v2/internal/cloud/gcpshared"
Expand All @@ -19,27 +18,19 @@ import (
)

// GetMarshaledServiceAccountURI returns the service account URI for the given cloud provider.
func GetMarshaledServiceAccountURI(provider cloudprovider.Provider, config *config.Config, pf pathprefix.PathPrefixer, log debugLog, fileHandler file.Handler,
) (string, error) {
log.Debugf("Getting service account URI")
switch provider {
func GetMarshaledServiceAccountURI(config *config.Config, fileHandler file.Handler) (string, error) {
switch config.GetProvider() {
case cloudprovider.GCP:
log.Debugf("Handling case for GCP")
log.Debugf("GCP service account key path %s", pf.PrefixPrintablePath(config.Provider.GCP.ServiceAccountKeyPath))

var key gcpshared.ServiceAccountKey
if err := fileHandler.ReadJSON(config.Provider.GCP.ServiceAccountKeyPath, &key); err != nil {
return "", fmt.Errorf("reading service account key from path %q: %w", pf.PrefixPrintablePath(config.Provider.GCP.ServiceAccountKeyPath), err)
return "", fmt.Errorf("reading service account key: %w", err)
}
log.Debugf("Read GCP service account key from path")
return key.ToCloudServiceAccountURI(), nil

case cloudprovider.AWS:
log.Debugf("Handling case for AWS")
return "", nil // AWS does not need a service account URI
case cloudprovider.Azure:
log.Debugf("Handling case for Azure")

case cloudprovider.Azure:
authMethod := azureshared.AuthMethodUserAssignedIdentity

creds := azureshared.ApplicationCredentials{
Expand All @@ -64,10 +55,9 @@ func GetMarshaledServiceAccountURI(provider cloudprovider.Provider, config *conf
return creds.ToCloudServiceAccountURI(), nil

case cloudprovider.QEMU:
log.Debugf("Handling case for QEMU")
return "", nil // QEMU does not use service account keys

default:
return "", fmt.Errorf("unsupported cloud provider %q", provider)
return "", fmt.Errorf("unsupported cloud provider %q", config.GetProvider())
}
}
2 changes: 2 additions & 0 deletions cli/internal/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("//bazel/go:go_test.bzl", "go_test")
go_library(
name = "cmd",
srcs = [
"apply.go",
"cloud.go",
"cmd.go",
"config.go",
Expand Down Expand Up @@ -95,6 +96,7 @@ go_library(
"@com_github_spf13_pflag//:pflag",
"@in_gopkg_yaml_v3//:yaml_v3",
"@io_k8s_apiextensions_apiserver//pkg/apis/apiextensions/v1:apiextensions",
"@io_k8s_apimachinery//pkg/api/errors",
"@io_k8s_apimachinery//pkg/runtime",
"@io_k8s_client_go//tools/clientcmd",
"@io_k8s_client_go//tools/clientcmd/api/latest",
Expand Down
Loading

0 comments on commit d4c0e19

Please sign in to comment.