Skip to content

Commit eefd3db

Browse files
committed
fix(postgresql): id not exist using name to get detail
1 parent 4159713 commit eefd3db

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/modules/postgresql/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import {
1010
createDbInstance,
1111
getDbInstanceDetail,
12+
getDbInstanceDetailByName,
1213
getDbExtranetAccess,
1314
toggleDbInstanceAccess,
1415
deleteDbInstance,
@@ -57,6 +58,9 @@ export default class Postgresql {
5758
if (dBInstanceId) {
5859
dbDetail = await getDbInstanceDetail(this.capi, dBInstanceId!);
5960
}
61+
if (!dbDetail) {
62+
dbDetail = await getDbInstanceDetailByName(this.capi, dBInstanceName!);
63+
}
6064

6165
if (dbDetail && dbDetail.DBInstanceId && dbDetail.Zone === zone) {
6266
const publicAccess = getDbExtranetAccess(dbDetail.DBInstanceNetInfo);

src/modules/postgresql/utils.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const TIMEOUT = 5 * 60 * 1000;
99
/**
1010
*
1111
* @param {object} capi capi instance
12-
* @param {*} dBInstanceName
12+
* @param {*} dBInstanceId
1313
*/
1414
export async function getDbInstanceDetail(
1515
capi: Capi,
@@ -37,6 +37,37 @@ export async function getDbInstanceDetail(
3737
return undefined;
3838
}
3939

40+
/**
41+
*
42+
* @param {object} capi capi instance
43+
* @param {*} dBInstanceName
44+
*/
45+
export async function getDbInstanceDetailByName(
46+
capi: Capi,
47+
dBInstanceName: string,
48+
): Promise<PostgresqlInstanceDetail | undefined> {
49+
// get instance detail
50+
try {
51+
const res = await APIS.DescribeServerlessDBInstances(capi, {
52+
Filter: [
53+
{
54+
Name: 'db-instance-name',
55+
Values: [dBInstanceName],
56+
},
57+
],
58+
});
59+
if (res.DBInstanceSet) {
60+
const {
61+
DBInstanceSet: [dbDetail],
62+
} = res;
63+
return dbDetail;
64+
}
65+
} catch (e) {
66+
console.log(e);
67+
}
68+
return undefined;
69+
}
70+
4071
/**
4172
* get db public access status
4273
* @param {array} netInfos network infos

0 commit comments

Comments
 (0)