Skip to content

Commit

Permalink
parent 09f6c3a
Browse files Browse the repository at this point in the history
author Netra Mali <netra.mali@hashicorp.com> 1699460954 -0500
committer Netra Mali <netra.mali@hashicorp.com> 1699981200 -0500

added organization scoped

Update CHANGELOG.md
  • Loading branch information
netramali committed Nov 14, 2023
1 parent 09f6c3a commit b090084
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 10 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# UNRELEASED
<!-- 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 -->

## Bug Fixes
* Removed unused field `AgentPoolID` from the Workspace model. (Callers should be using the `AgentPool` relation instead) by @brandonc [#815](https://github.com/hashicorp/go-tfe/pull/815)

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

# v1.39.1

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/google/go-querystring v1.1.0
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-retryablehttp v0.7.5
github.com/hashicorp/go-slug v0.13.1
github.com/hashicorp/go-slug v0.13.2
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d
Expand All @@ -19,6 +19,6 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/sys v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxC
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/go-slug v0.13.1 h1:2it55HK4vVXsBoCgUQ7Y2ADQpBaU1ge25VRp1wzZpTM=
github.com/hashicorp/go-slug v0.13.1/go.mod h1:RA4C+ezyC2nDsiPM5+1djqagveBBJdSN/fM2QCUziYQ=
github.com/hashicorp/go-slug v0.13.2 h1:ArlarJ8w1Rinx4P1N6Sr00t+GmjJWtYZuSEDYPQBErA=
github.com/hashicorp/go-slug v0.13.2/go.mod h1:RA4C+ezyC2nDsiPM5+1djqagveBBJdSN/fM2QCUziYQ=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
Expand Down Expand Up @@ -41,8 +41,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
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
1 change: 0 additions & 1 deletion workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ type WorkspaceList struct {
type Workspace struct {
ID string `jsonapi:"primary,workspaces"`
Actions *WorkspaceActions `jsonapi:"attr,actions"`
AgentPoolID string `jsonapi:"attr,agent-pool-id"`
AllowDestroyPlan bool `jsonapi:"attr,allow-destroy-plan"`
AssessmentsEnabled bool `jsonapi:"attr,assessments-enabled"`
AutoApply bool `jsonapi:"attr,auto-apply"`
Expand Down

0 comments on commit b090084

Please sign in to comment.