Code cleanup
This commit is contained in:
@@ -148,6 +148,12 @@ describe("extractSecret", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("loadSecrets when using Connect", () => {
|
describe("loadSecrets when using Connect", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
process.env[envConnectHost] = "https://localhost:8000";
|
||||||
|
process.env[envConnectToken] = "token";
|
||||||
|
process.env[envServiceAccountToken] = "";
|
||||||
|
});
|
||||||
|
|
||||||
it("sets the client info and gets the executed output", async () => {
|
it("sets the client info and gets the executed output", async () => {
|
||||||
await loadSecrets(true);
|
await loadSecrets(true);
|
||||||
|
|
||||||
@@ -275,6 +281,15 @@ describe("loadSecrets when using Service Account", () => {
|
|||||||
expect(core.exportVariable).not.toHaveBeenCalled();
|
expect(core.exportVariable).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("wraps createClient errors with a descriptive message", async () => {
|
||||||
|
(createClient as jest.Mock).mockRejectedValue(
|
||||||
|
new Error("invalid token format"),
|
||||||
|
);
|
||||||
|
await expect(loadSecrets(false)).rejects.toThrow(
|
||||||
|
"Service account authentication failed: invalid token format",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
describe("multiple refs", () => {
|
describe("multiple refs", () => {
|
||||||
const ref1 = "op://vault/item/field";
|
const ref1 = "op://vault/item/field";
|
||||||
const ref2 = "op://vault/other/item";
|
const ref2 = "op://vault/other/item";
|
||||||
|
|||||||
16
src/utils.ts
16
src/utils.ts
@@ -30,7 +30,7 @@ export const validateAuth = (): void => {
|
|||||||
core.info(`Authenticated with ${authType}.`);
|
core.info(`Authenticated with ${authType}.`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getEnvVarNamesWithSecretRefs = (): string[] =>
|
const getEnvVarNamesWithSecretRefs = (): string[] =>
|
||||||
Object.keys(process.env).filter(
|
Object.keys(process.env).filter(
|
||||||
(key) =>
|
(key) =>
|
||||||
typeof process.env[key] === "string" &&
|
typeof process.env[key] === "string" &&
|
||||||
@@ -58,8 +58,6 @@ export const extractSecret = (
|
|||||||
envName: string,
|
envName: string,
|
||||||
shouldExportEnv: boolean,
|
shouldExportEnv: boolean,
|
||||||
): void => {
|
): void => {
|
||||||
core.info(`Populating variable: ${envName}`);
|
|
||||||
|
|
||||||
const ref = process.env[envName];
|
const ref = process.env[envName];
|
||||||
if (!ref) {
|
if (!ref) {
|
||||||
return;
|
return;
|
||||||
@@ -70,16 +68,8 @@ export const extractSecret = (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldExportEnv) {
|
setResolvedSecret(envName, secretValue, shouldExportEnv);
|
||||||
core.exportVariable(envName, secretValue);
|
|
||||||
} else {
|
|
||||||
core.setOutput(envName, secretValue);
|
|
||||||
}
|
|
||||||
// Skip setSecret for empty strings to avoid the warning:
|
|
||||||
// "Can't add secret mask for empty string in ##[add-mask] command."
|
|
||||||
if (secretValue) {
|
|
||||||
core.setSecret(secretValue);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connect loads secrets via the 1Password CLI
|
// Connect loads secrets via the 1Password CLI
|
||||||
|
|||||||
Reference in New Issue
Block a user