-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathprivate_registries.go
More file actions
263 lines (223 loc) · 11.5 KB
/
private_registries.go
File metadata and controls
263 lines (223 loc) · 11.5 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// 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"
)
// PrivateRegistriesService handles communication with the private registries
// methods of the GitHub API.
//
// GitHub API docs: https://docs.github.com/rest/private-registries
type PrivateRegistriesService service
// PrivateRegistryType represents the type of private registry.
type PrivateRegistryType string
const (
PrivateRegistryTypeMavenRepository PrivateRegistryType = "maven_repository"
PrivateRegistryTypeNugetFeed PrivateRegistryType = "nuget_feed"
PrivateRegistryTypeGoProxyServer PrivateRegistryType = "goproxy_server"
PrivateRegistryTypeNpmRegistry PrivateRegistryType = "npm_registry"
PrivateRegistryTypeRubygemsServer PrivateRegistryType = "rubygems_server"
PrivateRegistryTypeCargoRegistry PrivateRegistryType = "cargo_registry"
PrivateRegistryTypeComposerRepository PrivateRegistryType = "composer_repository"
PrivateRegistryTypeDockerRegistry PrivateRegistryType = "docker_registry"
PrivateRegistryTypeGitSource PrivateRegistryType = "git_source"
PrivateRegistryTypeHelmRegistry PrivateRegistryType = "helm_registry"
PrivateRegistryTypeHexOrganization PrivateRegistryType = "hex_organization"
PrivateRegistryTypeHexRepository PrivateRegistryType = "hex_repository"
PrivateRegistryTypePubRepository PrivateRegistryType = "pub_repository"
PrivateRegistryTypePythonIndex PrivateRegistryType = "python_index"
PrivateRegistryTypeTerraformRegistry PrivateRegistryType = "terraform_registry"
)
// PrivateRegistryVisibility represents the visibility of a private registry.
type PrivateRegistryVisibility string
const (
PrivateRegistryVisibilityPrivate PrivateRegistryVisibility = "private"
PrivateRegistryVisibilityAll PrivateRegistryVisibility = "all"
PrivateRegistryVisibilitySelected PrivateRegistryVisibility = "selected"
)
// PrivateRegistry represents a private registry configuration.
type PrivateRegistry struct {
// Name of the private registry.
Name *string `json:"name,omitempty"`
// RegistryType is the type of private registry. You can find the list of supported types in PrivateRegistryType.
RegistryType *string `json:"registry_type,omitempty"`
// Username to use when authenticating with the private registry.
// This field is omitted if the private registry does not require a username for authentication.
Username *string `json:"username,omitempty"`
// CreatedAt is the timestamp when the private registry was created.
CreatedAt *Timestamp `json:"created_at,omitempty"`
// UpdatedAt is the timestamp when the private registry was last updated.
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
// Visibility is the visibility of the private registry. Possible values are: "private", "all", and "selected".
Visibility *PrivateRegistryVisibility `json:"visibility,omitempty"`
}
// PrivateRegistries represents a list of private registries.
type PrivateRegistries struct {
// TotalCount is the total number of private registries.
TotalCount *int `json:"total_count,omitempty"`
// Configurations is the list of private registry configurations.
Configurations []*PrivateRegistry `json:"configurations,omitempty"`
}
// CreateOrganizationPrivateRegistry represents the payload to create a private registry.
type CreateOrganizationPrivateRegistry struct {
// RegistryType is the type of private registry.
// You can find the list of supported types in PrivateRegistryType.
RegistryType string `json:"registry_type"`
// URL is the URL of the private registry.
URL string `json:"url"`
// The username to use when authenticating with the private registry.
// This field should be omitted if the private registry does not require a username for authentication.
Username *string `json:"username,omitempty"`
// The value for your secret, encrypted with [LibSodium](https://libsodium.gitbook.io/doc/bindings_for_other_languages)
// using the public key retrieved from the PrivateRegistriesService.GetOrganizationPrivateRegistriesPublicKey.
EncryptedValue string `json:"encrypted_value"`
// KeyID is the ID of the public key used to encrypt the secret.
KeyID string `json:"key_id"`
// Visibility is the visibility of the private registry.
// Possible values are: "private", "all", and "selected".
Visibility PrivateRegistryVisibility `json:"visibility"`
// An array of repository IDs that can access the organization private registry.
// You can only provide a list of repository IDs when CreateOrganizationPrivateRegistry.Visibility is set to PrivateRegistryVisibilitySelected.
// This field should be omitted if visibility is set to PrivateRegistryVisibilityAll or PrivateRegistryVisibilityPrivate.
SelectedRepositoryIDs []int64 `json:"selected_repository_ids,omitempty"`
}
// UpdateOrganizationPrivateRegistry represents the payload to update a private registry.
type UpdateOrganizationPrivateRegistry struct {
// RegistryType is the type of private registry.
// You can find the list of supported types in PrivateRegistryType.
RegistryType *string `json:"registry_type,omitempty"`
// URL is the URL of the private registry.
URL *string `json:"url,omitempty"`
// The username to use when authenticating with the private registry.
// This field should be omitted if the private registry does not require a username for authentication.
Username *string `json:"username,omitempty"`
// The value for your secret, encrypted with [LibSodium](https://libsodium.gitbook.io/doc/bindings_for_other_languages)
// using the public key retrieved from the PrivateRegistriesService.GetOrganizationPrivateRegistriesPublicKey.
EncryptedValue *string `json:"encrypted_value,omitempty"`
// KeyID is the ID of the public key used to encrypt the secret.
KeyID *string `json:"key_id,omitempty"`
// Visibility is the visibility of the private registry.
// Possible values are: "private", "all", and "selected".
Visibility *PrivateRegistryVisibility `json:"visibility,omitempty"`
// An array of repository IDs that can access the organization private registry.
// You can only provide a list of repository IDs when CreateOrganizationPrivateRegistry.Visibility is set to PrivateRegistryVisibilitySelected.
// This field should be omitted if visibility is set to PrivateRegistryVisibilityAll or PrivateRegistryVisibilityPrivate.
SelectedRepositoryIDs []int64 `json:"selected_repository_ids,omitempty"`
}
// ListOrganizationPrivateRegistries lists private registries for an organization.
//
// GitHub API docs: https://docs.github.com/rest/private-registries/organization-configurations#list-private-registries-for-an-organization
//
//meta:operation GET /orgs/{org}/private-registries
func (s *PrivateRegistriesService) ListOrganizationPrivateRegistries(ctx context.Context, org string, opts *ListOptions) (*PrivateRegistries, *Response, error) {
u := fmt.Sprintf("orgs/%v/private-registries", org)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var privateRegistries PrivateRegistries
resp, err := s.client.Do(ctx, req, &privateRegistries)
if err != nil {
return nil, resp, err
}
return &privateRegistries, resp, nil
}
// CreateOrganizationPrivateRegistry creates a private registry configuration with an encrypted value for an organization.
//
// GitHub API docs: https://docs.github.com/rest/private-registries/organization-configurations#create-a-private-registry-for-an-organization
//
//meta:operation POST /orgs/{org}/private-registries
func (s *PrivateRegistriesService) CreateOrganizationPrivateRegistry(ctx context.Context, org string, privateRegistry CreateOrganizationPrivateRegistry) (*PrivateRegistry, *Response, error) {
u := fmt.Sprintf("orgs/%v/private-registries", org)
req, err := s.client.NewRequest("POST", u, privateRegistry)
if err != nil {
return nil, nil, err
}
var result PrivateRegistry
resp, err := s.client.Do(ctx, req, &result)
if err != nil {
return nil, resp, err
}
return &result, resp, nil
}
// GetOrganizationPrivateRegistriesPublicKey retrieves the public key for encrypting secrets for an organization's private registries.
//
// GitHub API docs: https://docs.github.com/rest/private-registries/organization-configurations#get-private-registries-public-key-for-an-organization
//
//meta:operation GET /orgs/{org}/private-registries/public-key
func (s *PrivateRegistriesService) GetOrganizationPrivateRegistriesPublicKey(ctx context.Context, org string) (*PublicKey, *Response, error) {
u := fmt.Sprintf("orgs/%v/private-registries/public-key", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var publicKey PublicKey
resp, err := s.client.Do(ctx, req, &publicKey)
if err != nil {
return nil, resp, err
}
return &publicKey, resp, nil
}
// GetOrganizationPrivateRegistry gets a specific private registry for an organization.
// The `name` parameter is the name of the private registry to retrieve. It is the same as PrivateRegistry.Name.
//
// GitHub API docs: https://docs.github.com/rest/private-registries/organization-configurations#get-a-private-registry-for-an-organization
//
//meta:operation GET /orgs/{org}/private-registries/{secret_name}
func (s *PrivateRegistriesService) GetOrganizationPrivateRegistry(ctx context.Context, org, secretName string) (*PrivateRegistry, *Response, error) {
u := fmt.Sprintf("orgs/%v/private-registries/%v", org, secretName)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var privateRegistry PrivateRegistry
resp, err := s.client.Do(ctx, req, &privateRegistry)
if err != nil {
return nil, resp, err
}
return &privateRegistry, resp, nil
}
// UpdateOrganizationPrivateRegistry updates a specific private registry for an organization.
// The `name` parameter is the name of the private registry to update. It is the same as PrivateRegistry.Name.
//
// GitHub API docs: https://docs.github.com/rest/private-registries/organization-configurations#update-a-private-registry-for-an-organization
//
//meta:operation PATCH /orgs/{org}/private-registries/{secret_name}
func (s *PrivateRegistriesService) UpdateOrganizationPrivateRegistry(ctx context.Context, org, secretName string, privateRegistry UpdateOrganizationPrivateRegistry) (*PrivateRegistry, *Response, error) {
u := fmt.Sprintf("orgs/%v/private-registries/%v", org, secretName)
req, err := s.client.NewRequest("PATCH", u, privateRegistry)
if err != nil {
return nil, nil, err
}
var updatedRegistry PrivateRegistry
resp, err := s.client.Do(ctx, req, &updatedRegistry)
if err != nil {
return nil, resp, err
}
return &updatedRegistry, resp, nil
}
// DeleteOrganizationPrivateRegistry deletes a specific private registry for an organization.
// The `name` parameter is the name of the private registry to delete. It is the same as PrivateRegistry.Name.
//
// GitHub API docs: https://docs.github.com/rest/private-registries/organization-configurations#delete-a-private-registry-for-an-organization
//
//meta:operation DELETE /orgs/{org}/private-registries/{secret_name}
func (s *PrivateRegistriesService) DeleteOrganizationPrivateRegistry(ctx context.Context, org, secretName string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/private-registries/%v", org, secretName)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, nil
}