Skip to content

Commit

Permalink
Remove some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyiliev committed Dec 29, 2023
1 parent 67b9221 commit 9323a9a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/clients/cloud_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewCloudAPIClient(fronteggClient *FronteggClient, cloudAPIEndpoint string)
func (c *CloudAPIClient) ListCloudProviders(ctx context.Context) ([]CloudProvider, error) {
providersEndpoint := fmt.Sprintf("%s/api/cloud-regions", c.Endpoint)

// You can reuse the FronteggClient's HTTPClient which already includes the Authorization token.
// Reuse the FronteggClient's HTTPClient which already includes the Authorization token.
resp, err := c.FronteggClient.HTTPClient.Get(providersEndpoint)
if err != nil {
return nil, fmt.Errorf("error listing cloud providers: %v", err)
Expand Down
12 changes: 4 additions & 8 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, version stri
defaultRegion := clients.Region(d.Get("default_region").(string))
application_name := fmt.Sprintf("terraform-provider-materialize v%s", version)

// TODO: Rework the logic to set the region from the default region or the resource specific region.
err := utils.SetDefaultRegion(string(defaultRegion))
if err != nil {
return nil, diag.FromErr(err)
Expand All @@ -157,7 +156,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, version stri
return nil, diag.Errorf("Unable to list cloud providers: %s", err)
}

// Map to store DB clients for all regions.
// Store the DB clients for all regions.
dbClients := make(map[clients.Region]*clients.DBClient)

for _, provider := range providers {
Expand All @@ -166,7 +165,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, version stri
log.Printf("[DEBUG] Region details for provider %s: %v\n", provider.ID, regionDetails)

if err != nil {
// Handle the error, possibly continue to the next provider
log.Printf("[ERROR] Error getting region details for provider %s: %v\n", provider.ID, err)
continue
}

Expand All @@ -180,21 +179,19 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, version stri
// Get the database connection details for the region
host, port, err := clients.SplitHostPort(regionDetails.RegionInfo.SqlAddress)
if err != nil {
// Handle the error, possibly continue to the next provider
log.Printf("[ERROR] Error splitting host and port for region %s: %v\n", provider.ID, err)
continue
}

// Assuming email is used as the username and is the same for all regions
user := fronteggClient.Email

// Instantiate a new DB client for the region
dbClient, diags := clients.NewDBClient(host, user, password, port, database, application_name, version, sslmode)
if diags.HasError() {
// Handle the error, possibly continue to the next provider
log.Printf("[ERROR] Error initializing DB client for region %s: %v\n", provider.ID, diags)
continue
}

// Store the DB client in the map, keyed by the region
dbClients[clients.Region(provider.ID)] = dbClient
}

Expand All @@ -203,7 +200,6 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, version stri
return nil, diag.Errorf("No database regions were initialized. Please check your configuration.")
}

// Debug log the dbClients map
log.Printf("[DEBUG] Initialized DB clients for regions: %v\n", dbClients)

// Construct and return the provider meta with all clients initialized.
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/provider_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func GetDBClientFromMeta(meta interface{}, d *schema.ResourceData) (*sqlx.DB, cl
return nil, "", fmt.Errorf("failed to get provider meta: %v", providerMeta)
}

// Determine the region to use
// Determine the region to use, if one is not specified, use the default region
var region clients.Region
if d != nil && d.Get("region") != "" {
region = clients.Region(d.Get("region").(string))
Expand Down

0 comments on commit 9323a9a

Please sign in to comment.