Skip to content

Commit 3e4dc2f

Browse files
authored
Merge pull request #1 from WSPluta/wallet-debug
Wallet debug
2 parents e6cd132 + 06ea5e1 commit 3e4dc2f

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

command_spec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ steps:
3131
shell: bash
3232
timeoutInSeconds: 300
3333
command: |
34-
cd /workspace/oci-multiplayer
34+
cd /workspace/save-the-wildlife
3535
adb_wallet_password="$(openssl rand -base64 12)_$RANDOM"
3636
oci db autonomous-database generate-wallet --autonomous-database-id ${adb_id} --file "/workspace/oci-multiplayer/deploy/k8s/base/score/wallet.zip" --password "$adb_wallet_password"
3737
- type: Command
3838
name: "Custom Kustomize with versions"
3939
shell: bash
4040
timeoutInSeconds: 300
4141
command: |
42-
cd /workspace/oci-multiplayer
42+
cd /workspace/save-the-wildlife
4343
redis_password=$(oci secrets secret-bundle get --secret-id ${redis_password_id} --query 'data."secret-bundle-content".content' | tr -d '\"' | base64 -d)
4444
adb_admin_password=$(oci secrets secret-bundle get --secret-id ${adb_admin_password_id} --query 'data."secret-bundle-content".content' | tr -d '\"' | base64 -d)
4545
npx zx scripts/kustom.mjs ${region_key} $redis_password $adb_admin_password ${adb_service}
@@ -73,4 +73,4 @@ steps:
7373
timeoutInSeconds: 100
7474
command: |
7575
LB_PUBLIC_IP=$(kubectl get svc ingress-nginx-controller -n ingress-nginx --template="{{range .status.loadBalancer.ingress}}{{.ip}}{{end}}")
76-
echo "http://$LB_PUBLIC_IP/"
76+
echo "http://$LB_PUBLIC_IP/"

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)