Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
99 lines (83 loc) · 2.42 KB
/
Copy pathutils.js
File metadata and controls
99 lines (83 loc) · 2.42 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const fs = require("fs");
/**
* Sets up authentication by reading from either a file or a string.
* The AUTH environment variable is set with the authentication details.
* @param {*} core - GitHub core library for setting outputs and environment variables.
*/
function setupAuth(core) {
let auth;
const fileName = process.env.AUTH_FILE_PATH;
const authStr = process.env.AUTH_STR;
// Check if any authentication method is provided
if (!checkEnvVarValid(fileName) && !checkEnvVarValid(authStr)) {
// core.info("Neither AUTH_FILE_PATH nor AUTH_STR is set. Proceeding using default provider environment variable names.");
return;
}
if (checkEnvVarValid(fileName)) {
try {
auth = fs.readFileSync(fileName, "utf-8");
} catch (error) {
core.error(error);
core.setFailed(`Cannot find auth file ${fileName}`);
return;
}
}
if (checkEnvVarValid(authStr)) {
auth = authStr;
}
core.info("Setting AUTH environment variable...");
core.exportVariable("AUTH", auth);
}
async function getStackqlCommand(core) {
// if (!checkEnvVarValid(process.env.AUTH)) {
// core.info("Cannot find AUTH environment variable when executing stackql. Proceeding using default provider environment variable names.");
// }
const [query, queryFilePath, auth, output = "json", vars] = [
process.env.QUERY,
process.env.QUERY_FILE_PATH,
process.env.AUTH,
process.env.OUTPUT,
process.env.VARS
];
if (!checkEnvVarValid(query) && !checkEnvVarValid(queryFilePath)) {
core.setFailed("Either query or query_file_path need to be set");
return;
}
let args = [];
if (queryFilePath) {
args = [
"exec",
"-i",
queryFilePath,
`--output='${output}'`,
];
}
if (query) {
args = [
"exec",
`"${query}"`,
`--output='${output}'`,
];
}
if (checkEnvVarValid(vars)) {
args.push(`--var="${vars}"`);
}
if (checkEnvVarValid(auth)) {
args.push(`--auth="${auth}"`);
}
try {
const stackQLCommand = `stackql ${args.join(" ")}`;
core.exportVariable('STACKQL_COMMAND', `${stackQLCommand}`);
// core.info(`STACKQL_COMMAND: ${stackQLCommand}`);
} catch (error) {
core.error(error);
core.setFailed("Error when executing stackql");
}
}
const checkEnvVarValid = (variable) => {
return variable !== null && variable !== undefined && variable !== "";
};
module.exports = {
setupAuth,
getStackqlCommand,
};