| 1 |
// Copyright 2023 The go-github AUTHORS. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package github |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"fmt" |
| 11 |
) |
| 12 |
|
| 13 |
// OIDCSubjectClaimCustomTemplate represents an OIDC subject claim customization template. |
| 14 |
type OIDCSubjectClaimCustomTemplate struct { |
| 15 |
UseDefault *bool `json:"use_default,omitempty"` |
| 16 |
IncludeClaimKeys []string `json:"include_claim_keys,omitempty"` |
| 17 |
} |
| 18 |
|
| 19 |
// GetOrgOIDCSubjectClaimCustomTemplate gets the subject claim customization template for an organization. |
| 20 |
// |
| 21 |
// GitHub API docs: https://docs.github.com/rest/actions/oidc#get-the-customization-template-for-an-oidc-subject-claim-for-an-organization |
| 22 |
// |
| 23 |
//meta:operation GET /orgs/{org}/actions/oidc/customization/sub |
| 24 |
func (s *ActionsService) GetOrgOIDCSubjectClaimCustomTemplate(ctx context.Context, org string) (*OIDCSubjectClaimCustomTemplate, *Response, error) { |
| 25 |
u := fmt.Sprintf("orgs/%v/actions/oidc/customization/sub", org) |
| 26 |
return s.getOIDCSubjectClaimCustomTemplate(ctx, u) |
| 27 |
} |
| 28 |
|
| 29 |
// GetRepoOIDCSubjectClaimCustomTemplate gets the subject claim customization template for a repository. |
| 30 |
// |
| 31 |
// GitHub API docs: https://docs.github.com/rest/actions/oidc#get-the-customization-template-for-an-oidc-subject-claim-for-a-repository |
| 32 |
// |
| 33 |
//meta:operation GET /repos/{owner}/{repo}/actions/oidc/customization/sub |
| 34 |
func (s *ActionsService) GetRepoOIDCSubjectClaimCustomTemplate(ctx context.Context, owner, repo string) (*OIDCSubjectClaimCustomTemplate, *Response, error) { |
| 35 |
u := fmt.Sprintf("repos/%v/%v/actions/oidc/customization/sub", owner, repo) |
| 36 |
return s.getOIDCSubjectClaimCustomTemplate(ctx, u) |
| 37 |
} |
| 38 |
|
| 39 |
func (s *ActionsService) getOIDCSubjectClaimCustomTemplate(ctx context.Context, url string) (*OIDCSubjectClaimCustomTemplate, *Response, error) { |
| 40 |
req, err := s.client.NewRequest("GET", url, nil) |
| 41 |
if err != nil { |
| 42 |
return nil, nil, err |
| 43 |
} |
| 44 |
|
| 45 |
tmpl := new(OIDCSubjectClaimCustomTemplate) |
| 46 |
resp, err := s.client.Do(ctx, req, tmpl) |
| 47 |
if err != nil { |
| 48 |
return nil, resp, err |
| 49 |
} |
| 50 |
|
| 51 |
return tmpl, resp, nil |
| 52 |
} |
| 53 |
|
| 54 |
// SetOrgOIDCSubjectClaimCustomTemplate sets the subject claim customization for an organization. |
| 55 |
// |
| 56 |
// GitHub API docs: https://docs.github.com/rest/actions/oidc#set-the-customization-template-for-an-oidc-subject-claim-for-an-organization |
| 57 |
// |
| 58 |
//meta:operation PUT /orgs/{org}/actions/oidc/customization/sub |
| 59 |
func (s *ActionsService) SetOrgOIDCSubjectClaimCustomTemplate(ctx context.Context, org string, template *OIDCSubjectClaimCustomTemplate) (*Response, error) { |
| 60 |
u := fmt.Sprintf("orgs/%v/actions/oidc/customization/sub", org) |
| 61 |
return s.setOIDCSubjectClaimCustomTemplate(ctx, u, template) |
| 62 |
} |
| 63 |
|
| 64 |
// SetRepoOIDCSubjectClaimCustomTemplate sets the subject claim customization for a repository. |
| 65 |
// |
| 66 |
// GitHub API docs: https://docs.github.com/rest/actions/oidc#set-the-customization-template-for-an-oidc-subject-claim-for-a-repository |
| 67 |
// |
| 68 |
//meta:operation PUT /repos/{owner}/{repo}/actions/oidc/customization/sub |
| 69 |
func (s *ActionsService) SetRepoOIDCSubjectClaimCustomTemplate(ctx context.Context, owner, repo string, template *OIDCSubjectClaimCustomTemplate) (*Response, error) { |
| 70 |
u := fmt.Sprintf("repos/%v/%v/actions/oidc/customization/sub", owner, repo) |
| 71 |
return s.setOIDCSubjectClaimCustomTemplate(ctx, u, template) |
| 72 |
} |
| 73 |
|
| 74 |
func (s *ActionsService) setOIDCSubjectClaimCustomTemplate(ctx context.Context, url string, template *OIDCSubjectClaimCustomTemplate) (*Response, error) { |
| 75 |
req, err := s.client.NewRequest("PUT", url, template) |
| 76 |
if err != nil { |
| 77 |
return nil, err |
| 78 |
} |
| 79 |
|
| 80 |
return s.client.Do(ctx, req, nil) |
| 81 |
} |