Merge pull request #20460 from hashicorp/svh/f-permissions
backend/remote: use the can-queue-apply permission
This commit is contained in:
commit
435b82d6d0
|
@ -18,7 +18,9 @@ func (b *Remote) opApply(stopCtx, cancelCtx context.Context, op *backend.Operati
|
|||
|
||||
var diags tfdiags.Diagnostics
|
||||
|
||||
if !w.Permissions.CanUpdate {
|
||||
// We should remove the `CanUpdate` part of this test, but for now
|
||||
// (to remain compatible with tfe.v2.1) we'll leave it in here.
|
||||
if !w.Permissions.CanUpdate && !w.Permissions.CanQueueApply {
|
||||
diags = diags.Append(tfdiags.Sourceless(
|
||||
tfdiags.Error,
|
||||
"Insufficient rights to apply changes",
|
||||
|
|
|
@ -972,6 +972,15 @@ func (m *mockWorkspaces) Delete(ctx context.Context, organization, workspace str
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *mockWorkspaces) RemoveVCSConnection(ctx context.Context, organization, workspace string) (*tfe.Workspace, error) {
|
||||
w, ok := m.workspaceNames[workspace]
|
||||
if !ok {
|
||||
return nil, tfe.ErrResourceNotFound
|
||||
}
|
||||
w.VCSRepo = nil
|
||||
return w, nil
|
||||
}
|
||||
|
||||
func (m *mockWorkspaces) Lock(ctx context.Context, workspaceID string, options tfe.WorkspaceLockOptions) (*tfe.Workspace, error) {
|
||||
w, ok := m.workspaceIDs[workspaceID]
|
||||
if !ok {
|
||||
|
|
2
go.mod
2
go.mod
|
@ -57,7 +57,7 @@ require (
|
|||
github.com/hashicorp/go-retryablehttp v0.5.1
|
||||
github.com/hashicorp/go-rootcerts v1.0.0
|
||||
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86 // indirect
|
||||
github.com/hashicorp/go-tfe v0.3.8
|
||||
github.com/hashicorp/go-tfe v0.3.10
|
||||
github.com/hashicorp/go-uuid v1.0.0
|
||||
github.com/hashicorp/go-version v1.1.0
|
||||
github.com/hashicorp/golang-lru v0.5.0 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -187,8 +187,8 @@ github.com/hashicorp/go-slug v0.2.0 h1:MVdZAkTmDsUi1AT+3NQDsn8n3ssnVSIHwiM6RcUHv
|
|||
github.com/hashicorp/go-slug v0.2.0/go.mod h1:+zDycQOzGqOqMW7Kn2fp9vz/NtqpMLQlgb9JUF+0km4=
|
||||
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86 h1:7YOlAIO2YWnJZkQp7B5eFykaIY7C9JndqAFQyVV5BhM=
|
||||
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
||||
github.com/hashicorp/go-tfe v0.3.8 h1:pUqxmnhZ7Dj3biugEEo2oGZ758zVQy70lx8p7p4JREY=
|
||||
github.com/hashicorp/go-tfe v0.3.8/go.mod h1:LHLchj07PCYgQqcyE5Sz+g4zrMNW+nALKbiSNTZedEs=
|
||||
github.com/hashicorp/go-tfe v0.3.10 h1:6uPnPHNPxXDe3k/Vt6fovygYTaWJ8f/7zdHc++f7NJU=
|
||||
github.com/hashicorp/go-tfe v0.3.10/go.mod h1:LHLchj07PCYgQqcyE5Sz+g4zrMNW+nALKbiSNTZedEs=
|
||||
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
|
||||
|
|
|
@ -80,7 +80,7 @@ type Organization struct {
|
|||
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
|
||||
Email string `jsonapi:"attr,email"`
|
||||
EnterprisePlan EnterprisePlanType `jsonapi:"attr,enterprise-plan"`
|
||||
OwnersTeamSamlRoleID string `jsonapi:"attr,owners-team-saml-role-id"`
|
||||
OwnersTeamSAMLRoleID string `jsonapi:"attr,owners-team-saml-role-id"`
|
||||
Permissions *OrganizationPermissions `jsonapi:"attr,permissions"`
|
||||
SAMLEnabled bool `jsonapi:"attr,saml-enabled"`
|
||||
SessionRemember int `jsonapi:"attr,session-remember"`
|
||||
|
@ -157,6 +157,18 @@ type OrganizationCreateOptions struct {
|
|||
|
||||
// Admin email address.
|
||||
Email *string `jsonapi:"attr,email"`
|
||||
|
||||
// Session expiration (minutes).
|
||||
SessionRemember *int `jsonapi:"attr,session-remember,omitempty"`
|
||||
|
||||
// Session timeout after inactivity (minutes).
|
||||
SessionTimeout *int `jsonapi:"attr,session-timeout,omitempty"`
|
||||
|
||||
// Authentication policy.
|
||||
CollaboratorAuthPolicy *AuthPolicyType `jsonapi:"attr,collaborator-auth-policy,omitempty"`
|
||||
|
||||
// The name of the "owners" team
|
||||
OwnersTeamSAMLRoleID *string `jsonapi:"attr,owners-team-saml-role-id,omitempty"`
|
||||
}
|
||||
|
||||
func (o OrganizationCreateOptions) valid() error {
|
||||
|
@ -235,6 +247,9 @@ type OrganizationUpdateOptions struct {
|
|||
|
||||
// Authentication policy.
|
||||
CollaboratorAuthPolicy *AuthPolicyType `jsonapi:"attr,collaborator-auth-policy,omitempty"`
|
||||
|
||||
// The name of the "owners" team
|
||||
OwnersTeamSAMLRoleID *string `jsonapi:"attr,owners-team-saml-role-id,omitempty"`
|
||||
}
|
||||
|
||||
// Update attributes of an existing organization.
|
||||
|
|
|
@ -122,10 +122,16 @@ type RunPermissions struct {
|
|||
|
||||
// RunStatusTimestamps holds the timestamps for individual run statuses.
|
||||
type RunStatusTimestamps struct {
|
||||
ErroredAt time.Time `json:"errored-at"`
|
||||
FinishedAt time.Time `json:"finished-at"`
|
||||
QueuedAt time.Time `json:"queued-at"`
|
||||
StartedAt time.Time `json:"started-at"`
|
||||
ErroredAt time.Time `json:"errored-at"`
|
||||
FinishedAt time.Time `json:"finished-at"`
|
||||
QueuedAt time.Time `json:"queued-at"`
|
||||
StartedAt time.Time `json:"started-at"`
|
||||
ApplyingAt time.Time `json:"applying-at"`
|
||||
AppliedAt time.Time `json:"applied-at"`
|
||||
PlanningAt time.Time `json:"planning-at"`
|
||||
PlannedAt time.Time `json:"planned-at"`
|
||||
PlannedAndFinishedAt time.Time `json:"planned-and-finished-at"`
|
||||
PlanQueuabledAt time.Time `json:"plan-queueable-at"`
|
||||
}
|
||||
|
||||
// RunListOptions represents the options for listing runs.
|
||||
|
|
|
@ -35,9 +35,6 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
// random is used to generate pseudo-random numbers.
|
||||
random = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
// ErrWorkspaceLocked is returned when trying to lock a
|
||||
// locked workspace.
|
||||
ErrWorkspaceLocked = errors.New("workspace already locked")
|
||||
|
@ -232,8 +229,11 @@ func rateLimitRetry(ctx context.Context, resp *http.Response, err error) (bool,
|
|||
// the reset time retrieved from the headers. But if the final wait time is
|
||||
// less then min, min will be used instead.
|
||||
func rateLimitBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
|
||||
// rnd is used to generate pseudo-random numbers.
|
||||
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
// First create some jitter bounded by the min and max durations.
|
||||
jitter := time.Duration(rand.Float64() * float64(max-min))
|
||||
jitter := time.Duration(rnd.Float64() * float64(max-min))
|
||||
|
||||
if resp != nil {
|
||||
if v := resp.Header.Get(headerRateReset); v != "" {
|
||||
|
|
|
@ -31,6 +31,9 @@ type Workspaces interface {
|
|||
// Delete a workspace by its name.
|
||||
Delete(ctx context.Context, organization string, workspace string) error
|
||||
|
||||
// RemoveVCSConnection from a workspace.
|
||||
RemoveVCSConnection(ctx context.Context, organization, workspace string) (*Workspace, error)
|
||||
|
||||
// Lock a workspace by its ID.
|
||||
Lock(ctx context.Context, workspaceID string, options WorkspaceLockOptions) (*Workspace, error)
|
||||
|
||||
|
@ -98,10 +101,13 @@ type WorkspaceActions struct {
|
|||
// WorkspacePermissions represents the workspace permissions.
|
||||
type WorkspacePermissions struct {
|
||||
CanDestroy bool `json:"can-destroy"`
|
||||
CanForceUnlock bool `json:"can-force-unlock"`
|
||||
CanLock bool `json:"can-lock"`
|
||||
CanQueueApply bool `json:"can-queue-apply"`
|
||||
CanQueueDestroy bool `json:"can-queue-destroy"`
|
||||
CanQueueRun bool `json:"can-queue-run"`
|
||||
CanReadSettings bool `json:"can-read-settings"`
|
||||
CanUnlock bool `json:"can-unlock"`
|
||||
CanUpdate bool `json:"can-update"`
|
||||
CanUpdateVariable bool `json:"can-update-variable"`
|
||||
}
|
||||
|
@ -333,6 +339,41 @@ func (s *workspaces) Delete(ctx context.Context, organization, workspace string)
|
|||
return s.client.do(ctx, req, nil)
|
||||
}
|
||||
|
||||
// workspaceRemoveVCSConnectionOptions
|
||||
type workspaceRemoveVCSConnectionOptions struct {
|
||||
ID string `jsonapi:"primary,workspaces"`
|
||||
VCSRepo *VCSRepoOptions `jsonapi:"attr,vcs-repo"`
|
||||
}
|
||||
|
||||
// RemoveVCSConnection from a workspace.
|
||||
func (s *workspaces) RemoveVCSConnection(ctx context.Context, organization, workspace string) (*Workspace, error) {
|
||||
if !validStringID(&organization) {
|
||||
return nil, errors.New("invalid value for organization")
|
||||
}
|
||||
if !validStringID(&workspace) {
|
||||
return nil, errors.New("invalid value for workspace")
|
||||
}
|
||||
|
||||
u := fmt.Sprintf(
|
||||
"organizations/%s/workspaces/%s",
|
||||
url.QueryEscape(organization),
|
||||
url.QueryEscape(workspace),
|
||||
)
|
||||
|
||||
req, err := s.client.newRequest("PATCH", u, &workspaceRemoveVCSConnectionOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
w := &Workspace{}
|
||||
err = s.client.do(ctx, req, w)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// WorkspaceLockOptions represents the options for locking a workspace.
|
||||
type WorkspaceLockOptions struct {
|
||||
// Specifies the reason for locking the workspace.
|
||||
|
|
|
@ -290,7 +290,7 @@ github.com/hashicorp/go-rootcerts
|
|||
github.com/hashicorp/go-safetemp
|
||||
# github.com/hashicorp/go-slug v0.2.0
|
||||
github.com/hashicorp/go-slug
|
||||
# github.com/hashicorp/go-tfe v0.3.8
|
||||
# github.com/hashicorp/go-tfe v0.3.10
|
||||
github.com/hashicorp/go-tfe
|
||||
# github.com/hashicorp/go-uuid v1.0.0
|
||||
github.com/hashicorp/go-uuid
|
||||
|
|
Loading…
Reference in New Issue