@@ -29157,62 +29157,47 @@ async function runAuth(coreAdapter = core) {
2915729157 coreAdapter.debug(`Key Secret: ${keySecret}`);
2915829158 coreAdapter.debug(`Base URL: ${baseUrl}`);
2915929159 // Authenticate and get the token
29160- try {
29161- const authResponse = await axios_1.default.post(`${baseUrl}/api/login`, `grant_type=client_credentials&client_id=${clientId}&client_secret=${keySecret}`, {
29162- headers: {
29163- 'Content-Type': 'application/x-www-form-urlencoded'
29164- },
29165- maxRedirects: 5 // Follow redirects
29166- });
29167- const token = authResponse.data.access_token;
29168- coreAdapter.debug(`Token: ${token}`);
29169- // Write token and other variables to a temporary file
29170- const tempDir = process.env.RUNNER_TEMP || os.tmpdir();
29171- const tokenFilePath = path.join(tempDir, 'meshstack_token.json');
29172- const tokenData = {
29173- token,
29174- baseUrl,
29175- };
29176- fs.writeFileSync(tokenFilePath, JSON.stringify(tokenData));
29177- coreAdapter.debug(`Token file path: ${tokenFilePath}`);
29178- // Indicate successful login
29179- coreAdapter.info('Login was successful.');
29180- // Output the token file path
29181- coreAdapter.setOutput('token_file', tokenFilePath);
29182- // Read token from the file
29183- const fileTokenData = JSON.parse(fs.readFileSync(tokenFilePath, 'utf8'));
29184- const fileToken = fileTokenData.token;
29185- }
29186- catch (authError) {
29187- if ((0, error_utils_1.isAxiosError)(authError)) {
29188- (0, error_utils_1.logAxiosError)(authError, coreAdapter, 'Authentication error');
29189- }
29190- else {
29191- coreAdapter.error(`Unexpected error: ${authError}`);
29192- }
29193- throw authError;
29194- }
29160+ const authResponse = await axios_1.default.post(`${baseUrl}/api/login`, `grant_type=client_credentials&client_id=${clientId}&client_secret=${keySecret}`, {
29161+ headers: {
29162+ 'Content-Type': 'application/x-www-form-urlencoded'
29163+ },
29164+ maxRedirects: 5 // Follow redirects
29165+ });
29166+ const token = authResponse.data.access_token;
29167+ coreAdapter.debug(`Token: ${token}`);
29168+ // Write token and other variables to a temporary file
29169+ const tempDir = process.env.RUNNER_TEMP || os.tmpdir();
29170+ const tokenFilePath = path.join(tempDir, 'meshstack_token.json');
29171+ const tokenData = {
29172+ token,
29173+ baseUrl,
29174+ };
29175+ fs.writeFileSync(tokenFilePath, JSON.stringify(tokenData));
29176+ coreAdapter.debug(`Token file path: ${tokenFilePath}`);
29177+ // Indicate successful login
29178+ coreAdapter.info('Login was successful.');
29179+ // Output the token file path
29180+ coreAdapter.setOutput('token_file', tokenFilePath);
29181+ // Read token from the file
29182+ const fileTokenData = JSON.parse(fs.readFileSync(tokenFilePath, 'utf8'));
29183+ const fileToken = fileTokenData.token;
2919529184 }
2919629185 catch (error) {
29197- // Exception handler of last resort
29198- if (error instanceof Error) {
29199- coreAdapter.setFailed(error.message);
29186+ // Handle all errors at this level
29187+ if ((0, error_utils_1.isAxiosError)(error)) {
29188+ (0, error_utils_1.logAxiosError)(error, coreAdapter, 'Authentication error');
29189+ }
29190+ else if (error instanceof Error) {
29191+ coreAdapter.error(error.message);
2920029192 }
2920129193 else {
29202- coreAdapter.setFailed(`An unknown error occurred : ${error}`);
29194+ coreAdapter.error(`Unexpected error: ${error}`);
2920329195 }
29204- throw error;
29196+ coreAdapter.setFailed(error instanceof Error ? error.message : String(error)) ;
2920529197 }
2920629198}
2920729199async function run() {
29208- try {
29209- await runAuth(core);
29210- }
29211- catch (error) {
29212- // Last-resort exception handler: prevent unhandled rejections
29213- // The error has already been logged and setFailed has been called
29214- process.exit(1);
29215- }
29200+ await runAuth(core);
2921629201}
2921729202// Only run if this file is executed directly (not imported)
2921829203if (require.main === require.cache[eval('__filename')]) {
0 commit comments