Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#2798 from 600lyy/add-bqcc-aws
Browse files Browse the repository at this point in the history
Add Support for Bigqueryconnection AWS
  • Loading branch information
google-oss-prow[bot] authored Sep 26, 2024
2 parents 5dc805e + 44378ec commit 318fe2d
Show file tree
Hide file tree
Showing 14 changed files with 607 additions and 5 deletions.
30 changes: 27 additions & 3 deletions apis/bigqueryconnection/v1alpha1/connection_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ type BigQueryConnectionConnectionSpec struct {
// Cloud SQL properties.
CloudSQLSpec *CloudSqlPropertiesSpec `json:"cloudSql,omitempty"`

/* NOTYET
// Amazon Web Services (AWS) properties.
Aws *AwsProperties `json:"aws,omitempty"`
*/
AwsSpec *AwsPropertiesSpec `json:"aws,omitempty"`

/* NOTYET
// Azure properties.
Expand Down Expand Up @@ -101,6 +99,8 @@ type BigQueryConnectionConnectionStatus struct {
// BigQueryConnectionConnectionSpec defines the desired state of BigQueryConnectionConnection
// +kcc:proto=google.cloud.bigquery.connection.v1.Connection
type BigQueryConnectionConnectionObservedState struct {
Aws *AwsPropertiesStatus `json:"aws,omitempty"`

CloudResource *CloudResourcePropertiesStatus `json:"cloudResource,omitempty"`

CloudSql *CloudSqlPropertiesStatus `json:"cloudSql,omitempty"`
Expand Down Expand Up @@ -137,6 +137,18 @@ type BigQueryConnectionConnectionObservedState struct {
HasCredential *bool `json:"hasCredential,omitempty"`
}

type AwsPropertiesSpec struct {
// Authentication using Google owned service account to assume into
// customer's AWS IAM Role.
AccessRole *AwsAccessRoleSpec `json:"accessRole,omitempty"`
}

type AwsAccessRoleSpec struct {
// The user’s AWS IAM Role that trusts the Google-owned AWS IAM user
// Connection.
IamRoleID *string `json:"iamRoleID,omitempty"`
}

type CloudResourcePropertiesSpec struct{}

type CloudSqlPropertiesSpec struct {
Expand All @@ -153,6 +165,18 @@ type CloudSqlPropertiesSpec struct {
Credential *CloudSqlCredential `json:"credential,omitempty"`
}

// +kcc:proto=google.cloud.bigquery.connection.v1.AwsProperties
type AwsPropertiesStatus struct {
AccessRole *AwsAccessRoleStatus `json:"accessRole,omitempty"`
}

// +kcc:proto=google.cloud.bigquery.connection.v1.AwsAccessRole
type AwsAccessRoleStatus struct {
// A unique Google-owned and Google-generated identity for the Connection.
// This identity will be used to access the user's AWS IAM Role.
Identity *string `json:"identity,omitempty"`
}

// +kcc:proto=google.cloud.bigquery.connection.v1.CloudSqlProperties
type CloudSqlPropertiesStatus struct {
// The account ID of the service used for the purpose of this connection.
Expand Down
90 changes: 90 additions & 0 deletions apis/bigqueryconnection/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ spec:
description: BigQueryConnectionConnectionSpec defines the desired state
to connect BigQuery to external resources
properties:
aws:
description: Amazon Web Services (AWS) properties.
properties:
accessRole:
description: Authentication using Google owned service account
to assume into customer's AWS IAM Role.
properties:
iamRoleID:
description: The user’s AWS IAM Role that trusts the Google-owned
AWS IAM user Connection.
type: string
type: object
type: object
cloudResource:
description: Use Cloud Resource properties.
type: object
Expand Down Expand Up @@ -212,6 +225,17 @@ spec:
description: ObservedState is the state of the resource as most recently
observed in GCP.
properties:
aws:
properties:
accessRole:
properties:
identity:
description: A unique Google-owned and Google-generated
identity for the Connection. This identity will be used
to access the user's AWS IAM Role.
type: string
type: object
type: object
cloudResource:
properties:
serviceAccountID:
Expand Down
31 changes: 31 additions & 0 deletions mockgcp/mockbigqueryconnection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,30 @@ func (s *ConnectionV1) CreateConnection(ctx context.Context, req *pb.CreateConne
return fmt.Sprintf("service-%[email protected]", req.GetParent())
}

buildAwsAccessRoleIdentity := func() string {
letterRunes := []rune("0123456789")
b := make([]rune, 21)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}

if _, ok := (req.Connection.Properties).(*pb.Connection_Aws); ok {
if aws := req.Connection.GetAws(); aws != nil {
obj.Properties = &pb.Connection_Aws{
Aws: &pb.AwsProperties{
AuthenticationMethod: &pb.AwsProperties_AccessRole{
AccessRole: &pb.AwsAccessRole{
IamRoleId: aws.GetAccessRole().GetIamRoleId(),
Identity: buildAwsAccessRoleIdentity(),
},
},
},
}
}
}

if _, ok := (req.Connection.Properties).(*pb.Connection_CloudResource); ok {
obj.Properties = &pb.Connection_CloudResource{
CloudResource: &pb.CloudResourceProperties{
Expand Down Expand Up @@ -152,6 +176,13 @@ func (s *ConnectionV1) UpdateConnection(ctx context.Context, req *pb.UpdateConne
}
}
obj.LastModifiedTime = now.Unix()

if _, ok := (req.Connection.Properties).(*pb.Connection_Aws); ok {
if mod := req.Connection.GetAws(); mod != nil {
obj.GetAws().GetAccessRole().IamRoleId = mod.GetAccessRole().IamRoleId
}
}

if err := s.storage.Update(ctx, fqn, obj); err != nil {
return nil, err
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 318fe2d

Please sign in to comment.