Enable Bucket Quota on Bucket Details (#776)
* Enable Bucket Quota on Bucket Details Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> * warnings Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> * remove uselss br Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
This commit is contained in:
@@ -311,6 +311,10 @@ func (ac adminClient) setBucketQuota(ctx context.Context, bucket string, quota *
|
||||
return ac.client.SetBucketQuota(ctx, bucket, quota)
|
||||
}
|
||||
|
||||
func (ac adminClient) getBucketQuota(ctx context.Context, bucket string) (madmin.BucketQuota, error) {
|
||||
return ac.client.GetBucketQuota(ctx, bucket)
|
||||
}
|
||||
|
||||
// serverHealthInfo implements mc.ServerHealthInfo - Connect to a minio server and call Health Info Management API
|
||||
func (ac adminClient) serverHealthInfo(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) <-chan madmin.HealthInfo {
|
||||
return ac.client.ServerHealthInfo(ctx, healthDataTypes, deadline)
|
||||
|
||||
@@ -1586,7 +1586,7 @@ func init() {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/listObjectsResponse"
|
||||
"$ref": "#/definitions/bucketQuota"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
@@ -4264,6 +4264,21 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"bucketQuota": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"quota": {
|
||||
"type": "integer"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"hard",
|
||||
"fifo"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"bucketReplicationDestination": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -8714,7 +8729,7 @@ func init() {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/listObjectsResponse"
|
||||
"$ref": "#/definitions/bucketQuota"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
@@ -12032,6 +12047,21 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"bucketQuota": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"quota": {
|
||||
"type": "integer"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"hard",
|
||||
"fifo"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"bucketReplicationDestination": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -42,7 +42,7 @@ type GetBucketQuotaOK struct {
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.ListObjectsResponse `json:"body,omitempty"`
|
||||
Payload *models.BucketQuota `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewGetBucketQuotaOK creates GetBucketQuotaOK with default headers values
|
||||
@@ -52,13 +52,13 @@ func NewGetBucketQuotaOK() *GetBucketQuotaOK {
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the get bucket quota o k response
|
||||
func (o *GetBucketQuotaOK) WithPayload(payload *models.ListObjectsResponse) *GetBucketQuotaOK {
|
||||
func (o *GetBucketQuotaOK) WithPayload(payload *models.BucketQuota) *GetBucketQuotaOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the get bucket quota o k response
|
||||
func (o *GetBucketQuotaOK) SetPayload(payload *models.ListObjectsResponse) {
|
||||
func (o *GetBucketQuotaOK) SetPayload(payload *models.BucketQuota) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,15 @@ func registerBucketQuotaHandlers(api *operations.ConsoleAPI) {
|
||||
}
|
||||
return user_api.NewSetBucketQuotaOK()
|
||||
})
|
||||
|
||||
// get bucket quota
|
||||
api.UserAPIGetBucketQuotaHandler = user_api.GetBucketQuotaHandlerFunc(func(params user_api.GetBucketQuotaParams, session *models.Principal) middleware.Responder {
|
||||
resp, err := getBucketQuotaResponse(session, params)
|
||||
if err != nil {
|
||||
return user_api.NewGetBucketQuotaDefault(int(err.Code)).WithPayload(err)
|
||||
}
|
||||
return user_api.NewGetBucketQuotaOK().WithPayload(resp)
|
||||
})
|
||||
}
|
||||
|
||||
func setBucketQuotaResponse(session *models.Principal, params user_api.SetBucketQuotaParams) *models.Error {
|
||||
@@ -85,3 +94,34 @@ func setBucketQuota(ctx context.Context, ac *adminClient, bucket *string, bucket
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getBucketQuotaResponse(session *models.Principal, params user_api.GetBucketQuotaParams) (*models.BucketQuota, *models.Error) {
|
||||
mAdmin, err := newMAdminClient(session)
|
||||
if err != nil {
|
||||
return nil, prepareError(err)
|
||||
}
|
||||
// create a minioClient interface implementation
|
||||
// defining the client to be used
|
||||
adminClient := adminClient{client: mAdmin}
|
||||
quota, err := getBucketQuota(params.HTTPRequest.Context(), &adminClient, ¶ms.Name)
|
||||
if err != nil {
|
||||
return nil, &models.Error{
|
||||
Code: 500,
|
||||
Message: swag.String(err.Error()),
|
||||
}
|
||||
}
|
||||
return quota, nil
|
||||
}
|
||||
|
||||
func getBucketQuota(ctx context.Context, ac *adminClient, bucket *string) (*models.BucketQuota, error) {
|
||||
|
||||
quota, err := ac.getBucketQuota(ctx, *bucket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &models.BucketQuota{
|
||||
Quota: int64(quota.Quota),
|
||||
Type: string(quota.Type),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user