Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variable sets permission to team project #1021

Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

* Add BETA support for adding custom project permission for variable sets `ProjectVariableSetsPermission` by @netramali [21879](https://github.com/hashicorp/atlas/pull/21879)

# v1.73.0

## Enhancements
Expand Down
15 changes: 15 additions & 0 deletions team_project_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ type TeamProjectAccess struct {
type TeamProjectAccessProjectPermissions struct {
ProjectSettingsPermission ProjectSettingsPermissionType `jsonapi:"attr,settings"`
ProjectTeamsPermission ProjectTeamsPermissionType `jsonapi:"attr,teams"`
// ProjectVariableSetsPermission represents read, manage, and no access custom permission for project-level variable sets
// This relation is considered BETA, SUBJECT TO CHANGE, and likely unavailable to most users.
ProjectVariableSetsPermission ProjectVariableSetsPermissionType `jsonapi:"attr,variable-sets"`
}

// WorkspacePermissions represents the team's permission on all workspaces in its project
Expand Down Expand Up @@ -104,6 +107,16 @@ const (
ProjectTeamsPermissionManage ProjectTeamsPermissionType = "manage"
)

// ProjectVariableSetsPermissionType represents the permission type to a project's variable sets
// This relation is considered BETA, SUBJECT TO CHANGE, and likely unavailable to most users.
type ProjectVariableSetsPermissionType string

const (
ProjectVariableSetsPermissionNone ProjectVariableSetsPermissionType = "none"
ProjectVariableSetsPermissionRead ProjectVariableSetsPermissionType = "read"
ProjectVariableSetsPermissionWrite ProjectVariableSetsPermissionType = "write"
)

// WorkspaceRunsPermissionType represents the permissiontype to project workspaces' runs
type WorkspaceRunsPermissionType string

Expand Down Expand Up @@ -143,6 +156,8 @@ const (
type TeamProjectAccessProjectPermissionsOptions struct {
netramali marked this conversation as resolved.
Show resolved Hide resolved
Settings *ProjectSettingsPermissionType `json:"settings,omitempty"`
Teams *ProjectTeamsPermissionType `json:"teams,omitempty"`
// This relation is considered BETA, SUBJECT TO CHANGE, and likely unavailable to most users.
VariableSets *ProjectVariableSetsPermissionType `json:"variable-sets,omitempty"`
netramali marked this conversation as resolved.
Show resolved Hide resolved
}

type TeamProjectAccessWorkspacePermissionsOptions struct {
Expand Down
14 changes: 10 additions & 4 deletions team_project_access_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ func TestTeamProjectAccessesAdd(t *testing.T) {
})

t.Run("with valid options for all custom TeamProject permissions", func(t *testing.T) {
skipUnlessBeta(t)
netramali marked this conversation as resolved.
Show resolved Hide resolved
options := TeamProjectAccessAddOptions{
Access: *ProjectAccess(TeamProjectAccessCustom),
Team: tmTest,
Project: pTest,
ProjectAccess: &TeamProjectAccessProjectPermissionsOptions{
Settings: ProjectSettingsPermission(ProjectSettingsPermissionUpdate),
Teams: ProjectTeamsPermission(ProjectTeamsPermissionManage),
Settings: ProjectSettingsPermission(ProjectSettingsPermissionUpdate),
Teams: ProjectTeamsPermission(ProjectTeamsPermissionManage),
VariableSets: ProjectVariableSetsPermission(ProjectVariableSetsPermissionWrite),
},
WorkspaceAccess: &TeamProjectAccessWorkspacePermissionsOptions{
Runs: WorkspaceRunsPermission(WorkspaceRunsPermissionApply),
Expand Down Expand Up @@ -209,6 +211,7 @@ func TestTeamProjectAccessesAdd(t *testing.T) {
assert.Equal(t, options.Access, item.Access)
assert.Equal(t, *options.ProjectAccess.Settings, item.ProjectAccess.ProjectSettingsPermission)
assert.Equal(t, *options.ProjectAccess.Teams, item.ProjectAccess.ProjectTeamsPermission)
assert.Equal(t, *options.ProjectAccess.VariableSets, item.ProjectAccess.ProjectVariableSetsPermission)
assert.Equal(t, *options.WorkspaceAccess.Runs, item.WorkspaceAccess.WorkspaceRunsPermission)
assert.Equal(t, *options.WorkspaceAccess.SentinelMocks, item.WorkspaceAccess.WorkspaceSentinelMocksPermission)
assert.Equal(t, *options.WorkspaceAccess.StateVersions, item.WorkspaceAccess.WorkspaceStateVersionsPermission)
Expand Down Expand Up @@ -352,11 +355,13 @@ func TestTeamProjectAccessesUpdate(t *testing.T) {
})

t.Run("with valid custom permissions attributes for all permissions", func(t *testing.T) {
skipUnlessBeta(t)
options := TeamProjectAccessUpdateOptions{
Access: ProjectAccess(TeamProjectAccessCustom),
ProjectAccess: &TeamProjectAccessProjectPermissionsOptions{
Settings: ProjectSettingsPermission(ProjectSettingsPermissionUpdate),
Teams: ProjectTeamsPermission(ProjectTeamsPermissionManage),
Settings: ProjectSettingsPermission(ProjectSettingsPermissionUpdate),
Teams: ProjectTeamsPermission(ProjectTeamsPermissionManage),
VariableSets: ProjectVariableSetsPermission(ProjectVariableSetsPermissionRead),
},
WorkspaceAccess: &TeamProjectAccessWorkspacePermissionsOptions{
Runs: WorkspaceRunsPermission(WorkspaceRunsPermissionPlan),
Expand All @@ -378,6 +383,7 @@ func TestTeamProjectAccessesUpdate(t *testing.T) {
assert.Equal(t, tpa.Access, TeamProjectAccessCustom)
assert.Equal(t, *options.ProjectAccess.Teams, tpa.ProjectAccess.ProjectTeamsPermission)
assert.Equal(t, *options.ProjectAccess.Settings, tpa.ProjectAccess.ProjectSettingsPermission)
assert.Equal(t, *options.ProjectAccess.VariableSets, tpa.ProjectAccess.ProjectVariableSetsPermission)
assert.Equal(t, *options.WorkspaceAccess.Runs, tpa.WorkspaceAccess.WorkspaceRunsPermission)
assert.Equal(t, *options.WorkspaceAccess.SentinelMocks, tpa.WorkspaceAccess.WorkspaceSentinelMocksPermission)
assert.Equal(t, *options.WorkspaceAccess.StateVersions, tpa.WorkspaceAccess.WorkspaceStateVersionsPermission)
Expand Down
5 changes: 5 additions & 0 deletions type_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func ProjectTeamsPermission(v ProjectTeamsPermissionType) *ProjectTeamsPermissio
return &v
}

// ProjectVariableSetsPermission returns a pointer to the given team access project type.
func ProjectVariableSetsPermission(v ProjectVariableSetsPermissionType) *ProjectVariableSetsPermissionType {
return &v
}

// WorkspaceRunsPermission returns a pointer to the given team access project type.
func WorkspaceRunsPermission(v WorkspaceRunsPermissionType) *WorkspaceRunsPermissionType {
return &v
Expand Down
Loading