Debian Codegraph @

github/enterprise_code_security_and_analysis.go

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