mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
Move cli/gcp to cli/internal/gcp
This commit is contained in:
parent
48b4f10207
commit
6cd93e4179
@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
azurecl "github.com/edgelesssys/constellation/cli/azure/client"
|
azurecl "github.com/edgelesssys/constellation/cli/azure/client"
|
||||||
gcpcl "github.com/edgelesssys/constellation/cli/gcp/client"
|
gcpcl "github.com/edgelesssys/constellation/cli/internal/gcp/client"
|
||||||
"github.com/edgelesssys/constellation/internal/state"
|
"github.com/edgelesssys/constellation/internal/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
azurecl "github.com/edgelesssys/constellation/cli/azure/client"
|
azurecl "github.com/edgelesssys/constellation/cli/azure/client"
|
||||||
"github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
|
"github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
|
||||||
gcpcl "github.com/edgelesssys/constellation/cli/gcp/client"
|
gcpcl "github.com/edgelesssys/constellation/cli/internal/gcp/client"
|
||||||
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
||||||
"github.com/edgelesssys/constellation/internal/gcpshared"
|
"github.com/edgelesssys/constellation/internal/gcpshared"
|
||||||
"github.com/edgelesssys/constellation/internal/state"
|
"github.com/edgelesssys/constellation/internal/state"
|
||||||
|
@ -7,9 +7,8 @@ import (
|
|||||||
|
|
||||||
azurecl "github.com/edgelesssys/constellation/cli/azure/client"
|
azurecl "github.com/edgelesssys/constellation/cli/azure/client"
|
||||||
"github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
|
"github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
|
||||||
"github.com/edgelesssys/constellation/cli/gcp"
|
"github.com/edgelesssys/constellation/cli/internal/gcp"
|
||||||
"github.com/edgelesssys/constellation/cli/gcp/client"
|
gcpcl "github.com/edgelesssys/constellation/cli/internal/gcp/client"
|
||||||
gcpcl "github.com/edgelesssys/constellation/cli/gcp/client"
|
|
||||||
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
||||||
"github.com/edgelesssys/constellation/internal/config"
|
"github.com/edgelesssys/constellation/internal/config"
|
||||||
"github.com/edgelesssys/constellation/internal/state"
|
"github.com/edgelesssys/constellation/internal/state"
|
||||||
@ -121,7 +120,7 @@ func (c *Creator) createGCP(ctx context.Context, cl gcpclient, config *config.Co
|
|||||||
return state.ConstellationState{}, err
|
return state.ConstellationState{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
createInput := client.CreateInstancesInput{
|
createInput := gcpcl.CreateInstancesInput{
|
||||||
CountCoordinators: coordCount,
|
CountCoordinators: coordCount,
|
||||||
CountNodes: nodeCount,
|
CountNodes: nodeCount,
|
||||||
ImageId: config.Provider.GCP.Image,
|
ImageId: config.Provider.GCP.Image,
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
azurecl "github.com/edgelesssys/constellation/cli/azure/client"
|
azurecl "github.com/edgelesssys/constellation/cli/azure/client"
|
||||||
gcpcl "github.com/edgelesssys/constellation/cli/gcp/client"
|
gcpcl "github.com/edgelesssys/constellation/cli/internal/gcp/client"
|
||||||
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
||||||
"github.com/edgelesssys/constellation/internal/config"
|
"github.com/edgelesssys/constellation/internal/config"
|
||||||
"github.com/edgelesssys/constellation/internal/state"
|
"github.com/edgelesssys/constellation/internal/state"
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
azurecl "github.com/edgelesssys/constellation/cli/azure/client"
|
azurecl "github.com/edgelesssys/constellation/cli/azure/client"
|
||||||
gcpcl "github.com/edgelesssys/constellation/cli/gcp/client"
|
gcpcl "github.com/edgelesssys/constellation/cli/internal/gcp/client"
|
||||||
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
||||||
"github.com/edgelesssys/constellation/internal/state"
|
"github.com/edgelesssys/constellation/internal/state"
|
||||||
)
|
)
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/edgelesssys/constellation/cli/azure"
|
"github.com/edgelesssys/constellation/cli/azure"
|
||||||
"github.com/edgelesssys/constellation/cli/cloud/cloudcmd"
|
"github.com/edgelesssys/constellation/cli/cloud/cloudcmd"
|
||||||
"github.com/edgelesssys/constellation/cli/gcp"
|
"github.com/edgelesssys/constellation/cli/internal/gcp"
|
||||||
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
||||||
"github.com/edgelesssys/constellation/internal/constants"
|
"github.com/edgelesssys/constellation/internal/constants"
|
||||||
"github.com/edgelesssys/constellation/internal/file"
|
"github.com/edgelesssys/constellation/internal/file"
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/cli/azure"
|
"github.com/edgelesssys/constellation/cli/azure"
|
||||||
"github.com/edgelesssys/constellation/cli/gcp"
|
"github.com/edgelesssys/constellation/cli/internal/gcp"
|
||||||
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
||||||
"github.com/edgelesssys/constellation/internal/constants"
|
"github.com/edgelesssys/constellation/internal/constants"
|
||||||
"github.com/edgelesssys/constellation/internal/file"
|
"github.com/edgelesssys/constellation/internal/file"
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/edgelesssys/constellation/cli/azure"
|
"github.com/edgelesssys/constellation/cli/azure"
|
||||||
"github.com/edgelesssys/constellation/cli/cloud/cloudcmd"
|
"github.com/edgelesssys/constellation/cli/cloud/cloudcmd"
|
||||||
"github.com/edgelesssys/constellation/cli/gcp"
|
"github.com/edgelesssys/constellation/cli/internal/gcp"
|
||||||
"github.com/edgelesssys/constellation/cli/internal/proto"
|
"github.com/edgelesssys/constellation/cli/internal/proto"
|
||||||
"github.com/edgelesssys/constellation/cli/internal/status"
|
"github.com/edgelesssys/constellation/cli/internal/status"
|
||||||
"github.com/edgelesssys/constellation/cli/internal/vpn"
|
"github.com/edgelesssys/constellation/cli/internal/vpn"
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/cli/azure"
|
"github.com/edgelesssys/constellation/cli/azure"
|
||||||
"github.com/edgelesssys/constellation/cli/gcp"
|
"github.com/edgelesssys/constellation/cli/internal/gcp"
|
||||||
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
|
||||||
|
|
||||||
|
"github.com/edgelesssys/constellation/internal/gcpshared"
|
||||||
adminpb "google.golang.org/genproto/googleapis/iam/admin/v1"
|
adminpb "google.golang.org/genproto/googleapis/iam/admin/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ func (c *Client) CreateServiceAccount(ctx context.Context, input ServiceAccountI
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return key.ConvertToCloudServiceAccountURI(), nil
|
return key.ToCloudServiceAccountURI(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) TerminateServiceAccount(ctx context.Context) error {
|
func (c *Client) TerminateServiceAccount(ctx context.Context) error {
|
||||||
@ -67,41 +67,6 @@ func (i ServiceAccountInput) addIAMPolicyBindingInput(serviceAccount string) Add
|
|||||||
return iamPolicyBindingInput
|
return iamPolicyBindingInput
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceAccountKey is a GCP service account key.
|
|
||||||
type ServiceAccountKey struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
ProjectID string `json:"project_id"`
|
|
||||||
PrivateKeyID string `json:"private_key_id"`
|
|
||||||
PrivateKey string `json:"private_key"`
|
|
||||||
ClientEmail string `json:"client_email"`
|
|
||||||
ClientID string `json:"client_id"`
|
|
||||||
AuthURI string `json:"auth_uri"`
|
|
||||||
TokenURI string `json:"token_uri"`
|
|
||||||
AuthProviderX509CertURL string `json:"auth_provider_x509_cert_url"`
|
|
||||||
ClientX509CertURL string `json:"client_x509_cert_url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConvertToCloudServiceAccountURI converts the ServiceAccountKey into a cloud service account URI.
|
|
||||||
func (k ServiceAccountKey) ConvertToCloudServiceAccountURI() string {
|
|
||||||
query := url.Values{}
|
|
||||||
query.Add("type", k.Type)
|
|
||||||
query.Add("project_id", k.ProjectID)
|
|
||||||
query.Add("private_key_id", k.PrivateKeyID)
|
|
||||||
query.Add("private_key", k.PrivateKey)
|
|
||||||
query.Add("client_email", k.ClientEmail)
|
|
||||||
query.Add("client_id", k.ClientID)
|
|
||||||
query.Add("auth_uri", k.AuthURI)
|
|
||||||
query.Add("token_uri", k.TokenURI)
|
|
||||||
query.Add("auth_provider_x509_cert_url", k.AuthProviderX509CertURL)
|
|
||||||
query.Add("client_x509_cert_url", k.ClientX509CertURL)
|
|
||||||
uri := url.URL{
|
|
||||||
Scheme: "serviceaccount",
|
|
||||||
Host: "gcp",
|
|
||||||
RawQuery: query.Encode(),
|
|
||||||
}
|
|
||||||
return uri.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) insertServiceAccount(ctx context.Context, input insertServiceAccountInput) (string, error) {
|
func (c *Client) insertServiceAccount(ctx context.Context, input insertServiceAccountInput) (string, error) {
|
||||||
req := input.createServiceAccountRequest()
|
req := input.createServiceAccountRequest()
|
||||||
account, err := c.iamAPI.CreateServiceAccount(ctx, req)
|
account, err := c.iamAPI.CreateServiceAccount(ctx, req)
|
||||||
@ -112,15 +77,15 @@ func (c *Client) insertServiceAccount(ctx context.Context, input insertServiceAc
|
|||||||
return account.Email, nil
|
return account.Email, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) createServiceAccountKey(ctx context.Context, email string) (ServiceAccountKey, error) {
|
func (c *Client) createServiceAccountKey(ctx context.Context, email string) (gcpshared.ServiceAccountKey, error) {
|
||||||
req := createServiceAccountKeyRequest(email)
|
req := createServiceAccountKeyRequest(email)
|
||||||
key, err := c.iamAPI.CreateServiceAccountKey(ctx, req)
|
key, err := c.iamAPI.CreateServiceAccountKey(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ServiceAccountKey{}, fmt.Errorf("creating service account key failed: %w", err)
|
return gcpshared.ServiceAccountKey{}, fmt.Errorf("creating service account key failed: %w", err)
|
||||||
}
|
}
|
||||||
var serviceAccountKey ServiceAccountKey
|
var serviceAccountKey gcpshared.ServiceAccountKey
|
||||||
if err := json.Unmarshal(key.PrivateKeyData, &serviceAccountKey); err != nil {
|
if err := json.Unmarshal(key.PrivateKeyData, &serviceAccountKey); err != nil {
|
||||||
return ServiceAccountKey{}, fmt.Errorf("decoding service account key JSON failed: %w", err)
|
return gcpshared.ServiceAccountKey{}, fmt.Errorf("decoding service account key JSON failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return serviceAccountKey, nil
|
return serviceAccountKey, nil
|
@ -4,9 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/url"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/edgelesssys/constellation/internal/gcpshared"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@ -14,7 +14,7 @@ import (
|
|||||||
func TestCreateServiceAccount(t *testing.T) {
|
func TestCreateServiceAccount(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
someErr := errors.New("someErr")
|
someErr := errors.New("someErr")
|
||||||
key := ServiceAccountKey{
|
key := gcpshared.ServiceAccountKey{
|
||||||
Type: "type",
|
Type: "type",
|
||||||
ProjectID: "project-id",
|
ProjectID: "project-id",
|
||||||
PrivateKeyID: "private-key-id",
|
PrivateKeyID: "private-key-id",
|
||||||
@ -91,7 +91,7 @@ func TestCreateServiceAccount(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
} else {
|
} else {
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal(key.ConvertToCloudServiceAccountURI(), serviceAccountKey)
|
assert.Equal(key.ToCloudServiceAccountURI(), serviceAccountKey)
|
||||||
assert.Equal("email", client.serviceAccount)
|
assert.Equal("email", client.serviceAccount)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -137,38 +137,3 @@ func TestTerminateServiceAccount(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertToCloudServiceAccountURI(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
require := require.New(t)
|
|
||||||
key := ServiceAccountKey{
|
|
||||||
Type: "type",
|
|
||||||
ProjectID: "project-id",
|
|
||||||
PrivateKeyID: "private-key-id",
|
|
||||||
PrivateKey: "private-key",
|
|
||||||
ClientEmail: "client-email",
|
|
||||||
ClientID: "client-id",
|
|
||||||
AuthURI: "auth-uri",
|
|
||||||
TokenURI: "token-uri",
|
|
||||||
AuthProviderX509CertURL: "auth-provider-x509-cert-url",
|
|
||||||
ClientX509CertURL: "client-x509-cert-url",
|
|
||||||
}
|
|
||||||
cloudServiceAccountURI := key.ConvertToCloudServiceAccountURI()
|
|
||||||
uri, err := url.Parse(cloudServiceAccountURI)
|
|
||||||
require.NoError(err)
|
|
||||||
query := uri.Query()
|
|
||||||
assert.Equal("serviceaccount", uri.Scheme)
|
|
||||||
assert.Equal("gcp", uri.Host)
|
|
||||||
assert.Equal(url.Values{
|
|
||||||
"type": []string{"type"},
|
|
||||||
"project_id": []string{"project-id"},
|
|
||||||
"private_key_id": []string{"private-key-id"},
|
|
||||||
"private_key": []string{"private-key"},
|
|
||||||
"client_email": []string{"client-email"},
|
|
||||||
"client_id": []string{"client-id"},
|
|
||||||
"auth_uri": []string{"auth-uri"},
|
|
||||||
"token_uri": []string{"token-uri"},
|
|
||||||
"auth_provider_x509_cert_url": []string{"auth-provider-x509-cert-url"},
|
|
||||||
"client_x509_cert_url": []string{"client-x509-cert-url"},
|
|
||||||
}, query)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user