This feature allows you to specify the n latest backups to keep in the bucket.
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package helpers
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"github.com/minio/minio-go/v7"
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
"os"
|
|
)
|
|
|
|
func GetCredentials() (string, string, error) {
|
|
// get credentials from env vars
|
|
keyName := os.Getenv("KEY_ID")
|
|
if keyName == "" {
|
|
return "", "", errors.New("missing or empty KEY_ID")
|
|
}
|
|
applicationKey := os.Getenv("APPLICATION_KEY")
|
|
if applicationKey == "" {
|
|
return "", "", errors.New("missing or empty APPLICATION_KEY")
|
|
}
|
|
return keyName, applicationKey, nil
|
|
}
|
|
|
|
func CreateClient(accessKeyID, secretAccessKey, endpoint string) (*minio.Client, error) {
|
|
// Initialize minio client object.
|
|
minioClient, err := minio.New(endpoint, &minio.Options{
|
|
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
|
|
Secure: true,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return minioClient, nil
|
|
}
|
|
|
|
func VerifyBucket(client *minio.Client, ctx context.Context, bucketName string) error {
|
|
exists, err := client.BucketExists(ctx, bucketName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if !exists {
|
|
return errors.New(fmt.Sprintf("bucket %s does not exist\n", bucketName))
|
|
}
|
|
|
|
return nil
|
|
}
|