diff options
Diffstat (limited to 'auth_s3.go')
-rw-r--r-- | auth_s3.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/auth_s3.go b/auth_s3.go new file mode 100644 index 0000000..4bbfe5e --- /dev/null +++ b/auth_s3.go @@ -0,0 +1,29 @@ +package main + +import ( + "net/http" + + "github.com/minio/minio-go/v7" + "github.com/minio/minio-go/v7/pkg/credentials" +) + +/* Check credentials against Minio */ +type S3Auth struct { + WithConfig *Config + OnMinioClient MinioClientHandler + OnFailure ErrorHandler +} + +func (s S3Auth) WithCreds(access_key, secret_key string) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mc, err := minio.New(s.WithConfig.Endpoint, &minio.Options{ + Creds: credentials.NewStaticV4(access_key, secret_key, ""), + Secure: s.WithConfig.UseSSL, + }) + if err != nil { + s.OnFailure.WithError(err).ServeHTTP(w, r) + return + } + s.OnMinioClient.WithMC(mc).ServeHTTP(w, r) + }) +} |