github.com/google/go-github/v49@v49.1.0/github/actions_oidc.go (about) 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/en/rest/actions/oidc#get-the-customization-template-for-an-oidc-subject-claim-for-an-organization 22 func (s *ActionsService) GetOrgOIDCSubjectClaimCustomTemplate(ctx context.Context, org string) (*OIDCSubjectClaimCustomTemplate, *Response, error) { 23 u := fmt.Sprintf("orgs/%v/actions/oidc/customization/sub", org) 24 return s.getOIDCSubjectClaimCustomTemplate(ctx, u) 25 } 26 27 // GetRepoOIDCSubjectClaimCustomTemplate gets the subject claim customization template for a repository. 28 // 29 // GitHub API docs: https://docs.github.com/en/rest/actions/oidc#get-the-customization-template-for-an-oidc-subject-claim-for-a-repository 30 func (s *ActionsService) GetRepoOIDCSubjectClaimCustomTemplate(ctx context.Context, owner, repo string) (*OIDCSubjectClaimCustomTemplate, *Response, error) { 31 u := fmt.Sprintf("repos/%v/%v/actions/oidc/customization/sub", owner, repo) 32 return s.getOIDCSubjectClaimCustomTemplate(ctx, u) 33 } 34 35 func (s *ActionsService) getOIDCSubjectClaimCustomTemplate(ctx context.Context, url string) (*OIDCSubjectClaimCustomTemplate, *Response, error) { 36 req, err := s.client.NewRequest("GET", url, nil) 37 if err != nil { 38 return nil, nil, err 39 } 40 41 tmpl := new(OIDCSubjectClaimCustomTemplate) 42 resp, err := s.client.Do(ctx, req, tmpl) 43 if err != nil { 44 return nil, resp, err 45 } 46 47 return tmpl, resp, nil 48 } 49 50 // SetOrgOIDCSubjectClaimCustomTemplate sets the subject claim customization for an organization. 51 // 52 // GitHub API docs: https://docs.github.com/en/rest/actions/oidc#set-the-customization-template-for-an-oidc-subject-claim-for-an-organization 53 func (s *ActionsService) SetOrgOIDCSubjectClaimCustomTemplate(ctx context.Context, org string, template *OIDCSubjectClaimCustomTemplate) (*Response, error) { 54 u := fmt.Sprintf("orgs/%v/actions/oidc/customization/sub", org) 55 return s.setOIDCSubjectClaimCustomTemplate(ctx, u, template) 56 } 57 58 // SetRepoOIDCSubjectClaimCustomTemplate sets the subject claim customization for a repository. 59 // 60 // GitHub API docs: https://docs.github.com/en/rest/actions/oidc#set-the-customization-template-for-an-oidc-subject-claim-for-a-repository 61 func (s *ActionsService) SetRepoOIDCSubjectClaimCustomTemplate(ctx context.Context, owner, repo string, template *OIDCSubjectClaimCustomTemplate) (*Response, error) { 62 u := fmt.Sprintf("repos/%v/%v/actions/oidc/customization/sub", owner, repo) 63 return s.setOIDCSubjectClaimCustomTemplate(ctx, u, template) 64 } 65 66 func (s *ActionsService) setOIDCSubjectClaimCustomTemplate(ctx context.Context, url string, template *OIDCSubjectClaimCustomTemplate) (*Response, error) { 67 req, err := s.client.NewRequest("PUT", url, template) 68 if err != nil { 69 return nil, err 70 } 71 72 return s.client.Do(ctx, req, nil) 73 }