bagage/auth_s3.go

30 lines
702 B
Go
Raw Normal View History

2021-08-23 18:40:03 +00:00
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)
})
}