Skip to content

Commit

Permalink
deploy, oci and setenv updates
Browse files Browse the repository at this point in the history
changing how we handling wallet connection strings and db name to consider exeptions when db name is different to display name
  • Loading branch information
WSPluta committed Oct 26, 2023
1 parent e6cd132 commit 6230a30
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scripts/deploy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,15 @@ async function createDBConfigFiles(
}

async function setScoreApplicationProperties(adbName, adbPassword) {
const properties = await readEnvJson();

const adbDisplayName = properties.adbDisplayName;

const pwdOutput = (await $`pwd`).stdout.trim();
await cd(`${pwdOutput}/deploy/k8s/base/score`);
try {
let { stdout, exitCode, stderr } =
await $`sed s/TEMPLATE_ADB_SERVICE/${adbName.toLowerCase()}_high/ application.properties.template | sed s/TEMPLATE_ADB_PASSWORD/${adbPassword}/ > application.properties`;
await $`sed s/TEMPLATE_ADB_SERVICE/${adbDisplayName}/ application.properties.template | sed s/TEMPLATE_ADB_PASSWORD/${adbPassword}/ > application.properties`;
if (exitCode !== 0) {
exitWithError(`Error creating application.properties: ${stderr}`);
}
Expand All @@ -130,7 +134,7 @@ async function downloadWallet(
) {
const adbs = await listAdbDatabases(compartmentId);
const adb = adbs.find(
(db) => db["db-name"].toLowerCase() === name.toLowerCase()
(db) => db["display-name"].toLowerCase() === name.toLowerCase()
);
await downloadAdbWallet(adb.id, walletFilePath, walletPassword);
}
Expand Down
53 changes: 53 additions & 0 deletions scripts/lib/oci.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@ export async function listAdbDatabases(compartmentId) {
}
}

export async function listAdbDatabasesbyname(adbName,compartmentId) {
try {
const { stdout, exitCode, stderr } = await $`oci db autonomous-database list --all --compartment-id ${compartmentId} --display-name ${adbName}`;
if (exitCode !== 0) {
console.error("Error:", stderr);
return;
}

const response = JSON.parse(stdout.trim());
// console.log("Full API Response:", response);

const connectionStrings = response.data[0]['connection-strings'];

if (typeof connectionStrings === 'object' && connectionStrings !== null) {

// Finding the 'HIGH' consumer group in profiles array
const highConsumerGroupDisplayName = connectionStrings.profiles.find(profile => profile['consumer-group'] === "HIGH");
if (highConsumerGroupDisplayName) {
const adbDisplayName = highConsumerGroupDisplayName['display-name'];
// console.log("adbDisplayName:", adbDisplayName);
return adbDisplayName;
} else {
console.error("Error: No 'HIGH' consumer group found in the response.");
}
} else {
console.error("Error: 'connection-strings' is not an object in the response.");
}
} catch (error) {
console.error("Error:", error);
}
}

export async function downloadAdbWallet(adbId, walletFilePath, walletPassword) {
try {
const { stdout, exitCode, stderr } =
Expand Down Expand Up @@ -124,6 +156,27 @@ export async function searchCompartmentIdByName(compartmentName) {
}
}

export async function searchAdbIdByName(adbName, compartmentId) {
if (!adbName) {
exitWithError("ADB name required");
}
try {
const { stdout, exitCode, stderr } =
await $`oci db autonomous-database list --compartment-id ${compartmentId} --query "data[?\"display-name\"=='${adbName}'].id"`;
if (exitCode !== 0) {
exitWithError(stderr);
}
const adbIds = JSON.parse(stdout.trim());
if (adbIds.length === 0) {
exitWithError("ADB name not found");
}
const adbId = adbIds[0];
return adbId;
} catch (error) {
exitWithError(error.stderr);
}
}

export async function uploadApiKeyFile(userId, publicKeyPath) {
if (!userId) {
exitWithError("User ID required");
Expand Down
7 changes: 7 additions & 0 deletions scripts/setenv.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getRegions,
getTenancyId,
searchCompartmentIdByName,
listAdbDatabasesbyname,
} from "./lib/oci.mjs";
import { createSelfSignedCert } from "./lib/tls.mjs";
import {
Expand Down Expand Up @@ -140,13 +141,19 @@ async function adbDetails() {
"Autonomous Database password"
);

const adbDisplayName = await listAdbDatabasesbyname(adbName, adbCompartmentId);


properties = {
...properties,
adbCompartmentId,
adbCompartmentName,
adbName,
adbPassword,
adbDisplayName,
};
// console.log("Properties:", properties);

}

async function printRegionNames(regions) {
Expand Down

0 comments on commit 6230a30

Please sign in to comment.