1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13 func (s *DependabotService) getPublicKey(ctx context.Context, url string) (*PublicKey, *Response, error) {
14 req, err := s.client.NewRequest("GET", url, nil)
15 if err != nil {
16 return nil, nil, err
17 }
18
19 pubKey := new(PublicKey)
20 resp, err := s.client.Do(ctx, req, pubKey)
21 if err != nil {
22 return nil, resp, err
23 }
24
25 return pubKey, resp, nil
26 }
27
28
29
30
31 func (s *DependabotService) GetRepoPublicKey(ctx context.Context, owner, repo string) (*PublicKey, *Response, error) {
32 url := fmt.Sprintf("repos/%v/%v/dependabot/secrets/public-key", owner, repo)
33 return s.getPublicKey(ctx, url)
34 }
35
36
37
38
39 func (s *DependabotService) GetOrgPublicKey(ctx context.Context, org string) (*PublicKey, *Response, error) {
40 url := fmt.Sprintf("orgs/%v/dependabot/secrets/public-key", org)
41 return s.getPublicKey(ctx, url)
42 }
43
44 func (s *DependabotService) listSecrets(ctx context.Context, url string, opts *ListOptions) (*Secrets, *Response, error) {
45 u, err := addOptions(url, opts)
46 if err != nil {
47 return nil, nil, err
48 }
49
50 req, err := s.client.NewRequest("GET", u, nil)
51 if err != nil {
52 return nil, nil, err
53 }
54
55 secrets := new(Secrets)
56 resp, err := s.client.Do(ctx, req, &secrets)
57 if err != nil {
58 return nil, resp, err
59 }
60
61 return secrets, resp, nil
62 }
63
64
65
66
67
68 func (s *DependabotService) ListRepoSecrets(ctx context.Context, owner, repo string, opts *ListOptions) (*Secrets, *Response, error) {
69 url := fmt.Sprintf("repos/%v/%v/dependabot/secrets", owner, repo)
70 return s.listSecrets(ctx, url, opts)
71 }
72
73
74
75
76
77 func (s *DependabotService) ListOrgSecrets(ctx context.Context, org string, opts *ListOptions) (*Secrets, *Response, error) {
78 url := fmt.Sprintf("orgs/%v/dependabot/secrets", org)
79 return s.listSecrets(ctx, url, opts)
80 }
81
82 func (s *DependabotService) getSecret(ctx context.Context, url string) (*Secret, *Response, error) {
83 req, err := s.client.NewRequest("GET", url, nil)
84 if err != nil {
85 return nil, nil, err
86 }
87
88 secret := new(Secret)
89 resp, err := s.client.Do(ctx, req, secret)
90 if err != nil {
91 return nil, resp, err
92 }
93
94 return secret, resp, nil
95 }
96
97
98
99
100 func (s *DependabotService) GetRepoSecret(ctx context.Context, owner, repo, name string) (*Secret, *Response, error) {
101 url := fmt.Sprintf("repos/%v/%v/dependabot/secrets/%v", owner, repo, name)
102 return s.getSecret(ctx, url)
103 }
104
105
106
107
108 func (s *DependabotService) GetOrgSecret(ctx context.Context, org, name string) (*Secret, *Response, error) {
109 url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v", org, name)
110 return s.getSecret(ctx, url)
111 }
112
113 func (s *DependabotService) putSecret(ctx context.Context, url string, eSecret *EncryptedSecret) (*Response, error) {
114 req, err := s.client.NewRequest("PUT", url, eSecret)
115 if err != nil {
116 return nil, err
117 }
118
119 return s.client.Do(ctx, req, nil)
120 }
121
122
123
124
125 func (s *DependabotService) CreateOrUpdateRepoSecret(ctx context.Context, owner, repo string, eSecret *EncryptedSecret) (*Response, error) {
126 url := fmt.Sprintf("repos/%v/%v/dependabot/secrets/%v", owner, repo, eSecret.Name)
127 return s.putSecret(ctx, url, eSecret)
128 }
129
130
131
132
133 func (s *DependabotService) CreateOrUpdateOrgSecret(ctx context.Context, org string, eSecret *EncryptedSecret) (*Response, error) {
134 url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v", org, eSecret.Name)
135 return s.putSecret(ctx, url, eSecret)
136 }
137
138 func (s *DependabotService) deleteSecret(ctx context.Context, url string) (*Response, error) {
139 req, err := s.client.NewRequest("DELETE", url, nil)
140 if err != nil {
141 return nil, err
142 }
143
144 return s.client.Do(ctx, req, nil)
145 }
146
147
148
149
150 func (s *DependabotService) DeleteRepoSecret(ctx context.Context, owner, repo, name string) (*Response, error) {
151 url := fmt.Sprintf("repos/%v/%v/dependabot/secrets/%v", owner, repo, name)
152 return s.deleteSecret(ctx, url)
153 }
154
155
156
157
158 func (s *DependabotService) DeleteOrgSecret(ctx context.Context, org, name string) (*Response, error) {
159 url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v", org, name)
160 return s.deleteSecret(ctx, url)
161 }
162
163
164
165
166 func (s *DependabotService) ListSelectedReposForOrgSecret(ctx context.Context, org, name string, opts *ListOptions) (*SelectedReposList, *Response, error) {
167 url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v/repositories", org, name)
168 u, err := addOptions(url, opts)
169 if err != nil {
170 return nil, nil, err
171 }
172
173 req, err := s.client.NewRequest("GET", u, nil)
174 if err != nil {
175 return nil, nil, err
176 }
177
178 result := new(SelectedReposList)
179 resp, err := s.client.Do(ctx, req, result)
180 if err != nil {
181 return nil, resp, err
182 }
183
184 return result, resp, nil
185 }
186
187
188
189
190 func (s *DependabotService) SetSelectedReposForOrgSecret(ctx context.Context, org, name string, ids SelectedRepoIDs) (*Response, error) {
191 url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v/repositories", org, name)
192 type repoIDs struct {
193 SelectedIDs SelectedRepoIDs `json:"selected_repository_ids"`
194 }
195
196 req, err := s.client.NewRequest("PUT", url, repoIDs{SelectedIDs: ids})
197 if err != nil {
198 return nil, err
199 }
200
201 return s.client.Do(ctx, req, nil)
202 }
203
204
205
206
207 func (s *DependabotService) AddSelectedRepoToOrgSecret(ctx context.Context, org, name string, repo *Repository) (*Response, error) {
208 url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v/repositories/%v", org, name, *repo.ID)
209 req, err := s.client.NewRequest("PUT", url, nil)
210 if err != nil {
211 return nil, err
212 }
213
214 return s.client.Do(ctx, req, nil)
215 }
216
217
218
219
220 func (s *DependabotService) RemoveSelectedRepoFromOrgSecret(ctx context.Context, org, name string, repo *Repository) (*Response, error) {
221 url := fmt.Sprintf("orgs/%v/dependabot/secrets/%v/repositories/%v", org, name, *repo.ID)
222 req, err := s.client.NewRequest("DELETE", url, nil)
223 if err != nil {
224 return nil, err
225 }
226
227 return s.client.Do(ctx, req, nil)
228 }
229
View as plain text