Skip to content

Commit

Permalink
Merge pull request #330 from hashicorp/sebasslash/organize-code
Browse files Browse the repository at this point in the history
Organize code structure
  • Loading branch information
sebasslash committed Feb 25, 2022
2 parents df4ec36 + 58a3199 commit a2b5498
Show file tree
Hide file tree
Showing 33 changed files with 1,568 additions and 1,570 deletions.
10 changes: 5 additions & 5 deletions admin_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ type AdminRuns interface {
ForceCancel(ctx context.Context, runID string, options AdminRunForceCancelOptions) error
}

// adminRuns implements the AdminRuns interface.
type adminRuns struct {
client *Client
}

type AdminRun struct {
ID string `jsonapi:"primary,runs"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
Expand Down Expand Up @@ -66,6 +61,11 @@ type AdminRunsListOptions struct {
Include []AdminRunIncludeOps `url:"include,omitempty"`
}

// adminRuns implements the AdminRuns interface.
type adminRuns struct {
client *Client
}

// List all the runs of the terraform enterprise installation.
// https://www.terraform.io/docs/cloud/api/admin/runs.html#list-all-runs
func (s *adminRuns) List(ctx context.Context, options *AdminRunsListOptions) (*AdminRunsList, error) {
Expand Down
28 changes: 14 additions & 14 deletions admin_setting_cost_estimation.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ type AdminCostEstimationSetting struct {
AzureTenantID string `jsonapi:"attr,azure-tenant-id"`
}

// AdminCostEstimationSettingOptions represents the admin options for updating
// the cost estimation settings.
// https://www.terraform.io/docs/cloud/api/admin/settings.html#request-body-1
type AdminCostEstimationSettingOptions struct {
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
AWSAccessKeyID *string `jsonapi:"attr,aws-access-key-id,omitempty"`
AWSAccessKey *string `jsonapi:"attr,aws-secret-key,omitempty"`
GCPCredentials *string `jsonapi:"attr,gcp-credentials,omitempty"`
AzureClientID *string `jsonapi:"attr,azure-client-id,omitempty"`
AzureClientSecret *string `jsonapi:"attr,azure-client-secret,omitempty"`
AzureSubscriptionID *string `jsonapi:"attr,azure-subscription-id,omitempty"`
AzureTenantID *string `jsonapi:"attr,azure-tenant-id,omitempty"`
}

// Read returns the cost estimation settings.
func (a *adminCostEstimationSettings) Read(ctx context.Context) (*AdminCostEstimationSetting, error) {
req, err := a.client.newRequest("GET", "admin/cost-estimation-settings", nil)
Expand All @@ -53,20 +67,6 @@ func (a *adminCostEstimationSettings) Read(ctx context.Context) (*AdminCostEstim
return ace, nil
}

// AdminCostEstimationSettingOptions represents the admin options for updating
// the cost estimation settings.
// https://www.terraform.io/docs/cloud/api/admin/settings.html#request-body-1
type AdminCostEstimationSettingOptions struct {
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
AWSAccessKeyID *string `jsonapi:"attr,aws-access-key-id,omitempty"`
AWSAccessKey *string `jsonapi:"attr,aws-secret-key,omitempty"`
GCPCredentials *string `jsonapi:"attr,gcp-credentials,omitempty"`
AzureClientID *string `jsonapi:"attr,azure-client-id,omitempty"`
AzureClientSecret *string `jsonapi:"attr,azure-client-secret,omitempty"`
AzureSubscriptionID *string `jsonapi:"attr,azure-subscription-id,omitempty"`
AzureTenantID *string `jsonapi:"attr,azure-tenant-id,omitempty"`
}

// Update updates the cost-estimation settings.
func (a *adminCostEstimationSettings) Update(ctx context.Context, options AdminCostEstimationSettingOptions) (*AdminCostEstimationSetting, error) {
req, err := a.client.newRequest("PATCH", "admin/cost-estimation-settings", &options)
Expand Down
24 changes: 12 additions & 12 deletions admin_setting_general.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ type AdminGeneralSetting struct {
DefaultRemoteStateAccess bool `jsonapi:"attr,default-remote-state-access"`
}

// AdminGeneralSettingsUpdateOptions represents the admin options for updating
// general settings.
// https://www.terraform.io/docs/cloud/api/admin/settings.html#request-body
type AdminGeneralSettingsUpdateOptions struct {
LimitUserOrgCreation *bool `jsonapi:"attr,limit-user-organization-creation,omitempty"`
APIRateLimitingEnabled *bool `jsonapi:"attr,api-rate-limiting-enabled,omitempty"`
APIRateLimit *int `jsonapi:"attr,api-rate-limit,omitempty"`
SendPassingStatusUntriggeredPlans *bool `jsonapi:"attr,send-passing-statuses-for-untriggered-speculative-plans,omitempty"`
AllowSpeculativePlansOnPR *bool `jsonapi:"attr,allow-speculative-plans-on-pull-requests-from-forks,omitempty"`
DefaultRemoteStateAccess *bool `jsonapi:"attr,default-remote-state-access,omitempty"`
}

// Read returns the general settings.
func (a *adminGeneralSettings) Read(ctx context.Context) (*AdminGeneralSetting, error) {
req, err := a.client.newRequest("GET", "admin/general-settings", nil)
Expand All @@ -55,18 +67,6 @@ func (a *adminGeneralSettings) Read(ctx context.Context) (*AdminGeneralSetting,
return ags, nil
}

// AdminGeneralSettingsUpdateOptions represents the admin options for updating
// general settings.
// https://www.terraform.io/docs/cloud/api/admin/settings.html#request-body
type AdminGeneralSettingsUpdateOptions struct {
LimitUserOrgCreation *bool `jsonapi:"attr,limit-user-organization-creation,omitempty"`
APIRateLimitingEnabled *bool `jsonapi:"attr,api-rate-limiting-enabled,omitempty"`
APIRateLimit *int `jsonapi:"attr,api-rate-limit,omitempty"`
SendPassingStatusUntriggeredPlans *bool `jsonapi:"attr,send-passing-statuses-for-untriggered-speculative-plans,omitempty"`
AllowSpeculativePlansOnPR *bool `jsonapi:"attr,allow-speculative-plans-on-pull-requests-from-forks,omitempty"`
DefaultRemoteStateAccess *bool `jsonapi:"attr,default-remote-state-access,omitempty"`
}

// Update updates the general settings.
func (a *adminGeneralSettings) Update(ctx context.Context, options AdminGeneralSettingsUpdateOptions) (*AdminGeneralSetting, error) {
req, err := a.client.newRequest("PATCH", "admin/general-settings", &options)
Expand Down
12 changes: 6 additions & 6 deletions admin_setting_twilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ type AdminTwilioSettingsUpdateOptions struct {
FromNumber *string `jsonapi:"attr,from-number,omitempty"`
}

// AdminTwilioSettingsVerifyOptions represents the test number to verify Twilio.
// https://www.terraform.io/docs/cloud/api/admin/settings.html#verify-twilio-settings
type AdminTwilioSettingsVerifyOptions struct {
TestNumber *string `jsonapi:"attr,test-number"`
}

// Update updates the Twilio settings.
func (a *adminTwilioSettings) Update(ctx context.Context, options AdminTwilioSettingsUpdateOptions) (*AdminTwilioSetting, error) {
req, err := a.client.newRequest("PATCH", "admin/twilio-settings", &options)
Expand All @@ -73,12 +79,6 @@ func (a *adminTwilioSettings) Update(ctx context.Context, options AdminTwilioSet
return twilio, nil
}

// AdminTwilioSettingsVerifyOptions represents the test number to verify Twilio.
// https://www.terraform.io/docs/cloud/api/admin/settings.html#verify-twilio-settings
type AdminTwilioSettingsVerifyOptions struct {
TestNumber *string `jsonapi:"attr,test-number"`
}

// Verify verifies Twilio settings.
func (a *adminTwilioSettings) Verify(ctx context.Context, options AdminTwilioSettingsVerifyOptions) error {
if err := options.valid(); err != nil {
Expand Down
56 changes: 28 additions & 28 deletions admin_terraform_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ type AdminTerraformVersionsListOptions struct {
Search string `url:"search[version],omitempty"`
}

// AdminTerraformVersionCreateOptions for creating a terraform version.
// https://www.terraform.io/docs/cloud/api/admin/terraform-versions.html#request-body
type AdminTerraformVersionCreateOptions struct {
Type string `jsonapi:"primary,terraform-versions"`
Version *string `jsonapi:"attr,version"`
URL *string `jsonapi:"attr,url"`
Sha *string `jsonapi:"attr,sha"`
Official *bool `jsonapi:"attr,official,omitempty"`
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
Beta *bool `jsonapi:"attr,beta,omitempty"`
}

// AdminTerraformVersionUpdateOptions for updating terraform version.
// https://www.terraform.io/docs/cloud/api/admin/terraform-versions.html#request-body
type AdminTerraformVersionUpdateOptions struct {
Type string `jsonapi:"primary,terraform-versions"`
Version *string `jsonapi:"attr,version,omitempty"`
URL *string `jsonapi:"attr,url,omitempty"`
Sha *string `jsonapi:"attr,sha,omitempty"`
Official *bool `jsonapi:"attr,official,omitempty"`
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
Beta *bool `jsonapi:"attr,beta,omitempty"`
}

// AdminTerraformVersionsList represents a list of terraform versions.
type AdminTerraformVersionsList struct {
*Pagination
Expand Down Expand Up @@ -107,20 +135,6 @@ func (a *adminTerraformVersions) Read(ctx context.Context, id string) (*AdminTer
return tfv, nil
}

// AdminTerraformVersionCreateOptions for creating a terraform version.
// https://www.terraform.io/docs/cloud/api/admin/terraform-versions.html#request-body
type AdminTerraformVersionCreateOptions struct {
Type string `jsonapi:"primary,terraform-versions"`
Version *string `jsonapi:"attr,version"`
URL *string `jsonapi:"attr,url"`
Sha *string `jsonapi:"attr,sha"`
Official *bool `jsonapi:"attr,official,omitempty"`
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
Beta *bool `jsonapi:"attr,beta,omitempty"`
}

// Create a new terraform version.
func (a *adminTerraformVersions) Create(ctx context.Context, options AdminTerraformVersionCreateOptions) (*AdminTerraformVersion, error) {
if err := options.valid(); err != nil {
Expand All @@ -140,20 +154,6 @@ func (a *adminTerraformVersions) Create(ctx context.Context, options AdminTerraf
return tfv, nil
}

// AdminTerraformVersionUpdateOptions for updating terraform version.
// https://www.terraform.io/docs/cloud/api/admin/terraform-versions.html#request-body
type AdminTerraformVersionUpdateOptions struct {
Type string `jsonapi:"primary,terraform-versions"`
Version *string `jsonapi:"attr,version,omitempty"`
URL *string `jsonapi:"attr,url,omitempty"`
Sha *string `jsonapi:"attr,sha,omitempty"`
Official *bool `jsonapi:"attr,official,omitempty"`
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
Beta *bool `jsonapi:"attr,beta,omitempty"`
}

// Update an existing terraform version.
func (a *adminTerraformVersions) Update(ctx context.Context, id string, options AdminTerraformVersionUpdateOptions) (*AdminTerraformVersion, error) {
if !validStringID(&id) {
Expand Down
58 changes: 29 additions & 29 deletions agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ type AgentPoolListOptions struct {
ListOptions
}

// AgentPoolCreateOptions represents the options for creating an agent pool.
type AgentPoolCreateOptions struct {
// 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"`
}

