Use swagger api for Add IDP Configuration (#3201)
This commit is contained in:
@@ -2928,6 +2928,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"post": {
|
"post": {
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"idp"
|
"idp"
|
||||||
],
|
],
|
||||||
@@ -12103,6 +12106,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"post": {
|
"post": {
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"idp"
|
"idp"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -3299,6 +3299,8 @@ paths:
|
|||||||
post:
|
post:
|
||||||
summary: Create IDP Configuration
|
summary: Create IDP Configuration
|
||||||
operationId: CreateConfiguration
|
operationId: CreateConfiguration
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
parameters:
|
parameters:
|
||||||
- name: type
|
- name: type
|
||||||
description: IDP Configuration Type
|
description: IDP Configuration Type
|
||||||
|
|||||||
@@ -5091,6 +5091,7 @@ export class Api<
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
body: body,
|
body: body,
|
||||||
secure: true,
|
secure: true,
|
||||||
|
type: ContentType.Json,
|
||||||
format: "json",
|
format: "json",
|
||||||
...params,
|
...params,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import {
|
|||||||
Switch,
|
Switch,
|
||||||
} from "mds";
|
} from "mds";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { ErrorResponseHandler } from "../../../common/types";
|
|
||||||
import { useAppDispatch } from "../../../store";
|
import { useAppDispatch } from "../../../store";
|
||||||
import { modalStyleUtils } from "../Common/FormComponents/common/styleLibrary";
|
import { modalStyleUtils } from "../Common/FormComponents/common/styleLibrary";
|
||||||
import {
|
import {
|
||||||
@@ -34,9 +33,11 @@ import {
|
|||||||
setHelpName,
|
setHelpName,
|
||||||
setServerNeedsRestart,
|
setServerNeedsRestart,
|
||||||
} from "../../../systemSlice";
|
} from "../../../systemSlice";
|
||||||
import useApi from "../Common/Hooks/useApi";
|
|
||||||
import PageHeaderWrapper from "../Common/PageHeaderWrapper/PageHeaderWrapper";
|
import PageHeaderWrapper from "../Common/PageHeaderWrapper/PageHeaderWrapper";
|
||||||
import HelpMenu from "../HelpMenu";
|
import HelpMenu from "../HelpMenu";
|
||||||
|
import { api } from "api";
|
||||||
|
import { ApiError, HttpResponse, SetIDPResponse } from "api/consoleApi";
|
||||||
|
import { errorToHandler } from "api/errors";
|
||||||
|
|
||||||
type AddIDPConfigurationProps = {
|
type AddIDPConfigurationProps = {
|
||||||
classes?: any;
|
classes?: any;
|
||||||
@@ -46,7 +47,6 @@ type AddIDPConfigurationProps = {
|
|||||||
title: string;
|
title: string;
|
||||||
backLink: string;
|
backLink: string;
|
||||||
formFields: object;
|
formFields: object;
|
||||||
endpoint: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const AddIDPConfiguration = ({
|
const AddIDPConfiguration = ({
|
||||||
@@ -56,7 +56,6 @@ const AddIDPConfiguration = ({
|
|||||||
backLink,
|
backLink,
|
||||||
title,
|
title,
|
||||||
formFields,
|
formFields,
|
||||||
endpoint,
|
|
||||||
}: AddIDPConfigurationProps) => {
|
}: AddIDPConfigurationProps) => {
|
||||||
const extraFormFields = {
|
const extraFormFields = {
|
||||||
name: {
|
name: {
|
||||||
@@ -76,16 +75,7 @@ const AddIDPConfiguration = ({
|
|||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const [fields, setFields] = useState<any>({});
|
const [fields, setFields] = useState<any>({});
|
||||||
|
const [loadingCreate, setLoadingCreate] = useState<boolean>(false);
|
||||||
const onSuccess = (res: any) => {
|
|
||||||
navigate(backLink);
|
|
||||||
dispatch(setServerNeedsRestart(res.restart === true));
|
|
||||||
};
|
|
||||||
|
|
||||||
const onError = (err: ErrorResponseHandler) =>
|
|
||||||
dispatch(setErrorSnackMessage(err));
|
|
||||||
|
|
||||||
const [loading, invokeApi] = useApi(onSuccess, onError);
|
|
||||||
|
|
||||||
const validSave = () => {
|
const validSave = () => {
|
||||||
for (const [key, value] of Object.entries(extraFormFields)) {
|
for (const [key, value] of Object.entries(extraFormFields)) {
|
||||||
@@ -108,6 +98,7 @@ const AddIDPConfiguration = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const addRecord = (event: React.FormEvent) => {
|
const addRecord = (event: React.FormEvent) => {
|
||||||
|
setLoadingCreate(true);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const name = fields["name"];
|
const name = fields["name"];
|
||||||
let input = "";
|
let input = "";
|
||||||
@@ -116,7 +107,17 @@ const AddIDPConfiguration = ({
|
|||||||
input += `${key}=${fields[key]} `;
|
input += `${key}=${fields[key]} `;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
invokeApi("POST", endpoint, { name, input });
|
|
||||||
|
api.idp
|
||||||
|
.createConfiguration("openid", { name, input })
|
||||||
|
.then((res: HttpResponse<SetIDPResponse, ApiError>) => {
|
||||||
|
navigate(backLink);
|
||||||
|
dispatch(setServerNeedsRestart(res.data.restart === true));
|
||||||
|
})
|
||||||
|
.catch(async (res: HttpResponse<SetIDPResponse, ApiError>) => {
|
||||||
|
dispatch(setErrorSnackMessage(errorToHandler(res.error)));
|
||||||
|
})
|
||||||
|
.finally(() => setLoadingCreate(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderFormField = (key: string, value: any) => {
|
const renderFormField = (key: string, value: any) => {
|
||||||
@@ -197,7 +198,7 @@ const AddIDPConfiguration = ({
|
|||||||
type="submit"
|
type="submit"
|
||||||
variant="callAction"
|
variant="callAction"
|
||||||
color="primary"
|
color="primary"
|
||||||
disabled={loading || !validSave()}
|
disabled={loadingCreate || !validSave()}
|
||||||
label={"Save"}
|
label={"Save"}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ const AddIDPOpenIDConfiguration = () => {
|
|||||||
header={"OpenID Configurations"}
|
header={"OpenID Configurations"}
|
||||||
backLink={IAM_PAGES.IDP_OPENID_CONFIGURATIONS}
|
backLink={IAM_PAGES.IDP_OPENID_CONFIGURATIONS}
|
||||||
title={"Create OpenID Configuration"}
|
title={"Create OpenID Configuration"}
|
||||||
endpoint={"/api/v1/idp/openid/"}
|
|
||||||
formFields={openIDFormFields}
|
formFields={openIDFormFields}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user