Use swagger api for delete single and multiple Service Accounts (#3199)
This commit is contained in:
@@ -4431,10 +4431,7 @@ func init() {
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
"$ref": "#/definitions/selectedSAs"
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -7985,6 +7982,12 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"selectedSAs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"selectedUsers": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -13616,10 +13619,7 @@ func init() {
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
"$ref": "#/definitions/selectedSAs"
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -17327,6 +17327,12 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"selectedSAs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"selectedUsers": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
||||
@@ -29,6 +29,9 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
// NewDeleteMultipleServiceAccountsParams creates a new DeleteMultipleServiceAccountsParams object
|
||||
@@ -52,7 +55,7 @@ type DeleteMultipleServiceAccountsParams struct {
|
||||
Required: true
|
||||
In: body
|
||||
*/
|
||||
SelectedSA []string
|
||||
SelectedSA models.SelectedSAs
|
||||
}
|
||||
|
||||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||
@@ -66,7 +69,7 @@ func (o *DeleteMultipleServiceAccountsParams) BindRequest(r *http.Request, route
|
||||
|
||||
if runtime.HasBody(r) {
|
||||
defer r.Body.Close()
|
||||
var body []string
|
||||
var body models.SelectedSAs
|
||||
if err := route.Consumer.Consume(r.Body, &body); err != nil {
|
||||
if err == io.EOF {
|
||||
res = append(res, errors.Required("selectedSA", "body", ""))
|
||||
@@ -74,8 +77,19 @@ func (o *DeleteMultipleServiceAccountsParams) BindRequest(r *http.Request, route
|
||||
res = append(res, errors.NewParseError("selectedSA", "body", "", err))
|
||||
}
|
||||
} else {
|
||||
// no validation required on inline body
|
||||
o.SelectedSA = body
|
||||
// validate body object
|
||||
if err := body.Validate(route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
ctx := validate.WithOperationRequest(r.Context())
|
||||
if err := body.ContextValidate(ctx, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) == 0 {
|
||||
o.SelectedSA = body
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = append(res, errors.Required("selectedSA", "body", ""))
|
||||
|
||||
44
models/selected_s_as.go
Normal file
44
models/selected_s_as.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2023 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 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/strfmt"
|
||||
)
|
||||
|
||||
// SelectedSAs selected s as
|
||||
//
|
||||
// swagger:model selectedSAs
|
||||
type SelectedSAs []string
|
||||
|
||||
// Validate validates this selected s as
|
||||
func (m SelectedSAs) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this selected s as based on context it is used
|
||||
func (m SelectedSAs) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
@@ -1425,9 +1425,7 @@ paths:
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
$ref: "#/definitions/selectedSAs"
|
||||
responses:
|
||||
204:
|
||||
description: A successful response.
|
||||
@@ -6196,3 +6194,8 @@ definitions:
|
||||
format: int64
|
||||
required:
|
||||
- exp
|
||||
|
||||
selectedSAs:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
|
||||
@@ -1537,6 +1537,8 @@ export interface MaxShareLinkExpResponse {
|
||||
exp: number;
|
||||
}
|
||||
|
||||
export type SelectedSAs = string[];
|
||||
|
||||
export type QueryParamsType = Record<string | number, any>;
|
||||
export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
|
||||
|
||||
@@ -2177,7 +2179,7 @@ export class Api<
|
||||
*/
|
||||
downloadMultipleObjects: (
|
||||
bucketName: string,
|
||||
objectList: string[],
|
||||
objectList: SelectedUsers,
|
||||
params: RequestParams = {},
|
||||
) =>
|
||||
this.request<File, ApiError>({
|
||||
@@ -2185,6 +2187,7 @@ export class Api<
|
||||
method: "POST",
|
||||
body: objectList,
|
||||
secure: true,
|
||||
type: ContentType.Json,
|
||||
...params,
|
||||
}),
|
||||
|
||||
@@ -3088,7 +3091,7 @@ export class Api<
|
||||
* @secure
|
||||
*/
|
||||
deleteMultipleServiceAccounts: (
|
||||
selectedSA: string[],
|
||||
selectedSA: SelectedSAs,
|
||||
params: RequestParams = {},
|
||||
) =>
|
||||
this.request<void, ApiError>({
|
||||
@@ -3096,6 +3099,7 @@ export class Api<
|
||||
method: "DELETE",
|
||||
body: selectedSA,
|
||||
secure: true,
|
||||
type: ContentType.Json,
|
||||
...params,
|
||||
}),
|
||||
|
||||
|
||||
@@ -14,14 +14,15 @@
|
||||
// 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/>.
|
||||
|
||||
import React, { Fragment } from "react";
|
||||
import { ErrorResponseHandler } from "../../../common/types";
|
||||
import useApi from "../Common/Hooks/useApi";
|
||||
import React, { Fragment, useState } from "react";
|
||||
import ConfirmDialog from "../Common/ModalWrapper/ConfirmDialog";
|
||||
import { ConfirmDeleteIcon } from "mds";
|
||||
import { encodeURLString } from "../../../common/utils";
|
||||
import { setErrorSnackMessage } from "../../../systemSlice";
|
||||
import { useAppDispatch } from "../../../store";
|
||||
import { api } from "api";
|
||||
import { ApiError, HttpResponse } from "api/consoleApi";
|
||||
import { errorToHandler } from "api/errors";
|
||||
|
||||
interface IDeleteServiceAccountProps {
|
||||
closeDeleteModalAndRefresh: (refresh: boolean) => void;
|
||||
@@ -35,22 +36,27 @@ const DeleteServiceAccount = ({
|
||||
selectedServiceAccount,
|
||||
}: IDeleteServiceAccountProps) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const onDelSuccess = () => closeDeleteModalAndRefresh(true);
|
||||
const onDelError = (err: ErrorResponseHandler) =>
|
||||
dispatch(setErrorSnackMessage(err));
|
||||
const onClose = () => closeDeleteModalAndRefresh(false);
|
||||
|
||||
const [deleteLoading, invokeDeleteApi] = useApi(onDelSuccess, onDelError);
|
||||
const [loadingDelete, setLoadingDelete] = useState<boolean>(false);
|
||||
|
||||
if (!selectedServiceAccount) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const onConfirmDelete = () => {
|
||||
invokeDeleteApi(
|
||||
"DELETE",
|
||||
`/api/v1/service-accounts/${encodeURLString(selectedServiceAccount)}`,
|
||||
);
|
||||
setLoadingDelete(true);
|
||||
api.serviceAccounts
|
||||
.deleteServiceAccount(encodeURLString(selectedServiceAccount))
|
||||
.then((_) => {
|
||||
closeDeleteModalAndRefresh(true);
|
||||
})
|
||||
.catch(async (res: HttpResponse<void, ApiError>) => {
|
||||
const err = (await res.json()) as ApiError;
|
||||
dispatch(setErrorSnackMessage(errorToHandler(err)));
|
||||
closeDeleteModalAndRefresh(false);
|
||||
})
|
||||
.finally(() => setLoadingDelete(false));
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -59,7 +65,7 @@ const DeleteServiceAccount = ({
|
||||
confirmText={"Delete"}
|
||||
isOpen={deleteOpen}
|
||||
titleIcon={<ConfirmDeleteIcon />}
|
||||
isLoading={deleteLoading}
|
||||
isLoading={loadingDelete}
|
||||
onConfirm={onConfirmDelete}
|
||||
onClose={onClose}
|
||||
confirmationContent={
|
||||
|
||||
@@ -14,13 +14,14 @@
|
||||
// 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/>.
|
||||
|
||||
import React, { Fragment } from "react";
|
||||
import React, { Fragment, useState } from "react";
|
||||
import { ConfirmDeleteIcon } from "mds";
|
||||
import { ErrorResponseHandler } from "../../../common/types";
|
||||
import useApi from "../../../screens/Console/Common/Hooks/useApi";
|
||||
import ConfirmDialog from "../../../screens/Console/Common/ModalWrapper/ConfirmDialog";
|
||||
import { setErrorSnackMessage } from "../../../systemSlice";
|
||||
import { useAppDispatch } from "../../../store";
|
||||
import { api } from "api";
|
||||
import { ApiError, HttpResponse } from "api/consoleApi";
|
||||
import { errorToHandler } from "api/errors";
|
||||
|
||||
interface IDeleteMultiSAsProps {
|
||||
closeDeleteModalAndRefresh: (refresh: boolean) => void;
|
||||
@@ -34,20 +35,25 @@ const DeleteMultipleSAs = ({
|
||||
selectedSAs,
|
||||
}: IDeleteMultiSAsProps) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const onDelSuccess = () => closeDeleteModalAndRefresh(true);
|
||||
const onDelError = (err: ErrorResponseHandler) =>
|
||||
dispatch(setErrorSnackMessage(err));
|
||||
const onClose = () => closeDeleteModalAndRefresh(false);
|
||||
const [deleteLoading, invokeDeleteApi] = useApi(onDelSuccess, onDelError);
|
||||
const [loadingDelete, setLoadingDelete] = useState<boolean>(false);
|
||||
|
||||
if (!selectedSAs) {
|
||||
return null;
|
||||
}
|
||||
const onConfirmDelete = () => {
|
||||
invokeDeleteApi(
|
||||
"DELETE",
|
||||
`/api/v1/service-accounts/delete-multi`,
|
||||
selectedSAs,
|
||||
);
|
||||
setLoadingDelete(true);
|
||||
api.serviceAccounts
|
||||
.deleteMultipleServiceAccounts(selectedSAs)
|
||||
.then((_) => {
|
||||
closeDeleteModalAndRefresh(true);
|
||||
})
|
||||
.catch(async (res: HttpResponse<void, ApiError>) => {
|
||||
const err = (await res.json()) as ApiError;
|
||||
dispatch(setErrorSnackMessage(errorToHandler(err)));
|
||||
closeDeleteModalAndRefresh(false);
|
||||
})
|
||||
.finally(() => setLoadingDelete(false));
|
||||
};
|
||||
return (
|
||||
<ConfirmDialog
|
||||
@@ -55,7 +61,7 @@ const DeleteMultipleSAs = ({
|
||||
confirmText={"Delete"}
|
||||
isOpen={deleteOpen}
|
||||
titleIcon={<ConfirmDeleteIcon />}
|
||||
isLoading={deleteLoading}
|
||||
isLoading={loadingDelete}
|
||||
onConfirm={onConfirmDelete}
|
||||
onClose={onClose}
|
||||
confirmationContent={
|
||||
|
||||
Reference in New Issue
Block a user