mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-04-07 20:50:09 +00:00
Revert "update got dependency and convert to esm module (#533)"
This reverts commit 77efb36ae3.
This commit is contained in:
parent
ee41aa2fcf
commit
e64032b55d
39 changed files with 14350 additions and 12246 deletions
|
|
@ -1,14 +1,12 @@
|
|||
import core from '@actions/core';
|
||||
import got from 'got';
|
||||
|
||||
import { normalizeOutputKey } from './utils.js';
|
||||
import { WILDCARD } from './constants.js';
|
||||
import { retrieveToken } from './auth.js';
|
||||
import { getSecrets } from './secrets.js';
|
||||
|
||||
// ncc doesn't compile jsonata imports properly, so we must use our own custom require
|
||||
import require from "./cjs-require.js";
|
||||
// @ts-check
|
||||
const core = require('@actions/core');
|
||||
const command = require('@actions/core/lib/command');
|
||||
const got = require('got').default;
|
||||
const jsonata = require('jsonata');
|
||||
const { normalizeOutputKey } = require('./utils');
|
||||
const { WILDCARD } = require('./constants');
|
||||
|
||||
const { auth: { retrieveToken }, secrets: { getSecrets } } = require('./index');
|
||||
|
||||
const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes', 'ldap', 'userpass'];
|
||||
const ENCODING_TYPES = ['base64', 'hex', 'utf8'];
|
||||
|
|
@ -221,8 +219,9 @@ function parseHeadersInput(inputKey, inputOptions) {
|
|||
}, new Map());
|
||||
}
|
||||
|
||||
export {
|
||||
module.exports = {
|
||||
exportSecrets,
|
||||
parseSecretsInput,
|
||||
parseHeadersInput,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { vi, describe, test, expect } from 'vitest';
|
||||
jest.mock('got');
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
|
||||
vi.mock('got');
|
||||
vi.mock('@actions/core');
|
||||
|
||||
import core from '@actions/core';
|
||||
import got from 'got';
|
||||
import {
|
||||
const command = require('@actions/core/lib/command');
|
||||
const core = require('@actions/core');
|
||||
const got = require('got');
|
||||
const {
|
||||
exportSecrets,
|
||||
parseSecretsInput,
|
||||
parseHeadersInput
|
||||
} from './action.js';
|
||||
} = require('./action');
|
||||
|
||||
import { when } from 'jest-when'
|
||||
const { when } = require('jest-when');
|
||||
|
||||
describe('parseSecretsInput', () => {
|
||||
it('parses simple secret', () => {
|
||||
|
|
@ -132,7 +132,7 @@ describe('parseHeaders', () => {
|
|||
|
||||
describe('exportSecrets', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
jest.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('url', expect.anything())
|
||||
|
|
|
|||
10
src/auth.js
10
src/auth.js
|
|
@ -1,8 +1,8 @@
|
|||
// @ts-check
|
||||
import core from '@actions/core';
|
||||
import * as fs from 'fs';
|
||||
import got from 'got';
|
||||
import rsasign from 'jsrsasign';
|
||||
const core = require('@actions/core');
|
||||
const rsasign = require('jsrsasign');
|
||||
const fs = require('fs');
|
||||
const { default: got } = require('got');
|
||||
|
||||
const defaultKubernetesTokenPath = '/var/run/secrets/kubernetes.io/serviceaccount/token'
|
||||
/***
|
||||
|
|
@ -154,6 +154,6 @@ async function getClientToken(client, method, path, payload) {
|
|||
* }} auth
|
||||
*/
|
||||
|
||||
export {
|
||||
module.exports = {
|
||||
retrieveToken,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
vi.mock('got');
|
||||
vi.mock('@actions/core');
|
||||
vi.mock('fs', () => ({
|
||||
stat: vi.fn().mockResolvedValue(null),
|
||||
jest.mock('got');
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
jest.mock('fs', () => ({
|
||||
stat: jest.fn().mockResolvedValue(null),
|
||||
promises: {
|
||||
access: vi.fn().mockResolvedValue(null),
|
||||
access: jest.fn().mockResolvedValue(null),
|
||||
}
|
||||
}));
|
||||
|
||||
import core from '@actions/core';
|
||||
import got from 'got'
|
||||
import * as fs from 'fs';
|
||||
import { when } from 'jest-when'
|
||||
const core = require('@actions/core');
|
||||
const got = require('got');
|
||||
const fs = require("fs")
|
||||
const { when } = require('jest-when');
|
||||
|
||||
import { retrieveToken } from './auth.js';
|
||||
|
||||
const {
|
||||
retrieveToken
|
||||
} = require('./auth');
|
||||
|
||||
|
||||
function mockInput(name, key) {
|
||||
|
|
@ -25,7 +27,7 @@ function mockInput(name, key) {
|
|||
|
||||
function mockApiResponse() {
|
||||
const response = { body: { auth: { client_token: testToken, renewable: true, policies: [], accessor: "accessor" } } }
|
||||
got.post = vi.fn()
|
||||
got.post = jest.fn()
|
||||
got.post.mockReturnValue(response)
|
||||
}
|
||||
const testToken = "testoken";
|
||||
|
|
@ -33,7 +35,7 @@ const testToken = "testoken";
|
|||
describe("test retrival for token", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
it("test retrival with approle", async () => {
|
||||
|
|
@ -74,7 +76,7 @@ describe("test retrival for token", () => {
|
|||
mockInput("kubernetesTokenPath", testTokenPath)
|
||||
mockInput("role", testRole)
|
||||
mockInput("path", testPath)
|
||||
fs.readFileSync = vi.fn()
|
||||
fs.readFileSync = jest.fn()
|
||||
fs.readFileSync.mockReturnValueOnce(jwtToken)
|
||||
const token = await retrieveToken(method, got)
|
||||
expect(token).toEqual(testToken)
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
// This allows us to use `require` in our ECMAScript module
|
||||
// See: https://github.com/vercel/ncc/issues/791
|
||||
// https://nodejs.org/api/module.html#modulecreaterequirefilename
|
||||
import { createRequire } from "module";
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
export default require;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
const WILDCARD = '*';
|
||||
|
||||
export {
|
||||
module.exports = {
|
||||
WILDCARD
|
||||
};
|
||||
};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import core from '@actions/core';
|
||||
import { exportSecrets } from './action.js';
|
||||
const core = require('@actions/core');
|
||||
const { exportSecrets } = require('./action');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import auth from './auth.js';
|
||||
import secrets from './secrets.js';
|
||||
const auth = require('./auth');
|
||||
const secrets = require('./secrets');
|
||||
|
||||
export default {
|
||||
module.exports = {
|
||||
auth,
|
||||
secrets
|
||||
};
|
||||
};
|
||||
|
|
@ -1,19 +1,17 @@
|
|||
import { vi, describe, test, expect } from 'vitest';
|
||||
jest.mock('@actions/core');
|
||||
|
||||
vi.mock('@actions/core');
|
||||
|
||||
import core from '@actions/core';
|
||||
import ServerMock from 'mock-http-server';
|
||||
import { exportSecrets } from './action.js';
|
||||
import { when } from 'jest-when';
|
||||
const core = require('@actions/core');
|
||||
const ServerMock = require("mock-http-server");
|
||||
const { exportSecrets } = require("./action");
|
||||
const { when } = require('jest-when');
|
||||
|
||||
describe('exportSecrets retries', () => {
|
||||
var server = new ServerMock({ host: "127.0.0.1", port: 0 });
|
||||
var calls = 0;
|
||||
|
||||
beforeEach(() => new Promise(done => {
|
||||
beforeEach((done) => {
|
||||
calls = 0;
|
||||
vi.resetAllMocks();
|
||||
jest.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('token', expect.anything())
|
||||
|
|
@ -30,11 +28,11 @@ describe('exportSecrets retries', () => {
|
|||
.mockReturnValueOnce('http://127.0.0.1:' + server.getHttpPort());
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
afterEach(() => new Promise(done => {
|
||||
afterEach((done) => {
|
||||
server.stop(done);
|
||||
}));
|
||||
});
|
||||
|
||||
function mockStatusCodes(statusCodes) {
|
||||
server.on({
|
||||
|
|
@ -53,19 +51,19 @@ describe('exportSecrets retries', () => {
|
|||
});
|
||||
}
|
||||
|
||||
it('retries on 412 status code', () => new Promise(done => {
|
||||
it('retries on 412 status code', (done) => {
|
||||
mockStatusCodes([412, 200])
|
||||
exportSecrets().then(() => {
|
||||
expect(calls).toEqual(2);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('retries on 500 status code', () => new Promise(done => {
|
||||
it('retries on 500 status code', (done) => {
|
||||
mockStatusCodes([500, 200])
|
||||
exportSecrets().then(() => {
|
||||
expect(calls).toEqual(2);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
import core from '@actions/core';
|
||||
import { WILDCARD } from './constants.js';
|
||||
import { normalizeOutputKey } from './utils.js';
|
||||
|
||||
// ncc doesn't compile jsonata imports properly, so we must use our own custom require
|
||||
import require from "./cjs-require.js";
|
||||
const jsonata = require('jsonata');
|
||||
|
||||
const jsonata = require("jsonata");
|
||||
const { WILDCARD } = require("./constants");
|
||||
const { normalizeOutputKey } = require("./utils");
|
||||
const core = require('@actions/core');
|
||||
|
||||
/**
|
||||
* @typedef {Object} SecretRequest
|
||||
|
|
@ -48,7 +44,7 @@ async function getSecrets(secretRequests, client, ignoreNotFound) {
|
|||
} catch (error) {
|
||||
const {response} = error;
|
||||
if (response?.statusCode === 404) {
|
||||
let notFoundMsg = `Unable to retrieve result for "${path}" because it was not found: ${response.body.trim()}`;
|
||||
notFoundMsg = `Unable to retrieve result for "${path}" because it was not found: ${response.body.trim()}`;
|
||||
const ignoreNotFound = (core.getInput('ignoreNotFound', { required: false }) || 'false').toLowerCase() != 'false';
|
||||
if (ignoreNotFound) {
|
||||
core.error(`✘ ${notFoundMsg}`);
|
||||
|
|
@ -169,7 +165,7 @@ const selectAndAppendResults = async (
|
|||
];
|
||||
};
|
||||
|
||||
export {
|
||||
module.exports = {
|
||||
getSecrets,
|
||||
selectData
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ function normalizeOutputKey(dataKey, isEnvVar = false) {
|
|||
return outputKey;
|
||||
}
|
||||
|
||||
export {
|
||||
normalizeOutputKey
|
||||
module.exports = {
|
||||
normalizeOutputKey
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue