Add create zone for tenant api (#194)
This commit is contained in:
@@ -102,6 +102,15 @@ func registerTenantHandlers(api *operations.McsAPI) {
|
||||
}
|
||||
return admin_api.NewUpdateTenantCreated()
|
||||
})
|
||||
|
||||
api.AdminAPITenantAddZoneHandler = admin_api.TenantAddZoneHandlerFunc(func(params admin_api.TenantAddZoneParams, session *models.Principal) middleware.Responder {
|
||||
err := getTenantAddZoneResponse(session, params)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return admin_api.NewTenantAddZoneDefault(500).WithPayload(&models.Error{Code: 500, Message: swag.String("Unable to update tenant")})
|
||||
}
|
||||
return admin_api.NewTenantAddZoneCreated()
|
||||
})
|
||||
}
|
||||
|
||||
// deleteTenantAction performs the actions of deleting a tenant
|
||||
@@ -180,8 +189,8 @@ func getTenantInfo(minioInstance *operator.MinIOInstance, tenantInfo *usageInfo)
|
||||
|
||||
for _, z := range minioInstance.Spec.Zones {
|
||||
zones = append(zones, &models.Zone{
|
||||
Name: z.Name,
|
||||
Servers: int64(z.Servers),
|
||||
Name: swag.String(z.Name),
|
||||
Servers: swag.Int64(int64(z.Servers)),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -465,8 +474,8 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
|
||||
if len(params.Body.Zones) > 0 {
|
||||
for _, zone := range params.Body.Zones {
|
||||
minInst.Spec.Zones = append(minInst.Spec.Zones, operator.Zone{
|
||||
Name: zone.Name,
|
||||
Servers: int32(zone.Servers),
|
||||
Name: *zone.Name,
|
||||
Servers: int32(*zone.Servers),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -544,9 +553,6 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClient, http
|
||||
|
||||
func getUpdateTenantResponse(session *models.Principal, params admin_api.UpdateTenantParams) error {
|
||||
ctx := context.Background()
|
||||
// TODO: use namespace of the tenant not from the controller
|
||||
currentNamespace := cluster.GetNs()
|
||||
|
||||
opClientClientSet, err := cluster.OperatorClient(session.SessionToken)
|
||||
if err != nil {
|
||||
log.Println("error getting operator client:", err)
|
||||
@@ -561,10 +567,50 @@ func getUpdateTenantResponse(session *models.Principal, params admin_api.UpdateT
|
||||
Timeout: 4 * time.Second,
|
||||
},
|
||||
}
|
||||
if err := updateTenantAction(ctx, opClient, httpC, currentNamespace, params); err != nil {
|
||||
if err := updateTenantAction(ctx, opClient, httpC, params.Namespace, params); err != nil {
|
||||
log.Println("error patching MinioInstance:", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// addTenantZone creates a zone to a defined tenant
|
||||
func addTenantZone(ctx context.Context, operatorClient OperatorClient, params admin_api.TenantAddZoneParams) error {
|
||||
minInst, err := operatorClient.MinIOInstanceGet(ctx, params.Namespace, params.Tenant, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
minInst.Spec.Zones = append(minInst.Spec.Zones, operator.Zone{
|
||||
Name: *params.Body.Name,
|
||||
Servers: int32(*params.Body.Servers),
|
||||
})
|
||||
|
||||
payloadBytes, err := json.Marshal(minInst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = operatorClient.MinIOInstancePatch(ctx, params.Namespace, minInst.Name, types.MergePatchType, payloadBytes, metav1.PatchOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getTenantAddZoneResponse(session *models.Principal, params admin_api.TenantAddZoneParams) error {
|
||||
ctx := context.Background()
|
||||
opClientClientSet, err := cluster.OperatorClient(session.SessionToken)
|
||||
if err != nil {
|
||||
log.Println("error getting operator client:", err)
|
||||
return err
|
||||
}
|
||||
opClient := &operatorClient{
|
||||
client: opClientClientSet,
|
||||
}
|
||||
if err := addTenantZone(ctx, opClient, params); err != nil {
|
||||
log.Println("error patching MinioInstance:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/minio/mcs/cluster"
|
||||
"github.com/minio/mcs/models"
|
||||
"github.com/minio/mcs/restapi/operations/admin_api"
|
||||
@@ -299,6 +300,97 @@ func Test_deleteTenantAction(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_TenantAddZone(t *testing.T) {
|
||||
opClient := opClientMock{}
|
||||
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
operatorClient OperatorClient
|
||||
nameSpace string
|
||||
mockMinioInstancePatch func(ctx context.Context, namespace string, instanceName string, pt types.PatchType, data []byte, options metav1.PatchOptions) (*v1.MinIOInstance, error)
|
||||
mockMinioInstanceGet func(ctx context.Context, namespace string, instanceName string, options metav1.GetOptions) (*v1.MinIOInstance, error)
|
||||
params admin_api.TenantAddZoneParams
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Add zone, no errors",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
operatorClient: opClient,
|
||||
nameSpace: "default",
|
||||
mockMinioInstancePatch: func(ctx context.Context, namespace string, instanceName string, pt types.PatchType, data []byte, options metav1.PatchOptions) (*v1.MinIOInstance, error) {
|
||||
return &v1.MinIOInstance{}, nil
|
||||
},
|
||||
mockMinioInstanceGet: func(ctx context.Context, namespace string, instanceName string, options metav1.GetOptions) (*v1.MinIOInstance, error) {
|
||||
return &v1.MinIOInstance{}, nil
|
||||
},
|
||||
params: admin_api.TenantAddZoneParams{
|
||||
Body: &models.Zone{
|
||||
Name: swag.String("zone-1"),
|
||||
Servers: swag.Int64(int64(4)),
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Error on patch, handle error",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
operatorClient: opClient,
|
||||
nameSpace: "default",
|
||||
mockMinioInstancePatch: func(ctx context.Context, namespace string, instanceName string, pt types.PatchType, data []byte, options metav1.PatchOptions) (*v1.MinIOInstance, error) {
|
||||
return nil, errors.New("errors")
|
||||
},
|
||||
mockMinioInstanceGet: func(ctx context.Context, namespace string, instanceName string, options metav1.GetOptions) (*v1.MinIOInstance, error) {
|
||||
return &v1.MinIOInstance{}, nil
|
||||
},
|
||||
params: admin_api.TenantAddZoneParams{
|
||||
Body: &models.Zone{
|
||||
Name: swag.String("zone-1"),
|
||||
Servers: swag.Int64(int64(4)),
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Error on get, handle error",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
operatorClient: opClient,
|
||||
nameSpace: "default",
|
||||
mockMinioInstancePatch: func(ctx context.Context, namespace string, instanceName string, pt types.PatchType, data []byte, options metav1.PatchOptions) (*v1.MinIOInstance, error) {
|
||||
return nil, errors.New("errors")
|
||||
},
|
||||
mockMinioInstanceGet: func(ctx context.Context, namespace string, instanceName string, options metav1.GetOptions) (*v1.MinIOInstance, error) {
|
||||
return nil, errors.New("errors")
|
||||
},
|
||||
params: admin_api.TenantAddZoneParams{
|
||||
Body: &models.Zone{
|
||||
Name: swag.String("zone-1"),
|
||||
Servers: swag.Int64(int64(4)),
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
opClientMinioInstanceGetMock = tt.args.mockMinioInstanceGet
|
||||
opClientMinioInstancePatchMock = tt.args.mockMinioInstancePatch
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := addTenantZone(tt.args.ctx, tt.args.operatorClient, tt.args.params); (err != nil) != tt.wantErr {
|
||||
t.Errorf("addTenantZone() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_UpdateTenantAction(t *testing.T) {
|
||||
opClient := opClientMock{}
|
||||
httpClientM := httpClientMock{}
|
||||
|
||||
@@ -1036,6 +1036,48 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"/namespaces/{namespace}/tenants/{tenant}/zones": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"AdminAPI"
|
||||
],
|
||||
"summary": "Tenant Add Zone",
|
||||
"operationId": "TenantAddZone",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "namespace",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "tenant",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/zone"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A successful response."
|
||||
},
|
||||
"default": {
|
||||
"description": "Generic error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/policies": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@@ -2681,6 +2723,10 @@ func init() {
|
||||
},
|
||||
"zone": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name",
|
||||
"servers"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
@@ -3707,6 +3753,48 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"/namespaces/{namespace}/tenants/{tenant}/zones": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"AdminAPI"
|
||||
],
|
||||
"summary": "Tenant Add Zone",
|
||||
"operationId": "TenantAddZone",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "namespace",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "tenant",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/zone"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "A successful response."
|
||||
},
|
||||
"default": {
|
||||
"description": "Generic error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/policies": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@@ -5366,6 +5454,10 @@ func init() {
|
||||
},
|
||||
"zone": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name",
|
||||
"servers"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
|
||||
90
restapi/operations/admin_api/tenant_add_zone.go
Normal file
90
restapi/operations/admin_api/tenant_add_zone.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
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/mcs/models"
|
||||
)
|
||||
|
||||
// TenantAddZoneHandlerFunc turns a function with the right signature into a tenant add zone handler
|
||||
type TenantAddZoneHandlerFunc func(TenantAddZoneParams, *models.Principal) middleware.Responder
|
||||
|
||||
// Handle executing the request and returning a response
|
||||
func (fn TenantAddZoneHandlerFunc) Handle(params TenantAddZoneParams, principal *models.Principal) middleware.Responder {
|
||||
return fn(params, principal)
|
||||
}
|
||||
|
||||
// TenantAddZoneHandler interface for that can handle valid tenant add zone params
|
||||
type TenantAddZoneHandler interface {
|
||||
Handle(TenantAddZoneParams, *models.Principal) middleware.Responder
|
||||
}
|
||||
|
||||
// NewTenantAddZone creates a new http.Handler for the tenant add zone operation
|
||||
func NewTenantAddZone(ctx *middleware.Context, handler TenantAddZoneHandler) *TenantAddZone {
|
||||
return &TenantAddZone{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/*TenantAddZone swagger:route POST /namespaces/{namespace}/tenants/{tenant}/zones AdminAPI tenantAddZone
|
||||
|
||||
Tenant Add Zone
|
||||
|
||||
*/
|
||||
type TenantAddZone struct {
|
||||
Context *middleware.Context
|
||||
Handler TenantAddZoneHandler
|
||||
}
|
||||
|
||||
func (o *TenantAddZone) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
route, rCtx, _ := o.Context.RouteInfo(r)
|
||||
if rCtx != nil {
|
||||
r = rCtx
|
||||
}
|
||||
var Params = NewTenantAddZoneParams()
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
145
restapi/operations/admin_api/tenant_add_zone_parameters.go
Normal file
145
restapi/operations/admin_api/tenant_add_zone_parameters.go
Normal file
@@ -0,0 +1,145 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
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 (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/minio/mcs/models"
|
||||
)
|
||||
|
||||
// NewTenantAddZoneParams creates a new TenantAddZoneParams object
|
||||
// no default values defined in spec.
|
||||
func NewTenantAddZoneParams() TenantAddZoneParams {
|
||||
|
||||
return TenantAddZoneParams{}
|
||||
}
|
||||
|
||||
// TenantAddZoneParams contains all the bound params for the tenant add zone operation
|
||||
// typically these are obtained from a http.Request
|
||||
//
|
||||
// swagger:parameters TenantAddZone
|
||||
type TenantAddZoneParams struct {
|
||||
|
||||
// HTTP Request Object
|
||||
HTTPRequest *http.Request `json:"-"`
|
||||
|
||||
/*
|
||||
Required: true
|
||||
In: body
|
||||
*/
|
||||
Body *models.Zone
|
||||
/*
|
||||
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 NewTenantAddZoneParams() beforehand.
|
||||
func (o *TenantAddZoneParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
|
||||
var res []error
|
||||
|
||||
o.HTTPRequest = r
|
||||
|
||||
if runtime.HasBody(r) {
|
||||
defer r.Body.Close()
|
||||
var body models.Zone
|
||||
if err := route.Consumer.Consume(r.Body, &body); err != nil {
|
||||
if err == io.EOF {
|
||||
res = append(res, errors.Required("body", "body", ""))
|
||||
} else {
|
||||
res = append(res, errors.NewParseError("body", "body", "", err))
|
||||
}
|
||||
} else {
|
||||
// validate body object
|
||||
if err := body.Validate(route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) == 0 {
|
||||
o.Body = &body
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = append(res, errors.Required("body", "body", ""))
|
||||
}
|
||||
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 *TenantAddZoneParams) 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 *TenantAddZoneParams) 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
|
||||
}
|
||||
113
restapi/operations/admin_api/tenant_add_zone_responses.go
Normal file
113
restapi/operations/admin_api/tenant_add_zone_responses.go
Normal file
@@ -0,0 +1,113 @@
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
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/mcs/models"
|
||||
)
|
||||
|
||||
// TenantAddZoneCreatedCode is the HTTP code returned for type TenantAddZoneCreated
|
||||
const TenantAddZoneCreatedCode int = 201
|
||||
|
||||
/*TenantAddZoneCreated A successful response.
|
||||
|
||||
swagger:response tenantAddZoneCreated
|
||||
*/
|
||||
type TenantAddZoneCreated struct {
|
||||
}
|
||||
|
||||
// NewTenantAddZoneCreated creates TenantAddZoneCreated with default headers values
|
||||
func NewTenantAddZoneCreated() *TenantAddZoneCreated {
|
||||
|
||||
return &TenantAddZoneCreated{}
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *TenantAddZoneCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||
|
||||
rw.WriteHeader(201)
|
||||
}
|
||||
|
||||
/*TenantAddZoneDefault Generic error response.
|
||||
|
||||
swagger:response tenantAddZoneDefault
|
||||
*/
|
||||
type TenantAddZoneDefault struct {
|
||||
_statusCode int
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.Error `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewTenantAddZoneDefault creates TenantAddZoneDefault with default headers values
|
||||
func NewTenantAddZoneDefault(code int) *TenantAddZoneDefault {
|
||||
if code <= 0 {
|
||||
code = 500
|
||||
}
|
||||
|
||||
return &TenantAddZoneDefault{
|
||||
_statusCode: code,
|
||||
}
|
||||
}
|
||||
|
||||
// WithStatusCode adds the status to the tenant add zone default response
|
||||
func (o *TenantAddZoneDefault) WithStatusCode(code int) *TenantAddZoneDefault {
|
||||
o._statusCode = code
|
||||
return o
|
||||
}
|
||||
|
||||
// SetStatusCode sets the status to the tenant add zone default response
|
||||
func (o *TenantAddZoneDefault) SetStatusCode(code int) {
|
||||
o._statusCode = code
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the tenant add zone default response
|
||||
func (o *TenantAddZoneDefault) WithPayload(payload *models.Error) *TenantAddZoneDefault {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the tenant add zone default response
|
||||
func (o *TenantAddZoneDefault) SetPayload(payload *models.Error) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *TenantAddZoneDefault) 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
|
||||
}
|
||||
}
|
||||
}
|
||||
124
restapi/operations/admin_api/tenant_add_zone_urlbuilder.go
Normal file
124
restapi/operations/admin_api/tenant_add_zone_urlbuilder.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// TenantAddZoneURL generates an URL for the tenant add zone operation
|
||||
type TenantAddZoneURL 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 *TenantAddZoneURL) WithBasePath(bp string) *TenantAddZoneURL {
|
||||
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 *TenantAddZoneURL) SetBasePath(bp string) {
|
||||
o._basePath = bp
|
||||
}
|
||||
|
||||
// Build a url path and query string
|
||||
func (o *TenantAddZoneURL) Build() (*url.URL, error) {
|
||||
var _result url.URL
|
||||
|
||||
var _path = "/namespaces/{namespace}/tenants/{tenant}/zones"
|
||||
|
||||
namespace := o.Namespace
|
||||
if namespace != "" {
|
||||
_path = strings.Replace(_path, "{namespace}", namespace, -1)
|
||||
} else {
|
||||
return nil, errors.New("namespace is required on TenantAddZoneURL")
|
||||
}
|
||||
|
||||
tenant := o.Tenant
|
||||
if tenant != "" {
|
||||
_path = strings.Replace(_path, "{tenant}", tenant, -1)
|
||||
} else {
|
||||
return nil, errors.New("tenant is required on TenantAddZoneURL")
|
||||
}
|
||||
|
||||
_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 *TenantAddZoneURL) 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 *TenantAddZoneURL) String() string {
|
||||
return o.Must(o.Build()).String()
|
||||
}
|
||||
|
||||
// BuildFull builds a full url with scheme, host, path and query string
|
||||
func (o *TenantAddZoneURL) BuildFull(scheme, host string) (*url.URL, error) {
|
||||
if scheme == "" {
|
||||
return nil, errors.New("scheme is required for a full url on TenantAddZoneURL")
|
||||
}
|
||||
if host == "" {
|
||||
return nil, errors.New("host is required for a full url on TenantAddZoneURL")
|
||||
}
|
||||
|
||||
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 *TenantAddZoneURL) StringFull(scheme, host string) string {
|
||||
return o.Must(o.BuildFull(scheme, host)).String()
|
||||
}
|
||||
@@ -201,6 +201,9 @@ func NewMcsAPI(spec *loads.Document) *McsAPI {
|
||||
AdminAPISetPolicyHandler: admin_api.SetPolicyHandlerFunc(func(params admin_api.SetPolicyParams, principal *models.Principal) middleware.Responder {
|
||||
return middleware.NotImplemented("operation admin_api.SetPolicy has not yet been implemented")
|
||||
}),
|
||||
AdminAPITenantAddZoneHandler: admin_api.TenantAddZoneHandlerFunc(func(params admin_api.TenantAddZoneParams, principal *models.Principal) middleware.Responder {
|
||||
return middleware.NotImplemented("operation admin_api.TenantAddZone has not yet been implemented")
|
||||
}),
|
||||
AdminAPITenantInfoHandler: admin_api.TenantInfoHandlerFunc(func(params admin_api.TenantInfoParams, principal *models.Principal) middleware.Responder {
|
||||
return middleware.NotImplemented("operation admin_api.TenantInfo has not yet been implemented")
|
||||
}),
|
||||
@@ -357,6 +360,8 @@ type McsAPI struct {
|
||||
AdminAPISetConfigHandler admin_api.SetConfigHandler
|
||||
// AdminAPISetPolicyHandler sets the operation handler for the set policy operation
|
||||
AdminAPISetPolicyHandler admin_api.SetPolicyHandler
|
||||
// AdminAPITenantAddZoneHandler sets the operation handler for the tenant add zone operation
|
||||
AdminAPITenantAddZoneHandler admin_api.TenantAddZoneHandler
|
||||
// AdminAPITenantInfoHandler sets the operation handler for the tenant info operation
|
||||
AdminAPITenantInfoHandler admin_api.TenantInfoHandler
|
||||
// AdminAPIUpdateGroupHandler sets the operation handler for the update group operation
|
||||
@@ -578,6 +583,9 @@ func (o *McsAPI) Validate() error {
|
||||
if o.AdminAPISetPolicyHandler == nil {
|
||||
unregistered = append(unregistered, "admin_api.SetPolicyHandler")
|
||||
}
|
||||
if o.AdminAPITenantAddZoneHandler == nil {
|
||||
unregistered = append(unregistered, "admin_api.TenantAddZoneHandler")
|
||||
}
|
||||
if o.AdminAPITenantInfoHandler == nil {
|
||||
unregistered = append(unregistered, "admin_api.TenantInfoHandler")
|
||||
}
|
||||
@@ -877,6 +885,10 @@ func (o *McsAPI) initHandlerCache() {
|
||||
o.handlers["PUT"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["PUT"]["/set-policy/{name}"] = admin_api.NewSetPolicy(o.context, o.AdminAPISetPolicyHandler)
|
||||
if o.handlers["POST"] == nil {
|
||||
o.handlers["POST"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["POST"]["/namespaces/{namespace}/tenants/{tenant}/zones"] = admin_api.NewTenantAddZone(o.context, o.AdminAPITenantAddZoneHandler)
|
||||
if o.handlers["GET"] == nil {
|
||||
o.handlers["GET"] = make(map[string]http.Handler)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user