Skip to content

Commit 015b033

Browse files
committed
Code cleanup
1 parent 24235f3 commit 015b033

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/utils.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ describe("extractSecret", () => {
148148
});
149149

150150
describe("loadSecrets when using Connect", () => {
151+
beforeEach(() => {
152+
process.env[envConnectHost] = "https://localhost:8000";
153+
process.env[envConnectToken] = "token";
154+
process.env[envServiceAccountToken] = "";
155+
});
156+
151157
it("sets the client info and gets the executed output", async () => {
152158
await loadSecrets(true);
153159

@@ -275,6 +281,15 @@ describe("loadSecrets when using Service Account", () => {
275281
expect(core.exportVariable).not.toHaveBeenCalled();
276282
});
277283

284+
it("wraps createClient errors with a descriptive message", async () => {
285+
(createClient as jest.Mock).mockRejectedValue(
286+
new Error("invalid token format"),
287+
);
288+
await expect(loadSecrets(false)).rejects.toThrow(
289+
"Service account authentication failed: invalid token format",
290+
);
291+
});
292+
278293
describe("multiple refs", () => {
279294
const ref1 = "op://vault/item/field";
280295
const ref2 = "op://vault/other/item";

src/utils.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const validateAuth = (): void => {
3030
core.info(`Authenticated with ${authType}.`);
3131
};
3232

33-
export const getEnvVarNamesWithSecretRefs = (): string[] =>
33+
const getEnvVarNamesWithSecretRefs = (): string[] =>
3434
Object.keys(process.env).filter(
3535
(key) =>
3636
typeof process.env[key] === "string" &&
@@ -58,8 +58,6 @@ export const extractSecret = (
5858
envName: string,
5959
shouldExportEnv: boolean,
6060
): void => {
61-
core.info(`Populating variable: ${envName}`);
62-
6361
const ref = process.env[envName];
6462
if (!ref) {
6563
return;
@@ -70,16 +68,8 @@ export const extractSecret = (
7068
return;
7169
}
7270

73-
if (shouldExportEnv) {
74-
core.exportVariable(envName, secretValue);
75-
} else {
76-
core.setOutput(envName, secretValue);
77-
}
78-
// Skip setSecret for empty strings to avoid the warning:
79-
// "Can't add secret mask for empty string in ##[add-mask] command."
80-
if (secretValue) {
81-
core.setSecret(secretValue);
82-
}
71+
setResolvedSecret(envName, secretValue, shouldExportEnv);
72+
8373
};
8474

8575
// Connect loads secrets via the 1Password CLI

0 commit comments

Comments
 (0)