Skip to content

Commit 799db94

Browse files
committed
Add UserTokensEnabled field for Organizations
1 parent d484ca0 commit 799db94

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Unreleased
22

3+
## Enhancements
4+
* Adds `UserTokensEnabled` field to `Organization` to support enabling/disabling user tokens for an organization by @JarrettSpiker [#???](https://github.com/hashicorp/go-tfe/pull/??)
5+
36
# v1.91.1
47

58
## Bug Fixes

organization.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type Organization struct {
116116
SendPassingStatusesForUntriggeredSpeculativePlans bool `jsonapi:"attr,send-passing-statuses-for-untriggered-speculative-plans"`
117117
RemainingTestableCount int `jsonapi:"attr,remaining-testable-count"`
118118
SpeculativePlanManagementEnabled bool `jsonapi:"attr,speculative-plan-management-enabled"`
119+
UserTokensEnabled bool `jsonapi:"attr,user-tokens-enabled"`
119120
// Optional: If enabled, SendPassingStatusesForUntriggeredSpeculativePlans needs to be false.
120121
AggregatedCommitStatusEnabled bool `jsonapi:"attr,aggregated-commit-status-enabled,omitempty"`
121122
// Note: This will be false for TFE versions older than v202211, where the setting was introduced.
@@ -261,6 +262,9 @@ type OrganizationCreateOptions struct {
261262

262263
// Optional: RegistryMonorepoSupportEnabled toggles whether monorepo support is enabled for the organization
263264
RegistryMonorepoSupportEnabled *bool `jsonapi:"attr,registry-monorepo-support-enabled,omitempty"`
265+
266+
// Optional: UserTokensEnabled toggles whether user tokens may be used to access resources in this organization.
267+
UserTokensEnabled *bool `jsonapi:"attr,user-tokens-enabled,omitempty"`
264268
}
265269

266270
// OrganizationUpdateOptions represents the options for updating an organization.
@@ -319,6 +323,9 @@ type OrganizationUpdateOptions struct {
319323

320324
// Optional: RegistryMonorepoSupportEnabled toggles whether monorepo support is enabled for the organization
321325
RegistryMonorepoSupportEnabled *bool `jsonapi:"attr,registry-monorepo-support-enabled,omitempty"`
326+
327+
// Optional: UserTokensEnabled toggles whether user tokens may be used to access resources in this organization.
328+
UserTokensEnabled *bool `jsonapi:"attr,user-tokens-enabled,omitempty"`
322329
}
323330

324331
// ReadRunQueueOptions represents the options for showing the queue.

organization_integration_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,44 @@ func TestOrganizationsUpdate(t *testing.T) {
291291
}
292292
})
293293

294+
t.Run("with new UserTokensEnabled option", func(t *testing.T) {
295+
orgTest, orgTestCleanup := createOrganization(t, client)
296+
t.Cleanup(orgTestCleanup)
297+
298+
assert.True(t, orgTest.UserTokensEnabled, "user tokens enabled by default")
299+
300+
// we need to switch to an owner's team token, otherwise the client (which auths with a user token)
301+
// wont be able to delete the org after we disable user tokens
302+
teamList, err := client.Teams.List(ctx, orgTest.Name, &TeamListOptions{
303+
Names: []string{"owners"},
304+
})
305+
require.NoError(t, err)
306+
//it should be the only team, we just created the org...
307+
require.Len(t, teamList.Items, 1)
308+
ownersTeam := teamList.Items[0]
309+
310+
ownerToken, ownerTokenCleanup := createTeamToken(t, client, ownersTeam)
311+
t.Cleanup(ownerTokenCleanup)
312+
313+
ownerClient := testClient(t)
314+
ownerClient.token = ownerToken.Token
315+
316+
options := OrganizationUpdateOptions{
317+
UserTokensEnabled: Bool(false),
318+
}
319+
320+
org, err := ownerClient.Organizations.Update(ctx, orgTest.Name, options)
321+
require.NoError(t, err)
322+
assert.False(t, org.UserTokensEnabled, "user tokens disabled")
323+
324+
options = OrganizationUpdateOptions{
325+
UserTokensEnabled: Bool(true),
326+
}
327+
org, err = ownerClient.Organizations.Update(ctx, orgTest.Name, options)
328+
require.NoError(t, err)
329+
assert.True(t, org.UserTokensEnabled, "user tokens re-enabled")
330+
})
331+
294332
t.Run("with valid options", func(t *testing.T) {
295333
orgTest, orgTestCleanup := createOrganization(t, client)
296334

0 commit comments

Comments
 (0)