// List all the agent pools of the given organization.
func (s *agentPools) List(ctx context.Context, organization string, options *AgentPoolListOptions) (*AgentPoolList, error) {
if !validStringID(&organization) {
Expand All @@ -76,28 +88,6 @@ func (s *agentPools) List(ctx context.Context, organization string, options *Age
return poolList, nil
}

// AgentPoolCreateOptions represents the options for creating an agent pool.
type AgentPoolCreateOptions struct {
// 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"`
}

func (o AgentPoolCreateOptions) valid() error {
if !validString(o.Name) {
return ErrRequiredName
}
if !validStringID(o.Name) {
return ErrInvalidName
}
return nil
}

// Create a new agent pool with the given options.
func (s *agentPools) Create(ctx context.Context, organization string, options AgentPoolCreateOptions) (*AgentPool, error) {
if !validStringID(&organization) {
Expand Down Expand Up @@ -156,13 +146,6 @@ type AgentPoolUpdateOptions struct {
Name *string `jsonapi:"attr,name"`
}

func (o AgentPoolUpdateOptions) valid() error {
if o.Name != nil && !validStringID(o.Name) {
return ErrInvalidName
}
return nil
}

// Update an agent pool by its ID.
func (s *agentPools) Update(ctx context.Context, agentPoolID string, options AgentPoolUpdateOptions) (*AgentPool, error) {
if !validStringID(&agentPoolID) {
Expand Down Expand Up @@ -202,3 +185,20 @@ func (s *agentPools) Delete(ctx context.Context, agentPoolID string) error {

return s.client.do(ctx, req, nil)
}

func (o AgentPoolCreateOptions) valid() error {
if !validString(o.Name) {
return ErrRequiredName
}
if !validStringID(o.Name) {
return ErrInvalidName
}
return nil
}

func (o AgentPoolUpdateOptions) valid() error {
if o.Name != nil && !validStringID(o.Name) {
return ErrInvalidName
}
return nil
}
36 changes: 18 additions & 18 deletions agent_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ type agentTokens struct {
client *Client
}

// AgentTokenList represents a list of agent tokens.
type AgentTokenList struct {
*Pagination
Items []*AgentToken
}

// AgentToken represents a Terraform Cloud agent token.
type AgentToken struct {
ID string `jsonapi:"primary,authentication-tokens"`
Expand All @@ -49,6 +43,24 @@ type AgentToken struct {
Token string `jsonapi:"attr,token"`
}

// AgentTokenList represents a list of agent tokens.
type AgentTokenList struct {
*Pagination
Items []*AgentToken
}

// AgentTokenCreateOptions represents the options for creating an agent token.
type AgentTokenCreateOptions struct {
// 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"`
}

// List all the agent tokens of the given agent pool.
func (s *agentTokens) List(ctx context.Context, agentPoolID string) (*AgentTokenList, error) {
if !validStringID(&agentPoolID) {
Expand All @@ -70,18 +82,6 @@ func (s *agentTokens) List(ctx context.Context, agentPoolID string) (*AgentToken
return tokenList, nil
}

// AgentTokenCreateOptions represents the options for creating an agent token.
type AgentTokenCreateOptions struct {
// 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"`
}

// Create a new agent token with the given options.
func (s *agentTokens) Create(ctx context.Context, agentPoolID string, options AgentTokenCreateOptions) (*AgentToken, error) {
if !validStringID(&agentPoolID) {
Expand Down
34 changes: 17 additions & 17 deletions configuration_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ type ConfigurationVersionListOptions struct {
Include []ConfigurationVersionIncludeOps `url:"include,omitempty"`
}

// ConfigurationVersionCreateOptions represents the options for creating a
// configuration version.
type ConfigurationVersionCreateOptions struct {
// 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.
AutoQueueRuns *bool `jsonapi:"attr,auto-queue-runs,omitempty"`

// When true, this configuration version can only be used for planning.
Speculative *bool `jsonapi:"attr,speculative,omitempty"`
}

// IngressAttributes include commit information associated with configuration versions sourced from VCS.
type IngressAttributes struct {
ID string `jsonapi:"primary,ingress-attributes"`
Expand Down Expand Up @@ -166,23 +183,6 @@ func (s *configurationVersions) List(ctx context.Context, workspaceID string, op
return cvl, nil
}

// ConfigurationVersionCreateOptions represents the options for creating a
// configuration version.
type ConfigurationVersionCreateOptions struct {
// 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.
AutoQueueRuns *bool `jsonapi:"attr,auto-queue-runs,omitempty"`

// When true, this configuration version can only be used for planning.
Speculative *bool `jsonapi:"attr,speculative,omitempty"`
}

// Create is used to create a new configuration version. The created
// configuration version will be usable once data is uploaded to it.
func (s *configurationVersions) Create(ctx context.Context, workspaceID string, options ConfigurationVersionCreateOptions) (*ConfigurationVersion, error) {
Expand Down

0 comments on commit a2b5498

Please sign in to comment.