Skip to content

Commit f5fcb6b

Browse files
committed
chore: adding change auth code
1 parent 076b1ea commit f5fcb6b

File tree

7 files changed

+177
-112
lines changed

7 files changed

+177
-112
lines changed

.github/workflows/test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test Action
2+
3+
on: push
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout repository
10+
uses: actions/checkout@v2
11+
12+
- name: Setup Meshstack Authentication
13+
id: setup-meshstack-auth
14+
uses: ./
15+
with:
16+
base_url: 'https://federation.dev.meshcloud.io'
17+
bb_run_uuid: 'example-uuid'
18+
steps: |
19+
[
20+
{ "id": "terraform-validate", "displayName": "terraform validate" },
21+
{ "id": "terraform-plan", "displayName": "terraform plan" },
22+
{ "id": "terraform-apply", "displayName": "terraform apply" }
23+
]
24+
client_id: ${{ secrets.CLIENT_ID }}
25+
key_secret: ${{ secrets.KEY_SECRET }}
26+
27+
# - name: Read token from file
28+
# id: read-token
29+
# run: |
30+
# token=$(cat ${{ steps.setup-meshstack-auth.outputs.token_file }} | jq -r .token)
31+
# echo "MESHSTACK_API_TOKEN=$token" >> $GITHUB_ENV
32+
33+
# - name: Send status
34+
# uses: meshcloud/actions-send-status@v0.0.1
35+
# with:
36+
# base_url: 'https://example.com'
37+
# bb_run_uuid: 'example-uuid'
38+
# step_id: "terraform-validate"
39+
# status: 'SUCCEEDED'
40+
# token: ${{ env.MESHSTACK_API_TOKEN }}
41+
# user_message: 'Successful validate Terraform configuration.'
42+
# system_message: 'Successful validate Terraform configuration.'
43+
#

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ jspm_packages/
4545
*.sln
4646
*.sw?
4747

48+
#testing secret
49+
.secrets

dist/index.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/******/ (() => { // webpackBootstrap
22
/******/ var __webpack_modules__ = ({
33

4-
/***/ 4822:
4+
/***/ 9283:
55
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
66

77
"use strict";
@@ -36,19 +36,37 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3636
const core = __importStar(__nccwpck_require__(2186));
3737
const github = __importStar(__nccwpck_require__(5438));
3838
const axios_1 = __importDefault(__nccwpck_require__(8757));
39+
const fs = __importStar(__nccwpck_require__(7147));
40+
const path = __importStar(__nccwpck_require__(1017));
41+
const os = __importStar(__nccwpck_require__(2037));
3942
async function run() {
4043
try {
4144
const baseUrl = core.getInput('base_url');
4245
const bbRunUuid = core.getInput('bb_run_uuid');
43-
const steps = core.getInput('steps');
44-
const token = core.getInput('token');
46+
const stepsInput = core.getInput('steps');
47+
const clientId = core.getInput('client_id');
48+
const keySecret = core.getInput('key_secret');
49+
// Parse the steps input
50+
const steps = JSON.parse(`[${stepsInput}]`);
51+
// Authenticate and get the token
52+
const authResponse = await axios_1.default.post(`${baseUrl}/api/login`, `grant_type=client_credentials&client_id=${clientId}&client_secret=${keySecret}`, {
53+
headers: {
54+
'Content-Type': 'application/x-www-form-urlencoded'
55+
}
56+
});
57+
const token = authResponse.data.access_token;
58+
// Write token to a temporary file
59+
const tempDir = process.env.RUNNER_TEMP || os.tmpdir();
60+
const tokenFilePath = path.join(tempDir, 'meshstack_token.json');
61+
fs.writeFileSync(tokenFilePath, JSON.stringify({ token }));
62+
// Register the source
4563
const response = await axios_1.default.post(`${baseUrl}/api/meshobjects/meshbuildingblockruns/${bbRunUuid}/status/source`, {
4664
source: {
4765
id: 'github',
4866
externalRunId: github.context.runId,
4967
externalRunUrl: `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`
5068
},
51-
steps: JSON.parse(steps)
69+
steps: steps
5270
}, {
5371
headers: {
5472
'Content-Type': 'application/vnd.meshcloud.api.meshbuildingblockrun.v1.hal+json',
@@ -57,6 +75,7 @@ async function run() {
5775
}
5876
});
5977
core.setOutput('response', response.data);
78+
core.setOutput('token_file', tokenFilePath);
6079
}
6180
catch (error) {
6281
if (error instanceof Error) {
@@ -40206,7 +40225,7 @@ module.exports = JSON.parse('{"application/1d-interleaved-parityfec":{"source":"
4020640225
/******/ // startup
4020740226
/******/ // Load entry module and return exports
4020840227
/******/ // This entry module is referenced by other modules so it can't be inlined
40209-
/******/ var __webpack_exports__ = __nccwpck_require__(4822);
40228+
/******/ var __webpack_exports__ = __nccwpck_require__(9283);
4021040229
/******/ module.exports = __webpack_exports__;
4021140230
/******/
4021240231
/******/ })()

lib/index.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)