mirror of
https://github.com/minio/minio.git
synced 2025-04-04 03:40:30 -04:00
improve error message for bucket metadata export/import API (#15120)
This commit is contained in:
parent
761dde2f1b
commit
b3ebc69034
@ -19,7 +19,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
@ -457,16 +456,16 @@ func (a adminAPIHandlers) ExportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
config, err := globalBucketMetadataSys.GetNotificationConfig(bucket)
|
config, err := globalBucketMetadataSys.GetNotificationConfig(bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.LogIf(ctx, err)
|
logger.LogIf(ctx, err)
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
configData, err := xml.Marshal(config)
|
configData, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case bucketLifecycleConfig:
|
case bucketLifecycleConfig:
|
||||||
@ -476,16 +475,16 @@ func (a adminAPIHandlers) ExportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logger.LogIf(ctx, err)
|
logger.LogIf(ctx, err)
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
configData, err := xml.Marshal(config)
|
configData, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case bucketQuotaConfigFile:
|
case bucketQuotaConfigFile:
|
||||||
@ -503,7 +502,7 @@ func (a adminAPIHandlers) ExportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case bucketSSEConfig:
|
case bucketSSEConfig:
|
||||||
@ -512,16 +511,16 @@ func (a adminAPIHandlers) ExportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
if errors.Is(err, BucketSSEConfigNotFound{Bucket: bucket}) {
|
if errors.Is(err, BucketSSEConfigNotFound{Bucket: bucket}) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
configData, err := xml.Marshal(config)
|
configData, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case bucketTaggingConfig:
|
case bucketTaggingConfig:
|
||||||
@ -530,16 +529,16 @@ func (a adminAPIHandlers) ExportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
if errors.Is(err, BucketTaggingNotFound{Bucket: bucket}) {
|
if errors.Is(err, BucketTaggingNotFound{Bucket: bucket}) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
configData, err := xml.Marshal(config)
|
configData, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case objectLockConfig:
|
case objectLockConfig:
|
||||||
@ -548,23 +547,23 @@ func (a adminAPIHandlers) ExportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
if errors.Is(err, BucketObjectLockConfigNotFound{Bucket: bucket}) {
|
if errors.Is(err, BucketObjectLockConfigNotFound{Bucket: bucket}) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
configData, err := xml.Marshal(config)
|
configData, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case bucketVersioningConfig:
|
case bucketVersioningConfig:
|
||||||
config, _, err := globalBucketMetadataSys.GetVersioningConfig(bucket)
|
config, _, err := globalBucketMetadataSys.GetVersioningConfig(bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// ignore empty versioning configs
|
// ignore empty versioning configs
|
||||||
@ -573,11 +572,11 @@ func (a adminAPIHandlers) ExportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
}
|
}
|
||||||
configData, err := xml.Marshal(config)
|
configData, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case bucketReplicationConfig:
|
case bucketReplicationConfig:
|
||||||
@ -586,17 +585,17 @@ func (a adminAPIHandlers) ExportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
if errors.Is(err, BucketReplicationConfigNotFound{Bucket: bucket}) {
|
if errors.Is(err, BucketReplicationConfigNotFound{Bucket: bucket}) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
configData, err := xml.Marshal(config)
|
configData, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case bucketTargetsFile:
|
case bucketTargetsFile:
|
||||||
@ -611,11 +610,11 @@ func (a adminAPIHandlers) ExportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
}
|
}
|
||||||
configData, err := xml.Marshal(config)
|
configData, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
if err = rawDataFn(bytes.NewReader(configData), cfgPath, len(configData)); err != nil {
|
||||||
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile), r.URL)
|
writeErrorResponse(ctx, w, exportError(ctx, err, cfgFile, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -672,7 +671,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
case objectLockConfig:
|
case objectLockConfig:
|
||||||
reader, err := file.Open()
|
reader, err := file.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
config, err := objectlock.ParseObjectLockConfig(reader)
|
config, err := objectlock.ParseObjectLockConfig(reader)
|
||||||
@ -685,7 +684,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
|
|
||||||
configData, err := xml.Marshal(config)
|
configData, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, ok := bucketMap[bucket]; !ok {
|
if _, ok := bucketMap[bucket]; !ok {
|
||||||
@ -695,7 +694,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
err = objectAPI.MakeBucketWithLocation(ctx, bucket, opts)
|
err = objectAPI.MakeBucketWithLocation(ctx, bucket, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(BucketExists); !ok {
|
if _, ok := err.(BucketExists); !ok {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -704,12 +703,12 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
|
|
||||||
// Deny object locking configuration settings on existing buckets without object lock enabled.
|
// Deny object locking configuration settings on existing buckets without object lock enabled.
|
||||||
if _, _, err = globalBucketMetadataSys.GetObjectLockConfig(bucket); err != nil {
|
if _, _, err = globalBucketMetadataSys.GetObjectLockConfig(bucket); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = globalBucketMetadataSys.Update(ctx, bucket, objectLockConfig, configData); err != nil {
|
if err = globalBucketMetadataSys.Update(ctx, bucket, objectLockConfig, configData); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,7 +722,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
ObjectLockConfig: &cfgStr,
|
ObjectLockConfig: &cfgStr,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -744,19 +743,19 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
case bucketVersioningConfig:
|
case bucketVersioningConfig:
|
||||||
reader, err := file.Open()
|
reader, err := file.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v, err := versioning.ParseConfig(io.LimitReader(reader, maxBucketVersioningConfigSize))
|
v, err := versioning.ParseConfig(io.LimitReader(reader, maxBucketVersioningConfigSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, ok := bucketMap[bucket]; !ok {
|
if _, ok := bucketMap[bucket]; !ok {
|
||||||
err = objectAPI.MakeBucketWithLocation(ctx, bucket, BucketOptions{})
|
err = objectAPI.MakeBucketWithLocation(ctx, bucket, BucketOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(BucketExists); !ok {
|
if _, ok := err.(BucketExists); !ok {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -791,12 +790,12 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
|
|
||||||
configData, err := xml.Marshal(v)
|
configData, err := xml.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketVersioningConfig, configData); err != nil {
|
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketVersioningConfig, configData); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -805,7 +804,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
for _, file := range zr.File {
|
for _, file := range zr.File {
|
||||||
reader, err := file.Open()
|
reader, err := file.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sz := file.FileInfo().Size()
|
sz := file.FileInfo().Size()
|
||||||
@ -823,7 +822,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
err = objectAPI.MakeBucketWithLocation(ctx, bucket, BucketOptions{})
|
err = objectAPI.MakeBucketWithLocation(ctx, bucket, BucketOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(BucketExists); !ok {
|
if _, ok := err.(BucketExists); !ok {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -835,7 +834,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
apiErr := errorCodes.ToAPIErr(ErrMalformedXML)
|
apiErr := errorCodes.ToAPIErr(ErrMalformedXML)
|
||||||
if event.IsEventError(err) {
|
if event.IsEventError(err) {
|
||||||
apiErr = importError(ctx, err, file.Name)
|
apiErr = importError(ctx, err, file.Name, bucket)
|
||||||
}
|
}
|
||||||
writeErrorResponse(ctx, w, apiErr, r.URL)
|
writeErrorResponse(ctx, w, apiErr, r.URL)
|
||||||
return
|
return
|
||||||
@ -843,12 +842,12 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
|
|
||||||
configData, err := xml.Marshal(config)
|
configData, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketNotificationConfig, configData); err != nil {
|
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketNotificationConfig, configData); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rulesMap := config.ToRulesMap()
|
rulesMap := config.ToRulesMap()
|
||||||
@ -862,13 +861,13 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
|
|
||||||
bucketPolicyBytes, err := ioutil.ReadAll(io.LimitReader(reader, sz))
|
bucketPolicyBytes, err := ioutil.ReadAll(io.LimitReader(reader, sz))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
bucketPolicy, err := policy.ParseConfig(bytes.NewReader(bucketPolicyBytes), bucket)
|
bucketPolicy, err := policy.ParseConfig(bytes.NewReader(bucketPolicyBytes), bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -880,12 +879,12 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
|
|
||||||
configData, err := json.Marshal(bucketPolicy)
|
configData, err := json.Marshal(bucketPolicy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketPolicyConfig, configData); err != nil {
|
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketPolicyConfig, configData); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Call site replication hook.
|
// Call site replication hook.
|
||||||
@ -894,37 +893,37 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
Policy: bucketPolicyBytes,
|
Policy: bucketPolicyBytes,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
case bucketLifecycleConfig:
|
case bucketLifecycleConfig:
|
||||||
bucketLifecycle, err := lifecycle.ParseLifecycleConfig(io.LimitReader(reader, sz))
|
bucketLifecycle, err := lifecycle.ParseLifecycleConfig(io.LimitReader(reader, sz))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the received bucket policy document
|
// Validate the received bucket policy document
|
||||||
if err = bucketLifecycle.Validate(); err != nil {
|
if err = bucketLifecycle.Validate(); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the transition storage ARNs
|
// Validate the transition storage ARNs
|
||||||
if err = validateTransitionTier(bucketLifecycle); err != nil {
|
if err = validateTransitionTier(bucketLifecycle); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
configData, err := xml.Marshal(bucketLifecycle)
|
configData, err := xml.Marshal(bucketLifecycle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketLifecycleConfig, configData); err != nil {
|
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketLifecycleConfig, configData); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case bucketSSEConfig:
|
case bucketSSEConfig:
|
||||||
@ -951,23 +950,23 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
_, err := GlobalKMS.GenerateKey(kmsKey, kmsContext)
|
_, err := GlobalKMS.GenerateKey(kmsKey, kmsContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, kes.ErrKeyNotFound) {
|
if errors.Is(err, kes.ErrKeyNotFound) {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, errKMSKeyNotFound, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, errKMSKeyNotFound, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configData, err := xml.Marshal(encConfig)
|
configData, err := xml.Marshal(encConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the bucket encryption configuration in the object layer
|
// Store the bucket encryption configuration in the object layer
|
||||||
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketSSEConfig, configData); err != nil {
|
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketSSEConfig, configData); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -981,7 +980,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
SSEConfig: &cfgStr,
|
SSEConfig: &cfgStr,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -995,12 +994,12 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
|
|
||||||
configData, err := xml.Marshal(tags)
|
configData, err := xml.Marshal(tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketTaggingConfig, configData); err != nil {
|
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketTaggingConfig, configData); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Call site replication hook.
|
// Call site replication hook.
|
||||||
@ -1013,7 +1012,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
Tags: &cfgStr,
|
Tags: &cfgStr,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case bucketQuotaConfigFile:
|
case bucketQuotaConfigFile:
|
||||||
@ -1025,7 +1024,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
|
|
||||||
quotaConfig, err := parseBucketQuota(bucket, data)
|
quotaConfig, err := parseBucketQuota(bucket, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1035,7 +1034,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketQuotaConfigFile, data); err != nil {
|
if err = globalBucketMetadataSys.Update(ctx, bucket, bucketQuotaConfigFile, data); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1050,19 +1049,9 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r *
|
|||||||
|
|
||||||
// Call site replication hook.
|
// Call site replication hook.
|
||||||
if err = globalSiteReplicationSys.BucketMetaHook(ctx, bucketMeta); err != nil {
|
if err = globalSiteReplicationSys.BucketMetaHook(ctx, bucketMeta); err != nil {
|
||||||
writeErrorResponse(ctx, w, importError(ctx, err, file.Name), r.URL)
|
writeErrorResponse(ctx, w, importError(ctx, err, file.Name, bucket), r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wraps import error for more context
|
|
||||||
func importError(ctx context.Context, err error, fname string) APIError {
|
|
||||||
return toAPIError(ctx, fmt.Errorf("error importing %s with %w", fname, err))
|
|
||||||
}
|
|
||||||
|
|
||||||
// wraps export error for more context
|
|
||||||
func exportError(ctx context.Context, err error, fname string) APIError {
|
|
||||||
return toAPIError(ctx, fmt.Errorf("error exporting %s with %w", fname, err))
|
|
||||||
}
|
|
||||||
|
@ -20,6 +20,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/minio/kes"
|
"github.com/minio/kes"
|
||||||
@ -223,3 +224,19 @@ func toAdminAPIErrCode(ctx context.Context, err error) APIErrorCode {
|
|||||||
return toAPIErrorCode(ctx, err)
|
return toAPIErrorCode(ctx, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wraps export error for more context
|
||||||
|
func exportError(ctx context.Context, err error, fname, entity string) APIError {
|
||||||
|
if entity == "" {
|
||||||
|
return toAPIError(ctx, fmt.Errorf("error exporting %s with: %w", fname, err))
|
||||||
|
}
|
||||||
|
return toAPIError(ctx, fmt.Errorf("error exporting %s from %s with: %w", entity, fname, err))
|
||||||
|
}
|
||||||
|
|
||||||
|
// wraps import error for more context
|
||||||
|
func importError(ctx context.Context, err error, fname, entity string) APIError {
|
||||||
|
if entity == "" {
|
||||||
|
return toAPIError(ctx, fmt.Errorf("error importing %s with: %w", fname, err))
|
||||||
|
}
|
||||||
|
return toAPIError(ctx, fmt.Errorf("error importing %s from %s with: %w", entity, fname, err))
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user