Skip to content

Commit

Permalink
update description to start with the name of the func
Browse files Browse the repository at this point in the history
  • Loading branch information
uturunku1 committed Feb 25, 2022
1 parent 5de4116 commit 47eccc9
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 59 deletions.
6 changes: 3 additions & 3 deletions admin_organization.go
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion admin_setting_smtp.go
Expand Up @@ -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
Expand Down
43 changes: 0 additions & 43 deletions ip_ranges.go
Expand Up @@ -2,10 +2,6 @@ package tfe

import (
"context"
"encoding/json"
"fmt"

"github.com/hashicorp/go-retryablehttp"
)

// Compile-time proof of interface implementation.
Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions notification_configuration.go
Expand Up @@ -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
Expand Down Expand Up @@ -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(&notificationConfigurationID) {
return nil, ErrInvalidNotificationConfigID
Expand Down Expand Up @@ -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(&notificationConfigurationID) {
Expand Down
2 changes: 1 addition & 1 deletion organization_tags.go
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions policy_set.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion registry_module.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion run_task.go
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion run_trigger.go
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions tfe.go
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion user.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 47eccc9

Please sign in to comment.