@@ -28,11 +28,20 @@ type OAuthClients interface {
2828 // Read an OAuth client by its ID.
2929 Read (ctx context.Context , oAuthClientID string ) (* OAuthClient , error )
3030
31+ // ReadWithOptions reads an oauth client by its ID using the options supplied.
32+ ReadWithOptions (ctx context.Context , oAuthClientID string , options * OAuthClientReadOptions ) (* OAuthClient , error )
33+
3134 // Update an existing OAuth client by its ID.
3235 Update (ctx context.Context , oAuthClientID string , options OAuthClientUpdateOptions ) (* OAuthClient , error )
3336
3437 // Delete an OAuth client by its ID.
3538 Delete (ctx context.Context , oAuthClientID string ) error
39+
40+ // AddProjects add projects to an oauth client.
41+ AddProjects (ctx context.Context , oAuthClientID string , options OAuthClientAddProjectsOptions ) error
42+
43+ // RemoveProjects remove projects from an oauth client.
44+ RemoveProjects (ctx context.Context , oAuthClientID string , options OAuthClientRemoveProjectsOptions ) error
3645}
3746
3847// oAuthClients implements OAuthClients.
@@ -86,12 +95,18 @@ type OAuthClient struct {
8695 // Relations
8796 Organization * Organization `jsonapi:"relation,organization"`
8897 OAuthTokens []* OAuthToken `jsonapi:"relation,oauth-tokens"`
98+ // **Note: This field is still in BETA and subject to change.**
99+ // The projects to which the oauth client applies.
100+ Projects []* Project `jsonapi:"relation,projects"`
89101}
90102
91103// A list of relations to include
92104type OAuthClientIncludeOpt string
93105
94- const OauthClientOauthTokens OAuthClientIncludeOpt = "oauth_tokens"
106+ const (
107+ OauthClientOauthTokens OAuthClientIncludeOpt = "oauth_tokens"
108+ OauthClientProjects OAuthClientIncludeOpt = "projects"
109+ )
95110
96111// OAuthClientListOptions represents the options for listing
97112// OAuth clients.
@@ -101,6 +116,15 @@ type OAuthClientListOptions struct {
101116 Include []OAuthClientIncludeOpt `url:"include,omitempty"`
102117}
103118
119+ // OAuthClientReadOptions are read options.
120+ // For a full list of relations, please see:
121+ // https://developer.hashicorp.com/terraform/cloud-docs/api-docs/oauth-clients#relationships
122+ type OAuthClientReadOptions struct {
123+ // Optional: A list of relations to include. See available resources
124+ // https://developer.hashicorp.com/terraform/cloud-docs/api-docs/oauth-clients#available-related-resources
125+ Include []OAuthClientIncludeOpt `url:"include,omitempty"`
126+ }
127+
104128// OAuthClientCreateOptions represents the options for creating an OAuth client.
105129type OAuthClientCreateOptions struct {
106130 // Type is a public field utilized by JSON:API to
@@ -124,6 +148,10 @@ type OAuthClientCreateOptions struct {
124148 // Optional: The token string you were given by your VCS provider.
125149 OAuthToken * string `jsonapi:"attr,oauth-token-string,omitempty"`
126150
151+ // **Note: This field is still in BETA and subject to change.**
152+ // Optional: The initial list of projects for which the oauth client should be associated with.
153+ Projects []* Project `jsonapi:"relation,projects,omitempty"`
154+
127155 // Optional: Private key associated with this vcs provider - only available for ado_server
128156 PrivateKey * string `jsonapi:"attr,private-key,omitempty"`
129157
@@ -173,6 +201,20 @@ type OAuthClientUpdateOptions struct {
173201 OrganizationScoped * bool `jsonapi:"attr,organization-scoped,omitempty"`
174202}
175203
204+ // OAuthClientAddProjectsOptions represents the options for adding projects
205+ // to an oauth client.
206+ type OAuthClientAddProjectsOptions struct {
207+ // The projects to add to an oauth client.
208+ Projects []* Project
209+ }
210+
211+ // OAuthClientRemoveProjectsOptions represents the options for removing
212+ // projects from an oauth client.
213+ type OAuthClientRemoveProjectsOptions struct {
214+ // The projects to remove from an oauth client.
215+ Projects []* Project
216+ }
217+
176218// List all the OAuth clients for a given organization.
177219func (s * oAuthClients ) List (ctx context.Context , organization string , options * OAuthClientListOptions ) (* OAuthClientList , error ) {
178220 if ! validStringID (& organization ) {
@@ -223,12 +265,19 @@ func (s *oAuthClients) Create(ctx context.Context, organization string, options
223265
224266// Read an OAuth client by its ID.
225267func (s * oAuthClients ) Read (ctx context.Context , oAuthClientID string ) (* OAuthClient , error ) {
268+ return s .ReadWithOptions (ctx , oAuthClientID , nil )
269+ }
270+
271+ func (s * oAuthClients ) ReadWithOptions (ctx context.Context , oAuthClientID string , options * OAuthClientReadOptions ) (* OAuthClient , error ) {
226272 if ! validStringID (& oAuthClientID ) {
227273 return nil , ErrInvalidOauthClientID
228274 }
275+ if err := options .valid (); err != nil {
276+ return nil , err
277+ }
229278
230279 u := fmt .Sprintf ("oauth-clients/%s" , url .QueryEscape (oAuthClientID ))
231- req , err := s .client .NewRequest ("GET" , u , nil )
280+ req , err := s .client .NewRequest ("GET" , u , options )
232281 if err != nil {
233282 return nil , err
234283 }
@@ -300,3 +349,63 @@ func (o OAuthClientCreateOptions) valid() error {
300349func (o * OAuthClientListOptions ) valid () error {
301350 return nil
302351}
352+
353+ // AddProjects adds projects to a given oauth client.
354+ func (s * oAuthClients ) AddProjects (ctx context.Context , oAuthClientID string , options OAuthClientAddProjectsOptions ) error {
355+ if ! validStringID (& oAuthClientID ) {
356+ return ErrInvalidOauthClientID
357+ }
358+ if err := options .valid (); err != nil {
359+ return err
360+ }
361+
362+ u := fmt .Sprintf ("oauth-clients/%s/relationships/projects" , url .QueryEscape (oAuthClientID ))
363+ req , err := s .client .NewRequest ("POST" , u , options .Projects )
364+ if err != nil {
365+ return err
366+ }
367+
368+ return req .Do (ctx , nil )
369+ }
370+
371+ // RemoveProjects removes projects from an oauth client.
372+ func (s * oAuthClients ) RemoveProjects (ctx context.Context , oAuthClientID string , options OAuthClientRemoveProjectsOptions ) error {
373+ if ! validStringID (& oAuthClientID ) {
374+ return ErrInvalidOauthClientID
375+ }
376+ if err := options .valid (); err != nil {
377+ return err
378+ }
379+
380+ u := fmt .Sprintf ("oauth-clients/%s/relationships/projects" , url .QueryEscape (oAuthClientID ))
381+ req , err := s .client .NewRequest ("DELETE" , u , options .Projects )
382+ if err != nil {
383+ return err
384+ }
385+
386+ return req .Do (ctx , nil )
387+ }
388+
389+ func (o OAuthClientAddProjectsOptions ) valid () error {
390+ if o .Projects == nil {
391+ return ErrRequiredProject
392+ }
393+ if len (o .Projects ) == 0 {
394+ return ErrProjectMinLimit
395+ }
396+ return nil
397+ }
398+
399+ func (o OAuthClientRemoveProjectsOptions ) valid () error {
400+ if o .Projects == nil {
401+ return ErrRequiredProject
402+ }
403+ if len (o .Projects ) == 0 {
404+ return ErrProjectMinLimit
405+ }
406+ return nil
407+ }
408+
409+ func (o * OAuthClientReadOptions ) valid () error {
410+ return nil
411+ }
0 commit comments