From dd47424281d43b5f5f38364b7df93ee309a84976 Mon Sep 17 00:00:00 2001 From: Yuwen Ma Date: Thu, 19 Sep 2024 17:14:06 +0000 Subject: [PATCH] fix: bigqueryconnectionconnection misuse projectNum for projectID --- mockgcp/mockbigqueryconnection/connection.go | 5 +++-- .../direct/bigqueryconnection/connection_controller.go | 9 ++++++++- .../bigqueryconnectionconnectionbasic/_http.log | 4 ++-- .../bigqueryconnectionconnectionfull/_http.log | 10 +++++----- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/mockgcp/mockbigqueryconnection/connection.go b/mockgcp/mockbigqueryconnection/connection.go index fc1cc3f542..b5fc3ae4cb 100644 --- a/mockgcp/mockbigqueryconnection/connection.go +++ b/mockgcp/mockbigqueryconnection/connection.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "math/rand" + "strconv" "strings" "time" @@ -155,11 +156,11 @@ type connectionName struct { } func (n *connectionName) String() string { - return "projects/" + n.Project.ID + "/locations/" + n.Location + "/connections/" + n.ResourceID + return "projects/" + strconv.FormatInt(n.Project.Number, 10) + "/locations/" + n.Location + "/connections/" + n.ResourceID } // parseConnectionName parses a string into a connectionName. -// The expected form is projects//locations//connections/ +// The expected form is projects//locations//connections/ func (s *MockService) parseConnectionName(name string) (*connectionName, error) { tokens := strings.Split(name, "/") diff --git a/pkg/controller/direct/bigqueryconnection/connection_controller.go b/pkg/controller/direct/bigqueryconnection/connection_controller.go index ede9520c1a..69f0f69c9c 100644 --- a/pkg/controller/direct/bigqueryconnection/connection_controller.go +++ b/pkg/controller/direct/bigqueryconnection/connection_controller.go @@ -166,7 +166,14 @@ func (a *Adapter) Create(ctx context.Context, createOp *directbase.CreateOperati if mapCtx.Err() != nil { return mapCtx.Err() } - status.ExternalRef = &created.Name + + tokens := strings.Split(created.Name, "/") + parent, err = a.id.Parent() + if err != nil { + return err + } + externalRef := parent + "/connections/" + tokens[5] + status.ExternalRef = &externalRef return setStatus(u, status) } diff --git a/pkg/test/resourcefixture/testdata/basic/bigqueryconnection/v1alpha1/bigqueryconnectionconnection/bigqueryconnectionconnectionbasic/_http.log b/pkg/test/resourcefixture/testdata/basic/bigqueryconnection/v1alpha1/bigqueryconnectionconnection/bigqueryconnectionconnectionbasic/_http.log index 11890e7a2e..d48b778beb 100644 --- a/pkg/test/resourcefixture/testdata/basic/bigqueryconnection/v1alpha1/bigqueryconnectionconnection/bigqueryconnectionconnectionbasic/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/bigqueryconnection/v1alpha1/bigqueryconnectionconnection/bigqueryconnectionconnectionbasic/_http.log @@ -24,7 +24,7 @@ X-Xss-Protection: 0 }, "creationTime": "123456789", "lastModifiedTime": "123456789", - "name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" + "name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" } --- @@ -51,7 +51,7 @@ X-Xss-Protection: 0 }, "creationTime": "123456789", "lastModifiedTime": "123456789", - "name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" + "name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" } --- diff --git a/pkg/test/resourcefixture/testdata/basic/bigqueryconnection/v1alpha1/bigqueryconnectionconnection/bigqueryconnectionconnectionfull/_http.log b/pkg/test/resourcefixture/testdata/basic/bigqueryconnection/v1alpha1/bigqueryconnectionconnection/bigqueryconnectionconnectionfull/_http.log index 52c09075c0..f516e5e746 100644 --- a/pkg/test/resourcefixture/testdata/basic/bigqueryconnection/v1alpha1/bigqueryconnectionconnection/bigqueryconnectionconnectionfull/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/bigqueryconnection/v1alpha1/bigqueryconnectionconnection/bigqueryconnectionconnectionfull/_http.log @@ -17,7 +17,7 @@ X-Xss-Protection: 0 { "error": { "code": 404, - "message": "Not found: Connection projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be", + "message": "Not found: Connection projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be", "status": "NOT_FOUND" } } @@ -54,7 +54,7 @@ X-Xss-Protection: 0 "description": "test connection for cloud resource", "friendlyName": "cloud-resource-connection", "lastModifiedTime": "123456789", - "name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" + "name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" } --- @@ -83,7 +83,7 @@ X-Xss-Protection: 0 "description": "test connection for cloud resource", "friendlyName": "cloud-resource-connection", "lastModifiedTime": "123456789", - "name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" + "name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" } --- @@ -118,7 +118,7 @@ X-Xss-Protection: 0 "description": "updated connection for cloud resource", "friendlyName": "cloud-resource-connection-updated", "lastModifiedTime": "123456789", - "name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" + "name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" } --- @@ -147,7 +147,7 @@ X-Xss-Protection: 0 "description": "updated connection for cloud resource", "friendlyName": "cloud-resource-connection-updated", "lastModifiedTime": "123456789", - "name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" + "name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be" } ---