Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions .github/workflows/stackql-exec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,20 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Prep Google Creds (Windows)
if: ${{ matrix.os == 'windows-latest'}}
run: | ## use the secret to create json file
$GoogleCreds = [System.Environment]::GetEnvironmentVariable("GOOGLE_CREDS_ENV")
$GoogleCredsDecoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($GoogleCreds))
Write-Output $GoogleCredsDecoded | Set-Content sa-key.json
shell: pwsh
env:
GOOGLE_CREDS_ENV: ${{ secrets.GOOGLE_CREDS }}

- name: Prep Google Creds (bash)
if: ${{ matrix.os != 'windows-latest' }}
shell: bash
run: | ## use the base64 encoded secret to create json file
sudo echo ${{ secrets.GOOGLE_CREDS }} | base64 -d > sa-key.json

- name: exec google example with query file
id: stackql-exec-file
uses: ./
with:
auth_obj_path: './stackql_scripts/auth.json'
query_file_path: './stackql_scripts/google-example.iql'
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_CREDS }}

- name: exec github example with query string
- name: exec github example with query string, use auth string to override
id: stackql-exec-string
uses: ./
with:
auth_str: '{ "github": { "type": "basic", "credentialsenvvar": "STACKQL_GITHUB_CREDS" } }'
query: "REGISTRY PULL github v23.01.00104;
query: "REGISTRY PULL github;
SHOW PROVIDERS;
select total_private_repos
from github.orgs.orgs
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Github Action as a wrapper for executing a single command in stackql, maps all s

## AUTH

### Use Environment Variables
- You can use [Github Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) to store the value of the environment variable, and use env to pass it to the action. For example:



`Example auth string`
```
{ "google": { "type": "service_account", "credentialsfilepath": "sa-key.json" },
Expand Down
32 changes: 16 additions & 16 deletions lib/tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ describe("util", () => {
process.env = AUTH_ENV;
});

it("should throw error when neither AUTH_STR or AUTH_FILE_PATH is set", () => {
process.env.AUTH_STR = undefined;
process.env.AUTH_FILE_PATH = undefined;
// it("should throw error when neither AUTH_STR or AUTH_FILE_PATH is set", () => {
// process.env.AUTH_STR = undefined;
// process.env.AUTH_FILE_PATH = undefined;

setupAuth(core);
expect(core.setFailed).toBeCalledWith(
"Either AUTH_FILE_PATH or AUTH_STR must be set."
);
});
// setupAuth(core);
// expect(core.setFailed).toBeCalledWith(
// "Either AUTH_FILE_PATH or AUTH_STR must be set."
// );
// });

it("should set AUTH environment variable when AUTH_STR is set", () => {
process.env.AUTH_FILE_PATH = undefined;
Expand Down Expand Up @@ -101,16 +101,16 @@ describe("util", () => {
);
});

it("should return error when there is no AUTH", async () => {
process.env = { ...EXECUTE_ENV };
process.env.AUTH = undefined;
// it("should return error when there is no AUTH", async () => {
// process.env = { ...EXECUTE_ENV };
// process.env.AUTH = undefined;

getStackqlCommand(core);
// getStackqlCommand(core);

expect(core.setFailed).toHaveBeenCalledWith(
"Cannot find AUTH environment variable when executing stackql"
);
});
// expect(core.setFailed).toHaveBeenCalledWith(
// "Cannot find AUTH environment variable when executing stackql"
// );
// });

it("should execute stackql with query file path", async () => {
process.env = { ...EXECUTE_ENV };
Expand Down
30 changes: 12 additions & 18 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@

function setupAuth(core) {
const fs = require("fs");
let auth;
const fileName = process.env.AUTH_FILE_PATH;
const authStr = process.env.AUTH_STR;

if (!checkEnvVarValid(fileName) && !checkEnvVarValid(authStr)) {
core.setFailed("Either AUTH_FILE_PATH or AUTH_STR must be set.");
return;
}

if (checkEnvVarValid(fileName)) {
try {
// Read the contents of the JSON file into a string
Expand All @@ -21,48 +15,48 @@ function setupAuth(core) {
}
}
if (checkEnvVarValid(authStr)) {
auth = authStr
auth = authStr;
}

core.info("Setting AUTH environment variable...");
core.exportVariable("AUTH", auth);
}

async function getStackqlCommand(core) {

if (!checkEnvVarValid(process.env.AUTH)) {
core.setFailed("Cannot find AUTH environment variable when executing stackql");
return;
}
// if (!checkEnvVarValid(process.env.AUTH)) {
// core.setFailed(
// "Cannot find AUTH environment variable when executing stackql"
// );
// return;
// }
let [query, queryFilePath, auth, output = "json"] = [
process.env.QUERY,
process.env.QUERY_FILE_PATH,
process.env.AUTH,
process.env.OUTPUT,
];



if (!checkEnvVarValid(query) && !checkEnvVarValid(queryFilePath)) {
core.setFailed("Either query or query_file_path need to be set");
return;
}

let args = [];
const authArg = auth ? `--auth='${auth}'` : "";
if (queryFilePath) {
args = [
"exec",
"-i",
queryFilePath,
`--auth='${auth}'`,
`--output='${output}'`
authArg,
`--output='${output}'`,
];
}
if (query) {
args = ["exec", `"${query}"`, `--auth='${auth}'`, `--output='${output}'`];
args = ["exec", `"${query}"`, authArg, `--output='${output}'`];
}
try {
core.exportVariable('STACKQL_COMMAND', `stackql ${args.join(" ")}`)
core.exportVariable("STACKQL_COMMAND", `stackql ${args.join(" ")}`);
} catch (error) {
core.error(error);
core.setFailed("Error when executing stackql");
Expand Down
2 changes: 1 addition & 1 deletion stackql_scripts/github-example.iql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
REGISTRY PULL github v23.01.00104;
REGISTRY PULL github;
SHOW PROVIDERS;
select total_private_repos
from github.orgs.orgs
Expand Down
2 changes: 1 addition & 1 deletion stackql_scripts/google-example.iql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
REGISTRY PULL google v23.01.00116;
REGISTRY PULL google;
SELECT name, status
FROM google.compute.instances
WHERE project = 'stackql-demo' AND zone = 'australia-southeast1-a';