mirror of
https://github.com/distribution/distribution.git
synced 2025-08-21 16:24:00 +00:00
s3: accept S3 parameter
This commit is contained in:
parent
03ff763453
commit
aabf07ec65
@ -84,6 +84,10 @@ var validObjectACLs = map[string]struct{}{}
|
|||||||
|
|
||||||
//DriverParameters A struct that encapsulates all of the driver parameters after all values have been set
|
//DriverParameters A struct that encapsulates all of the driver parameters after all values have been set
|
||||||
type DriverParameters struct {
|
type DriverParameters struct {
|
||||||
|
// S3 is an optional parameter. If specified, it will use the existing session
|
||||||
|
// to construct the Driver.
|
||||||
|
S3 *s3.S3
|
||||||
|
|
||||||
AccessKey string
|
AccessKey string
|
||||||
SecretKey string
|
SecretKey string
|
||||||
Bucket string
|
Bucket string
|
||||||
@ -342,6 +346,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
|
|||||||
sessionToken := ""
|
sessionToken := ""
|
||||||
|
|
||||||
params := DriverParameters{
|
params := DriverParameters{
|
||||||
|
nil,
|
||||||
fmt.Sprint(accessKey),
|
fmt.Sprint(accessKey),
|
||||||
fmt.Sprint(secretKey),
|
fmt.Sprint(secretKey),
|
||||||
fmt.Sprint(bucket),
|
fmt.Sprint(bucket),
|
||||||
@ -398,6 +403,8 @@ func getParameterAsInt64(parameters map[string]interface{}, name string, default
|
|||||||
// New constructs a new Driver with the given AWS credentials, region, encryption flag, and
|
// New constructs a new Driver with the given AWS credentials, region, encryption flag, and
|
||||||
// bucketName
|
// bucketName
|
||||||
func New(params DriverParameters) (*Driver, error) {
|
func New(params DriverParameters) (*Driver, error) {
|
||||||
|
s3obj := params.S3
|
||||||
|
if s3obj == nil {
|
||||||
if !params.V4Auth &&
|
if !params.V4Auth &&
|
||||||
(params.RegionEndpoint == "" ||
|
(params.RegionEndpoint == "" ||
|
||||||
strings.Contains(params.RegionEndpoint, "s3.amazonaws.com")) {
|
strings.Contains(params.RegionEndpoint, "s3.amazonaws.com")) {
|
||||||
@ -453,12 +460,13 @@ func New(params DriverParameters) (*Driver, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create new session with aws config: %v", err)
|
return nil, fmt.Errorf("failed to create new session with aws config: %v", err)
|
||||||
}
|
}
|
||||||
s3obj := s3.New(sess)
|
s3obj = s3.New(sess)
|
||||||
|
|
||||||
// enable S3 compatible signature v2 signing instead
|
// enable S3 compatible signature v2 signing instead
|
||||||
if !params.V4Auth {
|
if !params.V4Auth {
|
||||||
setv2Handlers(s3obj)
|
setv2Handlers(s3obj)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO Currently multipart uploads have no timestamps, so this would be unwise
|
// TODO Currently multipart uploads have no timestamps, so this would be unwise
|
||||||
// if you initiated a new s3driver while another one is running on the same bucket.
|
// if you initiated a new s3driver while another one is running on the same bucket.
|
||||||
|
@ -77,6 +77,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parameters := DriverParameters{
|
parameters := DriverParameters{
|
||||||
|
nil,
|
||||||
accessKey,
|
accessKey,
|
||||||
secretKey,
|
secretKey,
|
||||||
bucket,
|
bucket,
|
||||||
|
Loading…
Reference in New Issue
Block a user