mirror of
https://github.com/minio/minio.git
synced 2025-12-08 16:53:11 -05:00
feat: Add ListBucketsWithMetadata extension API (#13219)
This commit is contained in:
@@ -306,6 +306,8 @@ func (api objectAPIHandlers) ListBucketsHandler(w http.ResponseWriter, r *http.R
|
||||
return
|
||||
}
|
||||
|
||||
metadata := r.Form.Get("metadata") == "true"
|
||||
|
||||
// If etcd, dns federation configured list buckets from etcd.
|
||||
var bucketsInfo []BucketInfo
|
||||
if globalDNSConfig != nil && globalBucketFederation {
|
||||
@@ -370,6 +372,49 @@ func (api objectAPIHandlers) ListBucketsHandler(w http.ResponseWriter, r *http.R
|
||||
}
|
||||
}
|
||||
|
||||
if metadata && !globalIsGateway {
|
||||
usageInfo, err := loadDataUsageFromBackend(ctx, objectAPI)
|
||||
if err != nil {
|
||||
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL)
|
||||
return
|
||||
}
|
||||
for i, bucket := range bucketsInfo {
|
||||
if bu, ok := usageInfo.BucketsUsage[bucket.Name]; ok {
|
||||
bucketsInfo[i].Usage = &BucketUsageInfo{
|
||||
Size: bu.Size,
|
||||
ObjectsCount: bu.ObjectsCount,
|
||||
ObjectSizesHistogram: StringMap{},
|
||||
}
|
||||
for k, v := range bu.ObjectSizesHistogram {
|
||||
bucketsInfo[i].Usage.ObjectSizesHistogram[k] = fmt.Sprint(v)
|
||||
}
|
||||
} else {
|
||||
bucketsInfo[i].Usage = &BucketUsageInfo{
|
||||
ObjectSizesHistogram: StringMap{},
|
||||
}
|
||||
}
|
||||
lcfg, _ := globalBucketObjectLockSys.Get(bucket.Name)
|
||||
quota, _ := globalBucketQuotaSys.Get(bucket.Name)
|
||||
var bquota *BucketQuotaConfig
|
||||
if quota != nil {
|
||||
bquota = &BucketQuotaConfig{
|
||||
Quota: quota.Quota,
|
||||
Type: quota.Type,
|
||||
}
|
||||
}
|
||||
rcfg, _ := globalBucketMetadataSys.GetReplicationConfig(ctx, bucket.Name)
|
||||
tcfg, _ := globalBucketMetadataSys.GetTaggingConfig(bucket.Name)
|
||||
bucketsInfo[i].Details = &BucketDetailsInfo{
|
||||
Versioning: globalBucketVersioningSys.Enabled(bucket.Name),
|
||||
VersioningSuspended: globalBucketVersioningSys.Suspended(bucket.Name),
|
||||
Replication: rcfg != nil,
|
||||
Locking: lcfg.LockEnabled,
|
||||
Quota: bquota,
|
||||
Tagging: tcfg,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate response.
|
||||
response := generateListBucketsResponse(bucketsInfo)
|
||||
encodedSuccessResponse := encodeResponse(response)
|
||||
|
||||
Reference in New Issue
Block a user