-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathcontainer_registry.go
More file actions
969 lines (774 loc) · 33.8 KB
/
container_registry.go
File metadata and controls
969 lines (774 loc) · 33.8 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
package govultr
import (
"context"
"fmt"
"net/http"
"github.com/google/go-querystring/query"
)
const vcrPath = "/v2/registry"
const vcrListPath = "/v2/registries"
// ContainerRegistryService is the interface to interact with the container
// registry endpoints on the Vultr API. Link :
// https://www.vultr.com/api/#tag/Container-Registry
type ContainerRegistryService interface {
Create(ctx context.Context, createReq *ContainerRegistryReq) (*ContainerRegistry, *http.Response, error)
Get(ctx context.Context, vcrID string) (*ContainerRegistry, *http.Response, error)
Update(ctx context.Context, vcrID string, updateReq *ContainerRegistryUpdateReq) (*ContainerRegistry, *http.Response, error)
Delete(ctx context.Context, vcrID string) error
List(ctx context.Context, options *ListOptions) ([]ContainerRegistry, *Meta, *http.Response, error)
ListRepositories(ctx context.Context, vcrID string, options *ListOptions) ([]ContainerRegistryRepo, *Meta, *http.Response, error)
GetRepository(ctx context.Context, vcrID, imageName string) (*ContainerRegistryRepo, *http.Response, error)
UpdateRepository(ctx context.Context, vcrID, imageName string, updateReq *ContainerRegistryRepoUpdateReq) (*ContainerRegistryRepo, *http.Response, error) //nolint:lll
DeleteRepository(ctx context.Context, vcrID, imageName string) error
ListReplications(ctx context.Context, vcrID string, options *ListOptions) ([]ContainerRegistryReplication, *Meta, *http.Response, error)
CreateReplication(ctx context.Context, vcrID, regionID string) (*ContainerRegistryReplication, *http.Response, error)
GetReplication(ctx context.Context, vcrID, regionID string) (*ContainerRegistryReplication, *http.Response, error)
DeleteReplication(ctx context.Context, vcrID, regionID string) error
UpdateRetentionSchedule(ctx context.Context, vcrID, schedule string) (*ContainerRegistryRetentionSchedule, *http.Response, error)
ExecuteRetention(ctx context.Context, vcrID string, dryRun bool) (*ContainerRegistryRetentionExecution, *http.Response, error)
ListRetentionRules(ctx context.Context, vcrID string, options *ListOptions) ([]ContainerRegistryRetentionRule, *Meta, *http.Response, error) //nolint:lll
GetRetentionRule(ctx context.Context, vcrID string, ruleID int) (*ContainerRegistryRetentionRule, *http.Response, error)
CreateRetentionRule(ctx context.Context, vcrID string, ruleReq *ContainerRegistryRetentionRuleReq) (*ContainerRegistryRetentionRule, *http.Response, error) //nolint:lll
UpdateRetentionRule(ctx context.Context, vcrID string, ruleID int, disabled bool) (*ContainerRegistryRetentionRule, *http.Response, error)
DeleteRetentionRule(ctx context.Context, vcrID string, ruleID int) error
ListRobots(ctx context.Context, vcrID string, options *ListOptions) ([]ContainerRegistryRobot, *Meta, *http.Response, error)
GetRobot(ctx context.Context, vcrID, robotName string) (*ContainerRegistryRobot, *http.Response, error)
UpdateRobot(ctx context.Context, vcrID, robotName string, updateReq *ContainerRegistryRobotReq) (*ContainerRegistryRobot, *http.Response, error) //nolint:lll
DeleteRobot(ctx context.Context, vcrID, robotName string) error
ListArtifacts(ctx context.Context, vcrID, imageName string, options *ListOptions) ([]ContainerRegistryArtifact, *Meta, *http.Response, error) //nolint:lll
GetArtifact(ctx context.Context, vcrID, imageName, artifactDigest string) (*ContainerRegistryArtifact, *http.Response, error)
DeleteArtifact(ctx context.Context, vcrID, imageName, artifactDigest string) error
CreateDockerCredentials(ctx context.Context, vcrID string, createOptions *DockerCredentialsOpt) (*ContainerRegistryDockerCredentials, *http.Response, error) //nolint:lll
ListRegions(ctx context.Context) ([]ContainerRegistryRegion, *Meta, *http.Response, error)
ListPlans(ctx context.Context) (*ContainerRegistryPlans, *http.Response, error)
}
// ContainerRegistryServiceHandler handles interaction between the container
// registry service and the Vultr API.
type ContainerRegistryServiceHandler struct {
client *Client
}
// ContainerRegistry represents a Vultr container registry subscription.
type ContainerRegistry struct {
ID string `json:"id"`
Name string `json:"name"`
URN string `json:"urn"`
Storage ContainerRegistryStorage `json:"storage"`
DateCreated string `json:"date_created"`
Public bool `json:"public"`
RootUser ContainerRegistryUser `json:"root_user"`
Metadata ContainerRegistryMetadata `json:"metadata"`
}
type containerRegistries struct {
ContainerRegistries []ContainerRegistry `json:"registries"`
Meta *Meta `json:"meta"`
}
// ContainerRegistryStorage represents the storage usage and limit.
type ContainerRegistryStorage struct {
Used ContainerRegistryStorageCount `json:"used"`
Allowed ContainerRegistryStorageCount `json:"allowed"`
}
// ContainerRegistryStorageCount represents the different storage usage counts.
type ContainerRegistryStorageCount struct {
Bytes float32 `json:"bytes"`
MegaBytes float32 `json:"mb"`
GigaBytes float32 `json:"gb"`
TeraBytes float32 `json:"tb"`
DateModified string `json:"updated_at"`
}
// ContainerRegistryUser contains the user data.
type ContainerRegistryUser struct {
ID int `json:"id"`
UserName string `json:"username"`
Password string `json:"password"`
Root bool `json:"root"`
DateCreated string `json:"added_at"`
DateModified string `json:"updated_at"`
}
// ContainerRegistryMetadata contains the meta data for the registry.
type ContainerRegistryMetadata struct {
Region ContainerRegistryRegion `json:"region"`
Subscription ContainerRegistrySubscription `json:"subscription"`
}
// ContainerRegistrySubscription contains the subscription information for the
// registry.
type ContainerRegistrySubscription struct {
Billing ContainerRegistrySubscriptionBilling `json:"billing"`
}
// ContainerRegistrySubscriptionBilling represents the subscription billing
// data on the registry.
type ContainerRegistrySubscriptionBilling struct {
MonthlyPrice float32 `json:"monthly_price"`
PendingCharges float32 `json:"pending_charges"`
}
// ContainerRegistryReq represents the data used to create a registry.
type ContainerRegistryReq struct {
Name string `json:"name"`
Public bool `json:"public"`
Region string `json:"region"`
Plan string `json:"plan"`
}
// ContainerRegistryUpdateReq represents the data used to update a registry.
type ContainerRegistryUpdateReq struct {
Public *bool `json:"public,omitempty"`
Plan *string `json:"plan,omitempty"`
}
// ContainerRegistryRepo represents the data of a registry repository.
type ContainerRegistryRepo struct {
Name string `json:"name"`
Image string `json:"image"`
Description string `json:"description"`
DateCreated string `json:"added_at"`
DateModified string `json:"updated_at"`
PullCount int `json:"pull_count"`
ArtifactCount int `json:"artifact_count"`
}
type containerRegistryRepos struct {
Repositories []ContainerRegistryRepo `json:"repositories"`
Meta *Meta `json:"meta"`
}
// ContainerRegistryRepoUpdateReq is the data to update a registry repository.
type ContainerRegistryRepoUpdateReq struct {
Description string `json:"description"`
}
// ContainerRegistryReplication represents a container registry replication.
type ContainerRegistryReplication struct {
Region string `json:"region"`
Namespace string `json:"namespace"`
URN string `json:"urn"`
}
// ContainerRegistryReplicationReq represents a container registry replication.
// request
type ContainerRegistryReplicationReq struct {
Region string `json:"region"`
}
type containerRegistryReplicationsBase struct {
Replications []ContainerRegistryReplication `json:"replications"`
Meta *Meta `json:"meta"`
}
// ContainerRegistryRetentionSchedule represents a container registry retention
// schedule.
type ContainerRegistryRetentionSchedule struct {
Schedule string `json:"schedule"`
NextScheduledTime string `json:"next_scheduled_time"`
}
// ContainerRegistryRetentionScheduleReq represents a container registry
// schedule request.
type ContainerRegistryRetentionScheduleReq struct {
Cron string `json:"cron"`
}
// ContainerRegistryRetentionExecution represents a container registry
// execution.
type ContainerRegistryRetentionExecution struct {
Start string `json:"start_time"`
End string `json:"end_time"`
Trigger string `json:"trigger"`
DryRun bool `json:"dry_run"`
}
// ContainerRegistryRetentionExecutionReq represents a container registry
// execution request.
type ContainerRegistryRetentionExecutionReq struct {
DryRun bool `json:"dry_run"`
}
// ContainerRegistryRetentionRule represents a container registry retention
// rule.
type ContainerRegistryRetentionRule struct {
ID int `json:"id"`
Disabled bool `json:"disabled"`
Action string `json:"action"`
Parameters ContainerRegistryRetentionRuleParameter `json:"params"`
ScopeSelector ContainerRegistryScopeSelector `json:"scope_selector"`
TagSelectors []ContainerRegistryRetentionRuleSelector `json:"tag_selectors"`
Template string `json:"template"`
}
// ContainerRegistryRetentionRuleParameter represents a container registry rule
// parameter.
type ContainerRegistryRetentionRuleParameter struct {
AdditionalProperty int `json:"additional_prop"`
}
// ContainerRegistryScopeSelector represents a container registry retention
// rule scope selector.
type ContainerRegistryScopeSelector struct {
Repository []ContainerRegistryRetentionRuleSelector `json:"repository"`
}
// ContainerRegistryRetentionRuleSelector represents a container registry
// retention rule selector.
type ContainerRegistryRetentionRuleSelector struct {
Decoration string `json:"decoration"`
Kind string `json:"kind"`
Pattern string `json:"pattern"`
}
type containerRegistryRetentionRulesBase struct {
Rules []ContainerRegistryRetentionRule `json:"retention_rules"`
Meta *Meta `json:"meta"`
}
// ContainerRegistryRetentionRuleReq represents the options for creating a
// container registry retention rule.
type ContainerRegistryRetentionRuleReq struct {
Type string `json:"rule_type"`
Count int `json:"count,omitempty"`
RepositoryAction string `json:"repository_action"`
RepositoryMatch string `json:"repository_match"`
TagAction string `json:"tag_action"`
TagMatch string `json:"tag_match"`
Untagged bool `json:"untagged"`
}
// ContainerRegistryRetentionRuleUpdateReq represents the options for updating
// a container registry retention rule.
type ContainerRegistryRetentionRuleUpdateReq struct {
Disabled bool `json:"disabled"`
}
// ContainerRegistryRobot represents the details of a container registry robot.
type ContainerRegistryRobot struct {
Name string `json:"name"`
Description string `json:"description"`
Secret string `json:"secret"`
Disable bool `json:"disable"`
Duration int `json:"duration"`
Permissions []ContainerRegistryRobotPermission `json:"permissions"`
DateCreated string `json:"creation_time"`
}
// ContainerRegistryRobotPermission represent container registry robot
// permission details.
type ContainerRegistryRobotPermission struct {
Kind string `json:"kind"`
Namespace string `json:"namespace"`
Access []ContainerRegistryRobotAccess `json:"access"`
}
// ContainerRegistryRobotAccess represents container registry robot access
// details.
type ContainerRegistryRobotAccess struct {
Action string `json:"action"`
Resource string `json:"resource"`
Effect string `json:"effect"`
}
type containerRegistryRobotsBase struct {
Robots []ContainerRegistryRobot `json:"robots"`
Meta *Meta `json:"meta"`
}
type ContainerRegistryRobotReq struct {
Description string `json:"description,omitempty"`
Disable bool `json:"disable,omitempty"`
Duration int `json:"duration,omitempty"`
Access ContainerRegistryRobotAccess `json:"access,omitempty"`
}
// ContainerRegistryArtifact represents a container registry artifact.
type ContainerRegistryArtifact struct {
ArtifactType string `json:"artifact_type"`
Digest string `json:"digest"`
ManifestMediaType string `json:"manifest_media_type"`
MediaType string `json:"media_type"`
RepositoryName string `json:"repository_name"`
Size int `json:"size"`
Type string `json:"type"`
Tags []ContainerRegistryArtifactTag `json:"tags"`
DatePulled string `json:"pull_time"`
DatePushed string `json:"push_time"`
}
// ContainerRegistryArtifactTag represents tags on an artifact.
type ContainerRegistryArtifactTag struct {
Name string `json:"name"`
Immutable bool `json:"immutable"`
DatePulled string `json:"pull_time"`
DatePushed string `json:"push_time"`
}
type containerRegistryArtifactsBase struct {
Artifacts []ContainerRegistryArtifact `json:"artifacts"`
Meta *Meta `json:"meta"`
}
// DockerCredentialsOpt contains the options used to create Docker credentials.
type DockerCredentialsOpt struct {
ExpirySeconds *int
WriteAccess *bool
}
// ContainerRegistryDockerCredentials represents the byte array of character
// data returned after creating a Docker credential.
type ContainerRegistryDockerCredentials []byte
// UnmarshalJSON is a custom unmarshal function for
// ContainerRegistryDockerCredentials.
func (c *ContainerRegistryDockerCredentials) UnmarshalJSON(b []byte) error {
*c = b
return nil
}
// String converts the ContainerRegistryDockerCredentials to a string.
func (c *ContainerRegistryDockerCredentials) String() string {
return string(*c)
}
// ContainerRegistryRegion represents the region data.
type ContainerRegistryRegion struct {
ID int `json:"id"`
Name string `json:"name"`
URN string `json:"urn"`
BaseURL string `json:"base_url"`
Public bool `json:"public"`
DateCreated string `json:"added_at"`
DateModified string `json:"updated_at"`
DataCenter ContainerRegistryRegionDataCenter `json:"data_center"`
}
// ContainerRegistryRegionDataCenter is the datacenter info for a given region.
type ContainerRegistryRegionDataCenter struct {
ID int `json:"id"`
Name string `json:"name"`
SiteCode string `json:"site_code"`
Region string `json:"region"`
Country string `json:"country"`
Continent string `json:"continent"`
Description string `json:"description"`
Airport string `json:"airport"`
}
type containerRegistryRegions struct {
Regions []ContainerRegistryRegion `json:"regions"`
Meta *Meta `json:"meta"`
}
// ContainerRegistryPlans contains all plan types.
type ContainerRegistryPlans struct {
Plans ContainerRegistryPlanTypes `json:"plans"`
}
// ContainerRegistryPlanTypes represent the different plan types.
type ContainerRegistryPlanTypes struct {
StartUp ContainerRegistryPlan `json:"start_up"`
Business ContainerRegistryPlan `json:"business"`
Premium ContainerRegistryPlan `json:"premium"`
Enterprise ContainerRegistryPlan `json:"enterprise"`
}
// ContainerRegistryPlan represent the plan data.
type ContainerRegistryPlan struct {
VanityName string `json:"vanity_name"`
MaxStorageMB int `json:"max_storage_mb"`
MonthlyPrice int `json:"monthly_price"`
}
// Get retrieves a contrainer registry by ID
func (h *ContainerRegistryServiceHandler) Get(ctx context.Context, id string) (*ContainerRegistry, *http.Response, error) {
req, errReq := h.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s", vcrPath, id), nil)
if errReq != nil {
return nil, nil, errReq
}
vcr := new(ContainerRegistry)
resp, errResp := h.client.DoWithContext(ctx, req, &vcr)
if errResp != nil {
return nil, resp, errResp
}
return vcr, resp, nil
}
// List retrieves the list of all container registries
func (h *ContainerRegistryServiceHandler) List(ctx context.Context, options *ListOptions) ([]ContainerRegistry, *Meta, *http.Response, error) { //nolint:lll,dupl
req, errReq := h.client.NewRequest(ctx, http.MethodGet, vcrListPath, nil)
if errReq != nil {
return nil, nil, nil, errReq
}
qStrings, errQ := query.Values(options)
if errQ != nil {
return nil, nil, nil, errQ
}
req.URL.RawQuery = qStrings.Encode()
vcrs := new(containerRegistries)
resp, errResp := h.client.DoWithContext(ctx, req, &vcrs)
if errResp != nil {
return nil, nil, resp, errResp
}
return vcrs.ContainerRegistries, vcrs.Meta, resp, nil
}
// Create creates a container registry
func (h *ContainerRegistryServiceHandler) Create(ctx context.Context, createReq *ContainerRegistryReq) (*ContainerRegistry, *http.Response, error) { //nolint:lll
req, errReq := h.client.NewRequest(ctx, http.MethodPost, vcrPath, createReq)
if errReq != nil {
return nil, nil, errReq
}
vcr := new(ContainerRegistry)
resp, errResp := h.client.DoWithContext(ctx, req, &vcr)
if errResp != nil {
return nil, resp, errResp
}
return vcr, resp, nil
}
// Update will update an existing container registry
func (h *ContainerRegistryServiceHandler) Update(ctx context.Context, vcrID string, updateReq *ContainerRegistryUpdateReq) (*ContainerRegistry, *http.Response, error) { //nolint:lll
req, errReq := h.client.NewRequest(ctx, http.MethodPut, fmt.Sprintf("%s/%s", vcrPath, vcrID), updateReq)
if errReq != nil {
return nil, nil, errReq
}
vcr := new(ContainerRegistry)
resp, errResp := h.client.DoWithContext(ctx, req, &vcr)
if errResp != nil {
return nil, resp, errResp
}
return vcr, resp, nil
}
// Delete will delete a container registry
func (h *ContainerRegistryServiceHandler) Delete(ctx context.Context, vcrID string) error {
req, errReq := h.client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s", vcrPath, vcrID), nil)
if errReq != nil {
return errReq
}
_, errResp := h.client.DoWithContext(ctx, req, nil)
if errResp != nil {
return errResp
}
return nil
}
// ListRepositories will get a list of the repositories for a existing
// container registry
func (h *ContainerRegistryServiceHandler) ListRepositories(ctx context.Context, vcrID string, options *ListOptions) ([]ContainerRegistryRepo, *Meta, *http.Response, error) { //nolint:lll,dupl
req, errReq := h.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s/repositories", vcrPath, vcrID), nil)
if errReq != nil {
return nil, nil, nil, errReq
}
qStrings, errQ := query.Values(options)
if errQ != nil {
return nil, nil, nil, errQ
}
req.URL.RawQuery = qStrings.Encode()
vcrRepos := new(containerRegistryRepos)
resp, errResp := h.client.DoWithContext(ctx, req, &vcrRepos)
if errResp != nil {
return nil, nil, resp, errResp
}
return vcrRepos.Repositories, vcrRepos.Meta, resp, nil
}
// GetRepository will return an existing repository of the requested registry
// ID and image name
func (h *ContainerRegistryServiceHandler) GetRepository(ctx context.Context, vcrID, imageName string) (*ContainerRegistryRepo, *http.Response, error) { //nolint:lll
req, errReq := h.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s/repository/%s", vcrPath, vcrID, imageName), nil)
if errReq != nil {
return nil, nil, errReq
}
vcrRepo := new(ContainerRegistryRepo)
resp, errResp := h.client.DoWithContext(ctx, req, &vcrRepo)
if errResp != nil {
return nil, resp, errResp
}
return vcrRepo, resp, nil
}
// UpdateRepository allows updating the repository with the specified registry
// ID and image name
func (h *ContainerRegistryServiceHandler) UpdateRepository(ctx context.Context, vcrID, imageName string, updateReq *ContainerRegistryRepoUpdateReq) (*ContainerRegistryRepo, *http.Response, error) { //nolint: lll
req, errReq := h.client.NewRequest(ctx, http.MethodPut, fmt.Sprintf("%s/%s/repository/%s", vcrPath, vcrID, imageName), updateReq)
if errReq != nil {
return nil, nil, errReq
}
vcrRepo := new(ContainerRegistryRepo)
resp, errResp := h.client.DoWithContext(ctx, req, &vcrRepo)
if errResp != nil {
return nil, resp, errResp
}
return vcrRepo, resp, nil
}
// DeleteRepository remove a repository from the container registry
func (h *ContainerRegistryServiceHandler) DeleteRepository(ctx context.Context, vcrID, imageName string) error {
req, errReq := h.client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s/repository/%s", vcrPath, vcrID, imageName), nil)
if errReq != nil {
return errReq
}
_, errResp := h.client.DoWithContext(ctx, req, nil)
if errResp != nil {
return errResp
}
return nil
}
// ListReplications retrieves a list of container registry replications
func (h *ContainerRegistryServiceHandler) ListReplications(ctx context.Context, vcrID string, options *ListOptions) ([]ContainerRegistryReplication, *Meta, *http.Response, error) { //nolint:lll,dupl
url := fmt.Sprintf("%s/%s/replications", vcrPath, vcrID)
req, err := h.client.NewRequest(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, nil, err
}
qStrings, err := query.Values(options)
if err != nil {
return nil, nil, nil, err
}
req.URL.RawQuery = qStrings.Encode()
replications := new(containerRegistryReplicationsBase)
resp, err := h.client.DoWithContext(ctx, req, &replications)
if err != nil {
return nil, nil, resp, err
}
return replications.Replications, replications.Meta, resp, nil
}
// CreateReplication creates a container registry replication
func (h *ContainerRegistryServiceHandler) CreateReplication(ctx context.Context, vcrID, regionID string) (*ContainerRegistryReplication, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/replication", vcrPath, vcrID)
req, err := h.client.NewRequest(ctx, http.MethodPost, url, &ContainerRegistryReplicationReq{Region: regionID})
if err != nil {
return nil, nil, err
}
replication := new(ContainerRegistryReplication)
resp, err := h.client.DoWithContext(ctx, req, &replication)
if err != nil {
return nil, resp, err
}
return replication, resp, nil
}
// GetReplication retrieves a container registry replication
func (h *ContainerRegistryServiceHandler) GetReplication(ctx context.Context, vcrID, regionID string) (*ContainerRegistryReplication, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/replication/%s", vcrPath, vcrID, regionID)
req, errReq := h.client.NewRequest(ctx, http.MethodGet, url, nil)
if errReq != nil {
return nil, nil, errReq
}
replication := new(ContainerRegistryReplication)
resp, errResp := h.client.DoWithContext(ctx, req, &replication)
if errResp != nil {
return nil, resp, errResp
}
return replication, resp, nil
}
// DeleteReplication deletes a container registry replication
func (h *ContainerRegistryServiceHandler) DeleteReplication(ctx context.Context, vcrID, regionID string) error {
url := fmt.Sprintf("%s/%s/replication/%s", vcrPath, vcrID, regionID)
req, err := h.client.NewRequest(ctx, http.MethodDelete, url, nil)
if err != nil {
return err
}
if _, err := h.client.DoWithContext(ctx, req, nil); err != nil {
return err
}
return nil
}
// UpdateRetentionSchedule updates a container registry retention schedule
func (h *ContainerRegistryServiceHandler) UpdateRetentionSchedule(ctx context.Context, vcrID, schedule string) (*ContainerRegistryRetentionSchedule, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/retention/schedule", vcrPath, vcrID)
req, err := h.client.NewRequest(ctx, http.MethodPut, url, &ContainerRegistryRetentionScheduleReq{Cron: schedule})
if err != nil {
return nil, nil, err
}
sched := new(ContainerRegistryRetentionSchedule)
resp, errResp := h.client.DoWithContext(ctx, req, &sched)
if errResp != nil {
return nil, resp, errResp
}
return sched, resp, nil
}
// ExecuteRetention triggers a container registry retention execution
func (h *ContainerRegistryServiceHandler) ExecuteRetention(ctx context.Context, vcrID string, dryRun bool) (*ContainerRegistryRetentionExecution, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/retention/executions", vcrPath, vcrID)
req, err := h.client.NewRequest(ctx, http.MethodPost, url, &ContainerRegistryRetentionExecutionReq{DryRun: dryRun})
if err != nil {
return nil, nil, err
}
execution := new(ContainerRegistryRetentionExecution)
resp, errResp := h.client.DoWithContext(ctx, req, &execution)
if errResp != nil {
return nil, resp, errResp
}
return execution, resp, nil
}
// ListRetentionRules retrieves a list of container registry retention rules
func (h *ContainerRegistryServiceHandler) ListRetentionRules(ctx context.Context, vcrID string, options *ListOptions) ([]ContainerRegistryRetentionRule, *Meta, *http.Response, error) { //nolint:lll,dupl
url := fmt.Sprintf("%s/%s/retention/rules", vcrPath, vcrID)
req, err := h.client.NewRequest(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, nil, err
}
qStrings, err := query.Values(options)
if err != nil {
return nil, nil, nil, err
}
req.URL.RawQuery = qStrings.Encode()
rules := new(containerRegistryRetentionRulesBase)
resp, err := h.client.DoWithContext(ctx, req, &rules)
if err != nil {
return nil, nil, resp, err
}
return rules.Rules, rules.Meta, resp, nil
}
// CreateRetentionRule creates a new container registry retention rule
func (h *ContainerRegistryServiceHandler) CreateRetentionRule(ctx context.Context, vcrID string, ruleReq *ContainerRegistryRetentionRuleReq) (*ContainerRegistryRetentionRule, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/retention/rules", vcrPath, vcrID)
req, err := h.client.NewRequest(ctx, http.MethodPost, url, ruleReq)
if err != nil {
return nil, nil, err
}
rule := new(ContainerRegistryRetentionRule)
resp, err := h.client.DoWithContext(ctx, req, &rule)
if err != nil {
return nil, resp, err
}
return rule, resp, nil
}
// GetRetentionRule retrieves a container registry retention rule
func (h *ContainerRegistryServiceHandler) GetRetentionRule(ctx context.Context, vcrID string, ruleID int) (*ContainerRegistryRetentionRule, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/retention/rules/%d", vcrPath, vcrID, ruleID)
req, err := h.client.NewRequest(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, err
}
rule := new(ContainerRegistryRetentionRule)
resp, err := h.client.DoWithContext(ctx, req, &rule)
if err != nil {
return nil, resp, err
}
return rule, resp, nil
}
// UpdateRetentionRule updates a container registry retention rule
func (h *ContainerRegistryServiceHandler) UpdateRetentionRule(ctx context.Context, vcrID string, ruleID int, disabled bool) (*ContainerRegistryRetentionRule, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/retention/rules/%d", vcrPath, vcrID, ruleID)
req, err := h.client.NewRequest(ctx, http.MethodPut, url, &ContainerRegistryRetentionRuleUpdateReq{Disabled: disabled})
if err != nil {
return nil, nil, err
}
rule := new(ContainerRegistryRetentionRule)
resp, err := h.client.DoWithContext(ctx, req, &rule)
if err != nil {
return nil, resp, err
}
return rule, resp, nil
}
// DeleteRetentionRule deletes a container registry retention rule
func (h *ContainerRegistryServiceHandler) DeleteRetentionRule(ctx context.Context, vcrID string, ruleID int) error {
url := fmt.Sprintf("%s/%s/retention/rules/%d", vcrPath, vcrID, ruleID)
req, err := h.client.NewRequest(ctx, http.MethodDelete, url, nil)
if err != nil {
return err
}
if _, err := h.client.DoWithContext(ctx, req, nil); err != nil {
return err
}
return nil
}
func (h *ContainerRegistryServiceHandler) ListRobots(ctx context.Context, vcrID string, options *ListOptions) ([]ContainerRegistryRobot, *Meta, *http.Response, error) { //nolint:lll,dupl
url := fmt.Sprintf("%s/%s/robots", vcrPath, vcrID)
req, err := h.client.NewRequest(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, nil, err
}
qStrings, err := query.Values(options)
if err != nil {
return nil, nil, nil, err
}
req.URL.RawQuery = qStrings.Encode()
bots := new(containerRegistryRobotsBase)
resp, err := h.client.DoWithContext(ctx, req, &bots)
if err != nil {
return nil, nil, resp, err
}
return bots.Robots, bots.Meta, resp, nil
}
func (h *ContainerRegistryServiceHandler) GetRobot(ctx context.Context, vcrID, robotName string) (*ContainerRegistryRobot, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/robot/%s", vcrPath, vcrID, robotName)
req, err := h.client.NewRequest(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, err
}
bot := new(ContainerRegistryRobot)
resp, err := h.client.DoWithContext(ctx, req, &bot)
if err != nil {
return nil, resp, err
}
return bot, resp, nil
}
func (h *ContainerRegistryServiceHandler) UpdateRobot(ctx context.Context, vcrID, robotName string, updateReq *ContainerRegistryRobotReq) (*ContainerRegistryRobot, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/robot/%s", vcrPath, vcrID, robotName)
req, err := h.client.NewRequest(ctx, http.MethodPut, url, updateReq)
if err != nil {
return nil, nil, err
}
bot := new(ContainerRegistryRobot)
resp, err := h.client.DoWithContext(ctx, req, &bot)
if err != nil {
return nil, resp, err
}
return bot, resp, nil
}
func (h *ContainerRegistryServiceHandler) DeleteRobot(ctx context.Context, vcrID, robotName string) error {
url := fmt.Sprintf("%s/%s/robot/%s", vcrPath, vcrID, robotName)
req, err := h.client.NewRequest(ctx, http.MethodDelete, url, nil)
if err != nil {
return err
}
if _, err := h.client.DoWithContext(ctx, req, nil); err != nil {
return err
}
return nil
}
func (h *ContainerRegistryServiceHandler) ListArtifacts(ctx context.Context, vcrID, imageName string, options *ListOptions) ([]ContainerRegistryArtifact, *Meta, *http.Response, error) { //nolint:lll,dupl
url := fmt.Sprintf("%s/%s/repository/%s/artifacts", vcrPath, vcrID, imageName)
req, err := h.client.NewRequest(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, nil, err
}
qStrings, err := query.Values(options)
if err != nil {
return nil, nil, nil, err
}
req.URL.RawQuery = qStrings.Encode()
artifacts := new(containerRegistryArtifactsBase)
resp, err := h.client.DoWithContext(ctx, req, &artifacts)
if err != nil {
return nil, nil, resp, err
}
return artifacts.Artifacts, artifacts.Meta, resp, nil
}
func (h *ContainerRegistryServiceHandler) GetArtifact(ctx context.Context, vcrID, imageName, artifactDigest string) (*ContainerRegistryArtifact, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/repository/%s/artifact/%s", vcrPath, vcrID, imageName, artifactDigest)
req, err := h.client.NewRequest(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, err
}
artifact := new(ContainerRegistryArtifact)
resp, err := h.client.DoWithContext(ctx, req, &artifact)
if err != nil {
return nil, resp, err
}
return artifact, resp, nil
}
func (h *ContainerRegistryServiceHandler) DeleteArtifact(ctx context.Context, vcrID, imageName, artifactDigest string) error {
url := fmt.Sprintf("%s/%s/repository/%s/artifact/%s", vcrPath, vcrID, imageName, artifactDigest)
req, err := h.client.NewRequest(ctx, http.MethodDelete, url, nil)
if err != nil {
return err
}
if _, err := h.client.DoWithContext(ctx, req, nil); err != nil {
return err
}
return nil
}
// CreateDockerCredentials will create new Docker credentials used by the
// Docker CLI
func (h *ContainerRegistryServiceHandler) CreateDockerCredentials(ctx context.Context, vcrID string, createOptions *DockerCredentialsOpt) (*ContainerRegistryDockerCredentials, *http.Response, error) { //nolint:lll
url := fmt.Sprintf("%s/%s/docker-credentials", vcrPath, vcrID)
req, errReq := h.client.NewRequest(ctx, http.MethodOptions, url, nil)
if errReq != nil {
return nil, nil, errReq
}
queryParam := req.URL.Query()
if createOptions.ExpirySeconds != nil {
queryParam.Add("expiry_seconds", fmt.Sprintf("%d", createOptions.ExpirySeconds))
}
if createOptions.WriteAccess != nil {
queryParam.Add("read_write", fmt.Sprintf("%t", *createOptions.WriteAccess))
}
req.URL.RawQuery = queryParam.Encode()
creds := new(ContainerRegistryDockerCredentials)
resp, errResp := h.client.DoWithContext(ctx, req, &creds)
if errResp != nil {
return nil, nil, errResp
}
return creds, resp, nil
}
// ListRegions will return a list of regions relevant to the container registry
// API operations
func (h *ContainerRegistryServiceHandler) ListRegions(ctx context.Context) ([]ContainerRegistryRegion, *Meta, *http.Response, error) {
req, errReq := h.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/region/list", vcrPath), nil)
if errReq != nil {
return nil, nil, nil, errReq
}
vcrRegions := new(containerRegistryRegions)
resp, errResp := h.client.DoWithContext(ctx, req, &vcrRegions)
if errResp != nil {
return nil, nil, resp, errResp
}
return vcrRegions.Regions, vcrRegions.Meta, resp, nil
}
// ListPlans returns a list of plans relevant to the container registry
// offerings
func (h *ContainerRegistryServiceHandler) ListPlans(ctx context.Context) (*ContainerRegistryPlans, *http.Response, error) {
req, errReq := h.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/plan/list", vcrPath), nil)
if errReq != nil {
return nil, nil, errReq
}
vcrPlans := new(ContainerRegistryPlans)
resp, errResp := h.client.DoWithContext(ctx, req, &vcrPlans)
if errResp != nil {
return nil, resp, errResp
}
return vcrPlans, resp, nil
}