Skip to content

Commit

Permalink
feat(warehouse): BQ test credentials refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ndopj committed Feb 18, 2024
1 parent e27dee0 commit 0bf7848
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/warehouse/bigquery_warehouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (r *BigQueryWarehouseResource) ImportState(ctx context.Context, req resourc
}
}

func (r *BigQueryWarehouseResource) addConnection(ctx context.Context, data BigQueryWarehouseResourceModel) (*BigQueryWarehouseResourceModel, diag.Diagnostics) {
func (r *BigQueryWarehouseResource) testCredentials(ctx context.Context, data BigQueryWarehouseResourceModel) (*client.TestBqCredentialsV2, diag.Diagnostics) {
var diagsResult diag.Diagnostics
type BqConnectionDetails map[string]interface{}
testResult := client.TestBqCredentialsV2{}
Expand All @@ -341,6 +341,18 @@ func (r *BigQueryWarehouseResource) addConnection(ctx context.Context, data BigQ
diags = append(diags, bqTestDiagnosticToDiags(testResult.TestBqCredentialsV2.ValidationResult.Errors)...)
diagsResult.Append(diags...)
return nil, diagsResult
} else {
return &testResult, diagsResult
}
}

func (r *BigQueryWarehouseResource) addConnection(ctx context.Context, data BigQueryWarehouseResourceModel) (*BigQueryWarehouseResourceModel, diag.Diagnostics) {
var diagsResult diag.Diagnostics
testResult, credentialsDiags := r.testCredentials(ctx, data)

if testResult == nil {
diagsResult.Append(credentialsDiags...)
return nil, diagsResult
}

addResult := client.AddConnection{}
Expand All @@ -355,7 +367,7 @@ func (r *BigQueryWarehouseResource) addConnection(ctx context.Context, data BigQ
createWarehouseType = &temp
}

variables = map[string]interface{}{
variables := map[string]interface{}{
"dcId": (*client.UUID)(collectorUuid),
"dwId": (*client.UUID)(warehouseUuid),
"key": testResult.TestBqCredentialsV2.Key,
Expand Down

0 comments on commit 0bf7848

Please sign in to comment.