Skip to content

Commit

Permalink
feat(bucket): Clean bucket structure and values
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyno-zeta committed Jul 3, 2021
1 parent 258bf2f commit c1b61f5
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 19 deletions.
8 changes: 1 addition & 7 deletions pkg/s3-proxy/bucket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import (
"time"

"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/config"
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/log"
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/metrics"
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/s3client"
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/tracing"
)

// ErrRemovalFolder will be raised when end user is trying to delete a folder and not a file.
Expand Down Expand Up @@ -50,16 +47,13 @@ type PutInput struct {

// NewClient will generate a new client to do GET,PUT or DELETE actions.
func NewClient(
tgt *config.TargetConfig, tplConfig *config.TemplateConfig, logger log.Logger,
tgt *config.TargetConfig,
mountPath string,
metricsCtx metrics.Client,
parentTrace tracing.Trace,
s3clientManager s3client.Manager,
) Client {
return &requestContext{
s3ClientManager: s3clientManager,
targetCfg: tgt,
mountPath: mountPath,
tplConfig: tplConfig,
}
}
1 change: 0 additions & 1 deletion pkg/s3-proxy/bucket/requestContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
type requestContext struct {
s3ClientManager s3client.Manager
targetCfg *config.TargetConfig
tplConfig *config.TemplateConfig
mountPath string
}

Expand Down
11 changes: 1 addition & 10 deletions pkg/s3-proxy/server/middlewares/bucket-request-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import (

"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/bucket"
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/config"
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/log"
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/metrics"
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/s3client"
"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/tracing"
"golang.org/x/net/context"
)

Expand All @@ -23,19 +20,13 @@ var bucketRequestContextKey = &contextKey{name: "bucket-request-context"}

func BucketRequestContext(
tgt *config.TargetConfig,
tplConfig *config.TemplateConfig,
path string,
metricsCli metrics.Client,
s3clientManager s3client.Manager,
) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
// Get logger
logEntry := log.GetLoggerFromContext(req.Context())
// Get request trace
trace := tracing.GetTraceFromContext(req.Context())
// Generate new bucket client
brctx := bucket.NewClient(tgt, tplConfig, logEntry, path, metricsCli, trace, s3clientManager)
brctx := bucket.NewClient(tgt, path, s3clientManager)
// Add bucket structure to request context by creating a new context
ctx := context.WithValue(req.Context(), bucketRequestContextKey, brctx)
// Create new request with new context
Expand Down
2 changes: 1 addition & 1 deletion pkg/s3-proxy/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (svr *Server) generateRouter() (http.Handler, error) {
rt2.Use(responsehandler.HTTPMiddleware(svr.cfgManager, targetKey))

// Add Bucket request context middleware to initialize it
rt2.Use(middlewares.BucketRequestContext(tgt, cfg.Templates, path, svr.metricsCl, svr.s3clientManager))
rt2.Use(middlewares.BucketRequestContext(tgt, path, svr.s3clientManager))

// Add authentication middleware to router
rt2.Use(authenticationSvc.Middleware(tgt.Resources))
Expand Down

0 comments on commit c1b61f5

Please # to comment.