Skip to content

Commit

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

func (r *TransactionalWarehouseResource) addConnection(ctx context.Context, data TransactionalWarehouseResourceModel) (*TransactionalWarehouseResourceModel, diag.Diagnostics) {
func (r *TransactionalWarehouseResource) testCredentials(ctx context.Context, data TransactionalWarehouseResourceModel) (*client.TestDatabaseCredentials, diag.Diagnostics) {
var diagsResult diag.Diagnostics
testResult := client.TestDatabaseCredentials{}
variables := map[string]interface{}{
Expand All @@ -382,6 +382,18 @@ func (r *TransactionalWarehouseResource) addConnection(ctx context.Context, data
diags = append(diags, databaseTestDiagnosticsToDiags(testResult.TestDatabaseCredentials.Validations)...)
diagsResult.Append(diags...)
return nil, diagsResult
} else {
return &testResult, diagsResult
}
}

func (r *TransactionalWarehouseResource) addConnection(ctx context.Context, data TransactionalWarehouseResourceModel) (*TransactionalWarehouseResourceModel, 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 @@ -396,7 +408,7 @@ func (r *TransactionalWarehouseResource) addConnection(ctx context.Context, data
createWarehouseType = &temp
}

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

0 comments on commit 7814a20

Please sign in to comment.