From 5c5e84b289ab994a5250dee7b3f23f69b1edc44d Mon Sep 17 00:00:00 2001 From: Alex <33497058+bexsoft@users.noreply.github.com> Date: Thu, 9 Apr 2020 18:39:49 -0500 Subject: [PATCH] Implemented User-Groups integration for mcs (#62) Implemented user-groups integration for mcs, this allows to store the user groups during the user creation. Co-authored-by: Benjamin Perez --- models/add_user_request.go | 17 ++ models/update_user.go | 98 +++++++++ .../Console/Buckets/ListBuckets/AddBucket.tsx | 4 - .../src/screens/Console/Users/AddUser.tsx | 8 +- restapi/admin_users.go | 62 +++++- restapi/admin_users_test.go | 49 ++++- restapi/embedded_spec.go | 186 +++++++++++++++++- restapi/operations/admin_api/get_user.go | 90 +++++++++ restapi/operations/admin_api/get_user_info.go | 90 +++++++++ .../admin_api/get_user_info_parameters.go | 89 +++++++++ .../admin_api/get_user_info_responses.go | 133 +++++++++++++ .../admin_api/get_user_info_urlbuilder.go | 116 +++++++++++ .../admin_api/get_user_parameters.go | 89 +++++++++ .../admin_api/get_user_responses.go | 133 +++++++++++++ .../admin_api/get_user_urlbuilder.go | 116 +++++++++++ .../operations/admin_api/update_user_info.go | 90 +++++++++ .../admin_api/update_user_info_parameters.go | 120 +++++++++++ .../admin_api/update_user_info_responses.go | 133 +++++++++++++ .../admin_api/update_user_info_urlbuilder.go | 116 +++++++++++ restapi/operations/mcs_api.go | 24 +++ swagger.yml | 61 ++++++ 21 files changed, 1803 insertions(+), 21 deletions(-) create mode 100644 models/update_user.go create mode 100644 restapi/operations/admin_api/get_user.go create mode 100644 restapi/operations/admin_api/get_user_info.go create mode 100644 restapi/operations/admin_api/get_user_info_parameters.go create mode 100644 restapi/operations/admin_api/get_user_info_responses.go create mode 100644 restapi/operations/admin_api/get_user_info_urlbuilder.go create mode 100644 restapi/operations/admin_api/get_user_parameters.go create mode 100644 restapi/operations/admin_api/get_user_responses.go create mode 100644 restapi/operations/admin_api/get_user_urlbuilder.go create mode 100644 restapi/operations/admin_api/update_user_info.go create mode 100644 restapi/operations/admin_api/update_user_info_parameters.go create mode 100644 restapi/operations/admin_api/update_user_info_responses.go create mode 100644 restapi/operations/admin_api/update_user_info_urlbuilder.go diff --git a/models/add_user_request.go b/models/add_user_request.go index 4d2264e8a..014752bc3 100644 --- a/models/add_user_request.go +++ b/models/add_user_request.go @@ -38,6 +38,10 @@ type AddUserRequest struct { // Required: true AccessKey *string `json:"accessKey"` + // groups + // Required: true + Groups []string `json:"groups"` + // secret key // Required: true SecretKey *string `json:"secretKey"` @@ -51,6 +55,10 @@ func (m *AddUserRequest) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateGroups(formats); err != nil { + res = append(res, err) + } + if err := m.validateSecretKey(formats); err != nil { res = append(res, err) } @@ -70,6 +78,15 @@ func (m *AddUserRequest) validateAccessKey(formats strfmt.Registry) error { return nil } +func (m *AddUserRequest) validateGroups(formats strfmt.Registry) error { + + if err := validate.Required("groups", "body", m.Groups); err != nil { + return err + } + + return nil +} + func (m *AddUserRequest) validateSecretKey(formats strfmt.Registry) error { if err := validate.Required("secretKey", "body", m.SecretKey); err != nil { diff --git a/models/update_user.go b/models/update_user.go new file mode 100644 index 000000000..f913697d2 --- /dev/null +++ b/models/update_user.go @@ -0,0 +1,98 @@ +// 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/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// UpdateUser update user +// +// swagger:model updateUser +type UpdateUser struct { + + // groups + // Required: true + Groups []string `json:"groups"` + + // status + // Required: true + Status *string `json:"status"` +} + +// Validate validates this update user +func (m *UpdateUser) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateGroups(formats); err != nil { + res = append(res, err) + } + + if err := m.validateStatus(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UpdateUser) validateGroups(formats strfmt.Registry) error { + + if err := validate.Required("groups", "body", m.Groups); err != nil { + return err + } + + return nil +} + +func (m *UpdateUser) validateStatus(formats strfmt.Registry) error { + + if err := validate.Required("status", "body", m.Status); err != nil { + return err + } + + return nil +} + +// MarshalBinary interface implementation +func (m *UpdateUser) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *UpdateUser) UnmarshalBinary(b []byte) error { + var res UpdateUser + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/portal-ui/src/screens/Console/Buckets/ListBuckets/AddBucket.tsx b/portal-ui/src/screens/Console/Buckets/ListBuckets/AddBucket.tsx index 75ad3f8ea..6ad610ee1 100644 --- a/portal-ui/src/screens/Console/Buckets/ListBuckets/AddBucket.tsx +++ b/portal-ui/src/screens/Console/Buckets/ListBuckets/AddBucket.tsx @@ -23,11 +23,7 @@ import { Dialog, DialogContent, DialogTitle, - FormControl, - InputLabel, LinearProgress, - MenuItem, - Select, TextField } from "@material-ui/core"; import { createStyles, Theme, withStyles } from "@material-ui/core/styles"; diff --git a/portal-ui/src/screens/Console/Users/AddUser.tsx b/portal-ui/src/screens/Console/Users/AddUser.tsx index 87aed6393..4927b12b7 100644 --- a/portal-ui/src/screens/Console/Users/AddUser.tsx +++ b/portal-ui/src/screens/Console/Users/AddUser.tsx @@ -86,7 +86,7 @@ class AddUserContent extends React.Component< saveRecord(event: React.FormEvent) { event.preventDefault(); - const { accessKey, addLoading, secretKey } = this.state; + const { accessKey, addLoading, secretKey, selectedGroups } = this.state; const { selectedUser } = this.props; if (addLoading) { return; @@ -96,7 +96,8 @@ class AddUserContent extends React.Component< api .invoke("PUT", `/api/v1/users/${selectedUser.accessKey}`, { accessKey, - secretKey: secretKey !== "" ? null : secretKey + secretKey: secretKey !== "" ? null : secretKey, + groups: selectedGroups }) .then(res => { this.setState( @@ -119,7 +120,8 @@ class AddUserContent extends React.Component< api .invoke("POST", "/api/v1/users", { accessKey, - secretKey + secretKey, + groups: selectedGroups }) .then(res => { this.setState( diff --git a/restapi/admin_users.go b/restapi/admin_users.go index 224756897..cbd66f2fc 100644 --- a/restapi/admin_users.go +++ b/restapi/admin_users.go @@ -65,6 +65,15 @@ func registerUsersHandlers(api *operations.McsAPI) { return admin_api.NewUpdateUserGroupsOK().WithPayload(userUpdateResponse) }) + // Get User + api.AdminAPIGetUserInfoHandler = admin_api.GetUserInfoHandlerFunc(func(params admin_api.GetUserInfoParams, principal *models.Principal) middleware.Responder { + userInfoResponse, err := getUserInfoResponse(params) + if err != nil { + return admin_api.NewGetUserDefault(500).WithPayload(&models.Error{Code: 500, Message: swag.String(err.Error())}) + } + + return admin_api.NewGetUserOK().WithPayload(userInfoResponse) + }) } func listUsers(ctx context.Context, client MinioAdmin) ([]*models.User, error) { @@ -116,18 +125,28 @@ func getListUsersResponse() (*models.ListUsersResponse, error) { } // addUser invokes adding a users on `MinioAdmin` and builds the response `models.User` -func addUser(ctx context.Context, client MinioAdmin, accessKey, secretKey *string) (*models.User, error) { +func addUser(ctx context.Context, client MinioAdmin, accessKey, secretKey *string, groups []string) (*models.User, error) { // Calls into MinIO to add a new user if there's an error return it - err := client.addUser(ctx, *accessKey, *secretKey) - if err != nil { + if err := client.addUser(ctx, *accessKey, *secretKey); err != nil { return nil, err } - userElem := &models.User{ - AccessKey: *accessKey, + if len(groups) > 0 { + userElem, errUG := updateUserGroups(ctx, client, *accessKey, groups) + + if errUG != nil { + return nil, errUG + } + return userElem, nil } - return userElem, nil + userRet := &models.User{ + AccessKey: *accessKey, + MemberOf: nil, + Policy: "", + Status: "", + } + return userRet, nil } func getUserAddResponse(params admin_api.AddUserParams) (*models.User, error) { @@ -141,7 +160,7 @@ func getUserAddResponse(params admin_api.AddUserParams) (*models.User, error) { // defining the client to be used adminClient := adminClient{client: mAdmin} - user, err := addUser(ctx, adminClient, params.Body.AccessKey, params.Body.SecretKey) + user, err := addUser(ctx, adminClient, params.Body.AccessKey, params.Body.SecretKey, params.Body.Groups) if err != nil { log.Println("error adding user:", err) return nil, err @@ -189,6 +208,35 @@ func getUserInfo(ctx context.Context, client MinioAdmin, accessKey string) (*mad return &userInfo, nil } +func getUserInfoResponse(params admin_api.GetUserInfoParams) (*models.User, error) { + ctx := context.Background() + + mAdmin, err := newMAdminClient() + if err != nil { + log.Println("error creating Madmin Client:", err) + return nil, err + } + + // create a minioClient interface implementation + // defining the client to be used + adminClient := adminClient{client: mAdmin} + + user, err := getUserInfo(ctx, adminClient, params.Name) + if err != nil { + log.Println("error getting user:", err) + return nil, err + } + + userInformation := &models.User{ + AccessKey: params.Name, + MemberOf: user.MemberOf, + Policy: user.PolicyName, + Status: string(user.Status), + } + + return userInformation, nil +} + // updateUserGroups invokes getUserInfo() to get the old groups from the user, // then we merge the list with the new groups list to have a shorter iteration between groups and we do a comparison between the current and old groups. // We delete or update the groups according the location in each list and send the user with the new groups from `MinioAdmin` to the client diff --git a/restapi/admin_users_test.go b/restapi/admin_users_test.go index 917b45f61..9cef0b9fc 100644 --- a/restapi/admin_users_test.go +++ b/restapi/admin_users_test.go @@ -79,6 +79,7 @@ func TestListUsers(t *testing.T) { minioListUsersMock = func() (map[string]madmin.UserInfo, error) { return mockUserMap, nil } + // get list users response this response should have Name, CreationDate, Size and Access // as part of of each user function := "listUsers()" @@ -113,14 +114,30 @@ func TestAddUser(t *testing.T) { // Test-1: valid case of adding a user with a proper access key accessKey := "ABCDEFGHI" secretKey := "ABCDEFGHIABCDEFGHI" + groups := []string{"group1", "group2", "group3"} + emptyGroupTest := []string{} + mockResponse := &madmin.UserInfo{ + MemberOf: []string{"group1", "group2", "gropup3"}, + PolicyName: "", + Status: "enabled", + SecretKey: "", + } // mock function response from addUser() return no error minioAddUserMock = func(accessKey, secretKey string) error { return nil } - // adds a valid user to MinIO + + minioGetUserInfoMock = func(accessKey string) (madmin.UserInfo, error) { + return *mockResponse, nil + } + + minioUpdateGroupMembersMock = func(remove madmin.GroupAddRemove) error { + return nil + } + // Test-1: Add a user function := "addUser()" - user, err := addUser(ctx, adminClient, &accessKey, &secretKey) + user, err := addUser(ctx, adminClient, &accessKey, &secretKey, groups) if err != nil { t.Errorf("Failed on %s:, error occurred: %s", function, err.Error()) } @@ -128,16 +145,38 @@ func TestAddUser(t *testing.T) { assert.Nil(err, "Error is not null") // the same access key should be in the model users assert.Equal(user.AccessKey, accessKey) - // Test-1: valid case + + // Test-2 Add a user with empty groups list + user, err = addUser(ctx, adminClient, &accessKey, &secretKey, emptyGroupTest) + // no error should have been returned + assert.Nil(err, "Error is not null") + // the same access key should be in the model users + assert.Equal(user.AccessKey, accessKey) + + // Test-3: valid case accessKey = "AB" secretKey = "ABCDEFGHIABCDEFGHI" - // mock function response from addUser() return no error minioAddUserMock = func(accessKey, secretKey string) error { return errors.New("error") } - user, err = addUser(ctx, adminClient, &accessKey, &secretKey) + user, err = addUser(ctx, adminClient, &accessKey, &secretKey, groups) + + // no error should have been returned + assert.Nil(user, "User is not null") + assert.NotNil(err, "An error should have been returned") + + if assert.Error(err) { + assert.Equal("error", err.Error()) + } + + // Test-4: add groups function returns an error + minioUpdateGroupMembersMock = func(remove madmin.GroupAddRemove) error { + return errors.New("error") + } + + user, err = addUser(ctx, adminClient, &accessKey, &secretKey, groups) // no error should have been returned assert.Nil(user, "User is not null") diff --git a/restapi/embedded_spec.go b/restapi/embedded_spec.go index 38dd21d20..ab2199218 100644 --- a/restapi/embedded_spec.go +++ b/restapi/embedded_spec.go @@ -1097,6 +1097,72 @@ func init() { } }, "/users/{name}": { + "get": { + "tags": [ + "AdminAPI" + ], + "summary": "Get User Info", + "operationId": "GetUserInfo", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/user" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + }, + "put": { + "tags": [ + "AdminAPI" + ], + "summary": "Update User Info", + "operationId": "UpdateUserInfo", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/updateUser" + } + } + ], + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/user" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + }, "delete": { "tags": [ "AdminAPI" @@ -1202,12 +1268,19 @@ func init() { "type": "object", "required": [ "accessKey", - "secretKey" + "secretKey", + "groups" ], "properties": { "accessKey": { "type": "string" }, + "groups": { + "type": "array", + "items": { + "type": "string" + } + }, "secretKey": { "type": "string" } @@ -1746,6 +1819,24 @@ func init() { } } }, + "updateUser": { + "type": "object", + "required": [ + "status", + "groups" + ], + "properties": { + "groups": { + "type": "array", + "items": { + "type": "string" + } + }, + "status": { + "type": "string" + } + } + }, "updateUserGroups": { "type": "object", "required": [ @@ -2858,6 +2949,72 @@ func init() { } }, "/users/{name}": { + "get": { + "tags": [ + "AdminAPI" + ], + "summary": "Get User Info", + "operationId": "GetUserInfo", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/user" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + }, + "put": { + "tags": [ + "AdminAPI" + ], + "summary": "Update User Info", + "operationId": "UpdateUserInfo", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/updateUser" + } + } + ], + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/user" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + }, "delete": { "tags": [ "AdminAPI" @@ -2963,12 +3120,19 @@ func init() { "type": "object", "required": [ "accessKey", - "secretKey" + "secretKey", + "groups" ], "properties": { "accessKey": { "type": "string" }, + "groups": { + "type": "array", + "items": { + "type": "string" + } + }, "secretKey": { "type": "string" } @@ -3507,6 +3671,24 @@ func init() { } } }, + "updateUser": { + "type": "object", + "required": [ + "status", + "groups" + ], + "properties": { + "groups": { + "type": "array", + "items": { + "type": "string" + } + }, + "status": { + "type": "string" + } + } + }, "updateUserGroups": { "type": "object", "required": [ diff --git a/restapi/operations/admin_api/get_user.go b/restapi/operations/admin_api/get_user.go new file mode 100644 index 000000000..4c70d0300 --- /dev/null +++ b/restapi/operations/admin_api/get_user.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/mcs/models" +) + +// GetUserHandlerFunc turns a function with the right signature into a get user handler +type GetUserHandlerFunc func(GetUserParams, *models.Principal) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetUserHandlerFunc) Handle(params GetUserParams, principal *models.Principal) middleware.Responder { + return fn(params, principal) +} + +// GetUserHandler interface for that can handle valid get user params +type GetUserHandler interface { + Handle(GetUserParams, *models.Principal) middleware.Responder +} + +// NewGetUser creates a new http.Handler for the get user operation +func NewGetUser(ctx *middleware.Context, handler GetUserHandler) *GetUser { + return &GetUser{Context: ctx, Handler: handler} +} + +/*GetUser swagger:route GET /users/{name} AdminAPI getUser + +Get User + +*/ +type GetUser struct { + Context *middleware.Context + Handler GetUserHandler +} + +func (o *GetUser) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewGetUserParams() + + 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_user_info.go b/restapi/operations/admin_api/get_user_info.go new file mode 100644 index 000000000..06dac10ac --- /dev/null +++ b/restapi/operations/admin_api/get_user_info.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/mcs/models" +) + +// GetUserInfoHandlerFunc turns a function with the right signature into a get user info handler +type GetUserInfoHandlerFunc func(GetUserInfoParams, *models.Principal) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetUserInfoHandlerFunc) Handle(params GetUserInfoParams, principal *models.Principal) middleware.Responder { + return fn(params, principal) +} + +// GetUserInfoHandler interface for that can handle valid get user info params +type GetUserInfoHandler interface { + Handle(GetUserInfoParams, *models.Principal) middleware.Responder +} + +// NewGetUserInfo creates a new http.Handler for the get user info operation +func NewGetUserInfo(ctx *middleware.Context, handler GetUserInfoHandler) *GetUserInfo { + return &GetUserInfo{Context: ctx, Handler: handler} +} + +/*GetUserInfo swagger:route GET /users/{name} AdminAPI getUserInfo + +Get User Info + +*/ +type GetUserInfo struct { + Context *middleware.Context + Handler GetUserInfoHandler +} + +func (o *GetUserInfo) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewGetUserInfoParams() + + 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_user_info_parameters.go b/restapi/operations/admin_api/get_user_info_parameters.go new file mode 100644 index 000000000..7466c399c --- /dev/null +++ b/restapi/operations/admin_api/get_user_info_parameters.go @@ -0,0 +1,89 @@ +// 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" +) + +// NewGetUserInfoParams creates a new GetUserInfoParams object +// no default values defined in spec. +func NewGetUserInfoParams() GetUserInfoParams { + + return GetUserInfoParams{} +} + +// GetUserInfoParams contains all the bound params for the get user info operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetUserInfo +type GetUserInfoParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name 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 NewGetUserInfoParams() beforehand. +func (o *GetUserInfoParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *GetUserInfoParams) bindName(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.Name = raw + + return nil +} diff --git a/restapi/operations/admin_api/get_user_info_responses.go b/restapi/operations/admin_api/get_user_info_responses.go new file mode 100644 index 000000000..6db8d6024 --- /dev/null +++ b/restapi/operations/admin_api/get_user_info_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/mcs/models" +) + +// GetUserInfoOKCode is the HTTP code returned for type GetUserInfoOK +const GetUserInfoOKCode int = 200 + +/*GetUserInfoOK A successful response. + +swagger:response getUserInfoOK +*/ +type GetUserInfoOK struct { + + /* + In: Body + */ + Payload *models.User `json:"body,omitempty"` +} + +// NewGetUserInfoOK creates GetUserInfoOK with default headers values +func NewGetUserInfoOK() *GetUserInfoOK { + + return &GetUserInfoOK{} +} + +// WithPayload adds the payload to the get user info o k response +func (o *GetUserInfoOK) WithPayload(payload *models.User) *GetUserInfoOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get user info o k response +func (o *GetUserInfoOK) SetPayload(payload *models.User) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetUserInfoOK) 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 + } + } +} + +/*GetUserInfoDefault Generic error response. + +swagger:response getUserInfoDefault +*/ +type GetUserInfoDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetUserInfoDefault creates GetUserInfoDefault with default headers values +func NewGetUserInfoDefault(code int) *GetUserInfoDefault { + if code <= 0 { + code = 500 + } + + return &GetUserInfoDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the get user info default response +func (o *GetUserInfoDefault) WithStatusCode(code int) *GetUserInfoDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the get user info default response +func (o *GetUserInfoDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the get user info default response +func (o *GetUserInfoDefault) WithPayload(payload *models.Error) *GetUserInfoDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get user info default response +func (o *GetUserInfoDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetUserInfoDefault) 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_user_info_urlbuilder.go b/restapi/operations/admin_api/get_user_info_urlbuilder.go new file mode 100644 index 000000000..539da6304 --- /dev/null +++ b/restapi/operations/admin_api/get_user_info_urlbuilder.go @@ -0,0 +1,116 @@ +// 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" +) + +// GetUserInfoURL generates an URL for the get user info operation +type GetUserInfoURL struct { + Name 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 *GetUserInfoURL) WithBasePath(bp string) *GetUserInfoURL { + 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 *GetUserInfoURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetUserInfoURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/users/{name}" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on GetUserInfoURL") + } + + _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 *GetUserInfoURL) 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 *GetUserInfoURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetUserInfoURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetUserInfoURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetUserInfoURL") + } + + 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 *GetUserInfoURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/restapi/operations/admin_api/get_user_parameters.go b/restapi/operations/admin_api/get_user_parameters.go new file mode 100644 index 000000000..1c2cff4c3 --- /dev/null +++ b/restapi/operations/admin_api/get_user_parameters.go @@ -0,0 +1,89 @@ +// 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" +) + +// NewGetUserParams creates a new GetUserParams object +// no default values defined in spec. +func NewGetUserParams() GetUserParams { + + return GetUserParams{} +} + +// GetUserParams contains all the bound params for the get user operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetUser +type GetUserParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name 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 NewGetUserParams() beforehand. +func (o *GetUserParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *GetUserParams) bindName(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.Name = raw + + return nil +} diff --git a/restapi/operations/admin_api/get_user_responses.go b/restapi/operations/admin_api/get_user_responses.go new file mode 100644 index 000000000..11850d866 --- /dev/null +++ b/restapi/operations/admin_api/get_user_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/mcs/models" +) + +// GetUserOKCode is the HTTP code returned for type GetUserOK +const GetUserOKCode int = 200 + +/*GetUserOK A successful response. + +swagger:response getUserOK +*/ +type GetUserOK struct { + + /* + In: Body + */ + Payload *models.User `json:"body,omitempty"` +} + +// NewGetUserOK creates GetUserOK with default headers values +func NewGetUserOK() *GetUserOK { + + return &GetUserOK{} +} + +// WithPayload adds the payload to the get user o k response +func (o *GetUserOK) WithPayload(payload *models.User) *GetUserOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get user o k response +func (o *GetUserOK) SetPayload(payload *models.User) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetUserOK) 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 + } + } +} + +/*GetUserDefault Generic error response. + +swagger:response getUserDefault +*/ +type GetUserDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetUserDefault creates GetUserDefault with default headers values +func NewGetUserDefault(code int) *GetUserDefault { + if code <= 0 { + code = 500 + } + + return &GetUserDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the get user default response +func (o *GetUserDefault) WithStatusCode(code int) *GetUserDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the get user default response +func (o *GetUserDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the get user default response +func (o *GetUserDefault) WithPayload(payload *models.Error) *GetUserDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get user default response +func (o *GetUserDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetUserDefault) 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_user_urlbuilder.go b/restapi/operations/admin_api/get_user_urlbuilder.go new file mode 100644 index 000000000..a949ec77f --- /dev/null +++ b/restapi/operations/admin_api/get_user_urlbuilder.go @@ -0,0 +1,116 @@ +// 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" +) + +// GetUserURL generates an URL for the get user operation +type GetUserURL struct { + Name 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 *GetUserURL) WithBasePath(bp string) *GetUserURL { + 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 *GetUserURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetUserURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/users/{name}" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on GetUserURL") + } + + _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 *GetUserURL) 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 *GetUserURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetUserURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetUserURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetUserURL") + } + + 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 *GetUserURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/restapi/operations/admin_api/update_user_info.go b/restapi/operations/admin_api/update_user_info.go new file mode 100644 index 000000000..8cc6f5ed9 --- /dev/null +++ b/restapi/operations/admin_api/update_user_info.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/mcs/models" +) + +// UpdateUserInfoHandlerFunc turns a function with the right signature into a update user info handler +type UpdateUserInfoHandlerFunc func(UpdateUserInfoParams, *models.Principal) middleware.Responder + +// Handle executing the request and returning a response +func (fn UpdateUserInfoHandlerFunc) Handle(params UpdateUserInfoParams, principal *models.Principal) middleware.Responder { + return fn(params, principal) +} + +// UpdateUserInfoHandler interface for that can handle valid update user info params +type UpdateUserInfoHandler interface { + Handle(UpdateUserInfoParams, *models.Principal) middleware.Responder +} + +// NewUpdateUserInfo creates a new http.Handler for the update user info operation +func NewUpdateUserInfo(ctx *middleware.Context, handler UpdateUserInfoHandler) *UpdateUserInfo { + return &UpdateUserInfo{Context: ctx, Handler: handler} +} + +/*UpdateUserInfo swagger:route PUT /users/{name} AdminAPI updateUserInfo + +Update User Info + +*/ +type UpdateUserInfo struct { + Context *middleware.Context + Handler UpdateUserInfoHandler +} + +func (o *UpdateUserInfo) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewUpdateUserInfoParams() + + 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/update_user_info_parameters.go b/restapi/operations/admin_api/update_user_info_parameters.go new file mode 100644 index 000000000..669f2e370 --- /dev/null +++ b/restapi/operations/admin_api/update_user_info_parameters.go @@ -0,0 +1,120 @@ +// 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 ( + "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" +) + +// NewUpdateUserInfoParams creates a new UpdateUserInfoParams object +// no default values defined in spec. +func NewUpdateUserInfoParams() UpdateUserInfoParams { + + return UpdateUserInfoParams{} +} + +// UpdateUserInfoParams contains all the bound params for the update user info operation +// typically these are obtained from a http.Request +// +// swagger:parameters UpdateUserInfo +type UpdateUserInfoParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: body + */ + Body *models.UpdateUser + /* + Required: true + In: path + */ + Name 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 NewUpdateUserInfoParams() beforehand. +func (o *UpdateUserInfoParams) 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.UpdateUser + 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")) + } + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *UpdateUserInfoParams) bindName(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.Name = raw + + return nil +} diff --git a/restapi/operations/admin_api/update_user_info_responses.go b/restapi/operations/admin_api/update_user_info_responses.go new file mode 100644 index 000000000..400aa60c5 --- /dev/null +++ b/restapi/operations/admin_api/update_user_info_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/mcs/models" +) + +// UpdateUserInfoOKCode is the HTTP code returned for type UpdateUserInfoOK +const UpdateUserInfoOKCode int = 200 + +/*UpdateUserInfoOK A successful response. + +swagger:response updateUserInfoOK +*/ +type UpdateUserInfoOK struct { + + /* + In: Body + */ + Payload *models.User `json:"body,omitempty"` +} + +// NewUpdateUserInfoOK creates UpdateUserInfoOK with default headers values +func NewUpdateUserInfoOK() *UpdateUserInfoOK { + + return &UpdateUserInfoOK{} +} + +// WithPayload adds the payload to the update user info o k response +func (o *UpdateUserInfoOK) WithPayload(payload *models.User) *UpdateUserInfoOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the update user info o k response +func (o *UpdateUserInfoOK) SetPayload(payload *models.User) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *UpdateUserInfoOK) 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 + } + } +} + +/*UpdateUserInfoDefault Generic error response. + +swagger:response updateUserInfoDefault +*/ +type UpdateUserInfoDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewUpdateUserInfoDefault creates UpdateUserInfoDefault with default headers values +func NewUpdateUserInfoDefault(code int) *UpdateUserInfoDefault { + if code <= 0 { + code = 500 + } + + return &UpdateUserInfoDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the update user info default response +func (o *UpdateUserInfoDefault) WithStatusCode(code int) *UpdateUserInfoDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the update user info default response +func (o *UpdateUserInfoDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the update user info default response +func (o *UpdateUserInfoDefault) WithPayload(payload *models.Error) *UpdateUserInfoDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the update user info default response +func (o *UpdateUserInfoDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *UpdateUserInfoDefault) 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/update_user_info_urlbuilder.go b/restapi/operations/admin_api/update_user_info_urlbuilder.go new file mode 100644 index 000000000..3f97d02b0 --- /dev/null +++ b/restapi/operations/admin_api/update_user_info_urlbuilder.go @@ -0,0 +1,116 @@ +// 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" +) + +// UpdateUserInfoURL generates an URL for the update user info operation +type UpdateUserInfoURL struct { + Name 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 *UpdateUserInfoURL) WithBasePath(bp string) *UpdateUserInfoURL { + 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 *UpdateUserInfoURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *UpdateUserInfoURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/users/{name}" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on UpdateUserInfoURL") + } + + _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 *UpdateUserInfoURL) 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 *UpdateUserInfoURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *UpdateUserInfoURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on UpdateUserInfoURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on UpdateUserInfoURL") + } + + 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 *UpdateUserInfoURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/restapi/operations/mcs_api.go b/restapi/operations/mcs_api.go index 02e197fe9..359ef2f9a 100644 --- a/restapi/operations/mcs_api.go +++ b/restapi/operations/mcs_api.go @@ -99,6 +99,9 @@ func NewMcsAPI(spec *loads.Document) *McsAPI { UserAPIDeleteBucketEventHandler: user_api.DeleteBucketEventHandlerFunc(func(params user_api.DeleteBucketEventParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation user_api.DeleteBucketEvent 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") + }), AdminAPIGroupInfoHandler: admin_api.GroupInfoHandlerFunc(func(params admin_api.GroupInfoParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation admin_api.GroupInfo has not yet been implemented") }), @@ -171,6 +174,9 @@ func NewMcsAPI(spec *loads.Document) *McsAPI { AdminAPIUpdateUserGroupsHandler: admin_api.UpdateUserGroupsHandlerFunc(func(params admin_api.UpdateUserGroupsParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation admin_api.UpdateUserGroups has not yet been implemented") }), + AdminAPIUpdateUserInfoHandler: admin_api.UpdateUserInfoHandlerFunc(func(params admin_api.UpdateUserInfoParams, principal *models.Principal) middleware.Responder { + return middleware.NotImplemented("operation admin_api.UpdateUserInfo has not yet been implemented") + }), KeyAuth: func(token string, scopes []string) (*models.Principal, error) { return nil, errors.NotImplemented("oauth2 bearer auth (key) has not yet been implemented") @@ -244,6 +250,8 @@ type McsAPI struct { UserAPIDeleteBucketHandler user_api.DeleteBucketHandler // UserAPIDeleteBucketEventHandler sets the operation handler for the delete bucket event operation UserAPIDeleteBucketEventHandler user_api.DeleteBucketEventHandler + // 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 AdminAPIGroupInfoHandler admin_api.GroupInfoHandler // UserAPIListBucketEventsHandler sets the operation handler for the list bucket events operation @@ -292,6 +300,8 @@ type McsAPI struct { AdminAPIUpdateGroupHandler admin_api.UpdateGroupHandler // AdminAPIUpdateUserGroupsHandler sets the operation handler for the update user groups operation AdminAPIUpdateUserGroupsHandler admin_api.UpdateUserGroupsHandler + // AdminAPIUpdateUserInfoHandler sets the operation handler for the update user info operation + AdminAPIUpdateUserInfoHandler admin_api.UpdateUserInfoHandler // ServeError is called when an error is received, there is a default handler // but you can set your own with this ServeError func(http.ResponseWriter, *http.Request, error) @@ -401,6 +411,9 @@ func (o *McsAPI) Validate() error { if o.UserAPIDeleteBucketEventHandler == nil { unregistered = append(unregistered, "user_api.DeleteBucketEventHandler") } + if o.AdminAPIGetUserInfoHandler == nil { + unregistered = append(unregistered, "admin_api.GetUserInfoHandler") + } if o.AdminAPIGroupInfoHandler == nil { unregistered = append(unregistered, "admin_api.GroupInfoHandler") } @@ -473,6 +486,9 @@ func (o *McsAPI) Validate() error { if o.AdminAPIUpdateUserGroupsHandler == nil { unregistered = append(unregistered, "admin_api.UpdateUserGroupsHandler") } + if o.AdminAPIUpdateUserInfoHandler == nil { + unregistered = append(unregistered, "admin_api.UpdateUserInfoHandler") + } if len(unregistered) > 0 { return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", ")) @@ -624,6 +640,10 @@ func (o *McsAPI) initHandlerCache() { 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) + } o.handlers["GET"]["/groups/{name}"] = admin_api.NewGroupInfo(o.context, o.AdminAPIGroupInfoHandler) if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) @@ -717,6 +737,10 @@ func (o *McsAPI) initHandlerCache() { o.handlers["PUT"] = make(map[string]http.Handler) } o.handlers["PUT"]["/users/{name}/groups"] = admin_api.NewUpdateUserGroups(o.context, o.AdminAPIUpdateUserGroupsHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/users/{name}"] = admin_api.NewUpdateUserInfo(o.context, o.AdminAPIUpdateUserInfoHandler) } // Serve creates a http handler to serve the API over HTTP diff --git a/swagger.yml b/swagger.yml index 5b4a63363..1900fef9f 100644 --- a/swagger.yml +++ b/swagger.yml @@ -251,6 +251,49 @@ paths: tags: - AdminAPI /users/{name}: + get: + summary: Get User Info + operationId: GetUserInfo + parameters: + - name: name + in: path + required: true + type: string + responses: + 200: + description: A successful response. + schema: + $ref: "#/definitions/user" + default: + description: Generic error response. + schema: + $ref: "#/definitions/error" + tags: + - AdminAPI + put: + summary: Update User Info + operationId: UpdateUserInfo + parameters: + - name: name + in: path + required: true + type: string + - name: body + in: body + required: true + schema: + $ref: "#/definitions/updateUser" + responses: + 200: + description: A successful response. + schema: + $ref: "#/definitions/user" + default: + description: Generic error response. + schema: + $ref: "#/definitions/error" + tags: + - AdminAPI delete: summary: Remove user operationId: RemoveUser @@ -833,11 +876,16 @@ definitions: required: - accessKey - secretKey + - groups properties: accessKey: type: string secretKey: type: string + groups: + type: array + items: + type: string group: type: object properties: @@ -1170,3 +1218,16 @@ definitions: type: array items: $ref: "#/definitions/notificationEndpointItem" + updateUser: + type: object + required: + - status + - groups + properties: + status: + type: string + groups: + type: array + items: + type: string +