mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 09:24:46 +00:00
feat(credentials): link directories to team secrets (#129)
This commit is contained in:
parent
e4723f31b1
commit
12a1d7f479
7 changed files with 265 additions and 27 deletions
46
packages/cli/src/secrets-link.test.ts
Normal file
46
packages/cli/src/secrets-link.test.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { mkdtempSync, mkdirSync, symlinkSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { linkedDirectory, readSecretsLink, requireSecretsLink, writeSecretsLink } from "./secrets-link.js";
|
||||
|
||||
describe("directory secrets links", () => {
|
||||
it("stores link metadata outside the linked project", () => {
|
||||
const sandbox = mkdtempSync(join(tmpdir(), "logicsrc-link-"));
|
||||
const project = join(sandbox, "project");
|
||||
const file = join(sandbox, "config", "secrets-links.json");
|
||||
mkdirSync(project);
|
||||
|
||||
const link = writeSecretsLink({ team: "acme", project: "web", env: "prod" }, project, file);
|
||||
|
||||
expect(readSecretsLink(project, file)).toEqual(link);
|
||||
expect(link.directory).toBe(project);
|
||||
expect(file.startsWith(project)).toBe(false);
|
||||
});
|
||||
|
||||
it("keys links by the real directory so symlinked paths share one link", () => {
|
||||
const sandbox = mkdtempSync(join(tmpdir(), "logicsrc-link-"));
|
||||
const project = join(sandbox, "project");
|
||||
const alias = join(sandbox, "alias");
|
||||
const file = join(sandbox, "secrets-links.json");
|
||||
mkdirSync(project);
|
||||
symlinkSync(project, alias, "dir");
|
||||
|
||||
writeSecretsLink({ team: "acme", project: "api", env: "staging" }, alias, file);
|
||||
|
||||
expect(linkedDirectory(alias)).toBe(project);
|
||||
expect(readSecretsLink(project, file)?.env).toBe("staging");
|
||||
});
|
||||
|
||||
it("requires an explicit link for each directory", () => {
|
||||
const sandbox = mkdtempSync(join(tmpdir(), "logicsrc-link-"));
|
||||
const linked = join(sandbox, "linked");
|
||||
const unlinked = join(sandbox, "unlinked");
|
||||
const file = join(sandbox, "secrets-links.json");
|
||||
mkdirSync(linked);
|
||||
mkdirSync(unlinked);
|
||||
writeSecretsLink({ team: "acme", project: "web", env: "prod" }, linked, file);
|
||||
|
||||
expect(() => requireSecretsLink(unlinked, file)).toThrow(/logicsrc secrets teams link/);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue