This repository was archived by the owner on Dec 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (73 loc) · 2.78 KB
/
index.js
File metadata and controls
85 lines (73 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const core = require('@actions/core');
const https = require('https');
const { version } = require('./package.json');
async function makeRequest(options) {
return new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
let body = '';
res.on('data', chunk => body += chunk);
res.on('end', () => {
try {
resolve({
statusCode: res.statusCode,
body: body ? JSON.parse(body) : null
});
} catch (e) {
resolve({
statusCode: res.statusCode,
body: body
});
}
});
});
req.on('error', reject);
req.end();
});
}
async function getEphemeralConnectionSettings(apiHost, apiKey, jobId) {
const url = new URL(`/api/job/${jobId}/ephemeral_database_info`, apiHost);
const options = {
hostname: url.hostname,
port: url.port || 443,
path: url.pathname,
method: 'GET',
headers: {
'Authorization': `apikey ${apiKey}`,
'User-Agent': 'Tonic-Github-Action',
'X-GitHub-Action': 'structural-get-ephemeral-db-details',
'X-GitHub-Action-Version': version
}
};
const response = await makeRequest(options);
if (response.statusCode >= 400) {
throw new Error(`HTTP ${response.statusCode}: ${JSON.stringify(response.body)}`);
}
return response.body;
}
async function run() {
try {
const apiHost = core.getInput('structural-url');
const apiKey = core.getInput('structural-api-key');
const jobId = core.getInput('job-id');
core.info(`Obtaining ephemeral database connection settings for database linked to job ID: ${jobId}`);
const ephemeralSettings = await getEphemeralConnectionSettings(apiHost, apiKey, jobId);
core.info('Ephemeral database connection settings retrieved');
// Set connection details outputs
core.setOutput('hostname', ephemeralSettings.hostname || '');
core.setOutput('port', ephemeralSettings.port ? ephemeralSettings.port.toString() : '');
core.setOutput('database-name', ephemeralSettings.databaseName || '');
core.setOutput('database-username', ephemeralSettings.databaseUserName || '');
core.setOutput('database-password', ephemeralSettings.databasePassword || '');
core.setOutput('database-type', ephemeralSettings.databaseType || '');
// Set ephemeral database metadata outputs
core.setOutput('database-entity-id', ephemeralSettings.databaseEntityId || '');
core.setOutput('entity-name', ephemeralSettings.name || '');
core.setOutput('status', ephemeralSettings.status || '');
// Set raw response
core.setOutput('raw-response', JSON.stringify(ephemeralSettings));
core.info('Ephemeral database connection details set as outputs successfully');
} catch (error) {
core.setFailed(error.message);
}
}
run();