github.com/google/go-github/v57@v57.0.0/github/enterprise_code_security_and_analysis.go (about) 1 // Copyright 2022 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 // EnterpriseSecurityAnalysisSettings represents security analysis settings for an enterprise. 14 type EnterpriseSecurityAnalysisSettings struct { 15 AdvancedSecurityEnabledForNewRepositories *bool `json:"advanced_security_enabled_for_new_repositories,omitempty"` 16 SecretScanningEnabledForNewRepositories *bool `json:"secret_scanning_enabled_for_new_repositories,omitempty"` 17 SecretScanningPushProtectionEnabledForNewRepositories *bool `json:"secret_scanning_push_protection_enabled_for_new_repositories,omitempty"` 18 SecretScanningPushProtectionCustomLink *string `json:"secret_scanning_push_protection_custom_link,omitempty"` 19 } 20 21 // GetCodeSecurityAndAnalysis gets code security and analysis features for an enterprise. 22 // 23 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/code-security-and-analysis#get-code-security-and-analysis-features-for-an-enterprise 24 // 25 //meta:operation GET /enterprises/{enterprise}/code_security_and_analysis 26 func (s *EnterpriseService) GetCodeSecurityAndAnalysis(ctx context.Context, enterprise string) (*EnterpriseSecurityAnalysisSettings, *Response, error) { 27 u := fmt.Sprintf("enterprises/%v/code_security_and_analysis", enterprise) 28 29 req, err := s.client.NewRequest("GET", u, nil) 30 if err != nil { 31 return nil, nil, err 32 } 33 34 settings := new(EnterpriseSecurityAnalysisSettings) 35 resp, err := s.client.Do(ctx, req, settings) 36 if err != nil { 37 return nil, resp, err 38 } 39 40 return settings, resp, nil 41 } 42 43 // UpdateCodeSecurityAndAnalysis updates code security and analysis features for new repositories in an enterprise. 44 // 45 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/code-security-and-analysis#update-code-security-and-analysis-features-for-an-enterprise 46 // 47 //meta:operation PATCH /enterprises/{enterprise}/code_security_and_analysis 48 func (s *EnterpriseService) UpdateCodeSecurityAndAnalysis(ctx context.Context, enterprise string, settings *EnterpriseSecurityAnalysisSettings) (*Response, error) { 49 u := fmt.Sprintf("enterprises/%v/code_security_and_analysis", enterprise) 50 req, err := s.client.NewRequest("PATCH", u, settings) 51 if err != nil { 52 return nil, err 53 } 54 55 resp, err := s.client.Do(ctx, req, nil) 56 if err != nil { 57 return resp, err 58 } 59 60 return resp, nil 61 } 62 63 // EnableDisableSecurityFeature enables or disables a security feature for all repositories in an enterprise. 64 // 65 // Valid values for securityProduct: "advanced_security", "secret_scanning", "secret_scanning_push_protection". 66 // Valid values for enablement: "enable_all", "disable_all". 67 // 68 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/code-security-and-analysis#enable-or-disable-a-security-feature 69 // 70 //meta:operation POST /enterprises/{enterprise}/{security_product}/{enablement} 71 func (s *EnterpriseService) EnableDisableSecurityFeature(ctx context.Context, enterprise, securityProduct, enablement string) (*Response, error) { 72 u := fmt.Sprintf("enterprises/%v/%v/%v", enterprise, securityProduct, enablement) 73 req, err := s.client.NewRequest("POST", u, nil) 74 if err != nil { 75 return nil, err 76 } 77 78 resp, err := s.client.Do(ctx, req, nil) 79 if err != nil { 80 return resp, err 81 } 82 83 return resp, nil 84 }