11package registry
22
33import (
4- "context"
5- "errors"
6- "github.com/aws/aws-sdk-go-v2/aws"
7- awsConfig "github.com/aws/aws-sdk-go-v2/config"
4+ "github.com/google/uuid"
85 "io/ioutil"
96 "os"
107 "path/filepath"
11- "strings"
12- "time"
13-
14- "github.com/aws/aws-sdk-go-v2/service/s3"
15- "github.com/google/uuid"
168
179 "google.golang.org/protobuf/proto"
1810 "google.golang.org/protobuf/types/known/timestamppb"
@@ -25,12 +17,6 @@ type FileRegistryStore struct {
2517 filePath string
2618}
2719
28- // A S3RegistryStore is a S3 object storage-based implementation of the RegistryStore interface
29- type S3RegistryStore struct {
30- filePath string
31- s3Client * s3.Client
32- }
33-
3420// NewFileRegistryStore creates a FileRegistryStore with the given configuration and infers
3521// the file path from the repo path and registry path.
3622func NewFileRegistryStore (config * RegistryConfig , repoPath string ) * FileRegistryStore {
@@ -44,26 +30,6 @@ func NewFileRegistryStore(config *RegistryConfig, repoPath string) *FileRegistry
4430 return & lr
4531}
4632
47- // NewS3RegistryStore creates a S3RegistryStore with the given configuration
48- func NewS3RegistryStore (config * RegistryConfig , repoPath string ) * S3RegistryStore {
49- var lr S3RegistryStore
50- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
51- defer cancel ()
52-
53- cfg , err := awsConfig .LoadDefaultConfig (ctx )
54- if err != nil {
55- lr = S3RegistryStore {
56- filePath : config .Path ,
57- }
58- } else {
59- lr = S3RegistryStore {
60- filePath : config .Path ,
61- s3Client : s3 .NewFromConfig (cfg ),
62- }
63- }
64- return & lr
65- }
66-
6733// GetRegistryProto reads and parses the registry proto from the file path.
6834func (r * FileRegistryStore ) GetRegistryProto () (* core.Registry , error ) {
6935 registry := & core.Registry {}
@@ -98,64 +64,3 @@ func (r *FileRegistryStore) writeRegistry(rp *core.Registry) error {
9864 }
9965 return nil
10066}
101-
102- func (r * S3RegistryStore ) GetRegistryProto () (* core.Registry , error ) {
103- bucket , key , err := r .parseS3Path ()
104- if err != nil {
105- return nil , err
106- }
107-
108- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
109- defer cancel ()
110- output , err := r .s3Client .GetObject (ctx ,
111- & s3.GetObjectInput {
112- Bucket : aws .String (bucket ),
113- Key : aws .String (key ),
114- })
115- if err != nil {
116- return nil , err
117- }
118- defer output .Body .Close ()
119-
120- data , err := ioutil .ReadAll (output .Body )
121- if err != nil {
122- return nil , err
123- }
124-
125- registry := & core.Registry {}
126- if err := proto .Unmarshal (data , registry ); err != nil {
127- return nil , err
128- }
129- return registry , nil
130- }
131-
132- func (r * S3RegistryStore ) UpdateRegistryProto (rp * core.Registry ) error {
133- return errors .New ("not implemented in S3RegistryStore" )
134- }
135-
136- func (r * S3RegistryStore ) Teardown () error {
137- bucket , key , err := r .parseS3Path ()
138- if err != nil {
139- return err
140- }
141- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
142- defer cancel ()
143- _ , err = r .s3Client .DeleteObject (ctx ,
144- & s3.DeleteObjectInput {
145- Bucket : aws .String (bucket ),
146- Key : aws .String (key ),
147- })
148- if err != nil {
149- return err
150- }
151- return nil
152- }
153-
154- func (r * S3RegistryStore ) parseS3Path () (string , string , error ) {
155- path := strings .TrimPrefix (r .filePath , "s3://" )
156- parts := strings .SplitN (path , "/" , 2 )
157- if len (parts ) != 2 {
158- return "" , "" , errors .New ("invalid S3 file path format" )
159- }
160- return parts [0 ], parts [1 ], nil
161- }
0 commit comments