Skip to content

Commit 29315e6

Browse files
committed
refactor: update API client methods and request structures
- Replaced deprecated API client methods with new request methods across multiple files. - Updated request body structures to align with the new API specifications. - Adjusted response handling to check for the correct status codes and response formats. - Enhanced error handling for resource provider, environment, deployment, and policy operations.
1 parent 357ac10 commit 29315e6

11 files changed

Lines changed: 1092 additions & 1049 deletions

File tree

cmd/ctrlc/root/sync/salesforce/common/util.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,23 +245,25 @@ func UpsertToCtrlplane(ctx context.Context, resources []api.ResourceProviderReso
245245
return fmt.Errorf("failed to create API client: %w", err)
246246
}
247247

248-
providerResp, err := ctrlplaneClient.UpsertResourceProviderWithResponse(ctx, workspaceId, api.UpsertResourceProviderJSONRequestBody{
248+
upsertReq := api.RequestResourceProviderUpsertJSONRequestBody{
249249
Name: providerName,
250-
})
250+
}
251+
providerResp, err := ctrlplaneClient.RequestResourceProviderUpsertWithResponse(ctx, workspaceId, upsertReq)
251252
if err != nil {
252253
return fmt.Errorf("failed to upsert resource provider: %w", err)
253254
}
254255

255-
if providerResp.JSON200 == nil {
256+
if providerResp.JSON202 == nil {
256257
return fmt.Errorf("failed to upsert resource provider: %s", providerResp.Body)
257258
}
258259

259-
providerId := providerResp.JSON200.Id
260+
providerId := providerResp.JSON202.Id
260261
log.Info("Upserting resources", "provider", providerName, "count", len(resources))
261262

262-
setResp, err := ctrlplaneClient.SetResourceProvidersResourcesWithResponse(ctx, workspaceId, providerId, api.SetResourceProvidersResourcesJSONRequestBody{
263+
patchReq := api.RequestResourceProvidersResourcesPatchJSONRequestBody{
263264
Resources: resources,
264-
})
265+
}
266+
setResp, err := ctrlplaneClient.RequestResourceProvidersResourcesPatchWithResponse(ctx, workspaceId, providerId, patchReq)
265267
if err != nil {
266268
return fmt.Errorf("failed to set resources: %w", err)
267269
}

cmd/ctrlc/root/sync/terraform/terraform.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,19 @@ func NewSyncTerraformCmd() *cobra.Command {
5858
}
5959

6060
providerName := fmt.Sprintf("tf-%s", organization)
61-
resp, err := ctrlplaneClient.UpsertResourceProviderWithResponse(ctx, workspaceId, api.UpsertResourceProviderJSONRequestBody{
61+
upsertReq := api.RequestResourceProviderUpsertJSONRequestBody{
6262
Name: providerName,
63-
})
63+
}
64+
resp, err := ctrlplaneClient.RequestResourceProviderUpsertWithResponse(ctx, workspaceId, upsertReq)
6465
if err != nil {
6566
return fmt.Errorf("failed to upsert resource provider: %w", err)
6667
}
6768

68-
if resp.JSON200 == nil {
69+
if resp.JSON202 == nil {
6970
return fmt.Errorf("failed to upsert resource provider: %s", resp.Body)
7071
}
7172

72-
providerId := resp.JSON200.Id
73+
providerId := resp.JSON202.Id
7374
fmt.Println("Provider ID:", providerId)
7475
workspaces, err := getWorkspacesInOrg(cmd.Context(), terraformClient, organization)
7576
if err != nil {
@@ -90,9 +91,10 @@ func NewSyncTerraformCmd() *cobra.Command {
9091
resources = append(resources, resource)
9192
}
9293

93-
upsertResp, err := ctrlplaneClient.SetResourceProvidersResources(ctx, workspaceId, providerId, api.SetResourceProvidersResourcesJSONRequestBody{
94+
patchReq := api.RequestResourceProvidersResourcesPatchJSONRequestBody{
9495
Resources: resources,
95-
})
96+
}
97+
upsertResp, err := ctrlplaneClient.RequestResourceProvidersResourcesPatch(ctx, workspaceId, providerId, patchReq)
9698
if err != nil {
9799
return fmt.Errorf("failed to upsert resources: %w", err)
98100
}

0 commit comments

Comments
 (0)