diff --git a/models/tenant.go b/models/tenant.go index 1d535a2e39..cbbcdff981 100644 --- a/models/tenant.go +++ b/models/tenant.go @@ -53,9 +53,6 @@ type Tenant struct { // total size TotalSize int64 `json:"total_size,omitempty"` - // used size - UsedSize int64 `json:"used_size,omitempty"` - // zones Zones []*Zone `json:"zones"` } diff --git a/models/tenant_usage.go b/models/tenant_usage.go new file mode 100644 index 0000000000..43aed0ef03 --- /dev/null +++ b/models/tenant_usage.go @@ -0,0 +1,60 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// TenantUsage tenant usage +// +// swagger:model tenantUsage +type TenantUsage struct { + + // used size + UsedSize int64 `json:"used_size,omitempty"` +} + +// Validate validates this tenant usage +func (m *TenantUsage) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *TenantUsage) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *TenantUsage) UnmarshalBinary(b []byte) error { + var res TenantUsage + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/portal-ui/bindata_assetfs.go b/portal-ui/bindata_assetfs.go index 6bfcecbbe8..29b9faa8a3 100644 --- a/portal-ui/bindata_assetfs.go +++ b/portal-ui/bindata_assetfs.go @@ -314,7 +314,7 @@ func buildAssetManifestJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/asset-manifest.json", size: 1324, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/asset-manifest.json", size: 1324, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -454,7 +454,7 @@ func buildIndexHtml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/index.html", size: 2653, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/index.html", size: 2653, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -634,7 +634,7 @@ func buildPrecacheManifest431582dfb340f36f9878214baec8dc4dJs() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/precache-manifest.431582dfb340f36f9878214baec8dc4d.js", size: 872, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/precache-manifest.431582dfb340f36f9878214baec8dc4d.js", size: 872, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -714,7 +714,7 @@ func buildServiceWorkerJs() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/service-worker.js", size: 1183, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/service-worker.js", size: 1183, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -734,7 +734,7 @@ func buildStaticCss2C54eff9aChunkCss() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/css/2.c54eff9a.chunk.css", size: 7679, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/css/2.c54eff9a.chunk.css", size: 7679, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -754,7 +754,7 @@ func buildStaticCss2C54eff9aChunkCssMap() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/css/2.c54eff9a.chunk.css.map", size: 14852, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/css/2.c54eff9a.chunk.css.map", size: 14852, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -774,7 +774,7 @@ func buildStaticCssMainDc35c5d0ChunkCss() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/css/main.dc35c5d0.chunk.css", size: 244, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/css/main.dc35c5d0.chunk.css", size: 244, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -794,7 +794,7 @@ func buildStaticCssMainDc35c5d0ChunkCssMap() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/css/main.dc35c5d0.chunk.css.map", size: 426, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/css/main.dc35c5d0.chunk.css.map", size: 426, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -814,7 +814,7 @@ func buildStaticJs256e77eefChunkJs() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/js/2.56e77eef.chunk.js", size: 1004066, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/js/2.56e77eef.chunk.js", size: 1004066, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -834,7 +834,7 @@ func buildStaticJs256e77eefChunkJsLicenseTxt() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/js/2.56e77eef.chunk.js.LICENSE.txt", size: 3031, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/js/2.56e77eef.chunk.js.LICENSE.txt", size: 3031, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -854,7 +854,7 @@ func buildStaticJs256e77eefChunkJsMap() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/js/2.56e77eef.chunk.js.map", size: 4194792, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/js/2.56e77eef.chunk.js.map", size: 4194792, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -874,7 +874,7 @@ func buildStaticJsMain8d549452ChunkJs() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/js/main.8d549452.chunk.js", size: 224981, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/js/main.8d549452.chunk.js", size: 224981, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -894,7 +894,7 @@ func buildStaticJsMain8d549452ChunkJsMap() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/js/main.8d549452.chunk.js.map", size: 768292, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/js/main.8d549452.chunk.js.map", size: 768292, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -914,7 +914,7 @@ func buildStaticJsRuntimeMainBa4e227dJs() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/js/runtime-main.ba4e227d.js", size: 1565, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/js/runtime-main.ba4e227d.js", size: 1565, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -934,7 +934,7 @@ func buildStaticJsRuntimeMainBa4e227dJsMap() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/js/runtime-main.ba4e227d.js.map", size: 8278, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/js/runtime-main.ba4e227d.js.map", size: 8278, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -954,7 +954,7 @@ func buildStaticMediaMinio_console_logo0851e1d0Svg() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "build/static/media/minio_console_logo.0851e1d0.svg", size: 2785, mode: os.FileMode(420), modTime: time.Unix(1595632751, 0)} + info := bindataFileInfo{name: "build/static/media/minio_console_logo.0851e1d0.svg", size: 2785, mode: os.FileMode(420), modTime: time.Unix(1595877009, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/restapi/admin_tenants.go b/restapi/admin_tenants.go index 66e4689262..9aa678e6a0 100644 --- a/restapi/admin_tenants.go +++ b/restapi/admin_tenants.go @@ -112,6 +112,15 @@ func registerTenantHandlers(api *operations.ConsoleAPI) { } return admin_api.NewTenantAddZoneCreated() }) + + api.AdminAPIGetTenantUsageHandler = admin_api.GetTenantUsageHandlerFunc(func(params admin_api.GetTenantUsageParams, session *models.Principal) middleware.Responder { + payload, err := getTenantUsageResponse(session, params) + if err != nil { + log.Println(err) + return admin_api.NewGetTenantUsageDefault(500).WithPayload(&models.Error{Code: 500, Message: swag.String("Unable to get tenant usage")}) + } + return admin_api.NewGetTenantUsageOK().WithPayload(payload) + }) } // deleteTenantAction performs the actions of deleting a tenant @@ -178,7 +187,7 @@ func getTenant(ctx context.Context, operatorClient OperatorClient, namespace, te return minInst, nil } -func getTenantInfo(tenant *operator.Tenant, tenantInfo *usageInfo) *models.Tenant { +func getTenantInfo(tenant *operator.Tenant) *models.Tenant { var instanceCount int64 var volumeCount int64 for _, zone := range tenant.Spec.Zones { @@ -217,7 +226,6 @@ func getTenantInfo(tenant *operator.Tenant, tenantInfo *usageInfo) *models.Tenan Zones: zones, Namespace: tenant.ObjectMeta.Namespace, Image: tenant.Spec.Image, - UsedSize: tenantInfo.DisksUsage, } } @@ -230,55 +238,18 @@ func getTenantInfoResponse(session *models.Principal, params admin_api.TenantInf if err != nil { return nil, err } - clientset, err := cluster.K8sClient(session.SessionToken) - if err != nil { - log.Println("error getting k8sClient:", err) - return nil, err - } opClient := &operatorClient{ client: opClientClientSet, } - k8sClient := &k8sClient{ - client: clientset, - } minTenant, err := getTenant(ctx, opClient, params.Namespace, params.Tenant) if err != nil { log.Println("error getting minioTenant:", err) return nil, err } - tenantScheme := getTenantScheme(minTenant) - svcName := minTenant.Spec.ServiceName - if svcName == "" { - svcName = minTenant.Name - // TODO: - // 1 get tenant services - // 2 filter out cluster ip svc - } - - mAdmin, err := getTenantAdminClient( - ctx, - k8sClient, - params.Namespace, - params.Tenant, - svcName, - tenantScheme) - if err != nil { - log.Println("error getting tenant's admin client:", err) - return nil, err - } - // create a minioClient interface implementation - // defining the client to be used - adminClient := adminClient{client: mAdmin} - // serialize output - adminInfo, err := getAdminInfo(ctx, adminClient) - if err != nil { - log.Println("error getting admin info:", err) - return nil, err - } - info := getTenantInfo(minTenant, adminInfo) + info := getTenantInfo(minTenant) return info, nil } @@ -684,3 +655,65 @@ func getTenantAddZoneResponse(session *models.Principal, params admin_api.Tenant } return nil } + +// getTenantUsageResponse returns the usage of a tenant +func getTenantUsageResponse(session *models.Principal, params admin_api.GetTenantUsageParams) (*models.TenantUsage, error) { + // 5 seconds timeout + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + opClientClientSet, err := cluster.OperatorClient(session.SessionToken) + if err != nil { + return nil, err + } + clientset, err := cluster.K8sClient(session.SessionToken) + if err != nil { + log.Println("error getting k8sClient:", err) + return nil, err + } + + opClient := &operatorClient{ + client: opClientClientSet, + } + k8sClient := &k8sClient{ + client: clientset, + } + + minTenant, err := getTenant(ctx, opClient, params.Namespace, params.Tenant) + if err != nil { + log.Println("error getting minioTenant:", err) + return nil, err + } + tenantScheme := getTenantScheme(minTenant) + + svcName := minTenant.Spec.ServiceName + if svcName == "" { + svcName = minTenant.Name + // TODO: + // 1 get tenant services + // 2 filter out cluster ip svc + } + + mAdmin, err := getTenantAdminClient( + ctx, + k8sClient, + params.Namespace, + params.Tenant, + svcName, + tenantScheme) + if err != nil { + log.Println("error getting tenant's admin client:", err) + return nil, err + } + // create a minioClient interface implementation + // defining the client to be used + adminClient := adminClient{client: mAdmin} + // serialize output + adminInfo, err := getAdminInfo(ctx, adminClient) + if err != nil { + log.Println("error getting admin info:", err) + return nil, err + } + info := &models.TenantUsage{UsedSize: adminInfo.Usage} + return info, nil +} diff --git a/restapi/admin_tenants_test.go b/restapi/admin_tenants_test.go index 80ee15e1b9..a008797578 100644 --- a/restapi/admin_tenants_test.go +++ b/restapi/admin_tenants_test.go @@ -315,13 +315,12 @@ func Test_TenantInfo(t *testing.T) { }, Namespace: "minio-ns", Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z", - UsedSize: int64(1024), }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := getTenantInfo(tt.args.minioTenant, tt.args.tenantInfo) + got := getTenantInfo(tt.args.minioTenant) if !reflect.DeepEqual(got, tt.want) { ji, _ := json.Marshal(got) vi, _ := json.Marshal(tt.want) diff --git a/restapi/embedded_spec.go b/restapi/embedded_spec.go index eb4a0ed463..97e23e291c 100644 --- a/restapi/embedded_spec.go +++ b/restapi/embedded_spec.go @@ -1036,6 +1036,43 @@ func init() { } } }, + "/namespaces/{namespace}/tenants/{tenant}/usage": { + "get": { + "tags": [ + "AdminAPI" + ], + "summary": "Get Usage For The Tenant", + "operationId": "GetTenantUsage", + "parameters": [ + { + "type": "string", + "name": "namespace", + "in": "path", + "required": true + }, + { + "type": "string", + "name": "tenant", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/tenantUsage" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + } + }, "/namespaces/{namespace}/tenants/{tenant}/zones": { "post": { "tags": [ @@ -2568,10 +2605,6 @@ func init() { "type": "integer", "format": "int64" }, - "used_size": { - "type": "integer", - "format": "int64" - }, "zones": { "type": "array", "items": { @@ -2609,6 +2642,15 @@ func init() { } } }, + "tenantUsage": { + "type": "object", + "properties": { + "used_size": { + "type": "integer", + "format": "int64" + } + } + }, "updateGroupRequest": { "type": "object", "required": [ @@ -3739,6 +3781,43 @@ func init() { } } }, + "/namespaces/{namespace}/tenants/{tenant}/usage": { + "get": { + "tags": [ + "AdminAPI" + ], + "summary": "Get Usage For The Tenant", + "operationId": "GetTenantUsage", + "parameters": [ + { + "type": "string", + "name": "namespace", + "in": "path", + "required": true + }, + { + "type": "string", + "name": "tenant", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/tenantUsage" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + } + }, "/namespaces/{namespace}/tenants/{tenant}/zones": { "post": { "tags": [ @@ -5285,10 +5364,6 @@ func init() { "type": "integer", "format": "int64" }, - "used_size": { - "type": "integer", - "format": "int64" - }, "zones": { "type": "array", "items": { @@ -5326,6 +5401,15 @@ func init() { } } }, + "tenantUsage": { + "type": "object", + "properties": { + "used_size": { + "type": "integer", + "format": "int64" + } + } + }, "updateGroupRequest": { "type": "object", "required": [ diff --git a/restapi/operations/admin_api/get_tenant_usage.go b/restapi/operations/admin_api/get_tenant_usage.go new file mode 100644 index 0000000000..aff8a3bb0f --- /dev/null +++ b/restapi/operations/admin_api/get_tenant_usage.go @@ -0,0 +1,90 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" + + "github.com/minio/console/models" +) + +// GetTenantUsageHandlerFunc turns a function with the right signature into a get tenant usage handler +type GetTenantUsageHandlerFunc func(GetTenantUsageParams, *models.Principal) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetTenantUsageHandlerFunc) Handle(params GetTenantUsageParams, principal *models.Principal) middleware.Responder { + return fn(params, principal) +} + +// GetTenantUsageHandler interface for that can handle valid get tenant usage params +type GetTenantUsageHandler interface { + Handle(GetTenantUsageParams, *models.Principal) middleware.Responder +} + +// NewGetTenantUsage creates a new http.Handler for the get tenant usage operation +func NewGetTenantUsage(ctx *middleware.Context, handler GetTenantUsageHandler) *GetTenantUsage { + return &GetTenantUsage{Context: ctx, Handler: handler} +} + +/*GetTenantUsage swagger:route GET /namespaces/{namespace}/tenants/{tenant}/usage AdminAPI getTenantUsage + +Get Usage For The Tenant + +*/ +type GetTenantUsage struct { + Context *middleware.Context + Handler GetTenantUsageHandler +} + +func (o *GetTenantUsage) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewGetTenantUsageParams() + + uprinc, aCtx, err := o.Context.Authorize(r, route) + if err != nil { + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + if aCtx != nil { + r = aCtx + } + var principal *models.Principal + if uprinc != nil { + principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise + } + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params, principal) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/restapi/operations/admin_api/get_tenant_usage_parameters.go b/restapi/operations/admin_api/get_tenant_usage_parameters.go new file mode 100644 index 0000000000..033bb8a4b1 --- /dev/null +++ b/restapi/operations/admin_api/get_tenant_usage_parameters.go @@ -0,0 +1,114 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" +) + +// NewGetTenantUsageParams creates a new GetTenantUsageParams object +// no default values defined in spec. +func NewGetTenantUsageParams() GetTenantUsageParams { + + return GetTenantUsageParams{} +} + +// GetTenantUsageParams contains all the bound params for the get tenant usage operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetTenantUsage +type GetTenantUsageParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Namespace string + /* + Required: true + In: path + */ + Tenant string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetTenantUsageParams() beforehand. +func (o *GetTenantUsageParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rNamespace, rhkNamespace, _ := route.Params.GetOK("namespace") + if err := o.bindNamespace(rNamespace, rhkNamespace, route.Formats); err != nil { + res = append(res, err) + } + + rTenant, rhkTenant, _ := route.Params.GetOK("tenant") + if err := o.bindTenant(rTenant, rhkTenant, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindNamespace binds and validates parameter Namespace from path. +func (o *GetTenantUsageParams) bindNamespace(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + o.Namespace = raw + + return nil +} + +// bindTenant binds and validates parameter Tenant from path. +func (o *GetTenantUsageParams) bindTenant(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + o.Tenant = raw + + return nil +} diff --git a/restapi/operations/admin_api/get_tenant_usage_responses.go b/restapi/operations/admin_api/get_tenant_usage_responses.go new file mode 100644 index 0000000000..866b722286 --- /dev/null +++ b/restapi/operations/admin_api/get_tenant_usage_responses.go @@ -0,0 +1,133 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/minio/console/models" +) + +// GetTenantUsageOKCode is the HTTP code returned for type GetTenantUsageOK +const GetTenantUsageOKCode int = 200 + +/*GetTenantUsageOK A successful response. + +swagger:response getTenantUsageOK +*/ +type GetTenantUsageOK struct { + + /* + In: Body + */ + Payload *models.TenantUsage `json:"body,omitempty"` +} + +// NewGetTenantUsageOK creates GetTenantUsageOK with default headers values +func NewGetTenantUsageOK() *GetTenantUsageOK { + + return &GetTenantUsageOK{} +} + +// WithPayload adds the payload to the get tenant usage o k response +func (o *GetTenantUsageOK) WithPayload(payload *models.TenantUsage) *GetTenantUsageOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get tenant usage o k response +func (o *GetTenantUsageOK) SetPayload(payload *models.TenantUsage) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetTenantUsageOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/*GetTenantUsageDefault Generic error response. + +swagger:response getTenantUsageDefault +*/ +type GetTenantUsageDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetTenantUsageDefault creates GetTenantUsageDefault with default headers values +func NewGetTenantUsageDefault(code int) *GetTenantUsageDefault { + if code <= 0 { + code = 500 + } + + return &GetTenantUsageDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the get tenant usage default response +func (o *GetTenantUsageDefault) WithStatusCode(code int) *GetTenantUsageDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the get tenant usage default response +func (o *GetTenantUsageDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the get tenant usage default response +func (o *GetTenantUsageDefault) WithPayload(payload *models.Error) *GetTenantUsageDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get tenant usage default response +func (o *GetTenantUsageDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetTenantUsageDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/restapi/operations/admin_api/get_tenant_usage_urlbuilder.go b/restapi/operations/admin_api/get_tenant_usage_urlbuilder.go new file mode 100644 index 0000000000..1bc9c5e066 --- /dev/null +++ b/restapi/operations/admin_api/get_tenant_usage_urlbuilder.go @@ -0,0 +1,124 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// GetTenantUsageURL generates an URL for the get tenant usage operation +type GetTenantUsageURL struct { + Namespace string + Tenant string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetTenantUsageURL) WithBasePath(bp string) *GetTenantUsageURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetTenantUsageURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetTenantUsageURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/namespaces/{namespace}/tenants/{tenant}/usage" + + namespace := o.Namespace + if namespace != "" { + _path = strings.Replace(_path, "{namespace}", namespace, -1) + } else { + return nil, errors.New("namespace is required on GetTenantUsageURL") + } + + tenant := o.Tenant + if tenant != "" { + _path = strings.Replace(_path, "{tenant}", tenant, -1) + } else { + return nil, errors.New("tenant is required on GetTenantUsageURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/api/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetTenantUsageURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetTenantUsageURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetTenantUsageURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetTenantUsageURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetTenantUsageURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetTenantUsageURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/restapi/operations/console_api.go b/restapi/operations/console_api.go index 0d3ab22825..d42994735a 100644 --- a/restapi/operations/console_api.go +++ b/restapi/operations/console_api.go @@ -117,6 +117,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI { AdminAPIGetResourceQuotaHandler: admin_api.GetResourceQuotaHandlerFunc(func(params admin_api.GetResourceQuotaParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation admin_api.GetResourceQuota has not yet been implemented") }), + AdminAPIGetTenantUsageHandler: admin_api.GetTenantUsageHandlerFunc(func(params admin_api.GetTenantUsageParams, principal *models.Principal) middleware.Responder { + return middleware.NotImplemented("operation admin_api.GetTenantUsage has not yet been implemented") + }), AdminAPIGetUserInfoHandler: admin_api.GetUserInfoHandlerFunc(func(params admin_api.GetUserInfoParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation admin_api.GetUserInfo has not yet been implemented") }), @@ -304,6 +307,8 @@ type ConsoleAPI struct { AdminAPIDeleteTenantHandler admin_api.DeleteTenantHandler // AdminAPIGetResourceQuotaHandler sets the operation handler for the get resource quota operation AdminAPIGetResourceQuotaHandler admin_api.GetResourceQuotaHandler + // AdminAPIGetTenantUsageHandler sets the operation handler for the get tenant usage operation + AdminAPIGetTenantUsageHandler admin_api.GetTenantUsageHandler // AdminAPIGetUserInfoHandler sets the operation handler for the get user info operation AdminAPIGetUserInfoHandler admin_api.GetUserInfoHandler // AdminAPIGroupInfoHandler sets the operation handler for the group info operation @@ -499,6 +504,9 @@ func (o *ConsoleAPI) Validate() error { if o.AdminAPIGetResourceQuotaHandler == nil { unregistered = append(unregistered, "admin_api.GetResourceQuotaHandler") } + if o.AdminAPIGetTenantUsageHandler == nil { + unregistered = append(unregistered, "admin_api.GetTenantUsageHandler") + } if o.AdminAPIGetUserInfoHandler == nil { unregistered = append(unregistered, "admin_api.GetUserInfoHandler") } @@ -776,6 +784,10 @@ func (o *ConsoleAPI) initHandlerCache() { if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) } + o.handlers["GET"]["/namespaces/{namespace}/tenants/{tenant}/usage"] = admin_api.NewGetTenantUsage(o.context, o.AdminAPIGetTenantUsageHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } o.handlers["GET"]["/users/{name}"] = admin_api.NewGetUserInfo(o.context, o.AdminAPIGetUserInfoHandler) if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) diff --git a/swagger.yml b/swagger.yml index 0a6696d35d..2e3a985dd9 100644 --- a/swagger.yml +++ b/swagger.yml @@ -1144,6 +1144,31 @@ paths: tags: - AdminAPI + /namespaces/{namespace}/tenants/{tenant}/usage: + get: + summary: Get Usage For The Tenant + operationId: GetTenantUsage + parameters: + - name: namespace + in: path + required: true + type: string + - name: tenant + in: path + required: true + type: string + responses: + 200: + description: A successful response. + schema: + $ref: "#/definitions/tenantUsage" + default: + description: Generic error response. + schema: + $ref: "#/definitions/error" + tags: + - AdminAPI + /namespaces/{namespace}/resourcequotas/{resource-quota-name}: get: summary: Get Resource Quota @@ -1704,6 +1729,10 @@ definitions: total_size: type: integer format: int64 + + tenantUsage: + type: object + properties: used_size: type: integer format: int64