@@ -6,10 +6,11 @@ import (
66 "fmt"
77 "io"
88 "io/fs"
9- "os"
109 "net/http"
10+ "os"
1111 "strconv"
1212 "strings"
13+
1314 "github.com/aws/aws-sdk-go/aws"
1415 "github.com/aws/aws-sdk-go/aws/credentials"
1516 "github.com/aws/aws-sdk-go/aws/session"
@@ -21,14 +22,22 @@ type FileUploader interface {
2122 UploadFile (src , dst string , meta * MetaData ) error
2223}
2324
25+ // NOTE(sean) Not a big deal but we can probably just use the FileUploader as the primary abstraction
26+ // rather than introducing UploaderConfig. The details of the config can be tracked as part of the
27+ // specific FileUploader internals.
28+ //
29+ // As an example, a FileUploader which simply logs that UploadFile would have been called and does
30+ // nothing else probably doesn't really need to know about endpoints or buckets.
31+ //
32+ // I'll leave this as a simple item to clean up when we have some free cycles.
2433type UploaderConfig interface {
2534 GetEndpoint () string
2635 GetBucket () string
2736}
2837
2938type PelicanFileUploaderConfig struct {
30- Endpoint string
31- Bucket string
39+ Endpoint string
40+ Bucket string
3241}
3342
3443type S3FileUploaderConfig struct {
@@ -45,9 +54,9 @@ type s3FileUploader struct {
4554}
4655
4756type pelicanFileUploader struct {
48- config PelicanFileUploaderConfig
49- client http.Client
50- jm JwtManager
57+ config PelicanFileUploaderConfig
58+ client http.Client
59+ jm JwtManager
5160}
5261
5362// GetEndpoint returns the endpoint for S3.
@@ -90,12 +99,12 @@ func NewS3FileUploader(config S3FileUploaderConfig) (*s3FileUploader, error) {
9099 }, nil
91100}
92101
93- //Initialize a new file uploader for Pelican by passing in a config, an initliaze JwtManager, and public key's id
102+ // Initialize a new file uploader for Pelican by passing in a config, an initliaze JwtManager, and public key's id
94103func NewPelicanFileUploader (config PelicanFileUploaderConfig , jm JwtManager ) (* pelicanFileUploader , error ) {
95104 return & pelicanFileUploader {
96- config : config ,
97- client : http.Client {},
98- jm : jm ,
105+ config : config ,
106+ client : http.Client {},
107+ jm : jm ,
99108 }, nil
100109}
101110
@@ -153,14 +162,18 @@ func (up *pelicanFileUploader) UploadFile(src, dst string, meta *MetaData) error
153162
154163 //Upload the file to Pelican
155164 req , err := http .NewRequest ("PUT" , fmt .Sprintf ("%s/%s/%s" , up .config .Endpoint , up .config .Bucket , dst ), f )
156- if err != nil {return err }
165+ if err != nil {
166+ return err
167+ }
157168 req .Header .Set ("Authorization" , "Bearer " + string (up .jm .SignedJwtToken ))
158169 resp , err := up .client .Do (req )
159- if err != nil {return err }
170+ if err != nil {
171+ return err
172+ }
160173 defer resp .Body .Close ()
161174
162175 // Check response status
163- if resp .StatusCode == http .StatusForbidden {
176+ if resp .StatusCode == http .StatusForbidden {
164177 // JWT token expired, regenerate it
165178 token , err := up .jm .generateJwtToken (& up .jm .PublicKeyID )
166179 if err != nil {
@@ -169,7 +182,7 @@ func (up *pelicanFileUploader) UploadFile(src, dst string, meta *MetaData) error
169182 up .jm .SignedJwtToken = token
170183
171184 // retry uploading file
172- err = up .UploadFile (src ,dst ,meta )
185+ err = up .UploadFile (src , dst , meta )
173186 if err != nil {
174187 return err
175188 }
@@ -180,7 +193,7 @@ func (up *pelicanFileUploader) UploadFile(src, dst string, meta *MetaData) error
180193 return fmt .Errorf ("error reading response body: %v" , err )
181194 }
182195 return fmt .Errorf ("pelican uploader failed, non-OK HTTP status: %v \n response body: %s" , resp .Status , body )
183- }
196+ }
184197
185198 uploadFileMetrics (stat , meta )
186199
0 commit comments