Files
athens/pkg/storage/minio/minio.go
Chris Mills 82ecff968f Correct issue with continuation token failures on deploy (#1415)
* Add working image for minio

Between RELEASE.2019-09-26T19-42-35Z and RELEASE.2019-10-02T21-19-38Z
there's an issue with continuation tokens that's caused #1414 and #1413
to fail.

Signed-off-by: Chris M <me@christophermills.co.uk>

* Undo docker changes, update minio to v6

* Narrow issue down to catalog compliance test

Signed-off-by: Chris M <me@christophermills.co.uk>
2019-10-08 16:54:20 -04:00

56 lines
1.4 KiB
Go

package minio
import (
"fmt"
"time"
"github.com/gomods/athens/pkg/config"
"github.com/gomods/athens/pkg/errors"
"github.com/gomods/athens/pkg/storage"
minio "github.com/minio/minio-go/v6"
)
type storageImpl struct {
minioClient *minio.Client
minioCore *minio.Core
bucketName string
}
func (s *storageImpl) versionLocation(module, version string) string {
return fmt.Sprintf("%s/%s", module, version)
}
// NewStorage returns a connected Minio or DigitalOcean Spaces storage
// that implements storage.Backend
func NewStorage(conf *config.MinioConfig, timeout time.Duration) (storage.Backend, error) {
const op errors.Op = "minio.NewStorage"
endpoint := conf.Endpoint
accessKeyID := conf.Key
secretAccessKey := conf.Secret
bucketName := conf.Bucket
region := conf.Region
useSSL := conf.EnableSSL
minioCore, err := minio.NewCore(endpoint, accessKeyID, secretAccessKey, useSSL)
if err != nil {
return nil, errors.E(op, err)
}
minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
if err != nil {
return nil, errors.E(op, err)
}
err = minioClient.MakeBucket(bucketName, region)
if err != nil {
// Check to see if we already own this bucket
exists, err := minioClient.BucketExists(bucketName)
if err != nil {
return nil, errors.E(op, err)
}
if !exists {
// MakeBucket Error takes priority
return nil, errors.E(op, err)
}
}
return &storageImpl{minioClient, minioCore, bucketName}, nil
}