From 31d18efa9af03cf02f632ba1ab9a359fe75fd64c Mon Sep 17 00:00:00 2001 From: Alex <33497058+bexsoft@users.noreply.github.com> Date: Mon, 14 Jun 2021 12:04:57 -0500 Subject: [PATCH] Added create namespace API (#808) --- models/namespace.go | 88 ++++++++++++++ restapi/admin_namespaces.go | 81 +++++++++++++ restapi/admin_namespaces_test.go | 63 ++++++++++ restapi/configure_console.go | 2 + restapi/embedded_spec.go | 82 +++++++++++++ .../operations/admin_api/create_namespace.go | 88 ++++++++++++++ .../admin_api/create_namespace_parameters.go | 102 ++++++++++++++++ .../admin_api/create_namespace_responses.go | 113 ++++++++++++++++++ .../admin_api/create_namespace_urlbuilder.go | 104 ++++++++++++++++ restapi/operations/console_api.go | 12 ++ swagger.yml | 29 ++++- 11 files changed, 763 insertions(+), 1 deletion(-) create mode 100644 models/namespace.go create mode 100644 restapi/admin_namespaces.go create mode 100644 restapi/admin_namespaces_test.go create mode 100644 restapi/operations/admin_api/create_namespace.go create mode 100644 restapi/operations/admin_api/create_namespace_parameters.go create mode 100644 restapi/operations/admin_api/create_namespace_responses.go create mode 100644 restapi/operations/admin_api/create_namespace_urlbuilder.go diff --git a/models/namespace.go b/models/namespace.go new file mode 100644 index 000000000..c50927a42 --- /dev/null +++ b/models/namespace.go @@ -0,0 +1,88 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2021 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 ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// Namespace namespace +// +// swagger:model namespace +type Namespace struct { + + // name + // Required: true + Name *string `json:"name"` +} + +// Validate validates this namespace +func (m *Namespace) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateName(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Namespace) validateName(formats strfmt.Registry) error { + + if err := validate.Required("name", "body", m.Name); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this namespace based on context it is used +func (m *Namespace) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *Namespace) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Namespace) UnmarshalBinary(b []byte) error { + var res Namespace + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/restapi/admin_namespaces.go b/restapi/admin_namespaces.go new file mode 100644 index 000000000..1d5e78d73 --- /dev/null +++ b/restapi/admin_namespaces.go @@ -0,0 +1,81 @@ +// This file is part of MinIO Kubernetes Cloud +// Copyright (c) 2021 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 restapi + +import ( + "context" + "errors" + + "github.com/go-openapi/runtime/middleware" + "github.com/minio/console/cluster" + "github.com/minio/console/models" + "github.com/minio/console/restapi/operations" + "github.com/minio/console/restapi/operations/admin_api" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/client-go/kubernetes/typed/core/v1" +) + +func registerNamespaceHandlers(api *operations.ConsoleAPI) { + // Add Namespace + api.AdminAPICreateNamespaceHandler = admin_api.CreateNamespaceHandlerFunc(func(params admin_api.CreateNamespaceParams, session *models.Principal) middleware.Responder { + err := getNamespaceCreatedResponse(session, params) + if err != nil { + return admin_api.NewCreateNamespaceDefault(int(err.Code)).WithPayload(err) + } + return nil + }) +} + +func getNamespaceCreatedResponse(session *models.Principal, params admin_api.CreateNamespaceParams) *models.Error { + ctx := context.Background() + + clientset, err := cluster.K8sClient(session.STSSessionToken) + + if err != nil { + return prepareError(err) + } + + namespace := *params.Body.Name + + errCreation := getNamespaceCreated(ctx, clientset.CoreV1(), namespace) + + if errCreation != nil { + return prepareError(errCreation) + } + + return nil +} + +func getNamespaceCreated(ctx context.Context, clientset v1.CoreV1Interface, namespace string) error { + if namespace == "" { + errNS := errors.New("Namespace cannot be blank") + + return errNS + } + + coreNamespace := corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: namespace, + }, + } + + _, err := clientset.Namespaces().Create(ctx, &coreNamespace, metav1.CreateOptions{}) + + return err +} diff --git a/restapi/admin_namespaces_test.go b/restapi/admin_namespaces_test.go new file mode 100644 index 000000000..b2d72d3f8 --- /dev/null +++ b/restapi/admin_namespaces_test.go @@ -0,0 +1,63 @@ +// This file is part of MinIO Console Server +// Copyright (c) 2021 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 restapi + +import ( + "context" + "testing" + + "k8s.io/client-go/kubernetes/fake" +) + +func Test_CreateNamespace(t *testing.T) { + type args struct { + ctx context.Context + namespace string + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "Namespace created successfully", + args: args{ + ctx: context.Background(), + namespace: "ns-test", + }, + wantErr: false, + }, + { + // Description: If the namespace is blank, an error should be returned + name: "Namespace creation failed", + args: args{ + ctx: context.Background(), + namespace: "", + }, + wantErr: true, + }, + } + for _, tt := range tests { + kubeClient := fake.NewSimpleClientset() + t.Run(tt.name, func(t *testing.T) { + err := getNamespaceCreated(tt.args.ctx, kubeClient.CoreV1(), tt.args.namespace) + if (err != nil) != tt.wantErr { + t.Errorf("getNamespaceCreated() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/restapi/configure_console.go b/restapi/configure_console.go index 5da808b6e..9b4e54b05 100644 --- a/restapi/configure_console.go +++ b/restapi/configure_console.go @@ -133,6 +133,8 @@ func configureAPI(api *operations.ConsoleAPI) http.Handler { registerDirectCSIHandlers(api) // Volumes handlers registerVolumesHandlers(api) + // Namespaces handlers + registerNamespaceHandlers(api) api.PreServerShutdown = func() {} diff --git a/restapi/embedded_spec.go b/restapi/embedded_spec.go index 94e95b367..c4f54822c 100644 --- a/restapi/embedded_spec.go +++ b/restapi/embedded_spec.go @@ -2440,6 +2440,36 @@ func init() { } } }, + "/namespace": { + "post": { + "tags": [ + "AdminAPI" + ], + "summary": "Creates a new Namespace with given information", + "operationId": "CreateNamespace", + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/namespace" + } + } + ], + "responses": { + "201": { + "description": "A successful response." + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + } + }, "/namespaces/{namespace}/resourcequotas/{resource-quota-name}": { "get": { "tags": [ @@ -5645,6 +5675,17 @@ func init() { } } }, + "namespace": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, "nodeLabels": { "type": "object", "additionalProperties": { @@ -9764,6 +9805,36 @@ func init() { } } }, + "/namespace": { + "post": { + "tags": [ + "AdminAPI" + ], + "summary": "Creates a new Namespace with given information", + "operationId": "CreateNamespace", + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/namespace" + } + } + ], + "responses": { + "201": { + "description": "A successful response." + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + } + }, "/namespaces/{namespace}/resourcequotas/{resource-quota-name}": { "get": { "tags": [ @@ -13597,6 +13668,17 @@ func init() { } } }, + "namespace": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, "nodeLabels": { "type": "object", "additionalProperties": { diff --git a/restapi/operations/admin_api/create_namespace.go b/restapi/operations/admin_api/create_namespace.go new file mode 100644 index 000000000..96f625006 --- /dev/null +++ b/restapi/operations/admin_api/create_namespace.go @@ -0,0 +1,88 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2021 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" +) + +// CreateNamespaceHandlerFunc turns a function with the right signature into a create namespace handler +type CreateNamespaceHandlerFunc func(CreateNamespaceParams, *models.Principal) middleware.Responder + +// Handle executing the request and returning a response +func (fn CreateNamespaceHandlerFunc) Handle(params CreateNamespaceParams, principal *models.Principal) middleware.Responder { + return fn(params, principal) +} + +// CreateNamespaceHandler interface for that can handle valid create namespace params +type CreateNamespaceHandler interface { + Handle(CreateNamespaceParams, *models.Principal) middleware.Responder +} + +// NewCreateNamespace creates a new http.Handler for the create namespace operation +func NewCreateNamespace(ctx *middleware.Context, handler CreateNamespaceHandler) *CreateNamespace { + return &CreateNamespace{Context: ctx, Handler: handler} +} + +/* CreateNamespace swagger:route POST /namespace AdminAPI createNamespace + +Creates a new Namespace with given information + +*/ +type CreateNamespace struct { + Context *middleware.Context + Handler CreateNamespaceHandler +} + +func (o *CreateNamespace) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewCreateNamespaceParams() + 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/create_namespace_parameters.go b/restapi/operations/admin_api/create_namespace_parameters.go new file mode 100644 index 000000000..0b526f6c7 --- /dev/null +++ b/restapi/operations/admin_api/create_namespace_parameters.go @@ -0,0 +1,102 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2021 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 ( + "context" + "io" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + "github.com/minio/console/models" +) + +// NewCreateNamespaceParams creates a new CreateNamespaceParams object +// +// There are no default values defined in the spec. +func NewCreateNamespaceParams() CreateNamespaceParams { + + return CreateNamespaceParams{} +} + +// CreateNamespaceParams contains all the bound params for the create namespace operation +// typically these are obtained from a http.Request +// +// swagger:parameters CreateNamespace +type CreateNamespaceParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: body + */ + Body *models.Namespace +} + +// 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 NewCreateNamespaceParams() beforehand. +func (o *CreateNamespaceParams) 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.Namespace + 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) + } + + ctx := validate.WithOperationRequest(context.Background()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Body = &body + } + } + } else { + res = append(res, errors.Required("body", "body", "")) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/restapi/operations/admin_api/create_namespace_responses.go b/restapi/operations/admin_api/create_namespace_responses.go new file mode 100644 index 000000000..6d670667c --- /dev/null +++ b/restapi/operations/admin_api/create_namespace_responses.go @@ -0,0 +1,113 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2021 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" +) + +// CreateNamespaceCreatedCode is the HTTP code returned for type CreateNamespaceCreated +const CreateNamespaceCreatedCode int = 201 + +/*CreateNamespaceCreated A successful response. + +swagger:response createNamespaceCreated +*/ +type CreateNamespaceCreated struct { +} + +// NewCreateNamespaceCreated creates CreateNamespaceCreated with default headers values +func NewCreateNamespaceCreated() *CreateNamespaceCreated { + + return &CreateNamespaceCreated{} +} + +// WriteResponse to the client +func (o *CreateNamespaceCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(201) +} + +/*CreateNamespaceDefault Generic error response. + +swagger:response createNamespaceDefault +*/ +type CreateNamespaceDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewCreateNamespaceDefault creates CreateNamespaceDefault with default headers values +func NewCreateNamespaceDefault(code int) *CreateNamespaceDefault { + if code <= 0 { + code = 500 + } + + return &CreateNamespaceDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the create namespace default response +func (o *CreateNamespaceDefault) WithStatusCode(code int) *CreateNamespaceDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the create namespace default response +func (o *CreateNamespaceDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the create namespace default response +func (o *CreateNamespaceDefault) WithPayload(payload *models.Error) *CreateNamespaceDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the create namespace default response +func (o *CreateNamespaceDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *CreateNamespaceDefault) 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/create_namespace_urlbuilder.go b/restapi/operations/admin_api/create_namespace_urlbuilder.go new file mode 100644 index 000000000..90ac21690 --- /dev/null +++ b/restapi/operations/admin_api/create_namespace_urlbuilder.go @@ -0,0 +1,104 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2021 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" +) + +// CreateNamespaceURL generates an URL for the create namespace operation +type CreateNamespaceURL struct { + _basePath string +} + +// 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 *CreateNamespaceURL) WithBasePath(bp string) *CreateNamespaceURL { + 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 *CreateNamespaceURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *CreateNamespaceURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/namespace" + + _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 *CreateNamespaceURL) 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 *CreateNamespaceURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *CreateNamespaceURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on CreateNamespaceURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on CreateNamespaceURL") + } + + 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 *CreateNamespaceURL) 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 739537fbe..e7f24c696 100644 --- a/restapi/operations/console_api.go +++ b/restapi/operations/console_api.go @@ -114,6 +114,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI { UserAPICreateBucketEventHandler: user_api.CreateBucketEventHandlerFunc(func(params user_api.CreateBucketEventParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation user_api.CreateBucketEvent has not yet been implemented") }), + AdminAPICreateNamespaceHandler: admin_api.CreateNamespaceHandlerFunc(func(params admin_api.CreateNamespaceParams, principal *models.Principal) middleware.Responder { + return middleware.NotImplemented("operation admin_api.CreateNamespace has not yet been implemented") + }), UserAPICreateServiceAccountHandler: user_api.CreateServiceAccountHandlerFunc(func(params user_api.CreateServiceAccountParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation user_api.CreateServiceAccount has not yet been implemented") }), @@ -498,6 +501,8 @@ type ConsoleAPI struct { AdminAPIConfigInfoHandler admin_api.ConfigInfoHandler // UserAPICreateBucketEventHandler sets the operation handler for the create bucket event operation UserAPICreateBucketEventHandler user_api.CreateBucketEventHandler + // AdminAPICreateNamespaceHandler sets the operation handler for the create namespace operation + AdminAPICreateNamespaceHandler admin_api.CreateNamespaceHandler // UserAPICreateServiceAccountHandler sets the operation handler for the create service account operation UserAPICreateServiceAccountHandler user_api.CreateServiceAccountHandler // AdminAPICreateTenantHandler sets the operation handler for the create tenant operation @@ -831,6 +836,9 @@ func (o *ConsoleAPI) Validate() error { if o.UserAPICreateBucketEventHandler == nil { unregistered = append(unregistered, "user_api.CreateBucketEventHandler") } + if o.AdminAPICreateNamespaceHandler == nil { + unregistered = append(unregistered, "admin_api.CreateNamespaceHandler") + } if o.UserAPICreateServiceAccountHandler == nil { unregistered = append(unregistered, "user_api.CreateServiceAccountHandler") } @@ -1297,6 +1305,10 @@ func (o *ConsoleAPI) initHandlerCache() { if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) } + o.handlers["POST"]["/namespace"] = admin_api.NewCreateNamespace(o.context, o.AdminAPICreateNamespaceHandler) + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) + } o.handlers["POST"]["/service-accounts"] = user_api.NewCreateServiceAccount(o.context, o.UserAPICreateServiceAccountHandler) if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) diff --git a/swagger.yml b/swagger.yml index 0d368b6e0..dc5a72112 100644 --- a/swagger.yml +++ b/swagger.yml @@ -2171,6 +2171,26 @@ paths: $ref: "#/definitions/error" tags: - AdminAPI + + /namespace: + post: + summary: Creates a new Namespace with given information + operationId: CreateNamespace + parameters: + - name: body + in: body + required: true + schema: + $ref: "#/definitions/namespace" + responses: + 201: + description: A successful response. + default: + description: Generic error response. + schema: + $ref: "#/definitions/error" + tags: + - AdminAPI /namespaces/{namespace}/tenants: get: @@ -5218,5 +5238,12 @@ definitions: type: array items: type: string - + + namespace: + type: object + required: + - name + properties: + name: + type: string