From 47eccc96f622c8c903cc0445da811366414ee9e1 Mon Sep 17 00:00:00 2001 From: uturunku1 Date: Fri, 25 Feb 2022 10:34:26 -0800 Subject: [PATCH] update description to start with the name of the func --- admin_organization.go | 6 ++--- admin_setting_smtp.go | 2 +- ip_ranges.go | 43 ----------------------------------- notification_configuration.go | 6 ++--- organization_tags.go | 2 +- policy_set.go | 8 +++---- registry_module.go | 2 +- run_task.go | 2 +- run_trigger.go | 2 +- tfe.go | 40 ++++++++++++++++++++++++++++++++ user.go | 2 +- 11 files changed, 56 insertions(+), 59 deletions(-) diff --git a/admin_organization.go b/admin_organization.go index d734457a9..5c73db05c 100644 --- a/admin_organization.go +++ b/admin_organization.go @@ -118,7 +118,7 @@ func (s *adminOrganizations) List(ctx context.Context, options *AdminOrganizatio return orgl, nil } -// List specific organizations in the Terraform Enterprise installation that have permission to use an organization's modules. +// ListModuleConsumers lists specific organizations in the Terraform Enterprise installation that have permission to use an organization's modules. func (s *adminOrganizations) ListModuleConsumers(ctx context.Context, organization string, options *AdminOrganizationListModuleConsumersOptions) (*AdminOrganizationList, error) { if !validStringID(&organization) { return nil, ErrInvalidOrg @@ -140,7 +140,7 @@ func (s *adminOrganizations) ListModuleConsumers(ctx context.Context, organizati return orgl, nil } -// Show an organization by its name. +// Read an organization by its name. func (s *adminOrganizations) Read(ctx context.Context, organization string) (*AdminOrganization, error) { if !validStringID(&organization) { return nil, ErrInvalidOrg @@ -182,7 +182,7 @@ func (s *adminOrganizations) Update(ctx context.Context, organization string, op return org, nil } -// Update an organization to specify a list of organizations that can use modules from the sharing organization's private registry. +// UpdateModuleConsumers updates an organization to specify a list of organizations that can use modules from the sharing organization's private registry. func (s *adminOrganizations) UpdateModuleConsumers(ctx context.Context, organization string, consumerOrganizationIDs []string) error { if !validStringID(&organization) { return ErrInvalidOrg diff --git a/admin_setting_smtp.go b/admin_setting_smtp.go index feec20662..57d950f56 100644 --- a/admin_setting_smtp.go +++ b/admin_setting_smtp.go @@ -77,7 +77,7 @@ type AdminSMTPSettingsUpdateOptions struct { TestEmailAddress *string `jsonapi:"attr,test-email-address,omitempty"` } -// Updat updates the SMTP settings. +// Update updates the SMTP settings. func (a *adminSMTPSettings) Update(ctx context.Context, options AdminSMTPSettingsUpdateOptions) (*AdminSMTPSetting, error) { if err := options.valid(); err != nil { return nil, err diff --git a/ip_ranges.go b/ip_ranges.go index 59cc2daf1..c03e3fd1f 100644 --- a/ip_ranges.go +++ b/ip_ranges.go @@ -2,10 +2,6 @@ package tfe import ( "context" - "encoding/json" - "fmt" - - "github.com/hashicorp/go-retryablehttp" ) // Compile-time proof of interface implementation. @@ -58,42 +54,3 @@ func (i *ipRanges) Read(ctx context.Context, modifiedSince string) (*IPRange, er return ir, nil } - -// The IP ranges API is not returning jsonapi like every other endpoint -// which means we need to handle it differently. -func (i *ipRanges) customDo(ctx context.Context, req *retryablehttp.Request, ir *IPRange) error { - // Wait will block until the limiter can obtain a new token - // or returns an error if the given context is canceled. - if err := i.client.limiter.Wait(ctx); err != nil { - return err - } - - // Add the context to the request. - req = req.WithContext(ctx) - - // Execute the request and check the response. - resp, err := i.client.http.Do(req) - if err != nil { - // If we got an error, and the context has been canceled, - // the context's error is probably more useful. - select { - case <-ctx.Done(): - return ctx.Err() - default: - return err - } - } - defer resp.Body.Close() - - if resp.StatusCode < 200 && resp.StatusCode >= 400 { - return fmt.Errorf("error HTTP response while retrieving IP ranges: %d", resp.StatusCode) - } else if resp.StatusCode == 304 { - return nil - } - - err = json.NewDecoder(resp.Body).Decode(ir) - if err != nil { - return err - } - return nil -} diff --git a/notification_configuration.go b/notification_configuration.go index 151f21116..e81f604a1 100644 --- a/notification_configuration.go +++ b/notification_configuration.go @@ -179,7 +179,7 @@ func (o NotificationConfigurationCreateOptions) valid() error { return nil } -// Creates a notification configuration with the given options. +// Create a notification configuration with the given options. func (s *notificationConfigurations) Create(ctx context.Context, workspaceID string, options NotificationConfigurationCreateOptions) (*NotificationConfiguration, error) { if !validStringID(&workspaceID) { return nil, ErrInvalidWorkspaceID @@ -256,7 +256,7 @@ type NotificationConfigurationUpdateOptions struct { EmailUsers []*User `jsonapi:"relation,users,omitempty"` } -// Updates a notification configuration with the given options. +// Update a notification configuration with the given options. func (s *notificationConfigurations) Update(ctx context.Context, notificationConfigurationID string, options NotificationConfigurationUpdateOptions) (*NotificationConfiguration, error) { if !validStringID(¬ificationConfigurationID) { return nil, ErrInvalidNotificationConfigID @@ -292,7 +292,7 @@ func (s *notificationConfigurations) Delete(ctx context.Context, notificationCon return s.client.do(ctx, req, nil) } -// Verifies a notification configuration by delivering a verification +// Verify a notification configuration by delivering a verification // payload to the configured url. func (s *notificationConfigurations) Verify(ctx context.Context, notificationConfigurationID string) (*NotificationConfiguration, error) { if !validStringID(¬ificationConfigurationID) { diff --git a/organization_tags.go b/organization_tags.go index c4d2ca971..f55c79947 100644 --- a/organization_tags.go +++ b/organization_tags.go @@ -152,7 +152,7 @@ type workspaceID struct { ID string `jsonapi:"primary,workspaces"` } -// Add workspaces to a tag +// AddWorkspaces adds workspaces to a tag func (s *organizationTags) AddWorkspaces(ctx context.Context, tag string, options AddWorkspacesToTagOptions) error { if !validStringID(&tag) { return ErrInvalidTag diff --git a/policy_set.go b/policy_set.go index 19379117f..93bf14d27 100644 --- a/policy_set.go +++ b/policy_set.go @@ -311,7 +311,7 @@ func (o PolicySetAddPoliciesOptions) valid() error { return nil } -// Add policies to a policy set +// AddPolicies adds policies to a policy set func (s *policySets) AddPolicies(ctx context.Context, policySetID string, options PolicySetAddPoliciesOptions) error { if !validStringID(&policySetID) { return ErrInvalidPolicySetID @@ -346,7 +346,7 @@ func (o PolicySetRemovePoliciesOptions) valid() error { return nil } -// Remove policies from a policy set +// RemovePolicies remove policies from a policy set func (s *policySets) RemovePolicies(ctx context.Context, policySetID string, options PolicySetRemovePoliciesOptions) error { if !validStringID(&policySetID) { return ErrInvalidPolicySetID @@ -381,7 +381,7 @@ func (o PolicySetAddWorkspacesOptions) valid() error { return nil } -// Add workspaces to a policy set. +// Addworkspaces adds workspaces to a policy set. func (s *policySets) AddWorkspaces(ctx context.Context, policySetID string, options PolicySetAddWorkspacesOptions) error { if !validStringID(&policySetID) { return ErrInvalidPolicySetID @@ -416,7 +416,7 @@ func (o PolicySetRemoveWorkspacesOptions) valid() error { return nil } -// Remove workspaces from a policy set. +// RemoveWorkspaces removes workspaces from a policy set. func (s *policySets) RemoveWorkspaces(ctx context.Context, policySetID string, options PolicySetRemoveWorkspacesOptions) error { if !validStringID(&policySetID) { return ErrInvalidPolicySetID diff --git a/registry_module.go b/registry_module.go index c17c34c5c..fe46e3ad0 100644 --- a/registry_module.go +++ b/registry_module.go @@ -214,7 +214,7 @@ func (o RegistryModuleCreateVersionOptions) valid() error { return nil } -// Create a new registry module version +// CreateVersion creates a new registry module version func (r *registryModules) CreateVersion(ctx context.Context, organization, name, provider string, options RegistryModuleCreateVersionOptions) (*RegistryModuleVersion, error) { if !validStringID(&organization) { return nil, ErrInvalidOrg diff --git a/run_task.go b/run_task.go index 50e90282f..09eccb5e3 100644 --- a/run_task.go +++ b/run_task.go @@ -269,7 +269,7 @@ func (s *runTasks) Delete(ctx context.Context, runTaskID string) error { return s.client.do(ctx, req, nil) } -// Convenient method to attach a run task to a workspace. See: WorkspaceRunTasks.Create() +// AttachToWorkspace is a convenient method to attach a run task to a workspace. See: WorkspaceRunTasks.Create() func (s *runTasks) AttachToWorkspace(ctx context.Context, workspaceID, runTaskID string, enforcement TaskEnforcementLevel) (*WorkspaceRunTask, error) { return s.client.WorkspaceRunTasks.Create(ctx, workspaceID, WorkspaceRunTaskCreateOptions{ EnforcementLevel: enforcement, diff --git a/run_trigger.go b/run_trigger.go index 67c72336c..8ffc5c1c7 100644 --- a/run_trigger.go +++ b/run_trigger.go @@ -118,7 +118,7 @@ func (o RunTriggerCreateOptions) valid() error { return nil } -// Creates a run trigger with the given options. +// Create a run trigger with the given options. func (s *runTriggers) Create(ctx context.Context, workspaceID string, options RunTriggerCreateOptions) (*RunTrigger, error) { if !validStringID(&workspaceID) { return nil, ErrInvalidWorkspaceID diff --git a/tfe.go b/tfe.go index 970a73295..118a8d52b 100644 --- a/tfe.go +++ b/tfe.go @@ -669,6 +669,46 @@ func (c *Client) do(ctx context.Context, req *retryablehttp.Request, v interface return unmarshalResponse(resp.Body, v) } +// customDo is similar to func (c *Client) do(ctx context.Context, req *retryablehttp.Request, v interface{}) error. Except that The IP ranges API is not returning jsonapi like every other endpoint +// which means we need to handle it differently. + +func (i *ipRanges) customDo(ctx context.Context, req *retryablehttp.Request, ir *IPRange) error { + // Wait will block until the limiter can obtain a new token + // or returns an error if the given context is canceled. + if err := i.client.limiter.Wait(ctx); err != nil { + return err + } + + // Add the context to the request. + req = req.WithContext(ctx) + + // Execute the request and check the response. + resp, err := i.client.http.Do(req) + if err != nil { + // If we got an error, and the context has been canceled, + // the context's error is probably more useful. + select { + case <-ctx.Done(): + return ctx.Err() + default: + return err + } + } + defer resp.Body.Close() + + if resp.StatusCode < 200 && resp.StatusCode >= 400 { + return fmt.Errorf("error HTTP response while retrieving IP ranges: %d", resp.StatusCode) + } else if resp.StatusCode == 304 { + return nil + } + + err = json.NewDecoder(resp.Body).Decode(ir) + if err != nil { + return err + } + return nil +} + func unmarshalResponse(responseBody io.Reader, model interface{}) error { // Get the value of model so we can test if it's a struct. dst := reflect.Indirect(reflect.ValueOf(model)) diff --git a/user.go b/user.go index 2c9488a49..337972b8d 100644 --- a/user.go +++ b/user.go @@ -76,7 +76,7 @@ type UserUpdateOptions struct { Email *string `jsonapi:"attr,email,omitempty"` } -// Update attributes of the currently authenticated user. +// UpdateCurrent updates attributes of the currently authenticated user. func (s *users) UpdateCurrent(ctx context.Context, options UserUpdateOptions) (*User, error) { req, err := s.client.newRequest("PATCH", "account/update", &options) if err != nil {