Skip to content

Commit

Permalink
Merge pull request #186 from baixinsui/feature/use_active_csps
Browse files Browse the repository at this point in the history
Credential Center Using Active Csps
  • Loading branch information
swaroopar committed Sep 6, 2023
2 parents 32066a8 + 43f6d7e commit 4a9dd72
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 13 deletions.
26 changes: 15 additions & 11 deletions src/components/content/credential/AddCredential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ColumnsType } from 'antd/es/table';
import { Button, Form, Image, Input, InputNumber, Select, Table, Tooltip } from 'antd';
import React, { ChangeEvent, useEffect, useState } from 'react';
import {
AdminService,
ApiError,
CloudServiceProvider,
CreateCredential,
Expand All @@ -28,13 +29,15 @@ function AddCredential({
credentialsQuery: UseQueryResult<never[]>;
onCancel: () => void;
}): React.JSX.Element {
const active = true;
const [form] = Form.useForm();
const [currentCsp, setCurrentCsp] = useState<CredentialVariables.csp | undefined>(undefined);
const [disable, setDisable] = useState<boolean>(false);
const [typeDisabled, setTypeDisabled] = useState<boolean>(true);
const [nameDisable, setNameDisable] = useState<boolean>(true);
const [currentType, setCurrentType] = useState<CredentialVariables.type | undefined>(undefined);
const [currentName, setCurrentName] = useState<string | undefined>(undefined);
const [activeCspList, setActiveCspList] = useState<CredentialVariables.csp[]>([]);
const [credentialTypeList, setCredentialTypeList] = useState<CredentialVariables.type[]>([]);
const [nameList, setNameList] = useState<string[]>([]);
const [credentialVariableList, setCredentialVariableList] = useState<CredentialVariable[]>([]);
Expand All @@ -43,6 +46,12 @@ function AddCredential({
const [tipType, setTipType] = useState<'error' | 'success' | undefined>(undefined);
const [addLoading, setAddLoading] = useState<boolean>(false);

const getCspsQuery = useQuery({
queryKey: ['getCspsQuery', active],
queryFn: () => AdminService.getCsps(active),
staleTime: 60000,
});

const credentialTypesQuery = useQuery({
queryKey: ['credentialTypesQuery', currentCsp],
queryFn: () => CredentialsManagementService.listCredentialTypes(currentCsp),
Expand All @@ -60,18 +69,13 @@ function AddCredential({
}, [credentialTypesQuery.data, credentialTypesQuery.isSuccess]);

useEffect(() => {
if (currentCsp !== undefined) {
if (credentialTypesQuery.error instanceof ApiError && 'details' in credentialTypesQuery.error.body) {
const response: Response = credentialTypesQuery.error.body as Response;
getTipInfo('error', response.details.join());
} else if (credentialTypesQuery.error instanceof Error) {
getTipInfo('error', credentialTypesQuery.error.message);
}
setDisable(true);
const csps = getCspsQuery.data;
if (csps !== undefined && csps.length > 0) {
setActiveCspList(csps as CredentialVariables.csp[]);
} else {
setCredentialTypeList([]);
setActiveCspList([]);
}
}, [credentialTypesQuery.error, currentCsp]);
}, [getCspsQuery.data, getCspsQuery.isSuccess]);

const credentialCapabilitiesQuery = useQuery({
queryKey: ['credentialCapabilitiesQuery', currentCsp, currentType],
Expand Down Expand Up @@ -358,7 +362,7 @@ function AddCredential({
<div className={'credential-from-input'}>
<Form.Item label='Csp' name='csp' rules={[{ required: true, message: 'Please Select Csp!' }]}>
<Select onSelect={handleCspSelect} size={'large'}>
{Object.values(CredentialVariables.csp).map((csp: CredentialVariables.csp) => {
{activeCspList.map((csp: CredentialVariables.csp) => {
return (
<Select.Option key={csp} value={csp} className={'credential-select-option-csp'}>
<Image
Expand Down
66 changes: 64 additions & 2 deletions src/xpanse-api/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,67 @@
}
}
},
"/xpanse/csp": {
"get": {
"tags": ["Admin"],
"description": "List cloud service provider.<br>Required role:<b> admin</b> or <b>isv</b> or <b>user</b>",
"operationId": "getCsps",
"parameters": [
{
"name": "active",
"in": "query",
"description": "Whether only list cloud service provider with active plugin.",
"required": true,
"schema": { "type": "boolean" }
}
],
"responses": {
"500": {
"description": "Internal Server Error",
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/Response" } } }
},
"400": {
"description": "Bad Request",
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/Response" } } }
},
"422": {
"description": "Unprocessable Entity",
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/Response" } } }
},
"403": {
"description": "Forbidden",
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/Response" } } }
},
"502": {
"description": "Bad Gateway",
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/Response" } } }
},
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "string",
"enum": [
"huawei",
"flexibleEngine",
"openstack",
"alicloud",
"aws",
"azure",
"google",
"scs"
]
}
}
}
}
}
}
}
},
"/xpanse/credentials/openapi/{csp}/{type}": {
"get": {
"tags": ["Credentials Management"],
Expand Down Expand Up @@ -1484,7 +1545,8 @@
"Unauthorized",
"Access Denied",
"Sensitive Field Encryption Or Decryption Failed Exception",
"Unsupported Enum Value"
"Unsupported Enum Value",
"Metrics Data Not Ready"
]
},
"details": {
Expand Down Expand Up @@ -2160,7 +2222,7 @@
"backendSystemType": {
"type": "string",
"description": "The type of backend system.",
"enum": ["IdentityProvider", "Database"]
"enum": ["IdentityProvider", "Database", "Terraform Boot"]
},
"name": { "type": "string", "description": "The name of backend system." },
"healthStatus": {
Expand Down
1 change: 1 addition & 0 deletions src/xpanse-api/generated/models/BackendSystemStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export namespace BackendSystemStatus {
export enum backendSystemType {
IDENTITY_PROVIDER = 'IdentityProvider',
DATABASE = 'Database',
TERRAFORM_BOOT = 'Terraform Boot',
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/xpanse-api/generated/models/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ export namespace Response {
ACCESS_DENIED = 'Access Denied',
SENSITIVE_FIELD_ENCRYPTION_OR_DECRYPTION_FAILED_EXCEPTION = 'Sensitive Field Encryption Or Decryption Failed Exception',
UNSUPPORTED_ENUM_VALUE = 'Unsupported Enum Value',
METRICS_DATA_NOT_READY = 'Metrics Data Not Ready',
}
}
27 changes: 27 additions & 0 deletions src/xpanse-api/generated/services/AdminService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,31 @@ export class AdminService {
},
});
}

/**
* List cloud service provider.<br>Required role:<b> admin</b> or <b>isv</b> or <b>user</b>
* @param active Whether only list cloud service provider with active plugin.
* @returns string OK
* @throws ApiError
*/
public static getCsps(
active: boolean
): CancelablePromise<
Array<'huawei' | 'flexibleEngine' | 'openstack' | 'alicloud' | 'aws' | 'azure' | 'google' | 'scs'>
> {
return __request(OpenAPI, {
method: 'GET',
url: '/xpanse/csp',
query: {
active: active,
},
errors: {
400: `Bad Request`,
403: `Forbidden`,
422: `Unprocessable Entity`,
500: `Internal Server Error`,
502: `Bad Gateway`,
},
});
}
}

0 comments on commit 4a9dd72

Please sign in to comment.