Skip to content

Commit

Permalink
TF-9705 Add organizationScoped to oauth_client resource (#812)
Browse files Browse the repository at this point in the history
* parent 09f6c3a
author Netra Mali <netra.mali@hashicorp.com> 1699460954 -0500
committer Netra Mali <netra.mali@hashicorp.com> 1699981200 -0500

added organization scoped

Update CHANGELOG.md

* remove changes

* Update go.sum

* Update workspace.go

* Update CHANGELOG.md

---------

Co-authored-by: Netra Mali <netra.mali@hashicorp.com>
  • Loading branch information
Netra2104 and netramali authored Nov 14, 2023
1 parent a17cfb1 commit 51a9039
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
## Bug Fixes
* Fixes a dependency build failure for 32 bit linux architectures by @brandonc [#814](https://github.com/hashicorp/go-tfe/pull/814)

## Enhancements
* Add organization scope field for oauth clients by @Netra2104 [#812](https://github.com/hashicorp/go-tfe/pull/812)

# v1.39.1

## Bug Fixes
Expand Down
12 changes: 12 additions & 0 deletions oauth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ type OAuthClient struct {
Secret string `jsonapi:"attr,secret"`
ServiceProvider ServiceProviderType `jsonapi:"attr,service-provider"`
ServiceProviderName string `jsonapi:"attr,service-provider-display-name"`
// **Note: This field is still in BETA and subject to change.**
OrganizationScoped bool `jsonapi:"attr,organization-scoped"`

// Relations
Organization *Organization `jsonapi:"relation,organization"`
Expand Down Expand Up @@ -134,6 +136,11 @@ type OAuthClientCreateOptions struct {

// Required: The VCS provider being connected with.
ServiceProvider *ServiceProviderType `jsonapi:"attr,service-provider"`

// **Note: This field is still in BETA and subject to change.**
// Optional: Whether the OAuthClient is available to all workspaces in the organization.
// True if the oauth client is organization scoped, false otherwise.
OrganizationScoped *bool `jsonapi:"attr,organization-scoped,omitempty"`
}

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

// Optional: The token string you were given by your VCS provider.
OAuthToken *string `jsonapi:"attr,oauth-token-string,omitempty"`

// **Note: This field is still in BETA and subject to change.**
// Optional: Whether the OAuthClient is available to all workspaces in the organization.
// True if the oauth client is organization scoped, false otherwise.
OrganizationScoped *bool `jsonapi:"attr,organization-scoped,omitempty"`
}

// List all the OAuth clients for a given organization.
Expand Down
35 changes: 34 additions & 1 deletion oauth_client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestOAuthClientsCreate(t *testing.T) {
assert.Equal(t, 1, len(oc.OAuthTokens))
assert.Equal(t, ServiceProviderGithub, oc.ServiceProvider)

t.Run("the organization relationship is decoded correcly", func(t *testing.T) {
t.Run("the organization relationship is decoded correctly", func(t *testing.T) {
assert.NotEmpty(t, oc.Organization)
})
})
Expand Down Expand Up @@ -224,6 +224,7 @@ func TestOAuthClientsRead(t *testing.T) {
assert.Equal(t, ocTest.ServiceProvider, oc.ServiceProvider)
assert.Equal(t, ocTest.ServiceProviderName, oc.ServiceProviderName)
assert.Equal(t, ocTest.OAuthTokens, oc.OAuthTokens)
assert.Equal(t, ocTest.OrganizationScoped, oc.OrganizationScoped)
})

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

func TestOAuthClientsUpdate(t *testing.T) {
skipUnlessBeta(t)
client := testClient(t)
ctx := context.Background()

orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

t.Run("updates organization scoped", func(t *testing.T) {
organizationScoped := false
organizationScopedTrue := true
options := OAuthClientCreateOptions{
APIURL: String("https://bbs.com"),
HTTPURL: String("https://bbs.com"),
ServiceProvider: ServiceProvider(ServiceProviderBitbucketServer),
OrganizationScoped: &organizationScopedTrue,
}

origOC, err := client.OAuthClients.Create(ctx, orgTest.Name, options)
require.NoError(t, err)
assert.NotEmpty(t, origOC.ID)

updateOpts := OAuthClientUpdateOptions{
OrganizationScoped: &organizationScoped,
}
oc, err := client.OAuthClients.Update(ctx, origOC.ID, updateOpts)
require.NoError(t, err)
assert.NotEmpty(t, oc.ID)
assert.NotEqual(t, origOC.OrganizationScoped, oc.OrganizationScoped)
})
}

const publicKey = `
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoKizy4xbN6qZFAwIJV24
Expand Down

0 comments on commit 51a9039

Please sign in to comment.