From 734bb65245add0754e4b8395fa8044c6510080d4 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:08:54 +1100 Subject: [PATCH 01/27] added setup auth function --- .github/workflows/set-up-stackql.yml | 2 ++ action.yml | 12 ++------ dist/index.js | 45 ++++++++++++++++++++++++++++ index.js | 45 ++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 9 deletions(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 1f598b6..85856e3 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -22,6 +22,8 @@ jobs: - name: Setup stackql uses: ./ + with: + authObjString: ${{secrets.authObjString}} - name: Validate Stackql Version run: | diff --git a/action.yml b/action.yml index db87682..51a7062 100644 --- a/action.yml +++ b/action.yml @@ -2,16 +2,10 @@ name: 'StackQL Studio - Setup StackQL' description: 'Sets up StackQL CLI in your GitHub Actions workflow.' author: 'Yuncheng Yang, StackQL' inputs: - platform: - description: 'Platform that function is running on' + authObjString: + description: 'The authentication object' required: false - # authentications_object_string: - # description: 'The authentication object' - # required: true - # stackql_wrapper: - # description: 'Whether or not to install a wrapper to wrap subsequent calls of the `stackql` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.' - # default: 'true' - # required: false + runs: using: 'node16' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index ec357af..77c78ea 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6748,12 +6748,57 @@ async function addPermission(){ } } +async function setupAuth(){ + /** + * AUTH='{ "google": { "credentialsfilepath": "creds/stackql-demo.json", "type": "service_account" }, + * "okta": { "credentialsenvvar": "OKTA_SECRET_KEY", "type": "api_key", credentials: '' }}' + */ + /** + * expected auth obj + * { + * okta :{ + * type: "api_key", + * credentialsenvvar: 'OKTA_SECRET_KEY', + * credentials: '' + * } + * } + */ + + /** + * When credentials envvar exist, set a env var in the action + * key = + * value = + */ + const authObjString = core.getInput("authObjString"); + try { + const authObj = JSON.parse(authObjString) + Object.keys(authObj).forEach(providerName =>{ + const providerAuth = authObj[providerName] + if (providerAuth.credentialsenvvar && providerAuth.credentials) { + core.exportVariable(providerAuth.credentialsenvvar, providerAuth.credentials) + delete authObj[providerName]['credentials'] + } + //TODO: if provider auth is a file + + }) + + const stackqlAuthString = JSON.stringify(authObj) + core.info('Setting AUTH string %o', stackqlAuthString) + core.exportVariable('AUTH', stackqlAuthString) + + } catch (error) { + throw Error('Error when setup auth %o', error) + } + +} + async function setup(){ const path = await downloadCLI() core.addPath(path) await addPermission() + setupAuth() } (async () => { diff --git a/index.js b/index.js index 41e18f9..546f507 100644 --- a/index.js +++ b/index.js @@ -46,12 +46,57 @@ async function addPermission(){ } } +async function setupAuth(){ + /** + * AUTH='{ "google": { "credentialsfilepath": "creds/stackql-demo.json", "type": "service_account" }, + * "okta": { "credentialsenvvar": "OKTA_SECRET_KEY", "type": "api_key", credentials: '' }}' + */ + /** + * expected auth obj + * { + * okta :{ + * type: "api_key", + * credentialsenvvar: 'OKTA_SECRET_KEY', + * credentials: '' + * } + * } + */ + + /** + * When credentials envvar exist, set a env var in the action + * key = + * value = + */ + const authObjString = core.getInput("authObjString"); + try { + const authObj = JSON.parse(authObjString) + Object.keys(authObj).forEach(providerName =>{ + const providerAuth = authObj[providerName] + if (providerAuth.credentialsenvvar && providerAuth.credentials) { + core.exportVariable(providerAuth.credentialsenvvar, providerAuth.credentials) + delete authObj[providerName]['credentials'] + } + //TODO: if provider auth is a file + + }) + + const stackqlAuthString = JSON.stringify(authObj) + core.info('Setting AUTH string %o', stackqlAuthString) + core.exportVariable('AUTH', stackqlAuthString) + + } catch (error) { + throw Error('Error when setup auth %o', error) + } + +} + async function setup(){ const path = await downloadCLI() core.addPath(path) await addPermission() + setupAuth() } (async () => { From 1c5fddf58abb653bdd3f6b58f17631b9ae74fc45 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:09:04 +1100 Subject: [PATCH 02/27] added setup auth function --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d760c4a --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# setup-stackql + +The `stackql/setup-stackql` action is a JavaScript action that sets up Terraform CLI in your GitHub Actions workflow by: + +- Downloading a latest Stackql CLI and adding it to the `PATH`. +- Setup AUTH env var in the Github Action + +## Auth object string +Example +``` +{ + "google": { "credentialsfilepath": "creds/stackql-demo.json", "type": "service_account" }, + "okta": { "credentialsenvvar": "OKTA_SECRET_KEY", "type": "api_key", credentials: '' } +} +``` + From 145ad0763f669ab388eb4d40b18dc1ff71fea416 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:16:09 +1100 Subject: [PATCH 03/27] debug setup auth error --- .github/workflows/set-up-stackql.yml | 2 +- dist/index.js | 3 +-- index.js | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 85856e3..d746959 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -23,7 +23,7 @@ jobs: - name: Setup stackql uses: ./ with: - authObjString: ${{secrets.authObjString}} + authObjString: ${{secrets.AUTH_OBJECT_STR}} - name: Validate Stackql Version run: | diff --git a/dist/index.js b/dist/index.js index 77c78ea..04de428 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6779,7 +6779,6 @@ async function setupAuth(){ delete authObj[providerName]['credentials'] } //TODO: if provider auth is a file - }) const stackqlAuthString = JSON.stringify(authObj) @@ -6787,7 +6786,7 @@ async function setupAuth(){ core.exportVariable('AUTH', stackqlAuthString) } catch (error) { - throw Error('Error when setup auth %o', error) + throw Error(`Error when setup auth ${error}`) } } diff --git a/index.js b/index.js index 546f507..99664ee 100644 --- a/index.js +++ b/index.js @@ -77,7 +77,6 @@ async function setupAuth(){ delete authObj[providerName]['credentials'] } //TODO: if provider auth is a file - }) const stackqlAuthString = JSON.stringify(authObj) @@ -85,7 +84,7 @@ async function setupAuth(){ core.exportVariable('AUTH', stackqlAuthString) } catch (error) { - throw Error('Error when setup auth %o', error) + throw Error(`Error when setup auth ${error}`) } } From ca6ad1bf0b40e3bf7506539da7fc28f5218e1ba9 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:21:35 +1100 Subject: [PATCH 04/27] debug setup auth error --- dist/index.js | 1 + index.js | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/index.js b/dist/index.js index 04de428..5e71507 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6771,6 +6771,7 @@ async function setupAuth(){ */ const authObjString = core.getInput("authObjString"); try { + core.info('auth Obj string is %o', authObjString) const authObj = JSON.parse(authObjString) Object.keys(authObj).forEach(providerName =>{ const providerAuth = authObj[providerName] diff --git a/index.js b/index.js index 99664ee..53f9c63 100644 --- a/index.js +++ b/index.js @@ -69,6 +69,7 @@ async function setupAuth(){ */ const authObjString = core.getInput("authObjString"); try { + core.info('auth Obj string is %o', authObjString) const authObj = JSON.parse(authObjString) Object.keys(authObj).forEach(providerName =>{ const providerAuth = authObj[providerName] From 57309dca7d8097be3913b4809ebe4b3715b55a06 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:23:07 +1100 Subject: [PATCH 05/27] debug setup auth error --- dist/index.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5e71507..98c60fb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6771,7 +6771,7 @@ async function setupAuth(){ */ const authObjString = core.getInput("authObjString"); try { - core.info('auth Obj string is %o', authObjString) + core.info(`auth Obj string is ${authObjString}` ) const authObj = JSON.parse(authObjString) Object.keys(authObj).forEach(providerName =>{ const providerAuth = authObj[providerName] diff --git a/index.js b/index.js index 53f9c63..25b636a 100644 --- a/index.js +++ b/index.js @@ -69,7 +69,7 @@ async function setupAuth(){ */ const authObjString = core.getInput("authObjString"); try { - core.info('auth Obj string is %o', authObjString) + core.info(`auth Obj string is ${authObjString}` ) const authObj = JSON.parse(authObjString) Object.keys(authObj).forEach(providerName =>{ const providerAuth = authObj[providerName] From 153d561d5e2ab35507c1292f12ebbbc5b04063e1 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:24:05 +1100 Subject: [PATCH 06/27] debug setup auth error --- .github/workflows/set-up-stackql.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index d746959..08aeadd 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -19,11 +19,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + authObjString: ${{secrets.AUTH_OBJECT_STR}} - name: Setup stackql uses: ./ - with: - authObjString: ${{secrets.AUTH_OBJECT_STR}} + - name: Validate Stackql Version run: | From 0020138cb5218938ab7ce41deee31a9106b032b7 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:27:43 +1100 Subject: [PATCH 07/27] debug setup auth error --- .github/workflows/set-up-stackql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 08aeadd..951d85c 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -20,7 +20,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - authObjString: ${{secrets.AUTH_OBJECT_STR}} + authObjString: ${{ secrets.AUTH_OBJECT_STR }} - name: Setup stackql uses: ./ From 193cbd834cd776c68f46a01159868afacd408f5a Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:28:12 +1100 Subject: [PATCH 08/27] move the input to correct step --- .github/workflows/set-up-stackql.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 951d85c..e045f6e 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -19,11 +19,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - with: - authObjString: ${{ secrets.AUTH_OBJECT_STR }} - name: Setup stackql uses: ./ + with: + authObjString: ${{ secrets.AUTH_OBJECT_STR }} - name: Validate Stackql Version From fca8cb7f7960dc9fc4654a323332fb9c04b8bea5 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:30:23 +1100 Subject: [PATCH 09/27] imporve error message --- dist/index.js | 5 +++++ index.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/dist/index.js b/dist/index.js index 98c60fb..020d781 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6772,6 +6772,11 @@ async function setupAuth(){ const authObjString = core.getInput("authObjString"); try { core.info(`auth Obj string is ${authObjString}` ) + + if(!authObjString) { + throw Error ('Cannot find auth object string') + } + const authObj = JSON.parse(authObjString) Object.keys(authObj).forEach(providerName =>{ const providerAuth = authObj[providerName] diff --git a/index.js b/index.js index 25b636a..f04497a 100644 --- a/index.js +++ b/index.js @@ -70,6 +70,11 @@ async function setupAuth(){ const authObjString = core.getInput("authObjString"); try { core.info(`auth Obj string is ${authObjString}` ) + + if(!authObjString) { + throw Error ('Cannot find auth object string') + } + const authObj = JSON.parse(authObjString) Object.keys(authObj).forEach(providerName =>{ const providerAuth = authObj[providerName] From 9b19a158c84c13646eb024f69bc63e1a8f5735ba Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:34:28 +1100 Subject: [PATCH 10/27] require auth string --- action.yml | 2 +- dist/index.js | 4 ++-- index.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 51a7062..c03c349 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,7 @@ author: 'Yuncheng Yang, StackQL' inputs: authObjString: description: 'The authentication object' - required: false + required: true runs: using: 'node16' diff --git a/dist/index.js b/dist/index.js index 020d781..771676f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6772,8 +6772,8 @@ async function setupAuth(){ const authObjString = core.getInput("authObjString"); try { core.info(`auth Obj string is ${authObjString}` ) - - if(!authObjString) { + + if(!authObjString || !authObjString.trim().length ) { throw Error ('Cannot find auth object string') } diff --git a/index.js b/index.js index f04497a..2e5e65b 100644 --- a/index.js +++ b/index.js @@ -70,8 +70,8 @@ async function setupAuth(){ const authObjString = core.getInput("authObjString"); try { core.info(`auth Obj string is ${authObjString}` ) - - if(!authObjString) { + + if(!authObjString || !authObjString.trim().length ) { throw Error ('Cannot find auth object string') } From 6964799d5b1711e4c8be568d6b9abc81811f51e7 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:36:35 +1100 Subject: [PATCH 11/27] testing what happen without the org --- .github/workflows/set-up-stackql.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index e045f6e..27bebc3 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -22,8 +22,8 @@ jobs: - name: Setup stackql uses: ./ - with: - authObjString: ${{ secrets.AUTH_OBJECT_STR }} + # with: + # # authObjString: ${{ secrets.AUTH_OBJECT_STR }} - name: Validate Stackql Version From 8260e0aebbdff8fb2e4caf9ccb2f081fe187d600 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:37:42 +1100 Subject: [PATCH 12/27] testing what happen without the org --- dist/index.js | 1 + index.js | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/index.js b/dist/index.js index 771676f..72e92bd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6771,6 +6771,7 @@ async function setupAuth(){ */ const authObjString = core.getInput("authObjString"); try { + core.info(core.getInput("authObjString")) core.info(`auth Obj string is ${authObjString}` ) if(!authObjString || !authObjString.trim().length ) { diff --git a/index.js b/index.js index 2e5e65b..1be7ab4 100644 --- a/index.js +++ b/index.js @@ -69,6 +69,7 @@ async function setupAuth(){ */ const authObjString = core.getInput("authObjString"); try { + core.info(core.getInput("authObjString")) core.info(`auth Obj string is ${authObjString}` ) if(!authObjString || !authObjString.trim().length ) { From cb77fcd32aad7ab6117899df4ba047ea3b7a98c1 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:38:44 +1100 Subject: [PATCH 13/27] testing what happen without the org --- .github/workflows/set-up-stackql.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 27bebc3..f7743c8 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -1,4 +1,4 @@ -name: 'Setup Terraform' +name: 'Setup StackQL' on: push: @@ -22,8 +22,8 @@ jobs: - name: Setup stackql uses: ./ - # with: - # # authObjString: ${{ secrets.AUTH_OBJECT_STR }} + with: + authObjString: 'test' - name: Validate Stackql Version From 62f99c3afa8e5124417a0574569aba6e0f86393e Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:40:22 +1100 Subject: [PATCH 14/27] remove quotes --- .github/workflows/set-up-stackql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index f7743c8..09c549b 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -23,7 +23,7 @@ jobs: - name: Setup stackql uses: ./ with: - authObjString: 'test' + authObjString: ${{ secrets.AUTH_OBJECT_STR }} - name: Validate Stackql Version From d153b5d82e4cceb4994ac3e20ff40b9054d98b8b Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:47:49 +1100 Subject: [PATCH 15/27] try if need to set as env instead --- .github/workflows/set-up-stackql.yml | 2 ++ dist/index.js | 1 + index.js | 1 + 3 files changed, 4 insertions(+) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 09c549b..169b177 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -24,6 +24,8 @@ jobs: uses: ./ with: authObjString: ${{ secrets.AUTH_OBJECT_STR }} + env: + AUTH_OBJ_STR: ${{ secrets.AUTH_OBJECT_STR }} - name: Validate Stackql Version diff --git a/dist/index.js b/dist/index.js index 72e92bd..4852402 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6772,6 +6772,7 @@ async function setupAuth(){ const authObjString = core.getInput("authObjString"); try { core.info(core.getInput("authObjString")) + core.info(process.env['AUTH_OBJ_STR']) core.info(`auth Obj string is ${authObjString}` ) if(!authObjString || !authObjString.trim().length ) { diff --git a/index.js b/index.js index 1be7ab4..0f5bbca 100644 --- a/index.js +++ b/index.js @@ -70,6 +70,7 @@ async function setupAuth(){ const authObjString = core.getInput("authObjString"); try { core.info(core.getInput("authObjString")) + core.info(process.env['AUTH_OBJ_STR']) core.info(`auth Obj string is ${authObjString}` ) if(!authObjString || !authObjString.trim().length ) { From d3710737f9c385808760b55966fc465859f1e097 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:50:31 +1100 Subject: [PATCH 16/27] try if need to set as env instead --- .github/workflows/set-up-stackql.yml | 2 -- dist/index.js | 4 +--- index.js | 4 +--- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 169b177..09c549b 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -24,8 +24,6 @@ jobs: uses: ./ with: authObjString: ${{ secrets.AUTH_OBJECT_STR }} - env: - AUTH_OBJ_STR: ${{ secrets.AUTH_OBJECT_STR }} - name: Validate Stackql Version diff --git a/dist/index.js b/dist/index.js index 4852402..2bdfc79 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6771,11 +6771,9 @@ async function setupAuth(){ */ const authObjString = core.getInput("authObjString"); try { - core.info(core.getInput("authObjString")) - core.info(process.env['AUTH_OBJ_STR']) core.info(`auth Obj string is ${authObjString}` ) - if(!authObjString || !authObjString.trim().length ) { + if(!authObjString || authObjString === "" ) { throw Error ('Cannot find auth object string') } diff --git a/index.js b/index.js index 0f5bbca..ab29a8c 100644 --- a/index.js +++ b/index.js @@ -69,11 +69,9 @@ async function setupAuth(){ */ const authObjString = core.getInput("authObjString"); try { - core.info(core.getInput("authObjString")) - core.info(process.env['AUTH_OBJ_STR']) core.info(`auth Obj string is ${authObjString}` ) - if(!authObjString || !authObjString.trim().length ) { + if(!authObjString || authObjString === "" ) { throw Error ('Cannot find auth object string') } From 88b41bd4d40e19504d39aea359fed8545e71c0b8 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 19:55:04 +1100 Subject: [PATCH 17/27] try imporve result logging --- dist/index.js | 3 +-- index.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2bdfc79..49bf6f5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6771,7 +6771,6 @@ async function setupAuth(){ */ const authObjString = core.getInput("authObjString"); try { - core.info(`auth Obj string is ${authObjString}` ) if(!authObjString || authObjString === "" ) { throw Error ('Cannot find auth object string') @@ -6788,7 +6787,7 @@ async function setupAuth(){ }) const stackqlAuthString = JSON.stringify(authObj) - core.info('Setting AUTH string %o', stackqlAuthString) + core.info(`Setting AUTH string ${stackqlAuthString}` ) core.exportVariable('AUTH', stackqlAuthString) } catch (error) { diff --git a/index.js b/index.js index ab29a8c..d9e4df6 100644 --- a/index.js +++ b/index.js @@ -69,7 +69,6 @@ async function setupAuth(){ */ const authObjString = core.getInput("authObjString"); try { - core.info(`auth Obj string is ${authObjString}` ) if(!authObjString || authObjString === "" ) { throw Error ('Cannot find auth object string') @@ -86,7 +85,7 @@ async function setupAuth(){ }) const stackqlAuthString = JSON.stringify(authObj) - core.info('Setting AUTH string %o', stackqlAuthString) + core.info(`Setting AUTH string ${stackqlAuthString}` ) core.exportVariable('AUTH', stackqlAuthString) } catch (error) { From 00532013e3627e4395370e24107e2d439b220fdd Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 20:04:43 +1100 Subject: [PATCH 18/27] added pull github setp in test workflow --- .github/workflows/set-up-stackql.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 09c549b..170d62a 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -28,4 +28,8 @@ jobs: - name: Validate Stackql Version run: | - stackql --version \ No newline at end of file + stackql --version + + - name: Pull Github + run: | + stackql exec "REGISTRY PULL github v23.01.00104;"" --auth="${AUTH}" \ No newline at end of file From c69af418f4c325e78ddd3e50a0e8764c13740c2e Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 20:05:37 +1100 Subject: [PATCH 19/27] added pull github setp in test workflow --- .github/workflows/set-up-stackql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 170d62a..7d7ff78 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -32,4 +32,4 @@ jobs: - name: Pull Github run: | - stackql exec "REGISTRY PULL github v23.01.00104;"" --auth="${AUTH}" \ No newline at end of file + stackql exec "REGISTRY PULL github v23.01.00104;" --auth="${AUTH}" \ No newline at end of file From 7eb7dfec5a3606a9c36c3afb03e706b8cce8b191 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 20:12:08 +1100 Subject: [PATCH 20/27] try to use a iql script; --- .github/workflows/set-up-stackql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 7d7ff78..6cb0618 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -32,4 +32,4 @@ jobs: - name: Pull Github run: | - stackql exec "REGISTRY PULL github v23.01.00104;" --auth="${AUTH}" \ No newline at end of file + stackql exec -i ./examples/get-github-commits --auth="${AUTH}" \ No newline at end of file From ad26b7d2f98622c7d81a336c3755f8b61d57c716 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 20:12:15 +1100 Subject: [PATCH 21/27] try to use a iql script; --- examples/get-github-commits.iql | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 examples/get-github-commits.iql diff --git a/examples/get-github-commits.iql b/examples/get-github-commits.iql new file mode 100644 index 0000000..bd8d9f1 --- /dev/null +++ b/examples/get-github-commits.iql @@ -0,0 +1,5 @@ +REGISTRY PULL github v23.01.00104; + +SELECT github.repos.commits.sha +FROM github.repos.commits +WHERE owner='stackql' AND repo='stackql'; \ No newline at end of file From c6780edee764d116f5af0e5d2f2baec6af6c32a1 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 20:13:01 +1100 Subject: [PATCH 22/27] try to use a iql script; --- .github/workflows/set-up-stackql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 6cb0618..14a7f04 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -32,4 +32,4 @@ jobs: - name: Pull Github run: | - stackql exec -i ./examples/get-github-commits --auth="${AUTH}" \ No newline at end of file + stackql exec -i ./examples/get-github-commits.iql --auth="${AUTH}" \ No newline at end of file From e8bbaf8c8036f2481488238823df3df1dd4e4996 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 20:15:12 +1100 Subject: [PATCH 23/27] try to use private resource --- examples/get-github-commits.iql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/get-github-commits.iql b/examples/get-github-commits.iql index bd8d9f1..ae4d067 100644 --- a/examples/get-github-commits.iql +++ b/examples/get-github-commits.iql @@ -1,5 +1,5 @@ REGISTRY PULL github v23.01.00104; - -SELECT github.repos.commits.sha -FROM github.repos.commits -WHERE owner='stackql' AND repo='stackql'; \ No newline at end of file +SHOW PROVIDERS; +select id, name, private +from github.repos_orgs.repos_orgs +where org = 'stackql'; \ No newline at end of file From 55c069f606403d4261dfe82d39a42ea0f31769d5 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 20:20:57 +1100 Subject: [PATCH 24/27] change the script based on updated doc --- examples/get-github-commits.iql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/get-github-commits.iql b/examples/get-github-commits.iql index ae4d067..f6e72cb 100644 --- a/examples/get-github-commits.iql +++ b/examples/get-github-commits.iql @@ -1,5 +1,5 @@ REGISTRY PULL github v23.01.00104; SHOW PROVIDERS; -select id, name, private -from github.repos_orgs.repos_orgs +select total_private_repos +from github.orgs.orgs where org = 'stackql'; \ No newline at end of file From 3fcab73042ff63a86c928178d093dd52c609b8c3 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 20:22:23 +1100 Subject: [PATCH 25/27] slight name change --- .github/workflows/set-up-stackql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 14a7f04..53798a5 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -30,6 +30,6 @@ jobs: run: | stackql --version - - name: Pull Github + - name: Use GitHub Provider run: | stackql exec -i ./examples/get-github-commits.iql --auth="${AUTH}" \ No newline at end of file From d521afd52a6474de00fda03f17b345c7faabe69b Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 23:48:46 +1100 Subject: [PATCH 26/27] remove setup auth in aciton, use github vars and secrets instead --- .github/workflows/set-up-stackql.yml | 7 ++-- action.yml | 5 +-- dist/index.js | 49 ---------------------------- index.js | 49 ---------------------------- 4 files changed, 5 insertions(+), 105 deletions(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 53798a5..20fc7ca 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -22,8 +22,6 @@ jobs: - name: Setup stackql uses: ./ - with: - authObjString: ${{ secrets.AUTH_OBJECT_STR }} - name: Validate Stackql Version @@ -32,4 +30,7 @@ jobs: - name: Use GitHub Provider run: | - stackql exec -i ./examples/get-github-commits.iql --auth="${AUTH}" \ No newline at end of file + stackql exec -i ./examples/get-github-commits.iql --auth="${AUTH}" + env: + AUTH: ${{ vars.AUTH }} + GITHUB_CREDS: ${{ secrets.STACKQL_GITHUB_CREDS }} \ No newline at end of file diff --git a/action.yml b/action.yml index c03c349..fbd6331 100644 --- a/action.yml +++ b/action.yml @@ -1,10 +1,7 @@ name: 'StackQL Studio - Setup StackQL' description: 'Sets up StackQL CLI in your GitHub Actions workflow.' author: 'Yuncheng Yang, StackQL' -inputs: - authObjString: - description: 'The authentication object' - required: true + runs: using: 'node16' diff --git a/dist/index.js b/dist/index.js index 49bf6f5..ec357af 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6748,61 +6748,12 @@ async function addPermission(){ } } -async function setupAuth(){ - /** - * AUTH='{ "google": { "credentialsfilepath": "creds/stackql-demo.json", "type": "service_account" }, - * "okta": { "credentialsenvvar": "OKTA_SECRET_KEY", "type": "api_key", credentials: '' }}' - */ - /** - * expected auth obj - * { - * okta :{ - * type: "api_key", - * credentialsenvvar: 'OKTA_SECRET_KEY', - * credentials: '' - * } - * } - */ - - /** - * When credentials envvar exist, set a env var in the action - * key = - * value = - */ - const authObjString = core.getInput("authObjString"); - try { - - if(!authObjString || authObjString === "" ) { - throw Error ('Cannot find auth object string') - } - - const authObj = JSON.parse(authObjString) - Object.keys(authObj).forEach(providerName =>{ - const providerAuth = authObj[providerName] - if (providerAuth.credentialsenvvar && providerAuth.credentials) { - core.exportVariable(providerAuth.credentialsenvvar, providerAuth.credentials) - delete authObj[providerName]['credentials'] - } - //TODO: if provider auth is a file - }) - - const stackqlAuthString = JSON.stringify(authObj) - core.info(`Setting AUTH string ${stackqlAuthString}` ) - core.exportVariable('AUTH', stackqlAuthString) - - } catch (error) { - throw Error(`Error when setup auth ${error}`) - } - -} - async function setup(){ const path = await downloadCLI() core.addPath(path) await addPermission() - setupAuth() } (async () => { diff --git a/index.js b/index.js index d9e4df6..41e18f9 100644 --- a/index.js +++ b/index.js @@ -46,61 +46,12 @@ async function addPermission(){ } } -async function setupAuth(){ - /** - * AUTH='{ "google": { "credentialsfilepath": "creds/stackql-demo.json", "type": "service_account" }, - * "okta": { "credentialsenvvar": "OKTA_SECRET_KEY", "type": "api_key", credentials: '' }}' - */ - /** - * expected auth obj - * { - * okta :{ - * type: "api_key", - * credentialsenvvar: 'OKTA_SECRET_KEY', - * credentials: '' - * } - * } - */ - - /** - * When credentials envvar exist, set a env var in the action - * key = - * value = - */ - const authObjString = core.getInput("authObjString"); - try { - - if(!authObjString || authObjString === "" ) { - throw Error ('Cannot find auth object string') - } - - const authObj = JSON.parse(authObjString) - Object.keys(authObj).forEach(providerName =>{ - const providerAuth = authObj[providerName] - if (providerAuth.credentialsenvvar && providerAuth.credentials) { - core.exportVariable(providerAuth.credentialsenvvar, providerAuth.credentials) - delete authObj[providerName]['credentials'] - } - //TODO: if provider auth is a file - }) - - const stackqlAuthString = JSON.stringify(authObj) - core.info(`Setting AUTH string ${stackqlAuthString}` ) - core.exportVariable('AUTH', stackqlAuthString) - - } catch (error) { - throw Error(`Error when setup auth ${error}`) - } - -} - async function setup(){ const path = await downloadCLI() core.addPath(path) await addPermission() - setupAuth() } (async () => { From 71aaf6b7535cc5335268ec86368cf2dd885f0820 Mon Sep 17 00:00:00 2001 From: Yuncheng Date: Sun, 22 Jan 2023 23:53:11 +1100 Subject: [PATCH 27/27] fix wrong env var name --- .github/workflows/set-up-stackql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/set-up-stackql.yml b/.github/workflows/set-up-stackql.yml index 20fc7ca..aa84b6b 100644 --- a/.github/workflows/set-up-stackql.yml +++ b/.github/workflows/set-up-stackql.yml @@ -33,4 +33,4 @@ jobs: stackql exec -i ./examples/get-github-commits.iql --auth="${AUTH}" env: AUTH: ${{ vars.AUTH }} - GITHUB_CREDS: ${{ secrets.STACKQL_GITHUB_CREDS }} \ No newline at end of file + STACKQL_GITHUB_CREDS: ${{ secrets.STACKQL_GITHUB_CREDS }} \ No newline at end of file