Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/artifacts-token-header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/computer": patch
---

`codemode:artifacts` tells code to clone and push with a token in a header, as [the docs](https://github.com/cloudflare/computer/blob/main/docs/17_isolate_javascript.md#codemodeartifacts) do, rather than calling `share()`'s URL clone-ready: git saves a clone's URL, token and all, in `.git/config`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Release link misses header example

The release note links to codemode:artifacts, which shows the shell URL workflow. The header example sits above that anchor under codemode:git.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

3 changes: 2 additions & 1 deletion docs/17_isolate_javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,8 @@ import { clone, push } from "codemode:git";
export default async function () {
const { remote } = await get("site");
const { plaintext } = await createToken("site", "write", "15m");
const headers = { Authorization: `Bearer ${plaintext}` };
// The plaintext ends in an `?expires=` hint that isn't part of the token.
const headers = { Authorization: `Bearer ${plaintext.split("?expires=")[0]}` };
await clone({ url: remote, dir: "site", headers });
// ...change and commit files...
return push({ dir: "site", ref: "main", headers });
Expand Down
8 changes: 8 additions & 0 deletions packages/computer/src/modules/artifacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,12 @@ describe("createArtifactsModule share", () => {
expect(description).toContain("createToken(name");
expect(description).toContain("share(name");
});

it("tells code to send a token in a header, not in the URL", () => {
const description = createArtifactsModule().description ?? "";
expect(description).toContain('headers: { Authorization: "Bearer <token>" }');
expect(description).toContain('plaintext.split("?expires=")[0]');
expect(description).toContain(".git/config");
expect(description).not.toContain("clone-ready");
});
});
2 changes: 1 addition & 1 deletion packages/computer/src/modules/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function createArtifactsModule(
},
});
return Object.assign(create, {
description: `Git repositories stored in Cloudflare Artifacts: \`create(name)\`, \`get(name)\`, \`list()\`, \`importArtifact(name, source)\`, and \`deleteArtifact(name)\`.${allowNetwork ? "" : " Importing from a remote URL is not allowed."} \`createToken(name, scope?, ttl?)\` mints a git token ("read" by default). \`share(name, { scope?, ttl? })\` returns a clone-ready URL with a token embedded; it is a credential, so never print or return it. \`ttl\` is seconds or a duration like "15m".`,
description: `Git repositories stored in Cloudflare Artifacts: \`create(name)\`, \`get(name)\`, \`list()\`, \`importArtifact(name, source)\`, and \`deleteArtifact(name)\`.${allowNetwork ? "" : " Importing from a remote URL is not allowed."} \`createToken(name, scope?, ttl?)\` mints a git token ("read" by default): to clone or push with the git module, pass \`get(name)\`'s \`remote\` as the URL and the token in \`headers: { Authorization: "Bearer <token>" }\`, not in the URL, which git saves in \`.git/config\`. The token is \`plaintext\` up to its \`?expires=\` hint, which isn't part of it: \`plaintext.split("?expires=")[0]\`. \`share(name, { scope?, ttl? })\` returns the remote URL with a token embedded, for git in a shell command: pass it in \`env\`, not in the command text. Tokens and shared URLs are credentials, so never print or return them. \`ttl\` is seconds or a duration like "15m".`,
});
}

Expand Down
Loading