@@ -28008,19 +28008,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
2800828008 return (mod && mod.__esModule) ? mod : { "default": mod };
2800928009};
2801028010Object.defineProperty(exports, "__esModule", ({ value: true }));
28011+ exports.runAuth = runAuth;
2801128012const core = __importStar(__nccwpck_require__(2186));
2801228013const axios_1 = __importDefault(__nccwpck_require__(8757));
2801328014const fs = __importStar(__nccwpck_require__(7147));
2801428015const path = __importStar(__nccwpck_require__(1017));
2801528016const os = __importStar(__nccwpck_require__(2037));
28016- async function run( ) {
28017+ async function runAuth(coreAdapter = core ) {
2801728018 try {
28018- const clientId = core .getInput('client_id');
28019- const keySecret = core .getInput('key_secret');
28020- const baseUrl = core .getInput('base_url');
28021- core .debug(`Client ID: ${clientId}`);
28022- core .debug(`Key Secret: ${keySecret}`);
28023- core .debug(`Base URL: ${baseUrl}`);
28019+ const clientId = coreAdapter .getInput('client_id');
28020+ const keySecret = coreAdapter .getInput('key_secret');
28021+ const baseUrl = coreAdapter .getInput('base_url');
28022+ coreAdapter .debug(`Client ID: ${clientId}`);
28023+ coreAdapter .debug(`Key Secret: ${keySecret}`);
28024+ coreAdapter .debug(`Base URL: ${baseUrl}`);
2802428025 // Authenticate and get the token
2802528026 try {
2802628027 const authResponse = await axios_1.default.post(`${baseUrl}/api/login`, `grant_type=client_credentials&client_id=${clientId}&client_secret=${keySecret}`, {
@@ -28030,7 +28031,7 @@ async function run() {
2803028031 maxRedirects: 5 // Follow redirects
2803128032 });
2803228033 const token = authResponse.data.access_token;
28033- core .debug(`Token: ${token}`);
28034+ coreAdapter .debug(`Token: ${token}`);
2803428035 // Write token and other variables to a temporary file
2803528036 const tempDir = process.env.RUNNER_TEMP || os.tmpdir();
2803628037 const tokenFilePath = path.join(tempDir, 'meshstack_token.json');
@@ -28039,36 +28040,43 @@ async function run() {
2803928040 baseUrl,
2804028041 };
2804128042 fs.writeFileSync(tokenFilePath, JSON.stringify(tokenData));
28042- core .debug(`Token file path: ${tokenFilePath}`);
28043+ coreAdapter .debug(`Token file path: ${tokenFilePath}`);
2804328044 // Indicate successful login
28044- core .info('Login was successful.');
28045+ coreAdapter .info('Login was successful.');
2804528046 // Output the token file path
28046- core .setOutput('token_file', tokenFilePath);
28047+ coreAdapter .setOutput('token_file', tokenFilePath);
2804728048 // Read token from the file
2804828049 const fileTokenData = JSON.parse(fs.readFileSync(tokenFilePath, 'utf8'));
2804928050 const fileToken = fileTokenData.token;
2805028051 }
2805128052 catch (authError) {
2805228053 if (axios_1.default.isAxiosError(authError)) {
2805328054 if (authError.response) {
28054- core .error(`Authentication error response: ${JSON.stringify(authError.response.data)}`);
28055- core .error(`Status code: ${authError.response.status}`);
28055+ coreAdapter .error(`Authentication error response: ${JSON.stringify(authError.response.data)}`);
28056+ coreAdapter .error(`Status code: ${authError.response.status}`);
2805628057 }
2805728058 else {
28058- core .error(`Authentication error message: ${authError.message}`);
28059+ coreAdapter .error(`Authentication error message: ${authError.message}`);
2805928060 }
2806028061 }
2806128062 else {
28062- core .error(`Unexpected error: ${authError}`);
28063+ coreAdapter .error(`Unexpected error: ${authError}`);
2806328064 }
2806428065 throw authError;
2806528066 }
2806628067 }
2806728068 catch (error) {
28068- core.setFailed(`Action failed with error: ${error}`);
28069+ coreAdapter.setFailed(`Action failed with error: ${error}`);
28070+ throw error;
2806928071 }
2807028072}
28071- run();
28073+ async function run() {
28074+ await runAuth(core);
28075+ }
28076+ // Only run if this file is executed directly (not imported)
28077+ if (require.main === require.cache[eval('__filename')]) {
28078+ run();
28079+ }
2807228080
2807328081
2807428082/***/ }),
0 commit comments