@mikarinneoracle/oci-cdk-code-only-preview 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/deploy-code-only.js +12 -4
- package/bin/destroy-code-only.js +12 -3
- package/package.json +1 -1
package/bin/deploy-code-only.js
CHANGED
|
@@ -89,17 +89,25 @@ function createArchive() {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
function jsonOci(args) {
|
|
92
|
-
const output = runOci([...args, '--output', 'json']);
|
|
92
|
+
const output = runOci([...args, '--output', 'json']).trim();
|
|
93
|
+
const objectStart = output.indexOf('{');
|
|
94
|
+
const arrayStart = output.indexOf('[');
|
|
95
|
+
const start = objectStart !== -1 ? objectStart : arrayStart;
|
|
96
|
+
const end = Math.max(output.lastIndexOf('}'), output.lastIndexOf(']'));
|
|
93
97
|
try {
|
|
94
|
-
return JSON.parse(output);
|
|
98
|
+
return JSON.parse(start === -1 || end < start ? output : output.slice(start, end + 1));
|
|
95
99
|
} catch {
|
|
96
100
|
fail(`OCI CLI returned invalid JSON for: ${args.join(' ')}`);
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
|
|
104
|
+
function resourceDisplayName(resource) {
|
|
105
|
+
return resource.displayName || resource['display-name'] || '';
|
|
106
|
+
}
|
|
107
|
+
|
|
100
108
|
function findApplicationId(compartmentId, appName) {
|
|
101
109
|
const result = jsonOci(['fn', 'application', 'list', '--compartment-id', compartmentId, '--all']);
|
|
102
|
-
const matches = (result.data || []).filter((app) => app
|
|
110
|
+
const matches = (result.data || []).filter((app) => resourceDisplayName(app) === appName);
|
|
103
111
|
if (matches.length === 0) {
|
|
104
112
|
fail(`Functions Application "${appName}" was not found. Code-only deploy requires an existing application.`);
|
|
105
113
|
}
|
|
@@ -109,7 +117,7 @@ function findApplicationId(compartmentId, appName) {
|
|
|
109
117
|
|
|
110
118
|
function findFunctionId(applicationId, functionName) {
|
|
111
119
|
const result = jsonOci(['fn', 'function', 'list', '--application-id', applicationId, '--all']);
|
|
112
|
-
const matches = (result.data || []).filter((fn) => fn
|
|
120
|
+
const matches = (result.data || []).filter((fn) => resourceDisplayName(fn) === functionName);
|
|
113
121
|
if (matches.length > 1) fail(`multiple functions are named "${functionName}" in the selected application.`);
|
|
114
122
|
return matches[0]?.id;
|
|
115
123
|
}
|
package/bin/destroy-code-only.js
CHANGED
|
@@ -24,8 +24,13 @@ function runOci(args) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function jsonOci(args) {
|
|
27
|
+
const output = runOci([...args, '--output', 'json']).trim();
|
|
28
|
+
const objectStart = output.indexOf('{');
|
|
29
|
+
const arrayStart = output.indexOf('[');
|
|
30
|
+
const start = objectStart !== -1 ? objectStart : arrayStart;
|
|
31
|
+
const end = Math.max(output.lastIndexOf('}'), output.lastIndexOf(']'));
|
|
27
32
|
try {
|
|
28
|
-
return JSON.parse(
|
|
33
|
+
return JSON.parse(start === -1 || end < start ? output : output.slice(start, end + 1));
|
|
29
34
|
} catch (error) {
|
|
30
35
|
fail(`OCI CLI returned invalid JSON for: ${args.join(' ')} (${error.message})`);
|
|
31
36
|
}
|
|
@@ -36,6 +41,10 @@ function yamlValue(contents, key) {
|
|
|
36
41
|
return (match?.[1] || match?.[2] || '').trim();
|
|
37
42
|
}
|
|
38
43
|
|
|
44
|
+
function resourceDisplayName(resource) {
|
|
45
|
+
return resource.displayName || resource['display-name'] || '';
|
|
46
|
+
}
|
|
47
|
+
|
|
39
48
|
function main() {
|
|
40
49
|
const compartmentId = (process.env.OCI_COMPARTMENT_ID || process.env.OCI_COMPARTMENT_OCID || '').trim();
|
|
41
50
|
if (!compartmentId) fail('set OCI_COMPARTMENT_ID (or OCI_COMPARTMENT_OCID).');
|
|
@@ -48,13 +57,13 @@ function main() {
|
|
|
48
57
|
|
|
49
58
|
const version = runOci(['--version']).trim();
|
|
50
59
|
const apps = jsonOci(['fn', 'application', 'list', '--compartment-id', compartmentId, '--all']).data || [];
|
|
51
|
-
const app = apps.find((item) => item
|
|
60
|
+
const app = apps.find((item) => resourceDisplayName(item) === appName);
|
|
52
61
|
if (!app) {
|
|
53
62
|
console.log(`Functions Application ${appName} is absent; no code-only function needs deletion.`);
|
|
54
63
|
return;
|
|
55
64
|
}
|
|
56
65
|
const functions = jsonOci(['fn', 'function', 'list', '--application-id', app.id, '--all']).data || [];
|
|
57
|
-
const matches = functions.filter((item) => item
|
|
66
|
+
const matches = functions.filter((item) => resourceDisplayName(item) === functionName);
|
|
58
67
|
if (matches.length === 0) {
|
|
59
68
|
console.log(`Code-only function ${functionName} is absent; continuing with Terraform destroy.`);
|
|
60
69
|
return;
|