Skip to content

Commit 51a9039

Browse files
Netra2104netramali
andauthored
TF-9705 Add organizationScoped to oauth_client resource (#812)
* parent 09f6c3a author Netra Mali <[email protected]> 1699460954 -0500 committer Netra Mali <[email protected]> 1699981200 -0500 added organization scoped Update CHANGELOG.md * remove changes * Update go.sum * Update workspace.go * Update CHANGELOG.md --------- Co-authored-by: Netra Mali <[email protected]>
1 parent a17cfb1 commit 51a9039

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
## Bug Fixes
99
* Fixes a dependency build failure for 32 bit linux architectures by @brandonc [#814](https://github.com/hashicorp/go-tfe/pull/814)
1010

11+
## Enhancements
12+
* Add organization scope field for oauth clients by @Netra2104 [#812](https://github.com/hashicorp/go-tfe/pull/812)
13+
1114
# v1.39.1
1215

1316
## Bug Fixes

oauth_client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ type OAuthClient struct {
8080
Secret string `jsonapi:"attr,secret"`
8181
ServiceProvider ServiceProviderType `jsonapi:"attr,service-provider"`
8282
ServiceProviderName string `jsonapi:"attr,service-provider-display-name"`
83+
// **Note: This field is still in BETA and subject to change.**
84+
OrganizationScoped bool `jsonapi:"attr,organization-scoped"`
8385

8486
// Relations
8587
Organization *Organization `jsonapi:"relation,organization"`
@@ -134,6 +136,11 @@ type OAuthClientCreateOptions struct {
134136

135137
// Required: The VCS provider being connected with.
136138
ServiceProvider *ServiceProviderType `jsonapi:"attr,service-provider"`
139+
140+
// **Note: This field is still in BETA and subject to change.**
141+
// Optional: Whether the OAuthClient is available to all workspaces in the organization.
142+
// True if the oauth client is organization scoped, false otherwise.
143+
OrganizationScoped *bool `jsonapi:"attr,organization-scoped,omitempty"`
137144
}
138145

139146
// OAuthClientUpdateOptions represents the options for updating an OAuth client.
@@ -159,6 +166,11 @@ type OAuthClientUpdateOptions struct {
159166

160167
// Optional: The token string you were given by your VCS provider.
161168
OAuthToken *string `jsonapi:"attr,oauth-token-string,omitempty"`
169+
170+
// **Note: This field is still in BETA and subject to change.**
171+
// Optional: Whether the OAuthClient is available to all workspaces in the organization.
172+
// True if the oauth client is organization scoped, false otherwise.
173+
OrganizationScoped *bool `jsonapi:"attr,organization-scoped,omitempty"`
162174
}
163175

164176
// List all the OAuth clients for a given organization.

oauth_client_integration_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestOAuthClientsCreate(t *testing.T) {
115115
assert.Equal(t, 1, len(oc.OAuthTokens))
116116
assert.Equal(t, ServiceProviderGithub, oc.ServiceProvider)
117117

118-
t.Run("the organization relationship is decoded correcly", func(t *testing.T) {
118+
t.Run("the organization relationship is decoded correctly", func(t *testing.T) {
119119
assert.NotEmpty(t, oc.Organization)
120120
})
121121
})
@@ -224,6 +224,7 @@ func TestOAuthClientsRead(t *testing.T) {
224224
assert.Equal(t, ocTest.ServiceProvider, oc.ServiceProvider)
225225
assert.Equal(t, ocTest.ServiceProviderName, oc.ServiceProviderName)
226226
assert.Equal(t, ocTest.OAuthTokens, oc.OAuthTokens)
227+
assert.Equal(t, ocTest.OrganizationScoped, oc.OrganizationScoped)
227228
})
228229

229230
t.Run("when the OAuth client does not exist", func(t *testing.T) {
@@ -383,6 +384,38 @@ func TestOAuthClientsCreateOptionsValid(t *testing.T) {
383384
})
384385
}
385386

387+
func TestOAuthClientsUpdate(t *testing.T) {
388+
skipUnlessBeta(t)
389+
client := testClient(t)
390+
ctx := context.Background()
391+
392+
orgTest, orgTestCleanup := createOrganization(t, client)
393+
defer orgTestCleanup()
394+
395+
t.Run("updates organization scoped", func(t *testing.T) {
396+
organizationScoped := false
397+
organizationScopedTrue := true
398+
options := OAuthClientCreateOptions{
399+
APIURL: String("https://bbs.com"),
400+
HTTPURL: String("https://bbs.com"),
401+
ServiceProvider: ServiceProvider(ServiceProviderBitbucketServer),
402+
OrganizationScoped: &organizationScopedTrue,
403+
}
404+
405+
origOC, err := client.OAuthClients.Create(ctx, orgTest.Name, options)
406+
require.NoError(t, err)
407+
assert.NotEmpty(t, origOC.ID)
408+
409+
updateOpts := OAuthClientUpdateOptions{
410+
OrganizationScoped: &organizationScoped,
411+
}
412+
oc, err := client.OAuthClients.Update(ctx, origOC.ID, updateOpts)
413+
require.NoError(t, err)
414+
assert.NotEmpty(t, oc.ID)
415+
assert.NotEqual(t, origOC.OrganizationScoped, oc.OrganizationScoped)
416+
})
417+
}
418+
386419
const publicKey = `
387420
-----BEGIN PUBLIC KEY-----
388421
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoKizy4xbN6qZFAwIJV24

0 commit comments

Comments
 (0)