mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-11-14 09:30:45 -05:00
cli: remove GCP ADC project name check
This commit is contained in:
parent
35cded6261
commit
9d264604c0
1 changed files with 0 additions and 25 deletions
|
|
@ -9,9 +9,7 @@ package client
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -23,7 +21,6 @@ import (
|
||||||
"github.com/edgelesssys/constellation/internal/cloud/cloudtypes"
|
"github.com/edgelesssys/constellation/internal/cloud/cloudtypes"
|
||||||
"github.com/edgelesssys/constellation/internal/state"
|
"github.com/edgelesssys/constellation/internal/state"
|
||||||
"go.uber.org/multierr"
|
"go.uber.org/multierr"
|
||||||
"golang.org/x/oauth2/google"
|
|
||||||
"google.golang.org/api/googleapi"
|
"google.golang.org/api/googleapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -189,28 +186,6 @@ func NewFromDefault(ctx context.Context) (*Client, error) {
|
||||||
|
|
||||||
// NewInitialized creates an initialized client.
|
// NewInitialized creates an initialized client.
|
||||||
func NewInitialized(ctx context.Context, project, zone, region, name string) (*Client, error) {
|
func NewInitialized(ctx context.Context, project, zone, region, name string) (*Client, error) {
|
||||||
// check if ADC are configured for the same project as the cluster
|
|
||||||
var defaultProject string
|
|
||||||
creds, err := google.FindDefaultCredentials(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// if the CLI is run by a service account, use the project of the service account
|
|
||||||
defaultProject = creds.ProjectID
|
|
||||||
// if the CLI is run by a user directly projectID will be empty, use the quota project id of the user instead
|
|
||||||
if defaultProject == "" {
|
|
||||||
var projectID struct {
|
|
||||||
ProjectID string `json:"quota_project_id"`
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(creds.JSON, &projectID); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defaultProject = projectID.ProjectID
|
|
||||||
}
|
|
||||||
if defaultProject != project {
|
|
||||||
return nil, fmt.Errorf("application default credentials are configured for project %q, but the cluster is configured for project %q", defaultProject, project)
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := NewFromDefault(ctx)
|
client, err := NewFromDefault(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue