-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathsecret_scanning_pattern_configs.go
More file actions
165 lines (136 loc) · 6.75 KB
/
secret_scanning_pattern_configs.go
File metadata and controls
165 lines (136 loc) · 6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright 2025 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"fmt"
)
// SecretScanningPatternConfigs represents a collection of GitHub secret scanning patterns
// and their settings related to push protection.
type SecretScanningPatternConfigs struct {
PatternConfigVersion *string `json:"pattern_config_version,omitempty"`
ProviderPatternOverrides []*SecretScanningPatternOverride `json:"provider_pattern_overrides,omitempty"`
CustomPatternOverrides []*SecretScanningPatternOverride `json:"custom_pattern_overrides,omitempty"`
}
// SecretScanningPatternOverride represents an override for provider partner or custom organization patterns.
type SecretScanningPatternOverride struct {
TokenType *string `json:"token_type,omitempty"`
CustomPatternVersion *string `json:"custom_pattern_version,omitempty"`
Slug *string `json:"slug,omitempty"`
DisplayName *string `json:"display_name,omitempty"`
AlertTotal *int `json:"alert_total,omitempty"`
AlertTotalPercentage *int `json:"alert_total_percentage,omitempty"`
FalsePositives *int `json:"false_positives,omitempty"`
FalsePositiveRate *int `json:"false_positive_rate,omitempty"`
Bypassrate *int `json:"bypass_rate,omitempty"`
DefaultSetting *string `json:"default_setting,omitempty"`
EnterpriseSetting *string `json:"enterprise_setting,omitempty"`
Setting *string `json:"setting,omitempty"`
}
// SecretScanningPatternConfigsUpdate represents a secret scanning pattern configurations update.
type SecretScanningPatternConfigsUpdate struct {
PatternConfigVersion *string `json:"pattern_config_version,omitempty"`
}
// SecretScanningPatternConfigsUpdateOptions specifies optional parameters to
// the SecretScanningService.UpdatePatternConfigsForEnterprise method and
// the SecretScanningService.UpdatePatternConfigsForOrg method.
type SecretScanningPatternConfigsUpdateOptions struct {
// The version of the entity.
PatternConfigVersion *string `json:"pattern_config_version,omitempty"`
// Pattern settings for provider patterns.
ProviderPatternSettings []*SecretScanningProviderPatternSetting `json:"provider_pattern_settings,omitempty"`
// Pattern settings for custom patterns.
CustomPatternSettings []*SecretScanningCustomPatternSetting `json:"custom_pattern_settings,omitempty"`
}
// SecretScanningProviderPatternSetting defines an optional pattern setting for provider patterns.
type SecretScanningProviderPatternSetting struct {
// The ID of the pattern to configure.
TokenType string `json:"token_type"`
// Push protection setting to set for the pattern.
// Can be one of: "not-set", "disabled", "enabled"
PushProtectionSetting string `json:"push_protection_setting"`
}
// SecretScanningCustomPatternSetting defines an optional pattern setting for custom patterns.
type SecretScanningCustomPatternSetting struct {
// The ID of the pattern to configure.
TokenType string `json:"token_type"`
// The version of the entity
CustomPatternVersion *string `json:"custom_pattern_version,omitempty"`
// Push protection setting to set for the pattern.
// Can be one of: "not-set", "disabled", "enabled"
PushProtectionSetting string `json:"push_protection_setting"`
}
// ListPatternConfigsForEnterprise lists the secret scanning pattern configurations for an enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/secret-scanning/push-protection#list-enterprise-pattern-configurations
//
//meta:operation GET /enterprises/{enterprise}/secret-scanning/pattern-configurations
func (s *SecretScanningService) ListPatternConfigsForEnterprise(ctx context.Context, enterprise string) (*SecretScanningPatternConfigs, *Response, error) {
u := fmt.Sprintf("enterprises/%v/secret-scanning/pattern-configurations", enterprise)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var patternConfigs *SecretScanningPatternConfigs
resp, err := s.client.Do(ctx, req, &patternConfigs)
if err != nil {
return nil, resp, err
}
return patternConfigs, resp, nil
}
// ListPatternConfigsForOrg lists the secret scanning pattern configurations for an organization.
//
// GitHub API docs: https://docs.github.com/rest/secret-scanning/push-protection#list-organization-pattern-configurations
//
//meta:operation GET /orgs/{org}/secret-scanning/pattern-configurations
func (s *SecretScanningService) ListPatternConfigsForOrg(ctx context.Context, org string) (*SecretScanningPatternConfigs, *Response, error) {
u := fmt.Sprintf("orgs/%v/secret-scanning/pattern-configurations", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var patternConfigs *SecretScanningPatternConfigs
resp, err := s.client.Do(ctx, req, &patternConfigs)
if err != nil {
return nil, resp, err
}
return patternConfigs, resp, nil
}
// UpdatePatternConfigsForEnterprise updates the secret scanning pattern configurations for an enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/secret-scanning/push-protection#update-enterprise-pattern-configurations
//
//meta:operation PATCH /enterprises/{enterprise}/secret-scanning/pattern-configurations
func (s *SecretScanningService) UpdatePatternConfigsForEnterprise(ctx context.Context, enterprise string, opts *SecretScanningPatternConfigsUpdateOptions) (*SecretScanningPatternConfigsUpdate, *Response, error) {
u := fmt.Sprintf("enterprises/%v/secret-scanning/pattern-configurations", enterprise)
req, err := s.client.NewRequest("PATCH", u, opts)
if err != nil {
return nil, nil, err
}
var patternConfigsUpdate *SecretScanningPatternConfigsUpdate
resp, err := s.client.Do(ctx, req, &patternConfigsUpdate)
if err != nil {
return nil, resp, err
}
return patternConfigsUpdate, resp, nil
}
// UpdatePatternConfigsForOrg updates the secret scanning pattern configurations for an organization.
//
// GitHub API docs: https://docs.github.com/rest/secret-scanning/push-protection#update-organization-pattern-configurations
//
//meta:operation PATCH /orgs/{org}/secret-scanning/pattern-configurations
func (s *SecretScanningService) UpdatePatternConfigsForOrg(ctx context.Context, org string, opts *SecretScanningPatternConfigsUpdateOptions) (*SecretScanningPatternConfigsUpdate, *Response, error) {
u := fmt.Sprintf("orgs/%v/secret-scanning/pattern-configurations", org)
req, err := s.client.NewRequest("PATCH", u, opts)
if err != nil {
return nil, nil, err
}
var patternConfigsUpdate *SecretScanningPatternConfigsUpdate
resp, err := s.client.Do(ctx, req, &patternConfigsUpdate)
if err != nil {
return nil, resp, err
}
return patternConfigsUpdate, resp, nil
}