Merge pull request #4076 from flavianmissi/s3-loglevel

registry: add loglevel support for aws s3 storage driver
This commit is contained in:
Milos Gajdos
2023-10-04 14:13:15 +01:00
committed by GitHub
4 changed files with 40 additions and 3 deletions

View File

@@ -119,6 +119,7 @@ type DriverParameters struct {
SessionToken string
UseDualStack bool
Accelerate bool
LogLevel aws.LogLevelType
}
func init() {
@@ -464,11 +465,39 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
fmt.Sprint(sessionToken),
useDualStackBool,
accelerateBool,
getS3LogLevelFromParam(parameters["loglevel"]),
}
return New(params)
}
func getS3LogLevelFromParam(param interface{}) aws.LogLevelType {
if param == nil {
return aws.LogOff
}
logLevelParam := param.(string)
var logLevel aws.LogLevelType
switch strings.ToLower(logLevelParam) {
case "off":
logLevel = aws.LogOff
case "debug":
logLevel = aws.LogDebug
case "debugwithsigning":
logLevel = aws.LogDebugWithSigning
case "debugwithhttpbody":
logLevel = aws.LogDebugWithHTTPBody
case "debugwithrequestretries":
logLevel = aws.LogDebugWithRequestRetries
case "debugwithrequesterrors":
logLevel = aws.LogDebugWithRequestErrors
case "debugwitheventstreambody":
logLevel = aws.LogDebugWithEventStreamBody
default:
logLevel = aws.LogOff
}
return logLevel
}
// getParameterAsInt64 converts parameters[name] to an int64 value (using
// defaultt if nil), verifies it is no smaller than min, and returns it.
func getParameterAsInt64(parameters map[string]interface{}, name string, defaultt int64, min int64, max int64) (int64, error) {
@@ -507,7 +536,7 @@ func New(params DriverParameters) (*Driver, error) {
return nil, fmt.Errorf("on Amazon S3 this storage driver can only be used with v4 authentication")
}
awsConfig := aws.NewConfig()
awsConfig := aws.NewConfig().WithLogLevel(params.LogLevel)
if params.AccessKey != "" && params.SecretKey != "" {
creds := credentials.NewStaticCredentials(

View File

@@ -21,8 +21,10 @@ import (
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
)
var s3DriverConstructor func(rootDirectory, storageClass string) (*Driver, error)
var skipS3 func() string
var (
s3DriverConstructor func(rootDirectory, storageClass string) (*Driver, error)
skipS3 func() string
)
func init() {
var (
@@ -42,6 +44,7 @@ func init() {
useDualStack = os.Getenv("S3_USE_DUALSTACK")
combineSmallPart = os.Getenv("MULTIPART_COMBINE_SMALL_PART")
accelerate = os.Getenv("S3_ACCELERATE")
logLevel = os.Getenv("S3_LOGLEVEL")
)
root, err := os.MkdirTemp("", "driver-")
@@ -135,6 +138,7 @@ func init() {
sessionToken,
useDualStackBool,
accelerateBool,
getS3LogLevelFromParam(logLevel),
}
return New(parameters)