From 23bab64442d615d0a05f2cfbef72c09a2aa0d063 Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Thu, 14 Nov 2024 01:05:54 -0500 Subject: [PATCH] add delete --- cmd/ctrlc/root/api/api.go | 4 +- cmd/ctrlc/root/api/delete/delete.go | 22 ++ .../root/api/delete/resource/resource.go | 70 ++++++ cmd/ctrlc/root/api/get/resource/resource.go | 47 ++-- internal/api/client.gen.go | 218 +++++++++--------- 5 files changed, 238 insertions(+), 123 deletions(-) create mode 100644 cmd/ctrlc/root/api/delete/delete.go create mode 100644 cmd/ctrlc/root/api/delete/resource/resource.go diff --git a/cmd/ctrlc/root/api/api.go b/cmd/ctrlc/root/api/api.go index 591f644..29b8a28 100644 --- a/cmd/ctrlc/root/api/api.go +++ b/cmd/ctrlc/root/api/api.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create" + "github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/delete" "github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/get" "github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/upsert" "github.com/spf13/cobra" @@ -12,7 +13,7 @@ import ( func NewAPICmd() *cobra.Command { cmd := &cobra.Command{ - Use: "api ", + Use: "api [flags]", Short: "API commands", Long: `Commands for interacting with the CtrlPlane API.`, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { @@ -41,6 +42,7 @@ func NewAPICmd() *cobra.Command { cmd.AddCommand(get.NewGetCmd()) cmd.AddCommand(create.NewCreateCmd()) cmd.AddCommand(upsert.NewUpsertCmd()) + cmd.AddCommand(delete.NewDeleteCmd()) return cmd } diff --git a/cmd/ctrlc/root/api/delete/delete.go b/cmd/ctrlc/root/api/delete/delete.go new file mode 100644 index 0000000..90406a9 --- /dev/null +++ b/cmd/ctrlc/root/api/delete/delete.go @@ -0,0 +1,22 @@ +package delete + +import ( + "github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/delete/resource" + "github.com/spf13/cobra" +) + +func NewDeleteCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "delete ", + Short: "Delete resources", + Long: `Commands for deleting resources.`, + RunE: func(cmd *cobra.Command, args []string) error { + return cmd.Help() + }, + } + + + cmd.AddCommand(resource.NewDeleteResourceCmd()) + + return cmd +} diff --git a/cmd/ctrlc/root/api/delete/resource/resource.go b/cmd/ctrlc/root/api/delete/resource/resource.go new file mode 100644 index 0000000..7458f6f --- /dev/null +++ b/cmd/ctrlc/root/api/delete/resource/resource.go @@ -0,0 +1,70 @@ +package resource + +import ( + "fmt" + + "github.com/MakeNowJust/heredoc/v2" + "github.com/ctrlplanedev/cli/internal/api" + "github.com/ctrlplanedev/cli/internal/cliutil" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +func NewDeleteResourceCmd() *cobra.Command { + var resourceId string + var workspace string + var identifier string + + cmd := &cobra.Command{ + Use: "resource [flags]", + Short: "Delete a resource", + Long: `Delete a resource by specifying either an ID or both a workspace and an identifier.`, + Example: heredoc.Doc(` + # Delete a resource by ID + $ ctrlc delete resource --id 123e4567-e89b-12d3-a456-426614174000 + + # Delete a resource by workspace and identifier + $ ctrlc delete resource --workspace 123e4567-e89b-12d3-a456-426614174000 --identifier myidentifier + + # Delete a resource using Go template syntax + $ ctrlc delete resource --id 123e4567-e89b-12d3-a456-426614174000 --template='{{.id}}' + `), + RunE: func(cmd *cobra.Command, args []string) error { + if resourceId == "" && (workspace == "" || identifier == "") { + return fmt.Errorf("either --id or both --workspace and --identifier must be provided") + } + + if resourceId != "" && (workspace != "" || identifier != "") { + return fmt.Errorf("--id and --workspace/--identifier are mutually exclusive") + } + + apiURL := viper.GetString("url") + apiKey := viper.GetString("api-key") + client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey) + if err != nil { + return fmt.Errorf("failed to delete resource API client: %w", err) + } + + if resourceId != "" { + resp, err := client.DeleteResource(cmd.Context(), resourceId) + if err != nil { + return fmt.Errorf("failed to delete resource by ID: %w", err) + } + return cliutil.HandleOutput(cmd, resp) + } + + resp, err := client.DeleteResourceByIdentifier(cmd.Context(), workspace, identifier) + if err != nil { + return fmt.Errorf("failed to delete resource by workspace and identifier: %w", err) + } + return cliutil.HandleOutput(cmd, resp) + }, + } + + // Add flags + cmd.Flags().StringVar(&resourceId, "id", "", "ID of the target resource") + cmd.Flags().StringVar(&workspace, "workspace", "", "Workspace of the target resource") + cmd.Flags().StringVar(&identifier, "identifier", "", "Identifier of the target resource") + + return cmd +} diff --git a/cmd/ctrlc/root/api/get/resource/resource.go b/cmd/ctrlc/root/api/get/resource/resource.go index 491a133..d6b4830 100644 --- a/cmd/ctrlc/root/api/get/resource/resource.go +++ b/cmd/ctrlc/root/api/get/resource/resource.go @@ -12,19 +12,32 @@ import ( func NewGetResourceCmd() *cobra.Command { var resourceId string + var workspace string + var identifier string cmd := &cobra.Command{ - Use: "target [flags]", - Short: "Get a target", - Long: `Get a target with the specified name and configuration.`, + Use: "resource [flags]", + Short: "Get a resource", + Long: `Get a resource by specifying either an ID or both a workspace and an identifier.`, Example: heredoc.Doc(` - # Get a target - $ ctrlc get target --name my-target + # Get a resource by ID + $ ctrlc get resource --id 123e4567-e89b-12d3-a456-426614174000 - # Get a target using Go template syntax - $ ctrlc get target --name my-target --template='{{.id}}' - `), + # Get a resource by workspace and identifier + $ ctrlc get resource --workspace myworkspace --identifier myidentifier + + # Get a resource using Go template syntax + $ ctrlc get resource --id 123e4567-e89b-12d3-a456-426614174000 --template='{{.id}}' + `), RunE: func(cmd *cobra.Command, args []string) error { + if resourceId == "" && (workspace == "" || identifier == "") { + return fmt.Errorf("either --id or both --workspace and --identifier must be provided") + } + + if resourceId != "" && (workspace != "" || identifier != "") { + return fmt.Errorf("--id and --workspace/--identifier are mutually exclusive") + } + apiURL := viper.GetString("url") apiKey := viper.GetString("api-key") client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey) @@ -32,18 +45,26 @@ func NewGetResourceCmd() *cobra.Command { return fmt.Errorf("failed to create API client: %w", err) } - resp, err := client.GetResource(cmd.Context(), resourceId) - if err != nil { - return fmt.Errorf("failed to get target: %w", err) + if resourceId != "" { + resp, err := client.GetResource(cmd.Context(), resourceId) + if err != nil { + return fmt.Errorf("failed to get resource by ID: %w", err) + } + return cliutil.HandleOutput(cmd, resp) } + resp, err := client.GetResourceByIdentifier(cmd.Context(), workspace, identifier) + if err != nil { + return fmt.Errorf("failed to get resource by workspace and identifier: %w", err) + } return cliutil.HandleOutput(cmd, resp) }, } // Add flags - cmd.Flags().StringVar(&resourceId, "id", "", "ID of the target (required)") - cmd.MarkFlagRequired("id") + cmd.Flags().StringVar(&resourceId, "id", "", "ID of the target resource") + cmd.Flags().StringVar(&workspace, "workspace", "", "Workspace of the target resource") + cmd.Flags().StringVar(&identifier, "identifier", "", "Identifier of the target resource") return cmd } diff --git a/internal/api/client.gen.go b/internal/api/client.gen.go index 38c874d..0113a92 100644 --- a/internal/api/client.gen.go +++ b/internal/api/client.gen.go @@ -369,14 +369,14 @@ type ClientInterface interface { SetTargetProvidersTargets(ctx context.Context, providerId string, body SetTargetProvidersTargetsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) - // UpsertTargetProvider request - UpsertTargetProvider(ctx context.Context, workspaceId string, name string, reqEditors ...RequestEditorFn) (*http.Response, error) + // DeleteResourceByIdentifier request + DeleteResourceByIdentifier(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*http.Response, error) - // DeleteTargetByIdentifier request - DeleteTargetByIdentifier(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*http.Response, error) + // GetResourceByIdentifier request + GetResourceByIdentifier(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*http.Response, error) - // GetTargetByIdentifier request - GetTargetByIdentifier(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*http.Response, error) + // UpsertTargetProvider request + UpsertTargetProvider(ctx context.Context, workspaceId string, name string, reqEditors ...RequestEditorFn) (*http.Response, error) } func (c *Client) CreateEnvironmentWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { @@ -655,8 +655,8 @@ func (c *Client) SetTargetProvidersTargets(ctx context.Context, providerId strin return c.Client.Do(req) } -func (c *Client) UpsertTargetProvider(ctx context.Context, workspaceId string, name string, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewUpsertTargetProviderRequest(c.Server, workspaceId, name) +func (c *Client) DeleteResourceByIdentifier(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteResourceByIdentifierRequest(c.Server, workspaceId, identifier) if err != nil { return nil, err } @@ -667,8 +667,8 @@ func (c *Client) UpsertTargetProvider(ctx context.Context, workspaceId string, n return c.Client.Do(req) } -func (c *Client) DeleteTargetByIdentifier(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewDeleteTargetByIdentifierRequest(c.Server, workspaceId, identifier) +func (c *Client) GetResourceByIdentifier(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetResourceByIdentifierRequest(c.Server, workspaceId, identifier) if err != nil { return nil, err } @@ -679,8 +679,8 @@ func (c *Client) DeleteTargetByIdentifier(ctx context.Context, workspaceId strin return c.Client.Do(req) } -func (c *Client) GetTargetByIdentifier(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewGetTargetByIdentifierRequest(c.Server, workspaceId, identifier) +func (c *Client) UpsertTargetProvider(ctx context.Context, workspaceId string, name string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUpsertTargetProviderRequest(c.Server, workspaceId, name) if err != nil { return nil, err } @@ -1270,8 +1270,8 @@ func NewSetTargetProvidersTargetsRequestWithBody(server string, providerId strin return req, nil } -// NewUpsertTargetProviderRequest generates requests for UpsertTargetProvider -func NewUpsertTargetProviderRequest(server string, workspaceId string, name string) (*http.Request, error) { +// NewDeleteResourceByIdentifierRequest generates requests for DeleteResourceByIdentifier +func NewDeleteResourceByIdentifierRequest(server string, workspaceId string, identifier string) (*http.Request, error) { var err error var pathParam0 string @@ -1283,7 +1283,7 @@ func NewUpsertTargetProviderRequest(server string, workspaceId string, name stri var pathParam1 string - pathParam1, err = runtime.StyleParamWithLocation("simple", false, "name", runtime.ParamLocationPath, name) + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "identifier", runtime.ParamLocationPath, identifier) if err != nil { return nil, err } @@ -1293,7 +1293,7 @@ func NewUpsertTargetProviderRequest(server string, workspaceId string, name stri return nil, err } - operationPath := fmt.Sprintf("/v1/workspaces/%s/target-providers/name/%s", pathParam0, pathParam1) + operationPath := fmt.Sprintf("/v1/workspaces/%s/resources/identifier/%s", pathParam0, pathParam1) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -1303,7 +1303,7 @@ func NewUpsertTargetProviderRequest(server string, workspaceId string, name stri return nil, err } - req, err := http.NewRequest("GET", queryURL.String(), nil) + req, err := http.NewRequest("DELETE", queryURL.String(), nil) if err != nil { return nil, err } @@ -1311,8 +1311,8 @@ func NewUpsertTargetProviderRequest(server string, workspaceId string, name stri return req, nil } -// NewDeleteTargetByIdentifierRequest generates requests for DeleteTargetByIdentifier -func NewDeleteTargetByIdentifierRequest(server string, workspaceId string, identifier string) (*http.Request, error) { +// NewGetResourceByIdentifierRequest generates requests for GetResourceByIdentifier +func NewGetResourceByIdentifierRequest(server string, workspaceId string, identifier string) (*http.Request, error) { var err error var pathParam0 string @@ -1334,7 +1334,7 @@ func NewDeleteTargetByIdentifierRequest(server string, workspaceId string, ident return nil, err } - operationPath := fmt.Sprintf("/v1/workspaces/%s/targets/identifier/%s", pathParam0, pathParam1) + operationPath := fmt.Sprintf("/v1/workspaces/%s/resources/identifier/%s", pathParam0, pathParam1) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -1344,7 +1344,7 @@ func NewDeleteTargetByIdentifierRequest(server string, workspaceId string, ident return nil, err } - req, err := http.NewRequest("DELETE", queryURL.String(), nil) + req, err := http.NewRequest("GET", queryURL.String(), nil) if err != nil { return nil, err } @@ -1352,8 +1352,8 @@ func NewDeleteTargetByIdentifierRequest(server string, workspaceId string, ident return req, nil } -// NewGetTargetByIdentifierRequest generates requests for GetTargetByIdentifier -func NewGetTargetByIdentifierRequest(server string, workspaceId string, identifier string) (*http.Request, error) { +// NewUpsertTargetProviderRequest generates requests for UpsertTargetProvider +func NewUpsertTargetProviderRequest(server string, workspaceId string, name string) (*http.Request, error) { var err error var pathParam0 string @@ -1365,7 +1365,7 @@ func NewGetTargetByIdentifierRequest(server string, workspaceId string, identifi var pathParam1 string - pathParam1, err = runtime.StyleParamWithLocation("simple", false, "identifier", runtime.ParamLocationPath, identifier) + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "name", runtime.ParamLocationPath, name) if err != nil { return nil, err } @@ -1375,7 +1375,7 @@ func NewGetTargetByIdentifierRequest(server string, workspaceId string, identifi return nil, err } - operationPath := fmt.Sprintf("/v1/workspaces/%s/targets/identifier/%s", pathParam0, pathParam1) + operationPath := fmt.Sprintf("/v1/workspaces/%s/target-providers/name/%s", pathParam0, pathParam1) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -1497,14 +1497,14 @@ type ClientWithResponsesInterface interface { SetTargetProvidersTargetsWithResponse(ctx context.Context, providerId string, body SetTargetProvidersTargetsJSONRequestBody, reqEditors ...RequestEditorFn) (*SetTargetProvidersTargetsResponse, error) - // UpsertTargetProviderWithResponse request - UpsertTargetProviderWithResponse(ctx context.Context, workspaceId string, name string, reqEditors ...RequestEditorFn) (*UpsertTargetProviderResponse, error) + // DeleteResourceByIdentifierWithResponse request + DeleteResourceByIdentifierWithResponse(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*DeleteResourceByIdentifierResponse, error) - // DeleteTargetByIdentifierWithResponse request - DeleteTargetByIdentifierWithResponse(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*DeleteTargetByIdentifierResponse, error) + // GetResourceByIdentifierWithResponse request + GetResourceByIdentifierWithResponse(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*GetResourceByIdentifierResponse, error) - // GetTargetByIdentifierWithResponse request - GetTargetByIdentifierWithResponse(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*GetTargetByIdentifierResponse, error) + // UpsertTargetProviderWithResponse request + UpsertTargetProviderWithResponse(ctx context.Context, workspaceId string, name string, reqEditors ...RequestEditorFn) (*UpsertTargetProviderResponse, error) } type CreateEnvironmentResponse struct { @@ -2016,18 +2016,19 @@ func (r SetTargetProvidersTargetsResponse) StatusCode() int { return 0 } -type UpsertTargetProviderResponse struct { +type DeleteResourceByIdentifierResponse struct { Body []byte HTTPResponse *http.Response JSON200 *struct { - Id string `json:"id"` - Name string `json:"name"` - WorkspaceId string `json:"workspaceId"` + Success *bool `json:"success,omitempty"` + } + JSON404 *struct { + Error *string `json:"error,omitempty"` } } // Status returns HTTPResponse.Status -func (r UpsertTargetProviderResponse) Status() string { +func (r DeleteResourceByIdentifierResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -2035,18 +2036,32 @@ func (r UpsertTargetProviderResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r UpsertTargetProviderResponse) StatusCode() int { +func (r DeleteResourceByIdentifierResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } -type DeleteTargetByIdentifierResponse struct { +type GetResourceByIdentifierResponse struct { Body []byte HTTPResponse *http.Response JSON200 *struct { - Success *bool `json:"success,omitempty"` + Id string `json:"id"` + Identifier string `json:"identifier"` + Metadata *map[string]string `json:"metadata,omitempty"` + Provider *struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + WorkspaceId *string `json:"workspaceId,omitempty"` + } `json:"provider,omitempty"` + ProviderId string `json:"providerId"` + Variables *[]struct { + Id *string `json:"id,omitempty"` + Key *string `json:"key,omitempty"` + Value *string `json:"value,omitempty"` + } `json:"variables,omitempty"` + WorkspaceId string `json:"workspaceId"` } JSON404 *struct { Error *string `json:"error,omitempty"` @@ -2054,7 +2069,7 @@ type DeleteTargetByIdentifierResponse struct { } // Status returns HTTPResponse.Status -func (r DeleteTargetByIdentifierResponse) Status() string { +func (r GetResourceByIdentifierResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -2062,40 +2077,25 @@ func (r DeleteTargetByIdentifierResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r DeleteTargetByIdentifierResponse) StatusCode() int { +func (r GetResourceByIdentifierResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } -type GetTargetByIdentifierResponse struct { +type UpsertTargetProviderResponse struct { Body []byte HTTPResponse *http.Response JSON200 *struct { - Id string `json:"id"` - Identifier string `json:"identifier"` - Metadata *map[string]string `json:"metadata,omitempty"` - Provider *struct { - Id *string `json:"id,omitempty"` - Name *string `json:"name,omitempty"` - WorkspaceId *string `json:"workspaceId,omitempty"` - } `json:"provider,omitempty"` - ProviderId string `json:"providerId"` - Variables *[]struct { - Id *string `json:"id,omitempty"` - Key *string `json:"key,omitempty"` - Value *string `json:"value,omitempty"` - } `json:"variables,omitempty"` + Id string `json:"id"` + Name string `json:"name"` WorkspaceId string `json:"workspaceId"` } - JSON404 *struct { - Error *string `json:"error,omitempty"` - } } // Status returns HTTPResponse.Status -func (r GetTargetByIdentifierResponse) Status() string { +func (r UpsertTargetProviderResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -2103,7 +2103,7 @@ func (r GetTargetByIdentifierResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r GetTargetByIdentifierResponse) StatusCode() int { +func (r UpsertTargetProviderResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } @@ -2309,31 +2309,31 @@ func (c *ClientWithResponses) SetTargetProvidersTargetsWithResponse(ctx context. return ParseSetTargetProvidersTargetsResponse(rsp) } -// UpsertTargetProviderWithResponse request returning *UpsertTargetProviderResponse -func (c *ClientWithResponses) UpsertTargetProviderWithResponse(ctx context.Context, workspaceId string, name string, reqEditors ...RequestEditorFn) (*UpsertTargetProviderResponse, error) { - rsp, err := c.UpsertTargetProvider(ctx, workspaceId, name, reqEditors...) +// DeleteResourceByIdentifierWithResponse request returning *DeleteResourceByIdentifierResponse +func (c *ClientWithResponses) DeleteResourceByIdentifierWithResponse(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*DeleteResourceByIdentifierResponse, error) { + rsp, err := c.DeleteResourceByIdentifier(ctx, workspaceId, identifier, reqEditors...) if err != nil { return nil, err } - return ParseUpsertTargetProviderResponse(rsp) + return ParseDeleteResourceByIdentifierResponse(rsp) } -// DeleteTargetByIdentifierWithResponse request returning *DeleteTargetByIdentifierResponse -func (c *ClientWithResponses) DeleteTargetByIdentifierWithResponse(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*DeleteTargetByIdentifierResponse, error) { - rsp, err := c.DeleteTargetByIdentifier(ctx, workspaceId, identifier, reqEditors...) +// GetResourceByIdentifierWithResponse request returning *GetResourceByIdentifierResponse +func (c *ClientWithResponses) GetResourceByIdentifierWithResponse(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*GetResourceByIdentifierResponse, error) { + rsp, err := c.GetResourceByIdentifier(ctx, workspaceId, identifier, reqEditors...) if err != nil { return nil, err } - return ParseDeleteTargetByIdentifierResponse(rsp) + return ParseGetResourceByIdentifierResponse(rsp) } -// GetTargetByIdentifierWithResponse request returning *GetTargetByIdentifierResponse -func (c *ClientWithResponses) GetTargetByIdentifierWithResponse(ctx context.Context, workspaceId string, identifier string, reqEditors ...RequestEditorFn) (*GetTargetByIdentifierResponse, error) { - rsp, err := c.GetTargetByIdentifier(ctx, workspaceId, identifier, reqEditors...) +// UpsertTargetProviderWithResponse request returning *UpsertTargetProviderResponse +func (c *ClientWithResponses) UpsertTargetProviderWithResponse(ctx context.Context, workspaceId string, name string, reqEditors ...RequestEditorFn) (*UpsertTargetProviderResponse, error) { + rsp, err := c.UpsertTargetProvider(ctx, workspaceId, name, reqEditors...) if err != nil { return nil, err } - return ParseGetTargetByIdentifierResponse(rsp) + return ParseUpsertTargetProviderResponse(rsp) } // ParseCreateEnvironmentResponse parses an HTTP response from a CreateEnvironmentWithResponse call @@ -2972,45 +2972,15 @@ func ParseSetTargetProvidersTargetsResponse(rsp *http.Response) (*SetTargetProvi return response, nil } -// ParseUpsertTargetProviderResponse parses an HTTP response from a UpsertTargetProviderWithResponse call -func ParseUpsertTargetProviderResponse(rsp *http.Response) (*UpsertTargetProviderResponse, error) { +// ParseDeleteResourceByIdentifierResponse parses an HTTP response from a DeleteResourceByIdentifierWithResponse call +func ParseDeleteResourceByIdentifierResponse(rsp *http.Response) (*DeleteResourceByIdentifierResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } - response := &UpsertTargetProviderResponse{ - Body: bodyBytes, - HTTPResponse: rsp, - } - - switch { - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest struct { - Id string `json:"id"` - Name string `json:"name"` - WorkspaceId string `json:"workspaceId"` - } - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON200 = &dest - - } - - return response, nil -} - -// ParseDeleteTargetByIdentifierResponse parses an HTTP response from a DeleteTargetByIdentifierWithResponse call -func ParseDeleteTargetByIdentifierResponse(rsp *http.Response) (*DeleteTargetByIdentifierResponse, error) { - bodyBytes, err := io.ReadAll(rsp.Body) - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &DeleteTargetByIdentifierResponse{ + response := &DeleteResourceByIdentifierResponse{ Body: bodyBytes, HTTPResponse: rsp, } @@ -3039,15 +3009,15 @@ func ParseDeleteTargetByIdentifierResponse(rsp *http.Response) (*DeleteTargetByI return response, nil } -// ParseGetTargetByIdentifierResponse parses an HTTP response from a GetTargetByIdentifierWithResponse call -func ParseGetTargetByIdentifierResponse(rsp *http.Response) (*GetTargetByIdentifierResponse, error) { +// ParseGetResourceByIdentifierResponse parses an HTTP response from a GetResourceByIdentifierWithResponse call +func ParseGetResourceByIdentifierResponse(rsp *http.Response) (*GetResourceByIdentifierResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } - response := &GetTargetByIdentifierResponse{ + response := &GetResourceByIdentifierResponse{ Body: bodyBytes, HTTPResponse: rsp, } @@ -3089,3 +3059,33 @@ func ParseGetTargetByIdentifierResponse(rsp *http.Response) (*GetTargetByIdentif return response, nil } + +// ParseUpsertTargetProviderResponse parses an HTTP response from a UpsertTargetProviderWithResponse call +func ParseUpsertTargetProviderResponse(rsp *http.Response) (*UpsertTargetProviderResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &UpsertTargetProviderResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + Id string `json:"id"` + Name string `json:"name"` + WorkspaceId string `json:"workspaceId"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +}