aboutsummaryrefslogtreecommitdiff
path: root/auth_s3.go
diff options
context:
space:
mode:
authorQuentin <quentin@deuxfleurs.fr>2021-08-23 20:40:03 +0200
committerQuentin <quentin@deuxfleurs.fr>2021-08-23 20:40:03 +0200
commit15e4d10fd4b35a2e70cc4fa6ad4117cd5c402cbc (patch)
tree0fe31ac79d5dbe480b1b386845b3dd8fcaa55bd4 /auth_s3.go
parent5d64be33e64eb75160b6fe37b01997de7e96237a (diff)
downloadbagage-15e4d10fd4b35a2e70cc4fa6ad4117cd5c402cbc.tar.gz
bagage-15e4d10fd4b35a2e70cc4fa6ad4117cd5c402cbc.zip
Refactor the codebase
Diffstat (limited to 'auth_s3.go')
-rw-r--r--auth_s3.go29
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)
+ })
+}