Skip to content

Commit 6230a30

Browse files
committed
deploy, oci and setenv updates
changing how we handling wallet connection strings and db name to consider exeptions when db name is different to display name
1 parent e6cd132 commit 6230a30

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

scripts/deploy.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,15 @@ async function createDBConfigFiles(
105105
}
106106

107107
async function setScoreApplicationProperties(adbName, adbPassword) {
108+
const properties = await readEnvJson();
109+
110+
const adbDisplayName = properties.adbDisplayName;
111+
108112
const pwdOutput = (await $`pwd`).stdout.trim();
109113
await cd(`${pwdOutput}/deploy/k8s/base/score`);
110114
try {
111115
let { stdout, exitCode, stderr } =
112-
await $`sed s/TEMPLATE_ADB_SERVICE/${adbName.toLowerCase()}_high/ application.properties.template | sed s/TEMPLATE_ADB_PASSWORD/${adbPassword}/ > application.properties`;
116+
await $`sed s/TEMPLATE_ADB_SERVICE/${adbDisplayName}/ application.properties.template | sed s/TEMPLATE_ADB_PASSWORD/${adbPassword}/ > application.properties`;
113117
if (exitCode !== 0) {
114118
exitWithError(`Error creating application.properties: ${stderr}`);
115119
}
@@ -130,7 +134,7 @@ async function downloadWallet(
130134
) {
131135
const adbs = await listAdbDatabases(compartmentId);
132136
const adb = adbs.find(
133-
(db) => db["db-name"].toLowerCase() === name.toLowerCase()
137+
(db) => db["display-name"].toLowerCase() === name.toLowerCase()
134138
);
135139
await downloadAdbWallet(adb.id, walletFilePath, walletPassword);
136140
}

scripts/lib/oci.mjs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,38 @@ export async function listAdbDatabases(compartmentId) {
4646
}
4747
}
4848

49+
export async function listAdbDatabasesbyname(adbName,compartmentId) {
50+
try {
51+
const { stdout, exitCode, stderr } = await $`oci db autonomous-database list --all --compartment-id ${compartmentId} --display-name ${adbName}`;
52+
if (exitCode !== 0) {
53+
console.error("Error:", stderr);
54+
return;
55+
}
56+
57+
const response = JSON.parse(stdout.trim());
58+
// console.log("Full API Response:", response);
59+
60+
const connectionStrings = response.data[0]['connection-strings'];
61+
62+
if (typeof connectionStrings === 'object' && connectionStrings !== null) {
63+
64+
// Finding the 'HIGH' consumer group in profiles array
65+
const highConsumerGroupDisplayName = connectionStrings.profiles.find(profile => profile['consumer-group'] === "HIGH");
66+
if (highConsumerGroupDisplayName) {
67+
const adbDisplayName = highConsumerGroupDisplayName['display-name'];
68+
// console.log("adbDisplayName:", adbDisplayName);
69+
return adbDisplayName;
70+
} else {
71+
console.error("Error: No 'HIGH' consumer group found in the response.");
72+
}
73+
} else {
74+
console.error("Error: 'connection-strings' is not an object in the response.");
75+
}
76+
} catch (error) {
77+
console.error("Error:", error);
78+
}
79+
}
80+
4981
export async function downloadAdbWallet(adbId, walletFilePath, walletPassword) {
5082
try {
5183
const { stdout, exitCode, stderr } =
@@ -124,6 +156,27 @@ export async function searchCompartmentIdByName(compartmentName) {
124156
}
125157
}
126158

159+
export async function searchAdbIdByName(adbName, compartmentId) {
160+
if (!adbName) {
161+
exitWithError("ADB name required");
162+
}
163+
try {
164+
const { stdout, exitCode, stderr } =
165+
await $`oci db autonomous-database list --compartment-id ${compartmentId} --query "data[?\"display-name\"=='${adbName}'].id"`;
166+
if (exitCode !== 0) {
167+
exitWithError(stderr);
168+
}
169+
const adbIds = JSON.parse(stdout.trim());
170+
if (adbIds.length === 0) {
171+
exitWithError("ADB name not found");
172+
}
173+
const adbId = adbIds[0];
174+
return adbId;
175+
} catch (error) {
176+
exitWithError(error.stderr);
177+
}
178+
}
179+
127180
export async function uploadApiKeyFile(userId, publicKeyPath) {
128181
if (!userId) {
129182
exitWithError("User ID required");

scripts/setenv.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getRegions,
1414
getTenancyId,
1515
searchCompartmentIdByName,
16+
listAdbDatabasesbyname,
1617
} from "./lib/oci.mjs";
1718
import { createSelfSignedCert } from "./lib/tls.mjs";
1819
import {
@@ -140,13 +141,19 @@ async function adbDetails() {
140141
"Autonomous Database password"
141142
);
142143

144+
const adbDisplayName = await listAdbDatabasesbyname(adbName, adbCompartmentId);
145+
146+
143147
properties = {
144148
...properties,
145149
adbCompartmentId,
146150
adbCompartmentName,
147151
adbName,
148152
adbPassword,
153+
adbDisplayName,
149154
};
155+
// console.log("Properties:", properties);
156+
150157
}
151158

152159
async function printRegionNames(regions) {

0 commit comments

Comments
 (0)