mirror of
https://github.com/minio/minio.git
synced 2025-04-05 12:20:34 -04:00
fix: translate tier add errors properly (#16191)
This commit is contained in:
parent
3eb2d086b2
commit
4bc367c490
@ -210,24 +210,6 @@ func toAdminAPIErr(ctx context.Context, err error) APIError {
|
|||||||
Description: err.Error(),
|
Description: err.Error(),
|
||||||
HTTPStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
}
|
}
|
||||||
case errors.Is(err, errTierBackendInUse):
|
|
||||||
apiErr = APIError{
|
|
||||||
Code: "XMinioAdminTierBackendInUse",
|
|
||||||
Description: err.Error(),
|
|
||||||
HTTPStatusCode: http.StatusBadRequest,
|
|
||||||
}
|
|
||||||
case errors.Is(err, errTierBackendNotEmpty):
|
|
||||||
apiErr = APIError{
|
|
||||||
Code: "XMinioAdminTierBackendNotEmpty",
|
|
||||||
Description: err.Error(),
|
|
||||||
HTTPStatusCode: http.StatusBadRequest,
|
|
||||||
}
|
|
||||||
case errors.Is(err, errTierInsufficientCreds):
|
|
||||||
apiErr = APIError{
|
|
||||||
Code: "XMinioAdminTierInsufficientCreds",
|
|
||||||
Description: err.Error(),
|
|
||||||
HTTPStatusCode: http.StatusBadRequest,
|
|
||||||
}
|
|
||||||
case errIsTierPermError(err):
|
case errIsTierPermError(err):
|
||||||
apiErr = APIError{
|
apiErr = APIError{
|
||||||
Code: "XMinioAdminTierInsufficientPermissions",
|
Code: "XMinioAdminTierInsufficientPermissions",
|
||||||
|
@ -100,6 +100,7 @@ func (api adminAPIHandlers) AddTierHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, errTierReservedName), r.URL)
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, errTierReservedName), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh from the disk in case we had missed notifications about edits from peers.
|
// Refresh from the disk in case we had missed notifications about edits from peers.
|
||||||
if err := globalTierConfigMgr.Reload(ctx, objAPI); err != nil {
|
if err := globalTierConfigMgr.Reload(ctx, objAPI); err != nil {
|
||||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||||
|
37
cmd/tier.go
37
cmd/tier.go
@ -22,8 +22,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -37,10 +37,29 @@ import (
|
|||||||
//go:generate msgp -file $GOFILE
|
//go:generate msgp -file $GOFILE
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errTierInsufficientCreds = errors.New("insufficient tier credentials supplied")
|
errTierMissingCredentials = AdminError{
|
||||||
errTierBackendInUse = errors.New("remote tier backend already in use")
|
Code: "XMinioAdminTierMissingCredentials",
|
||||||
errTierTypeUnsupported = errors.New("unsupported tier type")
|
Message: "Specified remote credentials are empty",
|
||||||
errTierBackendNotEmpty = errors.New("remote tier not empty")
|
StatusCode: http.StatusForbidden,
|
||||||
|
}
|
||||||
|
|
||||||
|
errTierBackendInUse = AdminError{
|
||||||
|
Code: "XMinioAdminTierBackendInUse",
|
||||||
|
Message: "Specified remote tier is already in use",
|
||||||
|
StatusCode: http.StatusConflict,
|
||||||
|
}
|
||||||
|
|
||||||
|
errTierTypeUnsupported = AdminError{
|
||||||
|
Code: "XMinioAdminTierTypeUnsupported",
|
||||||
|
Message: "Specified tier type is unsupported",
|
||||||
|
StatusCode: http.StatusBadRequest,
|
||||||
|
}
|
||||||
|
|
||||||
|
errTierBackendNotEmpty = AdminError{
|
||||||
|
Code: "XMinioAdminTierBackendNotEmpty",
|
||||||
|
Message: "Specified remote backend is not empty",
|
||||||
|
StatusCode: http.StatusBadRequest,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -185,7 +204,7 @@ func (config *TierConfigMgr) Edit(ctx context.Context, tierName string, creds ma
|
|||||||
switch tierType {
|
switch tierType {
|
||||||
case madmin.S3:
|
case madmin.S3:
|
||||||
if (creds.AccessKey == "" || creds.SecretKey == "") && !creds.AWSRole {
|
if (creds.AccessKey == "" || creds.SecretKey == "") && !creds.AWSRole {
|
||||||
return errTierInsufficientCreds
|
return errTierMissingCredentials
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case creds.AWSRole:
|
case creds.AWSRole:
|
||||||
@ -196,18 +215,18 @@ func (config *TierConfigMgr) Edit(ctx context.Context, tierName string, creds ma
|
|||||||
}
|
}
|
||||||
case madmin.Azure:
|
case madmin.Azure:
|
||||||
if creds.SecretKey == "" {
|
if creds.SecretKey == "" {
|
||||||
return errTierInsufficientCreds
|
return errTierMissingCredentials
|
||||||
}
|
}
|
||||||
cfg.Azure.AccountKey = creds.SecretKey
|
cfg.Azure.AccountKey = creds.SecretKey
|
||||||
|
|
||||||
case madmin.GCS:
|
case madmin.GCS:
|
||||||
if creds.CredsJSON == nil {
|
if creds.CredsJSON == nil {
|
||||||
return errTierInsufficientCreds
|
return errTierMissingCredentials
|
||||||
}
|
}
|
||||||
cfg.GCS.Creds = base64.URLEncoding.EncodeToString(creds.CredsJSON)
|
cfg.GCS.Creds = base64.URLEncoding.EncodeToString(creds.CredsJSON)
|
||||||
case madmin.MinIO:
|
case madmin.MinIO:
|
||||||
if creds.AccessKey == "" || creds.SecretKey == "" {
|
if creds.AccessKey == "" || creds.SecretKey == "" {
|
||||||
return errTierInsufficientCreds
|
return errTierMissingCredentials
|
||||||
}
|
}
|
||||||
cfg.MinIO.AccessKey = creds.AccessKey
|
cfg.MinIO.AccessKey = creds.AccessKey
|
||||||
cfg.MinIO.SecretKey = creds.SecretKey
|
cfg.MinIO.SecretKey = creds.SecretKey
|
||||||
|
Loading…
x
Reference in New Issue
Block a user