Skip to content

Commit

Permalink
added organization scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
netramali committed Nov 9, 2023
1 parent 09f6c3a commit a3d237e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!-- Add CHANGELOG entry to this section for any PR awaiting the next release -->
<!-- Please also include if this is a Bug Fix, Enhancement, or Feature -->

* 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
7 changes: 7 additions & 0 deletions oauth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type OAuthClient struct {
Secret string `jsonapi:"attr,secret"`
ServiceProvider ServiceProviderType `jsonapi:"attr,service-provider"`
ServiceProviderName string `jsonapi:"attr,service-provider-display-name"`
OrganizationScoped bool `jsonapi:"attr,organization-scoped"`

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

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

// 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 +163,9 @@ type OAuthClientUpdateOptions struct {

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

// 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
28 changes: 26 additions & 2 deletions 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 @@ -183,7 +183,6 @@ func TestOAuthClientsCreate_rsaKeyPair(t *testing.T) {

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

t.Run("with key, rsa public/private key options", func(t *testing.T) {
key := randomString(t)
options := OAuthClientCreateOptions{
Expand Down Expand Up @@ -224,6 +223,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 @@ -429,6 +429,30 @@ func TestOAuthClientsUpdate_rsaKeyPair(t *testing.T) {
assert.Equal(t, newKey, oc.Key)
})

t.Run("updates organization scoped", func(t *testing.T) {
skipUnlessBeta(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)
})

t.Run("errors when missing key", func(t *testing.T) {
originalKey := randomString(t)
options := OAuthClientCreateOptions{
Expand Down

0 comments on commit a3d237e

Please sign in to comment.