From 77fb7aacee939016ab6a6ff24c17d1e8f68ae8b6 Mon Sep 17 00:00:00 2001 From: Omar Ismail Date: Thu, 11 Mar 2021 09:33:20 -0500 Subject: [PATCH] Change create/update options in resources to match JSON:API Type field (#190) * Update create/update options to match JSON:API Type field --- agent_pool.go | 20 +++++++++--------- agent_token.go | 10 ++++----- configuration_version.go | 10 ++++----- notification_configuration.go | 20 +++++++++--------- oauth_client.go | 10 ++++----- oauth_token.go | 10 ++++----- organization.go | 20 +++++++++--------- organization_membership.go | 9 ++++---- plan_export.go | 10 ++++----- policy.go | 20 +++++++++--------- policy_set.go | 20 +++++++++--------- policy_set_parameter.go | 20 +++++++++--------- registry_module.go | 20 +++++++++--------- run.go | 10 ++++----- run_trigger.go | 10 ++++----- ssh_key.go | 10 ++++----- state_version.go | 10 ++++----- team.go | 20 +++++++++--------- team_access.go | 20 +++++++++--------- user.go | 10 ++++----- variable.go | 20 +++++++++--------- workspace.go | 40 +++++++++++++++++------------------ 22 files changed, 175 insertions(+), 174 deletions(-) diff --git a/agent_pool.go b/agent_pool.go index 45523f02d..f1021f0b6 100644 --- a/agent_pool.go +++ b/agent_pool.go @@ -78,8 +78,11 @@ func (s *agentPools) List(ctx context.Context, organization string, options Agen // AgentPoolCreateOptions represents the options for creating an agent pool. type AgentPoolCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,agent-pools"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,agent-pools"` // A name to identify the agent pool. Name *string `jsonapi:"attr,name"` @@ -105,9 +108,6 @@ func (s *agentPools) Create(ctx context.Context, organization string, options Ag return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("organizations/%s/agent-pools", url.QueryEscape(organization)) req, err := s.client.newRequest("POST", u, &options) if err != nil { @@ -146,8 +146,11 @@ func (s *agentPools) Read(ctx context.Context, agentpoolID string) (*AgentPool, // AgentPoolUpdateOptions represents the options for updating an agent pool. type AgentPoolUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,agent-pools"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,agent-pools"` // A new name to identify the agent pool. Name *string `jsonapi:"attr,name"` @@ -170,9 +173,6 @@ func (s *agentPools) Update(ctx context.Context, agentPoolID string, options Age return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("agent-pools/%s", url.QueryEscape(agentPoolID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { diff --git a/agent_token.go b/agent_token.go index b39fec608..0c9c655c0 100644 --- a/agent_token.go +++ b/agent_token.go @@ -72,8 +72,11 @@ func (s *agentTokens) List(ctx context.Context, agentPoolID string) (*AgentToken // AgentTokenGenerateOptions represents the options for creating an agent token. type AgentTokenGenerateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,agent-tokens"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,agent-tokens"` // Description of the token Description *string `jsonapi:"attr,description"` @@ -89,9 +92,6 @@ func (s *agentTokens) Generate(ctx context.Context, agentPoolID string, options return nil, ErrAgentTokenDescription } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("agent-pools/%s/authentication-tokens", url.QueryEscape(agentPoolID)) req, err := s.client.newRequest("POST", u, &options) if err != nil { diff --git a/configuration_version.go b/configuration_version.go index 96e16548d..92e214a71 100644 --- a/configuration_version.go +++ b/configuration_version.go @@ -122,8 +122,11 @@ func (s *configurationVersions) List(ctx context.Context, workspaceID string, op // ConfigurationVersionCreateOptions represents the options for creating a // configuration version. type ConfigurationVersionCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,configuration-versions"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,configuration-versions"` // When true, runs are queued automatically when the configuration version // is uploaded. @@ -140,9 +143,6 @@ func (s *configurationVersions) Create(ctx context.Context, workspaceID string, return nil, ErrInvalidWorkspaceID } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("workspaces/%s/configuration-versions", url.QueryEscape(workspaceID)) req, err := s.client.newRequest("POST", u, &options) if err != nil { diff --git a/notification_configuration.go b/notification_configuration.go index 2bd642a94..77b03b753 100644 --- a/notification_configuration.go +++ b/notification_configuration.go @@ -131,8 +131,11 @@ func (s *notificationConfigurations) List(ctx context.Context, workspaceID strin // NotificationConfigurationCreateOptions represents the options for // creating a new notification configuration. type NotificationConfigurationCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,notification-configurations"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,notification-configurations"` // The destination type of the notification configuration DestinationType *NotificationDestinationType `jsonapi:"attr,destination-type"` @@ -188,9 +191,6 @@ func (s *notificationConfigurations) Create(ctx context.Context, workspaceID str return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("workspaces/%s/notification-configurations", url.QueryEscape(workspaceID)) req, err := s.client.newRequest("POST", u, &options) if err != nil { @@ -230,8 +230,11 @@ func (s *notificationConfigurations) Read(ctx context.Context, notificationConfi // NotificationConfigurationUpdateOptions represents the options for // updating a existing notification configuration. type NotificationConfigurationUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,notification-configurations"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,notification-configurations"` // Whether the notification configuration should be enabled or not Enabled *bool `jsonapi:"attr,enabled,omitempty"` @@ -262,9 +265,6 @@ func (s *notificationConfigurations) Update(ctx context.Context, notificationCon return nil, errors.New("invalid value for notification configuration ID") } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("notification-configurations/%s", url.QueryEscape(notificationConfigurationID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { diff --git a/oauth_client.go b/oauth_client.go index 69791cc4e..9b3ddcfca 100644 --- a/oauth_client.go +++ b/oauth_client.go @@ -108,8 +108,11 @@ func (s *oAuthClients) List(ctx context.Context, organization string, options OA // OAuthClientCreateOptions represents the options for creating an OAuth client. type OAuthClientCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,oauth-clients"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,oauth-clients"` // The base URL of your VCS provider's API. APIURL *string `jsonapi:"attr,api-url"` @@ -155,9 +158,6 @@ func (s *oAuthClients) Create(ctx context.Context, organization string, options return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("organizations/%s/oauth-clients", url.QueryEscape(organization)) req, err := s.client.newRequest("POST", u, &options) if err != nil { diff --git a/oauth_token.go b/oauth_token.go index 248fc2528..95283ea10 100644 --- a/oauth_token.go +++ b/oauth_token.go @@ -103,8 +103,11 @@ func (s *oAuthTokens) Read(ctx context.Context, oAuthTokenID string) (*OAuthToke // OAuthTokenUpdateOptions represents the options for updating an OAuth token. type OAuthTokenUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,oauth-tokens"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,oauth-tokens"` // A private SSH key to be used for git clone operations. PrivateSSHKey *string `jsonapi:"attr,ssh-key"` @@ -116,9 +119,6 @@ func (s *oAuthTokens) Update(ctx context.Context, oAuthTokenID string, options O return nil, errors.New("invalid value for OAuth token ID") } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("oauth-tokens/%s", url.QueryEscape(oAuthTokenID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { diff --git a/organization.go b/organization.go index d3a3983f4..f36e77c75 100644 --- a/organization.go +++ b/organization.go @@ -155,8 +155,11 @@ func (s *organizations) List(ctx context.Context, options OrganizationListOption // OrganizationCreateOptions represents the options for creating an organization. type OrganizationCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,organizations"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,organizations"` // Name of the organization. Name *string `jsonapi:"attr,name"` @@ -199,9 +202,6 @@ func (s *organizations) Create(ctx context.Context, options OrganizationCreateOp return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - req, err := s.client.newRequest("POST", "organizations", &options) if err != nil { return nil, err @@ -239,8 +239,11 @@ func (s *organizations) Read(ctx context.Context, organization string) (*Organiz // OrganizationUpdateOptions represents the options for updating an organization. type OrganizationUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,organizations"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,organizations"` // New name for the organization. Name *string `jsonapi:"attr,name,omitempty"` @@ -270,9 +273,6 @@ func (s *organizations) Update(ctx context.Context, organization string, options return nil, ErrInvalidOrg } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("organizations/%s", url.QueryEscape(organization)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { diff --git a/organization_membership.go b/organization_membership.go index c9756d089..79ea8aee4 100644 --- a/organization_membership.go +++ b/organization_membership.go @@ -94,8 +94,11 @@ func (s *organizationMemberships) List(ctx context.Context, organization string, // OrganizationMembershipCreateOptions represents the options for creating an organization membership. type OrganizationMembershipCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,organization-memberships"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,organization-memberships"` // User's email address. Email *string `jsonapi:"attr,email"` @@ -117,8 +120,6 @@ func (s *organizationMemberships) Create(ctx context.Context, organization strin return nil, err } - options.ID = "" - u := fmt.Sprintf("organizations/%s/organization-memberships", url.QueryEscape(organization)) req, err := s.client.newRequest("POST", u, &options) if err != nil { diff --git a/plan_export.go b/plan_export.go index cf9e9ced8..ff895e521 100644 --- a/plan_export.go +++ b/plan_export.go @@ -75,8 +75,11 @@ type PlanExport struct { // PlanExportCreateOptions represents the options for exporting data from a plan. type PlanExportCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,plan-exports"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,plan-exports"` // The plan to export. Plan *Plan `jsonapi:"relation,plan"` @@ -100,9 +103,6 @@ func (s *planExports) Create(ctx context.Context, options PlanExportCreateOption return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - req, err := s.client.newRequest("POST", "plan-exports", &options) if err != nil { return nil, err diff --git a/policy.go b/policy.go index 322fc927c..5118ab9b0 100644 --- a/policy.go +++ b/policy.go @@ -110,8 +110,11 @@ func (s *policies) List(ctx context.Context, organization string, options Policy // PolicyCreateOptions represents the options for creating a new policy. type PolicyCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,policies"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,policies"` // The name of the policy. Name *string `jsonapi:"attr,name"` @@ -159,9 +162,6 @@ func (s *policies) Create(ctx context.Context, organization string, options Poli return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("organizations/%s/policies", url.QueryEscape(organization)) req, err := s.client.newRequest("POST", u, &options) if err != nil { @@ -200,8 +200,11 @@ func (s *policies) Read(ctx context.Context, policyID string) (*Policy, error) { // PolicyUpdateOptions represents the options for updating a policy. type PolicyUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,policies"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,policies"` // A description of the policy's purpose. Description *string `jsonapi:"attr,description,omitempty"` @@ -216,9 +219,6 @@ func (s *policies) Update(ctx context.Context, policyID string, options PolicyUp return nil, errors.New("invalid value for policy ID") } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("policies/%s", url.QueryEscape(policyID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { diff --git a/policy_set.go b/policy_set.go index 81c78a017..d86568628 100644 --- a/policy_set.go +++ b/policy_set.go @@ -107,8 +107,11 @@ func (s *policySets) List(ctx context.Context, organization string, options Poli // PolicySetCreateOptions represents the options for creating a new policy set. type PolicySetCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,policy-sets"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,policy-sets"` // The name of the policy set. Name *string `jsonapi:"attr,name"` @@ -157,9 +160,6 @@ func (s *policySets) Create(ctx context.Context, organization string, options Po return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("organizations/%s/policy-sets", url.QueryEscape(organization)) req, err := s.client.newRequest("POST", u, &options) if err != nil { @@ -198,8 +198,11 @@ func (s *policySets) Read(ctx context.Context, policySetID string) (*PolicySet, // PolicySetUpdateOptions represents the options for updating a policy set. type PolicySetUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,policy-sets"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,policy-sets"` /// The name of the policy set. Name *string `jsonapi:"attr,name,omitempty"` @@ -240,9 +243,6 @@ func (s *policySets) Update(ctx context.Context, policySetID string, options Pol return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("policy-sets/%s", url.QueryEscape(policySetID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { diff --git a/policy_set_parameter.go b/policy_set_parameter.go index 6e2587b90..5c229bede 100644 --- a/policy_set_parameter.go +++ b/policy_set_parameter.go @@ -89,8 +89,11 @@ func (s *policySetParameters) List(ctx context.Context, policySetID string, opti // PolicySetParameterCreateOptions represents the options for creating a new parameter. type PolicySetParameterCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,vars"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,vars"` // The name of the parameter. Key *string `jsonapi:"attr,key"` @@ -127,9 +130,6 @@ func (s *policySetParameters) Create(ctx context.Context, policySetID string, op return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("policy-sets/%s/parameters", url.QueryEscape(policySetID)) req, err := s.client.newRequest("POST", u, &options) if err != nil { @@ -171,8 +171,11 @@ func (s *policySetParameters) Read(ctx context.Context, policySetID string, para // PolicySetParameterUpdateOptions represents the options for updating a parameter. type PolicySetParameterUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,vars"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,vars"` // The name of the parameter. Key *string `jsonapi:"attr,key,omitempty"` @@ -193,9 +196,6 @@ func (s *policySetParameters) Update(ctx context.Context, policySetID string, pa return nil, errors.New("invalid value for parameter ID") } - // Make sure we don't send a user provided ID. - options.ID = parameterID - u := fmt.Sprintf("policy-sets/%s/parameters/%s", url.QueryEscape(policySetID), url.QueryEscape(parameterID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { diff --git a/registry_module.go b/registry_module.go index 0616a066f..750eb2da6 100644 --- a/registry_module.go +++ b/registry_module.go @@ -110,8 +110,11 @@ type RegistryModuleVersionStatuses struct { // RegistryModuleCreateOptions is used when creating a registry module without a VCS repo type RegistryModuleCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,registry-modules"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,registry-modules"` Name *string `jsonapi:"attr,name"` Provider *string `jsonapi:"attr,provider"` @@ -142,9 +145,6 @@ func (r *registryModules) Create(ctx context.Context, organization string, optio return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf( "organizations/%s/registry-modules", url.QueryEscape(organization), @@ -165,8 +165,11 @@ func (r *registryModules) Create(ctx context.Context, organization string, optio // RegistryModuleCreateVersionOptions is used when creating a registry module version type RegistryModuleCreateVersionOptions struct { - // For internal use only! - ID string `jsonapi:"primary,registry-module-versions"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,registry-module-versions"` Version *string `jsonapi:"attr,version"` } @@ -202,9 +205,6 @@ func (r *registryModules) CreateVersion(ctx context.Context, organization string return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf( "registry-modules/%s/%s/%s/versions", url.QueryEscape(organization), diff --git a/run.go b/run.go index 245a8fa67..dcb2aa508 100644 --- a/run.go +++ b/run.go @@ -176,8 +176,11 @@ func (s *runs) List(ctx context.Context, workspaceID string, options RunListOpti // RunCreateOptions represents the options for creating a new run. type RunCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,runs"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,runs"` // Specifies if this plan is a destroy plan, which will destroy all // provisioned resources. @@ -221,9 +224,6 @@ func (s *runs) Create(ctx context.Context, options RunCreateOptions) (*Run, erro return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - req, err := s.client.newRequest("POST", "runs", &options) if err != nil { return nil, err diff --git a/run_trigger.go b/run_trigger.go index 5402e670a..eb8005a1c 100644 --- a/run_trigger.go +++ b/run_trigger.go @@ -99,8 +99,11 @@ func (s *runTriggers) List(ctx context.Context, workspaceID string, options RunT // RunTriggerCreateOptions represents the options for // creating a new run trigger. type RunTriggerCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,run-triggers"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,run-triggers"` // The source workspace Sourceable *Workspace `jsonapi:"relation,sourceable"` @@ -122,9 +125,6 @@ func (s *runTriggers) Create(ctx context.Context, workspaceID string, options Ru return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("workspaces/%s/run-triggers", url.QueryEscape(workspaceID)) req, err := s.client.newRequest("POST", u, &options) if err != nil { diff --git a/ssh_key.go b/ssh_key.go index 334e88bc4..55f500b64 100644 --- a/ssh_key.go +++ b/ssh_key.go @@ -77,8 +77,11 @@ func (s *sshKeys) List(ctx context.Context, organization string, options SSHKeyL // SSHKeyCreateOptions represents the options for creating an SSH key. type SSHKeyCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,ssh-keys"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,ssh-keys"` // A name to identify the SSH key. Name *string `jsonapi:"attr,name"` @@ -107,9 +110,6 @@ func (s *sshKeys) Create(ctx context.Context, organization string, options SSHKe return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("organizations/%s/ssh-keys", url.QueryEscape(organization)) req, err := s.client.newRequest("POST", u, &options) if err != nil { diff --git a/state_version.go b/state_version.go index 4ba52eee9..8b4e6dec8 100644 --- a/state_version.go +++ b/state_version.go @@ -104,8 +104,11 @@ func (s *stateVersions) List(ctx context.Context, options StateVersionListOption // StateVersionCreateOptions represents the options for creating a state version. type StateVersionCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,state-versions"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,state-versions"` // The lineage of the state. Lineage *string `jsonapi:"attr,lineage,omitempty"` @@ -149,9 +152,6 @@ func (s *stateVersions) Create(ctx context.Context, workspaceID string, options return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("workspaces/%s/state-versions", url.QueryEscape(workspaceID)) req, err := s.client.newRequest("POST", u, &options) if err != nil { diff --git a/team.go b/team.go index b2b47cb62..8a59790df 100644 --- a/team.go +++ b/team.go @@ -99,8 +99,11 @@ func (s *teams) List(ctx context.Context, organization string, options TeamListO // TeamCreateOptions represents the options for creating a team. type TeamCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,teams"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,teams"` // Name of the team. Name *string `jsonapi:"attr,name"` @@ -135,9 +138,6 @@ func (s *teams) Create(ctx context.Context, organization string, options TeamCre return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("organizations/%s/teams", url.QueryEscape(organization)) req, err := s.client.newRequest("POST", u, &options) if err != nil { @@ -176,8 +176,11 @@ func (s *teams) Read(ctx context.Context, teamID string) (*Team, error) { // TeamUpdateOptions represents the options for updating a team. type TeamUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,teams"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,teams"` // New name for the team Name *string `jsonapi:"attr,name,omitempty"` @@ -195,9 +198,6 @@ func (s *teams) Update(ctx context.Context, teamID string, options TeamUpdateOpt return nil, errors.New("invalid value for team ID") } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("teams/%s", url.QueryEscape(teamID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { diff --git a/team_access.go b/team_access.go index 7226eeb45..5be3ef18b 100644 --- a/team_access.go +++ b/team_access.go @@ -139,8 +139,11 @@ func (s *teamAccesses) List(ctx context.Context, options TeamAccessListOptions) // TeamAccessAddOptions represents the options for adding team access. type TeamAccessAddOptions struct { - // For internal use only! - ID string `jsonapi:"primary,team-workspaces"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,team-workspaces"` // The type of access to grant. Access *AccessType `jsonapi:"attr,access"` @@ -179,9 +182,6 @@ func (s *teamAccesses) Add(ctx context.Context, options TeamAccessAddOptions) (* return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - req, err := s.client.newRequest("POST", "team-workspaces", &options) if err != nil { return nil, err @@ -219,8 +219,11 @@ func (s *teamAccesses) Read(ctx context.Context, teamAccessID string) (*TeamAcce // TeamAccessUpdateOptions represents the options for updating team access. type TeamAccessUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,team-workspaces"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,team-workspaces"` // The type of access to grant. Access *AccessType `jsonapi:"attr,access,omitempty"` @@ -240,9 +243,6 @@ func (s *teamAccesses) Update(ctx context.Context, teamAccessID string, options return nil, errors.New("invalid value for team access ID") } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("team-workspaces/%s", url.QueryEscape(teamAccessID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { diff --git a/user.go b/user.go index f0ca28ee3..96b64c8b4 100644 --- a/user.go +++ b/user.go @@ -63,8 +63,11 @@ func (s *users) ReadCurrent(ctx context.Context) (*User, error) { // UserUpdateOptions represents the options for updating a user. type UserUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,users"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,users"` // New username. Username *string `jsonapi:"attr,username,omitempty"` @@ -75,9 +78,6 @@ type UserUpdateOptions struct { // Update attributes of the currently authenticated user. func (s *users) Update(ctx context.Context, options UserUpdateOptions) (*User, error) { - // Make sure we don't send a user provided ID. - options.ID = "" - req, err := s.client.newRequest("PATCH", "account/update", &options) if err != nil { return nil, err diff --git a/variable.go b/variable.go index b68b2954a..60b52ca37 100644 --- a/variable.go +++ b/variable.go @@ -94,8 +94,11 @@ func (s *variables) List(ctx context.Context, workspaceID string, options Variab // VariableCreateOptions represents the options for creating a new variable. type VariableCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,vars"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,vars"` // The name of the variable. Key *string `jsonapi:"attr,key"` @@ -135,9 +138,6 @@ func (s *variables) Create(ctx context.Context, workspaceID string, options Vari return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("workspaces/%s/vars", url.QueryEscape(workspaceID)) req, err := s.client.newRequest("POST", u, &options) if err != nil { @@ -179,8 +179,11 @@ func (s *variables) Read(ctx context.Context, workspaceID string, variableID str // VariableUpdateOptions represents the options for updating a variable. type VariableUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,vars"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,vars"` // The name of the variable. Key *string `jsonapi:"attr,key,omitempty"` @@ -207,9 +210,6 @@ func (s *variables) Update(ctx context.Context, workspaceID string, variableID s return nil, errors.New("invalid value for variable ID") } - // Make sure we don't send a user provided ID. - options.ID = variableID - u := fmt.Sprintf("workspaces/%s/vars/%s", url.QueryEscape(workspaceID), url.QueryEscape(variableID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { diff --git a/workspace.go b/workspace.go index 06ac13be3..867400739 100644 --- a/workspace.go +++ b/workspace.go @@ -167,8 +167,11 @@ func (s *workspaces) List(ctx context.Context, organization string, options Work // WorkspaceCreateOptions represents the options for creating a new workspace. type WorkspaceCreateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,workspaces"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,workspaces"` // Required when execution-mode is set to agent. The ID of the agent pool // belonging to the workspace's organization. This value must not be specified @@ -277,9 +280,6 @@ func (s *workspaces) Create(ctx context.Context, organization string, options Wo return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("organizations/%s/workspaces", url.QueryEscape(organization)) req, err := s.client.newRequest("POST", u, &options) if err != nil { @@ -346,8 +346,11 @@ func (s *workspaces) ReadByID(ctx context.Context, workspaceID string) (*Workspa // WorkspaceUpdateOptions represents the options for updating a workspace. type WorkspaceUpdateOptions struct { - // For internal use only! - ID string `jsonapi:"primary,workspaces"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,workspaces"` // Required when execution-mode is set to agent. The ID of the agent pool // belonging to the workspace's organization. This value must not be specified @@ -442,9 +445,6 @@ func (s *workspaces) Update(ctx context.Context, organization, workspace string, return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf( "organizations/%s/workspaces/%s", url.QueryEscape(organization), @@ -470,9 +470,6 @@ func (s *workspaces) UpdateByID(ctx context.Context, workspaceID string, options return nil, ErrInvalidWorkspaceID } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("workspaces/%s", url.QueryEscape(workspaceID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { @@ -654,8 +651,11 @@ func (s *workspaces) ForceUnlock(ctx context.Context, workspaceID string) (*Work // WorkspaceAssignSSHKeyOptions represents the options to assign an SSH key to // a workspace. type WorkspaceAssignSSHKeyOptions struct { - // For internal use only! - ID string `jsonapi:"primary,workspaces"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,workspaces"` // The SSH key ID to assign. SSHKeyID *string `jsonapi:"attr,id"` @@ -680,9 +680,6 @@ func (s *workspaces) AssignSSHKey(ctx context.Context, workspaceID string, optio return nil, err } - // Make sure we don't send a user provided ID. - options.ID = "" - u := fmt.Sprintf("workspaces/%s/relationships/ssh-key", url.QueryEscape(workspaceID)) req, err := s.client.newRequest("PATCH", u, &options) if err != nil { @@ -701,8 +698,11 @@ func (s *workspaces) AssignSSHKey(ctx context.Context, workspaceID string, optio // workspaceUnassignSSHKeyOptions represents the options to unassign an SSH key // to a workspace. type workspaceUnassignSSHKeyOptions struct { - // For internal use only! - ID string `jsonapi:"primary,workspaces"` + // Type is a public field utilized by JSON:API to + // set the resource type via the field tag. + // It is not a user-defined value and does not need to be set. + // https://jsonapi.org/format/#crud-creating + Type string `jsonapi:"primary,workspaces"` // Must be nil to unset the currently assigned SSH key. SSHKeyID *string `jsonapi:"attr,id"`