diff --git a/integrationTests/basic/approle_auth.test.js b/integrationTests/basic/approle_auth.test.js index a16d10b..e26cbc0 100644 --- a/integrationTests/basic/approle_auth.test.js +++ b/integrationTests/basic/approle_auth.test.js @@ -1,11 +1,11 @@ jest.mock('@actions/core'); jest.mock('@actions/core/lib/command'); -const core = require('@actions/core'); +import * as core from '@actions/core'; import got from 'got'; -const { when } = require('jest-when'); +import { when } from 'jest-when' -const { exportSecrets } = require('../../src/action'); +import exportSecrets from '../../src/action.js'; const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`; const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}` diff --git a/integrationTests/basic/integration.test.js b/integrationTests/basic/integration.test.js index 3e85b92..03a4acb 100644 --- a/integrationTests/basic/integration.test.js +++ b/integrationTests/basic/integration.test.js @@ -1,11 +1,11 @@ jest.mock('@actions/core'); jest.mock('@actions/core/lib/command'); -const core = require('@actions/core'); +import * as core from '@actions/core'; import got from 'got'; -const { when } = require('jest-when'); +import { when } from 'jest-when' -const { exportSecrets } = require('../../src/action'); +import exportSecrets from '../../src/action.js'; const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`; const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}` diff --git a/integrationTests/basic/jwt_auth.test.js b/integrationTests/basic/jwt_auth.test.js index 4163b46..646cd03 100644 --- a/integrationTests/basic/jwt_auth.test.js +++ b/integrationTests/basic/jwt_auth.test.js @@ -1,17 +1,17 @@ jest.mock('@actions/core'); jest.mock('@actions/core/lib/command'); -const core = require('@actions/core'); -const rsasign = require('jsrsasign'); -const { +import * as core from '@actions/core'; +import rsasign from 'jsrsasign'; +import { privateRsaKey, privateRsaKeyBase64, publicRsaKey -} = require('./rsa_keys'); +} from './rsa_keys.js'); import got from 'got'; -const { when } = require('jest-when'); +import { when } from 'jest-when' -const { exportSecrets } = require('../../src/action'); +import exportSecrets from '../../src/action.js'; const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`; const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}` diff --git a/integrationTests/basic/rsa_keys.js b/integrationTests/basic/rsa_keys.js index 13ea27d..598cdd9 100644 --- a/integrationTests/basic/rsa_keys.js +++ b/integrationTests/basic/rsa_keys.js @@ -42,7 +42,7 @@ LrJEY9tZaRF8xraMZiOcBcyAt6S/TS29HttJ6+zlhcWx34fItEZ8jA5gzhTmspOY -----END PUBLIC KEY----- `; -module.exports = { +export { privateRsaKey, privateRsaKeyBase64, publicRsaKey diff --git a/integrationTests/basic/userpass_auth.test.js b/integrationTests/basic/userpass_auth.test.js index 407ea6a..c448bc9 100644 --- a/integrationTests/basic/userpass_auth.test.js +++ b/integrationTests/basic/userpass_auth.test.js @@ -1,11 +1,11 @@ jest.mock('@actions/core'); jest.mock('@actions/core/lib/command'); -const core = require('@actions/core'); +import * as core from '@actions/core'; import got from 'got'; -const { when } = require('jest-when'); +import { when } from 'jest-when' -const { exportSecrets } = require('../../src/action'); +import exportSecrets from '../../src/action.js'; const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`; const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}` diff --git a/integrationTests/e2e-tls/setup.js b/integrationTests/e2e-tls/setup.js index 0709256..ff54a3e 100644 --- a/integrationTests/e2e-tls/setup.js +++ b/integrationTests/e2e-tls/setup.js @@ -1,5 +1,5 @@ import got from 'got'; -const core = require('@actions/core'); +import * as core from '@actions/core'; const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`; const caCertificateRaw = `${process.env.VAULTCA}`; diff --git a/integrationTests/enterprise/enterprise.test.js b/integrationTests/enterprise/enterprise.test.js index c96e2d9..4ef6d00 100644 --- a/integrationTests/enterprise/enterprise.test.js +++ b/integrationTests/enterprise/enterprise.test.js @@ -1,11 +1,11 @@ jest.mock('@actions/core'); jest.mock('@actions/core/lib/command'); -const core = require('@actions/core'); +import * as core from '@actions/core'; import got from 'got'; -const { when } = require('jest-when'); +import { when } from 'jest-when' -const { exportSecrets } = require('../../src/action'); +import exportSecrets from '../../src/action.js'; const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8201'}`; const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}` diff --git a/jest.config.js b/jest.config.js index 7916d69..409fd89 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,3 +1,9 @@ -module.exports = { +// module.exports = { +// transform: {}, +// testPathIgnorePatterns: ['/node_modules/', '/integrationTests/'], +// }; + +export default { + transform: {}, testPathIgnorePatterns: ['/node_modules/', '/integrationTests/'], }; diff --git a/jsconfig.json b/jsconfig.json index e7fe98e..27625de 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -7,4 +7,4 @@ "compilerOptions": { "target": "es2018" } -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index afc0ed6..5a3c488 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3,6 +3,7 @@ "version": "0.1.0", "lockfileVersion": 2, "requires": true, + "type": "module", "packages": { "": { "name": "vault-action", diff --git a/package.json b/package.json index e91a8a4..735bdac 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "vault-action", "version": "0.1.0", "description": "A Github Action that allows you to consume vault secrets as secure environment variables.", + "type": "module", "main": "dist/index.js", "scripts": { "build": "ncc build src/entry.js -o dist", diff --git a/src/action.js b/src/action.js index 332ed78..95969e1 100644 --- a/src/action.js +++ b/src/action.js @@ -1,12 +1,13 @@ // @ts-check -const core = require('@actions/core'); -const command = require('@actions/core/lib/command'); +import * as core from '@actions/core'; +import * as command from '@actions/core/lib/command'; import got from 'got'; -const jsonata = require('jsonata'); -const { normalizeOutputKey } = require('./utils'); -const { WILDCARD } = require('./constants'); +import jsonata from 'jsonata'; +import { normalizeOutputKey } from './utils.js'; +import { WILDCARD } from './constants.js'; -const { auth: { retrieveToken }, secrets: { getSecrets } } = require('./index'); +import { retrieveToken } from './auth.js'; +import { getSecrets } from './secrets.js'; const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes', 'ldap', 'userpass']; const ENCODING_TYPES = ['base64', 'hex', 'utf8']; @@ -220,9 +221,8 @@ function parseHeadersInput(inputKey, inputOptions) { }, new Map()); } -module.exports = { +export { exportSecrets, parseSecretsInput, parseHeadersInput, -}; - +} diff --git a/src/action.test.js b/src/action.test.js index b987b20..1f26c7e 100644 --- a/src/action.test.js +++ b/src/action.test.js @@ -1,17 +1,19 @@ +import { jest } from '@jest/globals'; + jest.mock('got'); jest.mock('@actions/core'); jest.mock('@actions/core/lib/command'); -const command = require('@actions/core/lib/command'); -const core = require('@actions/core'); +import * as command from '@actions/core/lib/command'; +import * as core from '@actions/core'; import got from 'got'; -const { +import { exportSecrets, parseSecretsInput, parseHeadersInput -} = require('./action'); +} from './action.js'; -const { when } = require('jest-when'); +import { when } from 'jest-when' describe('parseSecretsInput', () => { it('parses simple secret', () => { diff --git a/src/auth.js b/src/auth.js index 630ad1e..b96d4a3 100644 --- a/src/auth.js +++ b/src/auth.js @@ -1,8 +1,8 @@ // @ts-check -const core = require('@actions/core'); -const rsasign = require('jsrsasign'); -const fs = require('fs'); -const { default: got } = require('got'); +import * as core from '@actions/core'; +import * as fs from 'fs'; +import got from 'got'; +import rsasign from 'jsrsasign'; const defaultKubernetesTokenPath = '/var/run/secrets/kubernetes.io/serviceaccount/token' /*** @@ -154,6 +154,6 @@ async function getClientToken(client, method, path, payload) { * }} auth */ -module.exports = { +export { retrieveToken, }; diff --git a/src/auth.test.js b/src/auth.test.js index 405fcb6..590bd86 100644 --- a/src/auth.test.js +++ b/src/auth.test.js @@ -1,3 +1,5 @@ +import { jest } from '@jest/globals'; + jest.mock('got'); jest.mock('@actions/core'); jest.mock('@actions/core/lib/command'); @@ -8,15 +10,12 @@ jest.mock('fs', () => ({ } })); -const core = require('@actions/core'); +import * as core from '@actions/core'; import * as got from 'got' -const fs = require("fs") -const { when } = require('jest-when'); +import * as fs from 'fs'; +import { when } from 'jest-when' - -const { - retrieveToken -} = require('./auth'); +import { retrieveToken } from './auth.js'; function mockInput(name, key) { diff --git a/src/constants.js b/src/constants.js index b005350..df7addb 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,5 +1,5 @@ const WILDCARD = '*'; -module.exports = { +export { WILDCARD -}; \ No newline at end of file +}; diff --git a/src/entry.js b/src/entry.js index ea764e6..a88396d 100644 --- a/src/entry.js +++ b/src/entry.js @@ -1,5 +1,5 @@ -const core = require('@actions/core'); -const { exportSecrets } = require('./action'); +import * as core from '@actions/core'; +import { exportSecrets } from './action.js'; (async () => { try { diff --git a/src/index.js b/src/index.js index d1d673b..cf4affa 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ -const auth = require('./auth'); -const secrets = require('./secrets'); +import auth from './auth.js'; +import secrets from './secrets.js'; -module.exports = { +export default { auth, secrets -}; \ No newline at end of file +}; diff --git a/src/retries.test.js b/src/retries.test.js index 285a7f2..185774f 100644 --- a/src/retries.test.js +++ b/src/retries.test.js @@ -1,9 +1,9 @@ jest.mock('@actions/core'); -const core = require('@actions/core'); -const ServerMock = require("mock-http-server"); -const { exportSecrets } = require("./action"); -const { when } = require('jest-when'); +import * as core from '@actions/core'; +import * as ServerMock from 'mock-http-server'; +import exportSecrets from './action.js'; +import { when } from 'jest-when' describe('exportSecrets retries', () => { var server = new ServerMock({ host: "127.0.0.1", port: 0 }); diff --git a/src/secrets.js b/src/secrets.js index 10677da..53766ba 100644 --- a/src/secrets.js +++ b/src/secrets.js @@ -1,7 +1,7 @@ -const jsonata = require("jsonata"); -const { WILDCARD } = require("./constants"); -const { normalizeOutputKey } = require("./utils"); -const core = require('@actions/core'); +import jsonata from 'jsonata'; +import { WILDCARD } from './constants.js'; +import { normalizeOutputKey } from './utils.js'; +import * as core from '@actions/core'; /** * @typedef {Object} SecretRequest @@ -165,7 +165,7 @@ const selectAndAppendResults = async ( ]; }; -module.exports = { +export { getSecrets, selectData } diff --git a/src/utils.js b/src/utils.js index b8dd863..b2fa151 100644 --- a/src/utils.js +++ b/src/utils.js @@ -14,6 +14,6 @@ function normalizeOutputKey(dataKey, isEnvVar = false) { return outputKey; } -module.exports = { - normalizeOutputKey +export { + normalizeOutputKey }; diff --git a/tsconfig.json b/tsconfig.json index 91e905b..49359fa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,4 +9,4 @@ "exclude": [ "node_modules" ] -} \ No newline at end of file +}