New Login Design (#1675)

Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
This commit is contained in:
Daniel Valdivia
2022-03-07 17:56:42 -08:00
committed by GitHub
parent 5e42f96eaf
commit 8e21039ef1
34 changed files with 3018 additions and 175 deletions

View File

@@ -75,6 +75,7 @@ func configureAPI(api *operations.OperatorAPI) http.Handler {
// Register login handlers
registerLoginHandlers(api)
registerSessionHandlers(api)
registerVersionHandlers(api)
// Operator Console
// Register tenant handlers

View File

@@ -52,6 +52,30 @@ func init() {
},
"basePath": "/api/v1",
"paths": {
"/check-version": {
"get": {
"security": [],
"tags": [
"UserAPI"
],
"summary": "Checks the current Operator version against the latest",
"operationId": "CheckMinIOVersion”",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/checkOperatorVersionResponse"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/cluster/allocatable-resources": {
"get": {
"tags": [
@@ -1863,6 +1887,17 @@ func init() {
}
}
},
"checkOperatorVersionResponse": {
"type": "object",
"properties": {
"current_version": {
"type": "string"
},
"latest_version": {
"type": "string"
}
}
},
"configureTenantRequest": {
"type": "object",
"properties": {
@@ -3921,6 +3956,30 @@ func init() {
},
"basePath": "/api/v1",
"paths": {
"/check-version": {
"get": {
"security": [],
"tags": [
"UserAPI"
],
"summary": "Checks the current Operator version against the latest",
"operationId": "CheckMinIOVersion”",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/checkOperatorVersionResponse"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/cluster/allocatable-resources": {
"get": {
"tags": [
@@ -6583,6 +6642,17 @@ func init() {
}
}
},
"checkOperatorVersionResponse": {
"type": "object",
"properties": {
"current_version": {
"type": "string"
},
"latest_version": {
"type": "string"
}
}
},
"configureTenantRequest": {
"type": "object",
"properties": {

View File

@@ -63,6 +63,9 @@ func NewOperatorAPI(spec *loads.Document) *OperatorAPI {
JSONProducer: runtime.JSONProducer(),
UserAPICheckMinIOVersionHandler: user_api.CheckMinIOVersionHandlerFunc(func(params user_api.CheckMinIOVersionParams) middleware.Responder {
return middleware.NotImplemented("operation user_api.CheckMinIOVersion has not yet been implemented")
}),
OperatorAPICreateNamespaceHandler: operator_api.CreateNamespaceHandlerFunc(func(params operator_api.CreateNamespaceParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation operator_api.CreateNamespace has not yet been implemented")
}),
@@ -253,6 +256,8 @@ type OperatorAPI struct {
// APIAuthorizer provides access control (ACL/RBAC/ABAC) by providing access to the request and authenticated principal
APIAuthorizer runtime.Authorizer
// UserAPICheckMinIOVersionHandler sets the operation handler for the check min i o version operation
UserAPICheckMinIOVersionHandler user_api.CheckMinIOVersionHandler
// OperatorAPICreateNamespaceHandler sets the operation handler for the create namespace operation
OperatorAPICreateNamespaceHandler operator_api.CreateNamespaceHandler
// OperatorAPICreateTenantHandler sets the operation handler for the create tenant operation
@@ -428,6 +433,9 @@ func (o *OperatorAPI) Validate() error {
unregistered = append(unregistered, "KeyAuth")
}
if o.UserAPICheckMinIOVersionHandler == nil {
unregistered = append(unregistered, "user_api.CheckMinIOVersionHandler")
}
if o.OperatorAPICreateNamespaceHandler == nil {
unregistered = append(unregistered, "operator_api.CreateNamespaceHandler")
}
@@ -667,6 +675,10 @@ func (o *OperatorAPI) initHandlerCache() {
o.handlers = make(map[string]map[string]http.Handler)
}
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/check-version"] = user_api.NewCheckMinIOVersion(o.context, o.UserAPICheckMinIOVersionHandler)
if o.handlers["POST"] == nil {
o.handlers["POST"] = make(map[string]http.Handler)
}

View File

@@ -0,0 +1,73 @@
// 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 <http://www.gnu.org/licenses/>.
//
package user_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"
)
// CheckMinIOVersionHandlerFunc turns a function with the right signature into a check min i o version handler
type CheckMinIOVersionHandlerFunc func(CheckMinIOVersionParams) middleware.Responder
// Handle executing the request and returning a response
func (fn CheckMinIOVersionHandlerFunc) Handle(params CheckMinIOVersionParams) middleware.Responder {
return fn(params)
}
// CheckMinIOVersionHandler interface for that can handle valid check min i o version params
type CheckMinIOVersionHandler interface {
Handle(CheckMinIOVersionParams) middleware.Responder
}
// NewCheckMinIOVersion creates a new http.Handler for the check min i o version operation
func NewCheckMinIOVersion(ctx *middleware.Context, handler CheckMinIOVersionHandler) *CheckMinIOVersion {
return &CheckMinIOVersion{Context: ctx, Handler: handler}
}
/* CheckMinIOVersion swagger:route GET /check-version UserAPI checkMinIOVersion
Checks the current Operator version against the latest
*/
type CheckMinIOVersion struct {
Context *middleware.Context
Handler CheckMinIOVersionHandler
}
func (o *CheckMinIOVersion) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewCheckMinIOVersionParams()
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) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}

View File

@@ -0,0 +1,63 @@
// 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 <http://www.gnu.org/licenses/>.
//
package user_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"
)
// NewCheckMinIOVersionParams creates a new CheckMinIOVersionParams object
//
// There are no default values defined in the spec.
func NewCheckMinIOVersionParams() CheckMinIOVersionParams {
return CheckMinIOVersionParams{}
}
// CheckMinIOVersionParams contains all the bound params for the check min i o version operation
// typically these are obtained from a http.Request
//
// swagger:parameters CheckMinIOVersion”
type CheckMinIOVersionParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
}
// 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 NewCheckMinIOVersionParams() beforehand.
func (o *CheckMinIOVersionParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,133 @@
// 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 <http://www.gnu.org/licenses/>.
//
package user_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"
)
// CheckMinIOVersionOKCode is the HTTP code returned for type CheckMinIOVersionOK
const CheckMinIOVersionOKCode int = 200
/*CheckMinIOVersionOK A successful response.
swagger:response checkMinIOVersionOK
*/
type CheckMinIOVersionOK struct {
/*
In: Body
*/
Payload *models.CheckOperatorVersionResponse `json:"body,omitempty"`
}
// NewCheckMinIOVersionOK creates CheckMinIOVersionOK with default headers values
func NewCheckMinIOVersionOK() *CheckMinIOVersionOK {
return &CheckMinIOVersionOK{}
}
// WithPayload adds the payload to the check min i o version o k response
func (o *CheckMinIOVersionOK) WithPayload(payload *models.CheckOperatorVersionResponse) *CheckMinIOVersionOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the check min i o version o k response
func (o *CheckMinIOVersionOK) SetPayload(payload *models.CheckOperatorVersionResponse) {
o.Payload = payload
}
// WriteResponse to the client
func (o *CheckMinIOVersionOK) 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
}
}
}
/*CheckMinIOVersionDefault Generic error response.
swagger:response checkMinIOVersionDefault
*/
type CheckMinIOVersionDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewCheckMinIOVersionDefault creates CheckMinIOVersionDefault with default headers values
func NewCheckMinIOVersionDefault(code int) *CheckMinIOVersionDefault {
if code <= 0 {
code = 500
}
return &CheckMinIOVersionDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the check min i o version default response
func (o *CheckMinIOVersionDefault) WithStatusCode(code int) *CheckMinIOVersionDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the check min i o version default response
func (o *CheckMinIOVersionDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the check min i o version default response
func (o *CheckMinIOVersionDefault) WithPayload(payload *models.Error) *CheckMinIOVersionDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the check min i o version default response
func (o *CheckMinIOVersionDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *CheckMinIOVersionDefault) 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
}
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
//
package user_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"
)
// CheckMinIOVersionURL generates an URL for the check min i o version operation
type CheckMinIOVersionURL 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 *CheckMinIOVersionURL) WithBasePath(bp string) *CheckMinIOVersionURL {
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 *CheckMinIOVersionURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *CheckMinIOVersionURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/check-version"
_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 *CheckMinIOVersionURL) 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 *CheckMinIOVersionURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *CheckMinIOVersionURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on CheckMinIOVersionURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on CheckMinIOVersionURL")
}
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 *CheckMinIOVersionURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -33,6 +33,8 @@ import (
"strings"
"time"
utils2 "github.com/minio/console/pkg/utils"
"github.com/dustin/go-humanize"
"github.com/minio/console/restapi"
@@ -1039,7 +1041,7 @@ func setImageRegistry(ctx context.Context, req *models.ImageRegistry, clientset
}
// updateTenantAction does an update on the minioTenant by patching the desired changes
func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, clientset v1.CoreV1Interface, httpCl cluster.HTTPClientI, namespace string, params operator_api.UpdateTenantParams) error {
func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, clientset v1.CoreV1Interface, httpCl utils2.HTTPClientI, namespace string, params operator_api.UpdateTenantParams) error {
imageToUpdate := params.Body.Image
imageRegistryReq := params.Body.ImageRegistry
@@ -1145,7 +1147,7 @@ func getUpdateTenantResponse(session *models.Principal, params operator_api.Upda
opClient := &operatorClient{
client: opClientClientSet,
}
httpC := &cluster.HTTPClient{
httpC := &utils2.HTTPClient{
Client: &http.Client{
Timeout: 4 * time.Second,
},

View File

@@ -28,10 +28,11 @@ import (
"testing"
"time"
"github.com/minio/console/pkg/utils"
"github.com/minio/console/operatorapi/operations/operator_api"
"github.com/go-openapi/swag"
"github.com/minio/console/cluster"
"github.com/minio/console/models"
miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2"
corev1 "k8s.io/api/core/v1"
@@ -895,7 +896,7 @@ func Test_UpdateTenantAction(t *testing.T) {
type args struct {
ctx context.Context
operatorClient OperatorClientI
httpCl cluster.HTTPClientI
httpCl utils.HTTPClientI
nameSpace string
tenantName string
mockTenantPatch func(ctx context.Context, namespace string, tenantName string, pt types.PatchType, data []byte, options metav1.PatchOptions) (*miniov2.Tenant, error)

View File

@@ -0,0 +1,53 @@
// This file is part of MinIO Console Server
// Copyright (c) 2022 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 operatorapi
import (
"github.com/go-openapi/runtime/middleware"
"github.com/minio/console/models"
"github.com/minio/console/operatorapi/operations"
"github.com/minio/console/operatorapi/operations/user_api"
"net/http"
"time"
"github.com/minio/console/pkg/utils"
)
func registerVersionHandlers(api *operations.OperatorAPI) {
api.UserAPICheckMinIOVersionHandler = user_api.CheckMinIOVersionHandlerFunc(func(params user_api.CheckMinIOVersionParams) middleware.Responder {
versionResponse, err := getVersionResponse()
if err != nil {
return user_api.NewCheckMinIOVersionDefault(int(err.Code)).WithPayload(err)
}
return user_api.NewCheckMinIOVersionOK().WithPayload(versionResponse)
})
}
// getSessionResponse parse the token of the current session and returns a list of allowed actions to render in the UI
func getVersionResponse() (*models.CheckOperatorVersionResponse, *models.Error) {
ver, err := utils.GetLatestMinIOImage(&utils.HTTPClient{
Client: &http.Client{
Timeout: 15 * time.Second,
}})
if err != nil {
return nil, prepareError(err)
}
return &models.CheckOperatorVersionResponse{
LatestVersion: *ver,
}, nil
}