@leed-ai/git-gateway-contract 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +50 -2
- package/dist/behaviour/assertions.d.ts +23 -0
- package/dist/behaviour/assertions.js +56 -0
- package/dist/behaviour/assertions.js.map +1 -0
- package/dist/behaviour/behaviour-case.d.ts +19 -0
- package/dist/behaviour/behaviour-case.js +12 -0
- package/dist/behaviour/behaviour-case.js.map +1 -0
- package/dist/behaviour/behaviour-suite.d.ts +30 -0
- package/dist/behaviour/behaviour-suite.js +50 -0
- package/dist/behaviour/behaviour-suite.js.map +1 -0
- package/dist/behaviour/commit-action-cases.d.ts +4 -0
- package/dist/behaviour/commit-action-cases.js +342 -0
- package/dist/behaviour/commit-action-cases.js.map +1 -0
- package/dist/behaviour/commit-write-cases.d.ts +4 -0
- package/dist/behaviour/commit-write-cases.js +234 -0
- package/dist/behaviour/commit-write-cases.js.map +1 -0
- package/dist/behaviour/fixtures.d.ts +29 -0
- package/dist/behaviour/fixtures.js +83 -0
- package/dist/behaviour/fixtures.js.map +1 -0
- package/dist/behaviour/lifecycle-cases.d.ts +4 -0
- package/dist/behaviour/lifecycle-cases.js +158 -0
- package/dist/behaviour/lifecycle-cases.js.map +1 -0
- package/dist/behaviour/promote-cases.d.ts +4 -0
- package/dist/behaviour/promote-cases.js +122 -0
- package/dist/behaviour/promote-cases.js.map +1 -0
- package/dist/behaviour/read-cases.d.ts +4 -0
- package/dist/behaviour/read-cases.js +248 -0
- package/dist/behaviour/read-cases.js.map +1 -0
- package/dist/behaviour/sync-cases.d.ts +4 -0
- package/dist/behaviour/sync-cases.js +205 -0
- package/dist/behaviour/sync-cases.js.map +1 -0
- package/dist/clock-B3MlpmVY.d.ts +10 -0
- package/dist/commit-BEZmeAOl.d.ts +23 -0
- package/dist/file-map-CxUveLWz.d.ts +18 -0
- package/dist/gateway-config-oVsdTEeK.d.ts +39 -0
- package/dist/gateway-error-body-BWzZFAQI.d.ts +214 -0
- package/dist/gateway-error.d.ts +30 -0
- package/dist/gateway-error.js +63 -0
- package/dist/gateway-error.js.map +1 -0
- package/dist/git-gateway-VA9Tc5tn.d.ts +358 -0
- package/dist/git-gateway.d.ts +2 -0
- package/dist/git-gateway.js +65 -0
- package/dist/git-gateway.js.map +1 -0
- package/dist/health.d.ts +9 -0
- package/dist/health.js +18 -0
- package/dist/health.js.map +1 -0
- package/dist/history-CqvHaUE-.d.ts +20 -0
- package/dist/package-name.d.ts +3 -0
- package/dist/package-name.js +6 -0
- package/dist/package-name.js.map +1 -0
- package/dist/proxy/audit-event.d.ts +61 -0
- package/dist/proxy/audit-event.js +97 -0
- package/dist/proxy/audit-event.js.map +1 -0
- package/dist/proxy/branch-rule.d.ts +72 -0
- package/dist/proxy/branch-rule.js +106 -0
- package/dist/proxy/branch-rule.js.map +1 -0
- package/dist/proxy/gateway-hooks.d.ts +58 -0
- package/dist/proxy/gateway-hooks.js +0 -0
- package/dist/proxy/git-operation.d.ts +17 -0
- package/dist/proxy/git-operation.js +32 -0
- package/dist/proxy/git-operation.js.map +1 -0
- package/dist/proxy/policy-result.d.ts +51 -0
- package/dist/proxy/policy-result.js +90 -0
- package/dist/proxy/policy-result.js.map +1 -0
- package/dist/proxy/principal.d.ts +18 -0
- package/dist/proxy/principal.js +32 -0
- package/dist/proxy/principal.js.map +1 -0
- package/dist/proxy/push-policy-result.d.ts +34 -0
- package/dist/proxy/push-policy-result.js +48 -0
- package/dist/proxy/push-policy-result.js.map +1 -0
- package/dist/proxy/push-policy.d.ts +146 -0
- package/dist/proxy/push-policy.js +112 -0
- package/dist/proxy/push-policy.js.map +1 -0
- package/dist/proxy/request-credential.d.ts +22 -0
- package/dist/proxy/request-credential.js +46 -0
- package/dist/proxy/request-credential.js.map +1 -0
- package/dist/proxy/smart-http-config.d.ts +22 -0
- package/dist/proxy/smart-http-config.js +40 -0
- package/dist/proxy/smart-http-config.js.map +1 -0
- package/dist/reference/apply-actions.d.ts +9 -0
- package/dist/reference/apply-actions.js +84 -0
- package/dist/reference/apply-actions.js.map +1 -0
- package/dist/reference/branch-methods.d.ts +7 -0
- package/dist/reference/branch-methods.js +105 -0
- package/dist/reference/branch-methods.js.map +1 -0
- package/dist/reference/bytes.d.ts +22 -0
- package/dist/reference/bytes.js +62 -0
- package/dist/reference/bytes.js.map +1 -0
- package/dist/reference/clock.d.ts +2 -0
- package/dist/reference/clock.js +18 -0
- package/dist/reference/clock.js.map +1 -0
- package/dist/reference/commit-method.d.ts +5 -0
- package/dist/reference/commit-method.js +83 -0
- package/dist/reference/commit-method.js.map +1 -0
- package/dist/reference/file-map.d.ts +2 -0
- package/dist/reference/file-map.js +24 -0
- package/dist/reference/file-map.js.map +1 -0
- package/dist/reference/hash.d.ts +10 -0
- package/dist/reference/hash.js +25 -0
- package/dist/reference/hash.js.map +1 -0
- package/dist/reference/history.d.ts +2 -0
- package/dist/reference/history.js +65 -0
- package/dist/reference/history.js.map +1 -0
- package/dist/reference/lifecycle-methods.d.ts +9 -0
- package/dist/reference/lifecycle-methods.js +48 -0
- package/dist/reference/lifecycle-methods.js.map +1 -0
- package/dist/reference/read-methods.d.ts +13 -0
- package/dist/reference/read-methods.js +68 -0
- package/dist/reference/read-methods.js.map +1 -0
- package/dist/reference/reference-gateway.d.ts +18 -0
- package/dist/reference/reference-gateway.js +35 -0
- package/dist/reference/reference-gateway.js.map +1 -0
- package/dist/reference/repo-state.d.ts +43 -0
- package/dist/reference/repo-state.js +45 -0
- package/dist/reference/repo-state.js.map +1 -0
- package/dist/reference/run-method.d.ts +13 -0
- package/dist/reference/run-method.js +15 -0
- package/dist/reference/run-method.js.map +1 -0
- package/dist/reference/three-way-merge.d.ts +16 -0
- package/dist/reference/three-way-merge.js +45 -0
- package/dist/reference/three-way-merge.js.map +1 -0
- package/dist/reference/trailer.d.ts +7 -0
- package/dist/reference/trailer.js +16 -0
- package/dist/reference/trailer.js.map +1 -0
- package/dist/reference/tree-index.d.ts +2 -0
- package/dist/reference/tree-index.js +66 -0
- package/dist/reference/tree-index.js.map +1 -0
- package/dist/reference/write-commit.d.ts +15 -0
- package/dist/reference/write-commit.js +44 -0
- package/dist/reference/write-commit.js.map +1 -0
- package/dist/rpc/commit-exists.d.ts +16 -0
- package/dist/rpc/commit-exists.js +30 -0
- package/dist/rpc/commit-exists.js.map +1 -0
- package/dist/rpc/commit.d.ts +172 -0
- package/dist/rpc/commit.js +115 -0
- package/dist/rpc/commit.js.map +1 -0
- package/dist/rpc/list-tree.d.ts +59 -0
- package/dist/rpc/list-tree.js +54 -0
- package/dist/rpc/list-tree.js.map +1 -0
- package/dist/rpc/log.d.ts +35 -0
- package/dist/rpc/log.js +41 -0
- package/dist/rpc/log.js.map +1 -0
- package/dist/rpc/mint-read-token.d.ts +17 -0
- package/dist/rpc/mint-read-token.js +36 -0
- package/dist/rpc/mint-read-token.js.map +1 -0
- package/dist/rpc/promote.d.ts +39 -0
- package/dist/rpc/promote.js +69 -0
- package/dist/rpc/promote.js.map +1 -0
- package/dist/rpc/read-file.d.ts +44 -0
- package/dist/rpc/read-file.js +56 -0
- package/dist/rpc/read-file.js.map +1 -0
- package/dist/rpc/repo-lifecycle.d.ts +39 -0
- package/dist/rpc/repo-lifecycle.js +64 -0
- package/dist/rpc/repo-lifecycle.js.map +1 -0
- package/dist/rpc/resolve-ref.d.ts +15 -0
- package/dist/rpc/resolve-ref.js +28 -0
- package/dist/rpc/resolve-ref.js.map +1 -0
- package/dist/rpc/sync-branch.d.ts +107 -0
- package/dist/rpc/sync-branch.js +114 -0
- package/dist/rpc/sync-branch.js.map +1 -0
- package/dist/schemas/commit-action.d.ts +100 -0
- package/dist/schemas/commit-action.js +138 -0
- package/dist/schemas/commit-action.js.map +1 -0
- package/dist/schemas/commit.d.ts +2 -0
- package/dist/schemas/commit.js +24 -0
- package/dist/schemas/commit.js.map +1 -0
- package/dist/schemas/content-encoding.d.ts +24 -0
- package/dist/schemas/content-encoding.js +41 -0
- package/dist/schemas/content-encoding.js.map +1 -0
- package/dist/schemas/examples.d.ts +38 -0
- package/dist/schemas/examples.js +32 -0
- package/dist/schemas/examples.js.map +1 -0
- package/dist/schemas/gateway-config.d.ts +2 -0
- package/dist/schemas/gateway-config.js +72 -0
- package/dist/schemas/gateway-config.js.map +1 -0
- package/dist/schemas/gateway-error-body.d.ts +2 -0
- package/dist/schemas/gateway-error-body.js +188 -0
- package/dist/schemas/gateway-error-body.js.map +1 -0
- package/dist/schemas/identity.d.ts +21 -0
- package/dist/schemas/identity.js +40 -0
- package/dist/schemas/identity.js.map +1 -0
- package/dist/schemas/names.d.ts +26 -0
- package/dist/schemas/names.js +58 -0
- package/dist/schemas/names.js.map +1 -0
- package/dist/schemas/ref-update.d.ts +10 -0
- package/dist/schemas/ref-update.js +25 -0
- package/dist/schemas/ref-update.js.map +1 -0
- package/dist/schemas/sha.d.ts +8 -0
- package/dist/schemas/sha.js +14 -0
- package/dist/schemas/sha.js.map +1 -0
- package/dist/schemas/tree-entry.d.ts +2 -0
- package/dist/schemas/tree-entry.js +62 -0
- package/dist/schemas/tree-entry.js.map +1 -0
- package/dist/storage/git-remote.d.ts +17 -0
- package/dist/storage/git-remote.js +31 -0
- package/dist/storage/git-remote.js.map +1 -0
- package/dist/storage/storage-backend.d.ts +61 -0
- package/dist/storage/storage-backend.js +0 -0
- package/dist/storage/storage-errors.d.ts +12 -0
- package/dist/storage/storage-errors.js +22 -0
- package/dist/storage/storage-errors.js.map +1 -0
- package/dist/storage/storage-input.d.ts +7 -0
- package/dist/storage/storage-input.js +14 -0
- package/dist/storage/storage-input.js.map +1 -0
- package/dist/storage/storage-read.d.ts +13 -0
- package/dist/storage/storage-read.js +30 -0
- package/dist/storage/storage-read.js.map +1 -0
- package/dist/storage/storage-repo-info.d.ts +16 -0
- package/dist/storage/storage-repo-info.js +30 -0
- package/dist/storage/storage-repo-info.js.map +1 -0
- package/dist/storage/storage-tree-entry.d.ts +21 -0
- package/dist/storage/storage-tree-entry.js +17 -0
- package/dist/storage/storage-tree-entry.js.map +1 -0
- package/dist/tree-entry-BM_1gou1.d.ts +41 -0
- package/dist/tree-index-Bk721Phv.d.ts +14 -0
- package/package.json +401 -4
- package/src/behaviour/assertions.ts +75 -0
- package/src/behaviour/behaviour-case.ts +28 -0
- package/src/behaviour/behaviour-suite.ts +76 -0
- package/src/behaviour/commit-action-cases.ts +253 -0
- package/src/behaviour/commit-write-cases.ts +205 -0
- package/src/behaviour/fixtures.ts +103 -0
- package/src/behaviour/lifecycle-cases.ts +104 -0
- package/src/behaviour/promote-cases.ts +78 -0
- package/src/behaviour/read-cases.ts +176 -0
- package/src/behaviour/sync-cases.ts +156 -0
- package/src/gateway-error.ts +72 -0
- package/src/git-gateway.ts +76 -0
- package/src/health.ts +26 -0
- package/src/package-name.ts +4 -0
- package/src/proxy/audit-event.ts +135 -0
- package/src/proxy/branch-rule.ts +190 -0
- package/src/proxy/gateway-hooks.ts +67 -0
- package/src/proxy/git-operation.ts +36 -0
- package/src/proxy/policy-result.ts +127 -0
- package/src/proxy/principal.ts +81 -0
- package/src/proxy/push-policy-result.ts +86 -0
- package/src/proxy/push-policy.ts +158 -0
- package/src/proxy/request-credential.ts +47 -0
- package/src/proxy/smart-http-config.ts +158 -0
- package/src/reference/apply-actions.ts +96 -0
- package/src/reference/branch-methods.ts +105 -0
- package/src/reference/bytes.ts +66 -0
- package/src/reference/clock.ts +19 -0
- package/src/reference/commit-method.ts +97 -0
- package/src/reference/file-map.ts +35 -0
- package/src/reference/hash.ts +25 -0
- package/src/reference/history.ts +78 -0
- package/src/reference/lifecycle-methods.ts +52 -0
- package/src/reference/read-methods.ts +87 -0
- package/src/reference/reference-gateway.ts +50 -0
- package/src/reference/repo-state.ts +83 -0
- package/src/reference/run-method.ts +25 -0
- package/src/reference/three-way-merge.ts +42 -0
- package/src/reference/trailer.ts +18 -0
- package/src/reference/tree-index.ts +65 -0
- package/src/reference/write-commit.ts +44 -0
- package/src/rpc/commit-exists.ts +46 -0
- package/src/rpc/commit.ts +156 -0
- package/src/rpc/list-tree.ts +78 -0
- package/src/rpc/log.ts +51 -0
- package/src/rpc/mint-read-token.ts +59 -0
- package/src/rpc/promote.ts +72 -0
- package/src/rpc/read-file.ts +75 -0
- package/src/rpc/repo-lifecycle.ts +103 -0
- package/src/rpc/resolve-ref.ts +41 -0
- package/src/rpc/sync-branch.ts +149 -0
- package/src/schemas/commit-action.ts +157 -0
- package/src/schemas/commit.ts +43 -0
- package/src/schemas/content-encoding.ts +58 -0
- package/src/schemas/examples.ts +24 -0
- package/src/schemas/gateway-config.ts +116 -0
- package/src/schemas/gateway-error-body.ts +230 -0
- package/src/schemas/identity.ts +57 -0
- package/src/schemas/names.ts +126 -0
- package/src/schemas/ref-update.ts +38 -0
- package/src/schemas/sha.ts +20 -0
- package/src/schemas/tree-entry.ts +72 -0
- package/src/storage/git-remote.ts +58 -0
- package/src/storage/storage-backend.ts +65 -0
- package/src/storage/storage-errors.ts +24 -0
- package/src/storage/storage-input.ts +14 -0
- package/src/storage/storage-read.ts +45 -0
- package/src/storage/storage-repo-info.ts +46 -0
- package/src/storage/storage-tree-entry.ts +20 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// src/proxy/git-operation.ts
|
|
3
|
+
/** What a smart-HTTP request does to a repository. */
|
|
4
|
+
const GitOperation = z.enum(["read", "write"]).meta({
|
|
5
|
+
id: "GitOperation",
|
|
6
|
+
title: "Git operation",
|
|
7
|
+
description: "What a git client asks to do to a repository through the gateway; Authorizer.authorize() decides each per principal and repository.",
|
|
8
|
+
enumDescriptions: {
|
|
9
|
+
read: "Clone or fetch: GET info/refs?service=git-upload-pack and POST git-upload-pack.",
|
|
10
|
+
write: "Push: GET info/refs?service=git-receive-pack and POST git-receive-pack."
|
|
11
|
+
},
|
|
12
|
+
examples: ["read", "write"]
|
|
13
|
+
});
|
|
14
|
+
/** The smart-HTTP endpoint a request reached. */
|
|
15
|
+
const SmartHttpEndpoint = z.enum([
|
|
16
|
+
"info-refs",
|
|
17
|
+
"upload-pack",
|
|
18
|
+
"receive-pack"
|
|
19
|
+
]).meta({
|
|
20
|
+
id: "SmartHttpEndpoint",
|
|
21
|
+
title: "Smart-HTTP endpoint",
|
|
22
|
+
description: "Which of the three git smart-HTTP endpoints of /<repo>.git a request reached.",
|
|
23
|
+
enumDescriptions: {
|
|
24
|
+
"info-refs": "GET /<repo>.git/info/refs?service=…: the ref advertisement (or the protocol v2 capabilities).",
|
|
25
|
+
"upload-pack": "POST /<repo>.git/git-upload-pack: fetch negotiation and the pack sent to the client.",
|
|
26
|
+
"receive-pack": "POST /<repo>.git/git-receive-pack: ref update commands and the pack pushed by the client."
|
|
27
|
+
},
|
|
28
|
+
examples: ["receive-pack"]
|
|
29
|
+
});
|
|
30
|
+
export { GitOperation, SmartHttpEndpoint };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=git-operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-operation.js","names":[],"sources":["../../src/proxy/git-operation.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\n/** What a smart-HTTP request does to a repository. */\nexport const GitOperation = z.enum(['read', 'write']).meta({\n id: 'GitOperation',\n title: 'Git operation',\n description:\n 'What a git client asks to do to a repository through the gateway; Authorizer.authorize() decides each per principal and repository.',\n enumDescriptions: {\n read: 'Clone or fetch: GET info/refs?service=git-upload-pack and POST git-upload-pack.',\n write: 'Push: GET info/refs?service=git-receive-pack and POST git-receive-pack.',\n },\n examples: ['read', 'write'],\n});\n\n/** A git operation, inferred from {@link GitOperation}. */\nexport type GitOperation = z.infer<typeof GitOperation>;\n\n/** The smart-HTTP endpoint a request reached. */\nexport const SmartHttpEndpoint = z.enum(['info-refs', 'upload-pack', 'receive-pack']).meta({\n id: 'SmartHttpEndpoint',\n title: 'Smart-HTTP endpoint',\n description: 'Which of the three git smart-HTTP endpoints of /<repo>.git a request reached.',\n enumDescriptions: {\n 'info-refs':\n 'GET /<repo>.git/info/refs?service=…: the ref advertisement (or the protocol v2 capabilities).',\n 'upload-pack': 'POST /<repo>.git/git-upload-pack: fetch negotiation and the pack sent to the client.',\n 'receive-pack':\n 'POST /<repo>.git/git-receive-pack: ref update commands and the pack pushed by the client.',\n },\n examples: ['receive-pack'],\n});\n\n/** A smart-HTTP endpoint, inferred from {@link SmartHttpEndpoint}. */\nexport type SmartHttpEndpoint = z.infer<typeof SmartHttpEndpoint>;\n"],"mappings":";;;AAIA,MAAa,eAAe,EAAE,KAAK,CAAC,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAK;CACzD,IAAI;CACJ,OAAO;CACP,aACE;CACF,kBAAkB;EAChB,MAAM;EACN,OAAO;CACT;CACA,UAAU,CAAC,QAAQ,OAAO;AAC5B,CAAC;;AAMD,MAAa,oBAAoB,EAAE,KAAK;CAAC;CAAa;CAAe;AAAc,CAAC,CAAC,CAAC,KAAK;CACzF,IAAI;CACJ,OAAO;CACP,aAAa;CACb,kBAAkB;EAChB,aACE;EACF,eAAe;EACf,gBACE;CACJ;CACA,UAAU,CAAC,cAAc;AAC3B,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The policy allows any update of the ref, force pushes included. */
|
|
3
|
+
export declare const RefDecisionAllow: z.ZodObject<{
|
|
4
|
+
ref: z.ZodString;
|
|
5
|
+
decision: z.ZodLiteral<"allow">;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
/** The policy allows the update only if it is a fast-forward. */
|
|
8
|
+
export declare const RefDecisionFastForwardOnly: z.ZodObject<{
|
|
9
|
+
ref: z.ZodString;
|
|
10
|
+
decision: z.ZodLiteral<"fast-forward-only">;
|
|
11
|
+
reason: z.ZodString;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
/** The policy refuses the update. */
|
|
14
|
+
export declare const RefDecisionDeny: z.ZodObject<{
|
|
15
|
+
ref: z.ZodString;
|
|
16
|
+
decision: z.ZodLiteral<"deny">;
|
|
17
|
+
reason: z.ZodString;
|
|
18
|
+
}, z.core.$strict>;
|
|
19
|
+
/** The branch policy's verdict on one ref update. */
|
|
20
|
+
export declare const RefDecision: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
21
|
+
ref: z.ZodString;
|
|
22
|
+
decision: z.ZodLiteral<"allow">;
|
|
23
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
24
|
+
ref: z.ZodString;
|
|
25
|
+
decision: z.ZodLiteral<"fast-forward-only">;
|
|
26
|
+
reason: z.ZodString;
|
|
27
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
28
|
+
ref: z.ZodString;
|
|
29
|
+
decision: z.ZodLiteral<"deny">;
|
|
30
|
+
reason: z.ZodString;
|
|
31
|
+
}, z.core.$strict>], "decision">;
|
|
32
|
+
/** A verdict on one ref update, inferred from {@link RefDecision}. */
|
|
33
|
+
export type RefDecision = z.infer<typeof RefDecision>;
|
|
34
|
+
/** What BranchPolicy.check() returns for a push. */
|
|
35
|
+
export declare const PolicyResult: z.ZodObject<{
|
|
36
|
+
refs: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
37
|
+
ref: z.ZodString;
|
|
38
|
+
decision: z.ZodLiteral<"allow">;
|
|
39
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
40
|
+
ref: z.ZodString;
|
|
41
|
+
decision: z.ZodLiteral<"fast-forward-only">;
|
|
42
|
+
reason: z.ZodString;
|
|
43
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
44
|
+
ref: z.ZodString;
|
|
45
|
+
decision: z.ZodLiteral<"deny">;
|
|
46
|
+
reason: z.ZodString;
|
|
47
|
+
}, z.core.$strict>], "decision">>;
|
|
48
|
+
}, z.core.$strict>;
|
|
49
|
+
/** A branch policy verdict, inferred from {@link PolicyResult}. */
|
|
50
|
+
export type PolicyResult = z.infer<typeof PolicyResult>;
|
|
51
|
+
//# sourceMappingURL=policy-result.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { FullRefName } from "../schemas/names.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/proxy/policy-result.ts
|
|
4
|
+
const policyReason = z.string().min(1).max(500).regex(/^[^\n\0]+$/).describe("Why the update is or would be refused, shown to the user by git as \"! [remote rejected] <ref> (<reason>)\": one line of 1–500 characters.");
|
|
5
|
+
/** The policy allows any update of the ref, force pushes included. */
|
|
6
|
+
const RefDecisionAllow = z.object({
|
|
7
|
+
ref: FullRefName.describe("The ref the update names."),
|
|
8
|
+
decision: z.literal("allow").describe("The update may proceed, whether or not it is a fast-forward.")
|
|
9
|
+
}).strict().meta({
|
|
10
|
+
id: "RefDecisionAllow",
|
|
11
|
+
title: "Ref decision: allow",
|
|
12
|
+
description: "The branch policy allows this update as it stands, force pushes included.",
|
|
13
|
+
examples: [{
|
|
14
|
+
ref: "refs/heads/feature/x",
|
|
15
|
+
decision: "allow"
|
|
16
|
+
}]
|
|
17
|
+
});
|
|
18
|
+
/** The policy allows the update only if it is a fast-forward. */
|
|
19
|
+
const RefDecisionFastForwardOnly = z.object({
|
|
20
|
+
ref: FullRefName.describe("The ref the update names."),
|
|
21
|
+
decision: z.literal("fast-forward-only").describe("The update may proceed only if the new commit contains the current head; the gateway checks ancestry and refuses otherwise. A creation (no current head) proceeds; a deletion (no new commit) is refused."),
|
|
22
|
+
reason: policyReason
|
|
23
|
+
}).strict().meta({
|
|
24
|
+
id: "RefDecisionFastForwardOnly",
|
|
25
|
+
title: "Ref decision: fast-forward only",
|
|
26
|
+
description: "The branch policy allows this update only as a fast-forward. The gateway proves the new commit descends from the old one (from the pushed pack and the backend) and refuses with `reason` when it does not or cannot be shown to. Creating a ref is allowed (there is no old head to lose); deleting one is refused with `reason` (there is no new commit to contain the old head). Moving an existing tag is never a fast-forward.",
|
|
27
|
+
examples: [{
|
|
28
|
+
ref: "refs/heads/main",
|
|
29
|
+
decision: "fast-forward-only",
|
|
30
|
+
reason: "force pushes to main are not allowed"
|
|
31
|
+
}]
|
|
32
|
+
});
|
|
33
|
+
/** The policy refuses the update. */
|
|
34
|
+
const RefDecisionDeny = z.object({
|
|
35
|
+
ref: FullRefName.describe("The ref the update names."),
|
|
36
|
+
decision: z.literal("deny").describe("The update is refused."),
|
|
37
|
+
reason: policyReason
|
|
38
|
+
}).strict().meta({
|
|
39
|
+
id: "RefDecisionDeny",
|
|
40
|
+
title: "Ref decision: deny",
|
|
41
|
+
description: "The branch policy refuses this update; git shows `reason` to the user.",
|
|
42
|
+
examples: [{
|
|
43
|
+
ref: "refs/heads/main",
|
|
44
|
+
decision: "deny",
|
|
45
|
+
reason: "main is protected"
|
|
46
|
+
}]
|
|
47
|
+
});
|
|
48
|
+
/** The branch policy's verdict on one ref update. */
|
|
49
|
+
const RefDecision = z.discriminatedUnion("decision", [
|
|
50
|
+
RefDecisionAllow,
|
|
51
|
+
RefDecisionFastForwardOnly,
|
|
52
|
+
RefDecisionDeny
|
|
53
|
+
]).meta({
|
|
54
|
+
id: "RefDecision",
|
|
55
|
+
title: "Ref decision",
|
|
56
|
+
description: "The branch policy verdict on one ref update, discriminated by `decision`.",
|
|
57
|
+
examples: [{
|
|
58
|
+
ref: "refs/heads/main",
|
|
59
|
+
decision: "deny",
|
|
60
|
+
reason: "main is protected"
|
|
61
|
+
}]
|
|
62
|
+
});
|
|
63
|
+
/** What BranchPolicy.check() returns for a push. */
|
|
64
|
+
const PolicyResult = z.object({ refs: z.array(RefDecision).max(1e4).superRefine((decisions, ctx) => {
|
|
65
|
+
const seen = /* @__PURE__ */ new Set();
|
|
66
|
+
decisions.forEach((decision, index) => {
|
|
67
|
+
if (seen.has(decision.ref)) ctx.addIssue({
|
|
68
|
+
code: "custom",
|
|
69
|
+
message: `the ref ${decision.ref} has more than one decision; a policy result names each ref once`,
|
|
70
|
+
path: [index, "ref"]
|
|
71
|
+
});
|
|
72
|
+
seen.add(decision.ref);
|
|
73
|
+
});
|
|
74
|
+
}).describe("One decision per update the policy was given, for the same refs, each ref named at most once (a result naming a ref twice is refused, so the gateway never has to pick between conflicting decisions). A push is forwarded only when every update is allowed; an update without a decision is refused.") }).strict().meta({
|
|
75
|
+
id: "PolicyResult",
|
|
76
|
+
title: "Policy result",
|
|
77
|
+
description: "The branch policy verdict on every ref update of one push. The gateway forwards the push only when all of them are allowed (fast-forward-only ones after their ancestry is proven); otherwise nothing is written and git reports each refused ref with its reason.",
|
|
78
|
+
examples: [{ refs: [{
|
|
79
|
+
ref: "refs/heads/main",
|
|
80
|
+
decision: "fast-forward-only",
|
|
81
|
+
reason: "force pushes to main are not allowed"
|
|
82
|
+
}, {
|
|
83
|
+
ref: "refs/tags/v1.0.0",
|
|
84
|
+
decision: "deny",
|
|
85
|
+
reason: "tags are created by the release pipeline"
|
|
86
|
+
}] }]
|
|
87
|
+
});
|
|
88
|
+
export { PolicyResult, RefDecision, RefDecisionAllow, RefDecisionDeny, RefDecisionFastForwardOnly };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=policy-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-result.js","names":[],"sources":["../../src/proxy/policy-result.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\nimport { FullRefName } from '../schemas/names.ts';\n\nconst policyReason = z\n .string()\n .min(1)\n .max(500)\n .regex(/^[^\\n\\0]+$/)\n .describe(\n 'Why the update is or would be refused, shown to the user by git as \"! [remote rejected] <ref> (<reason>)\": one line of 1–500 characters.',\n );\n\n/** The policy allows any update of the ref, force pushes included. */\nexport const RefDecisionAllow = z\n .object({\n ref: FullRefName.describe('The ref the update names.'),\n decision: z.literal('allow').describe('The update may proceed, whether or not it is a fast-forward.'),\n })\n .strict()\n .meta({\n id: 'RefDecisionAllow',\n title: 'Ref decision: allow',\n description: 'The branch policy allows this update as it stands, force pushes included.',\n examples: [{ ref: 'refs/heads/feature/x', decision: 'allow' }],\n });\n\n/** The policy allows the update only if it is a fast-forward. */\nexport const RefDecisionFastForwardOnly = z\n .object({\n ref: FullRefName.describe('The ref the update names.'),\n decision: z\n .literal('fast-forward-only')\n .describe(\n 'The update may proceed only if the new commit contains the current head; the gateway checks ancestry and refuses otherwise. A creation (no current head) proceeds; a deletion (no new commit) is refused.',\n ),\n reason: policyReason,\n })\n .strict()\n .meta({\n id: 'RefDecisionFastForwardOnly',\n title: 'Ref decision: fast-forward only',\n description:\n 'The branch policy allows this update only as a fast-forward. The gateway proves the new commit descends from the old one (from the pushed pack and the backend) and refuses with `reason` when it does not or cannot be shown to. Creating a ref is allowed (there is no old head to lose); deleting one is refused with `reason` (there is no new commit to contain the old head). Moving an existing tag is never a fast-forward.',\n examples: [\n {\n ref: 'refs/heads/main',\n decision: 'fast-forward-only',\n reason: 'force pushes to main are not allowed',\n },\n ],\n });\n\n/** The policy refuses the update. */\nexport const RefDecisionDeny = z\n .object({\n ref: FullRefName.describe('The ref the update names.'),\n decision: z.literal('deny').describe('The update is refused.'),\n reason: policyReason,\n })\n .strict()\n .meta({\n id: 'RefDecisionDeny',\n title: 'Ref decision: deny',\n description: 'The branch policy refuses this update; git shows `reason` to the user.',\n examples: [{ ref: 'refs/heads/main', decision: 'deny', reason: 'main is protected' }],\n });\n\n/** The branch policy's verdict on one ref update. */\nexport const RefDecision = z\n .discriminatedUnion('decision', [RefDecisionAllow, RefDecisionFastForwardOnly, RefDecisionDeny])\n .meta({\n id: 'RefDecision',\n title: 'Ref decision',\n description: 'The branch policy verdict on one ref update, discriminated by `decision`.',\n examples: [{ ref: 'refs/heads/main', decision: 'deny', reason: 'main is protected' }],\n });\n\n/** A verdict on one ref update, inferred from {@link RefDecision}. */\nexport type RefDecision = z.infer<typeof RefDecision>;\n\n/** What BranchPolicy.check() returns for a push. */\nexport const PolicyResult = z\n .object({\n refs: z\n .array(RefDecision)\n .max(10_000)\n .superRefine((decisions, ctx) => {\n const seen = new Set<string>();\n decisions.forEach((decision, index) => {\n if (seen.has(decision.ref)) {\n ctx.addIssue({\n code: 'custom',\n message: `the ref ${decision.ref} has more than one decision; a policy result names each ref once`,\n path: [index, 'ref'],\n });\n }\n seen.add(decision.ref);\n });\n })\n .describe(\n 'One decision per update the policy was given, for the same refs, each ref named at most once (a result naming a ref twice is refused, so the gateway never has to pick between conflicting decisions). A push is forwarded only when every update is allowed; an update without a decision is refused.',\n ),\n })\n .strict()\n .meta({\n id: 'PolicyResult',\n title: 'Policy result',\n description:\n 'The branch policy verdict on every ref update of one push. The gateway forwards the push only when all of them are allowed (fast-forward-only ones after their ancestry is proven); otherwise nothing is written and git reports each refused ref with its reason.',\n examples: [\n {\n refs: [\n {\n ref: 'refs/heads/main',\n decision: 'fast-forward-only',\n reason: 'force pushes to main are not allowed',\n },\n { ref: 'refs/tags/v1.0.0', decision: 'deny', reason: 'tags are created by the release pipeline' },\n ],\n },\n ],\n });\n\n/** A branch policy verdict, inferred from {@link PolicyResult}. */\nexport type PolicyResult = z.infer<typeof PolicyResult>;\n"],"mappings":";;;AAKA,MAAM,eAAe,EAClB,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,MAAM,YAAY,CAAC,CACnB,SACC,4IACF;;AAGF,MAAa,mBAAmB,EAC7B,OAAO;CACN,KAAK,YAAY,SAAS,2BAA2B;CACrD,UAAU,EAAE,QAAQ,OAAO,CAAC,CAAC,SAAS,8DAA8D;AACtG,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,KAAK;EAAwB,UAAU;CAAQ,CAAC;AAC/D,CAAC;;AAGH,MAAa,6BAA6B,EACvC,OAAO;CACN,KAAK,YAAY,SAAS,2BAA2B;CACrD,UAAU,EACP,QAAQ,mBAAmB,CAAC,CAC5B,SACC,2MACF;CACF,QAAQ;AACV,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR;EACE,KAAK;EACL,UAAU;EACV,QAAQ;CACV,CACF;AACF,CAAC;;AAGH,MAAa,kBAAkB,EAC5B,OAAO;CACN,KAAK,YAAY,SAAS,2BAA2B;CACrD,UAAU,EAAE,QAAQ,MAAM,CAAC,CAAC,SAAS,wBAAwB;CAC7D,QAAQ;AACV,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,KAAK;EAAmB,UAAU;EAAQ,QAAQ;CAAoB,CAAC;AACtF,CAAC;;AAGH,MAAa,cAAc,EACxB,mBAAmB,YAAY;CAAC;CAAkB;CAA4B;AAAe,CAAC,CAAC,CAC/F,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,KAAK;EAAmB,UAAU;EAAQ,QAAQ;CAAoB,CAAC;AACtF,CAAC;;AAMH,MAAa,eAAe,EACzB,OAAO,EACN,MAAM,EACH,MAAM,WAAW,CAAC,CAClB,IAAI,GAAM,CAAC,CACX,aAAa,WAAW,QAAQ;CAC/B,MAAM,uBAAO,IAAI,IAAY;CAC7B,UAAU,SAAS,UAAU,UAAU;EACrC,IAAI,KAAK,IAAI,SAAS,GAAG,GACvB,IAAI,SAAS;GACX,MAAM;GACN,SAAS,WAAW,SAAS,IAAI;GACjC,MAAM,CAAC,OAAO,KAAK;EACrB,CAAC;EAEH,KAAK,IAAI,SAAS,GAAG;CACvB,CAAC;AACH,CAAC,CAAC,CACD,SACC,wSACF,EACJ,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR,EACE,MAAM,CACJ;EACE,KAAK;EACL,UAAU;EACV,QAAQ;CACV,GACA;EAAE,KAAK;EAAoB,UAAU;EAAQ,QAAQ;CAA2C,CAClG,EACF,CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** A role or group name a deployment grants a principal. */
|
|
3
|
+
export declare const Role: z.ZodString;
|
|
4
|
+
/** A role name, inferred from {@link Role}. */
|
|
5
|
+
export type Role = z.infer<typeof Role>;
|
|
6
|
+
/** Who a smart-HTTP request acts for, as an Authenticator established it. */
|
|
7
|
+
export declare const Principal: z.ZodObject<{
|
|
8
|
+
subject: z.ZodString;
|
|
9
|
+
name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
10
|
+
email: z.ZodDefault<z.ZodNullable<z.ZodEmail>>;
|
|
11
|
+
roles: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
12
|
+
expiresAt: z.ZodDefault<z.ZodNullable<z.ZodISODateTime>>;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
/** A principal as an authenticator may write it (defaults optional). */
|
|
15
|
+
export type PrincipalInput = z.input<typeof Principal>;
|
|
16
|
+
/** A complete principal, inferred from {@link Principal}. */
|
|
17
|
+
export type Principal = z.output<typeof Principal>;
|
|
18
|
+
//# sourceMappingURL=principal.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Timestamp } from "../schemas/identity.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/proxy/principal.ts
|
|
4
|
+
/** A role or group name a deployment grants a principal. */
|
|
5
|
+
const Role = z.string().min(1).max(100).regex(/^[^\s\0]+$/).meta({
|
|
6
|
+
id: "Role",
|
|
7
|
+
title: "Role",
|
|
8
|
+
description: "A role or group the deployment grants a principal, matched by branch-policy rules and authorizers: 1–100 characters without whitespace or NUL. Case-sensitive.",
|
|
9
|
+
examples: ["maintainer", "site:acme:editor"]
|
|
10
|
+
});
|
|
11
|
+
/** Who a smart-HTTP request acts for, as an Authenticator established it. */
|
|
12
|
+
const Principal = z.object({
|
|
13
|
+
subject: z.string().min(1).max(255).regex(/^[^\n\0]+$/).describe("Stable identifier of the caller in the deployment (e.g. the JWT \"sub\" claim or a user id): 1–255 characters without newline or NUL. Used for policy matching, audit and caching; never a credential."),
|
|
14
|
+
name: z.string().min(1).max(255).regex(/^[^\n\0]+$/).nullable().default(null).describe("Display name for logs and audit, 1–255 characters without newline or NUL; null (the default) when the authenticator does not know one."),
|
|
15
|
+
email: z.email().max(255).nullable().default(null).describe("Email address, at most 255 characters; null (the default) when unknown."),
|
|
16
|
+
roles: z.array(Role).max(100).default([]).describe("Roles or groups granted to the caller, at most 100; default none."),
|
|
17
|
+
expiresAt: Timestamp.nullable().default(null).describe("When the credential that established this principal stops being valid, as an ISO 8601 UTC timestamp; cached decisions never outlive it. Null (the default) when the credential does not expire or the authenticator does not say.")
|
|
18
|
+
}).strict().meta({
|
|
19
|
+
id: "Principal",
|
|
20
|
+
title: "Principal",
|
|
21
|
+
description: "Who a smart-HTTP request acts for, as returned by an Authenticator. Authorizers, branch policy, the audit hook and the decision cache all key on it; it never carries the credential itself.",
|
|
22
|
+
examples: [{
|
|
23
|
+
subject: "user:42",
|
|
24
|
+
name: "Ada Lovelace",
|
|
25
|
+
email: "ada@example.com",
|
|
26
|
+
roles: ["maintainer"],
|
|
27
|
+
expiresAt: "2026-11-20T10:30:00.000Z"
|
|
28
|
+
}]
|
|
29
|
+
});
|
|
30
|
+
export { Principal, Role };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=principal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principal.js","names":[],"sources":["../../src/proxy/principal.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\nimport { Timestamp } from '../schemas/identity.ts';\n\n/** A role or group name a deployment grants a principal. */\nexport const Role = z\n .string()\n .min(1)\n .max(100)\n .regex(/^[^\\s\\0]+$/)\n .meta({\n id: 'Role',\n title: 'Role',\n description:\n 'A role or group the deployment grants a principal, matched by branch-policy rules and authorizers: 1–100 characters without whitespace or NUL. Case-sensitive.',\n examples: ['maintainer', 'site:acme:editor'],\n });\n\n/** A role name, inferred from {@link Role}. */\nexport type Role = z.infer<typeof Role>;\n\n/** Who a smart-HTTP request acts for, as an Authenticator established it. */\nexport const Principal = z\n .object({\n subject: z\n .string()\n .min(1)\n .max(255)\n .regex(/^[^\\n\\0]+$/)\n .describe(\n 'Stable identifier of the caller in the deployment (e.g. the JWT \"sub\" claim or a user id): 1–255 characters without newline or NUL. Used for policy matching, audit and caching; never a credential.',\n ),\n name: z\n .string()\n .min(1)\n .max(255)\n .regex(/^[^\\n\\0]+$/)\n .nullable()\n .default(null)\n .describe(\n 'Display name for logs and audit, 1–255 characters without newline or NUL; null (the default) when the authenticator does not know one.',\n ),\n email: z\n .email()\n .max(255)\n .nullable()\n .default(null)\n .describe('Email address, at most 255 characters; null (the default) when unknown.'),\n roles: z\n .array(Role)\n .max(100)\n .default([])\n .describe('Roles or groups granted to the caller, at most 100; default none.'),\n expiresAt: Timestamp.nullable()\n .default(null)\n .describe(\n 'When the credential that established this principal stops being valid, as an ISO 8601 UTC timestamp; cached decisions never outlive it. Null (the default) when the credential does not expire or the authenticator does not say.',\n ),\n })\n .strict()\n .meta({\n id: 'Principal',\n title: 'Principal',\n description:\n 'Who a smart-HTTP request acts for, as returned by an Authenticator. Authorizers, branch policy, the audit hook and the decision cache all key on it; it never carries the credential itself.',\n examples: [\n {\n subject: 'user:42',\n name: 'Ada Lovelace',\n email: 'ada@example.com',\n roles: ['maintainer'],\n expiresAt: '2026-11-20T10:30:00.000Z',\n },\n ],\n });\n\n/** A principal as an authenticator may write it (defaults optional). */\nexport type PrincipalInput = z.input<typeof Principal>;\n/** A complete principal, inferred from {@link Principal}. */\nexport type Principal = z.output<typeof Principal>;\n"],"mappings":";;;;AAMA,MAAa,OAAO,EACjB,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,MAAM,YAAY,CAAC,CACnB,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CAAC,cAAc,kBAAkB;AAC7C,CAAC;;AAMH,MAAa,YAAY,EACtB,OAAO;CACN,SAAS,EACN,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,MAAM,YAAY,CAAC,CACnB,SACC,wMACF;CACF,MAAM,EACH,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,MAAM,YAAY,CAAC,CACnB,SAAS,CAAC,CACV,QAAQ,IAAI,CAAC,CACb,SACC,wIACF;CACF,OAAO,EACJ,MAAM,CAAC,CACP,IAAI,GAAG,CAAC,CACR,SAAS,CAAC,CACV,QAAQ,IAAI,CAAC,CACb,SAAS,yEAAyE;CACrF,OAAO,EACJ,MAAM,IAAI,CAAC,CACX,IAAI,GAAG,CAAC,CACR,QAAQ,CAAC,CAAC,CAAC,CACX,SAAS,mEAAmE;CAC/E,WAAW,UAAU,SAAS,CAAC,CAC5B,QAAQ,IAAI,CAAC,CACb,SACC,mOACF;AACJ,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR;EACE,SAAS;EACT,MAAM;EACN,OAAO;EACP,OAAO,CAAC,YAAY;EACpB,WAAW;CACb,CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** What a push policy asks the gateway to compute before it is called. */
|
|
3
|
+
export declare const PushPolicyNeeds: z.ZodObject<{
|
|
4
|
+
changedPaths: z.ZodBoolean;
|
|
5
|
+
}, z.core.$strict>;
|
|
6
|
+
/** What a push policy needs, inferred from {@link PushPolicyNeeds}. */
|
|
7
|
+
export type PushPolicyNeeds = z.infer<typeof PushPolicyNeeds>;
|
|
8
|
+
/** A push policy's verdict on one ref update: allow or deny. */
|
|
9
|
+
export declare const PushRefDecision: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
10
|
+
ref: z.ZodString;
|
|
11
|
+
decision: z.ZodLiteral<"allow">;
|
|
12
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
13
|
+
ref: z.ZodString;
|
|
14
|
+
decision: z.ZodLiteral<"deny">;
|
|
15
|
+
reason: z.ZodString;
|
|
16
|
+
}, z.core.$strict>], "decision">;
|
|
17
|
+
/** A push policy's verdict on one update, inferred from {@link PushRefDecision}. */
|
|
18
|
+
export type PushRefDecision = z.infer<typeof PushRefDecision>;
|
|
19
|
+
/** What PushPolicy.check() returns. */
|
|
20
|
+
export declare const PushPolicyResult: z.ZodObject<{
|
|
21
|
+
refs: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
22
|
+
ref: z.ZodString;
|
|
23
|
+
decision: z.ZodLiteral<"allow">;
|
|
24
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
25
|
+
ref: z.ZodString;
|
|
26
|
+
decision: z.ZodLiteral<"deny">;
|
|
27
|
+
reason: z.ZodString;
|
|
28
|
+
}, z.core.$strict>], "decision">>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
/** A push policy verdict, inferred from {@link PushPolicyResult}. */
|
|
31
|
+
export type PushPolicyResult = z.infer<typeof PushPolicyResult>;
|
|
32
|
+
/** A push policy verdict as a policy may write it, inferred from {@link PushPolicyResult}. */
|
|
33
|
+
export type PushPolicyResultInput = z.input<typeof PushPolicyResult>;
|
|
34
|
+
//# sourceMappingURL=push-policy-result.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RefDecisionAllow, RefDecisionDeny } from "./policy-result.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/proxy/push-policy-result.ts
|
|
4
|
+
/** What a push policy asks the gateway to compute before it is called. */
|
|
5
|
+
const PushPolicyNeeds = z.object({ changedPaths: z.boolean().describe("true to be given, for every update, the commits it brings with the paths each changes (PushPolicyUpdate.commits). That means buffering and reading the pushed pack and reading trees from storage, bounded by SmartHttpConfig.maxPushPolicyPackBytes, maxPushPolicyObjectBytes, maxPushPolicyReads and maxChangedPaths; a push past a bound is refused as uncheckable. false to decide from the ref updates alone, before the pack is read (`commits` is then null).") }).strict().meta({
|
|
6
|
+
id: "PushPolicyNeeds",
|
|
7
|
+
title: "Push policy needs",
|
|
8
|
+
description: "What PushPolicy.needs() returns for a push: whether check() needs the changed paths of every update.",
|
|
9
|
+
examples: [{ changedPaths: true }]
|
|
10
|
+
});
|
|
11
|
+
/** A push policy's verdict on one ref update: allow or deny. */
|
|
12
|
+
const PushRefDecision = z.discriminatedUnion("decision", [RefDecisionAllow, RefDecisionDeny]).meta({
|
|
13
|
+
id: "PushRefDecision",
|
|
14
|
+
title: "Push ref decision",
|
|
15
|
+
description: "The push policy verdict on one ref update: allow it, or deny it with a reason git shows.",
|
|
16
|
+
examples: [{
|
|
17
|
+
ref: "refs/heads/main",
|
|
18
|
+
decision: "deny",
|
|
19
|
+
reason: "generated/ is written by the build pipeline"
|
|
20
|
+
}]
|
|
21
|
+
});
|
|
22
|
+
/** What PushPolicy.check() returns. */
|
|
23
|
+
const PushPolicyResult = z.object({ refs: z.array(PushRefDecision).max(1e4).superRefine((decisions, ctx) => {
|
|
24
|
+
const seen = /* @__PURE__ */ new Set();
|
|
25
|
+
decisions.forEach((decision, index) => {
|
|
26
|
+
if (seen.has(decision.ref)) ctx.addIssue({
|
|
27
|
+
code: "custom",
|
|
28
|
+
message: `the ref ${decision.ref} has more than one decision; a push policy result names each ref once`,
|
|
29
|
+
path: [index, "ref"]
|
|
30
|
+
});
|
|
31
|
+
seen.add(decision.ref);
|
|
32
|
+
});
|
|
33
|
+
}).describe("One decision per update the policy was given, each ref named at most once. An update without a decision is refused, and a push is written only when every update is allowed; otherwise each refused ref is reported with its reason and the rest as \"not updated: another update in this push was refused\".") }).strict().meta({
|
|
34
|
+
id: "PushPolicyResult",
|
|
35
|
+
title: "Push policy result",
|
|
36
|
+
description: "The push policy verdict on every ref update of one push. It runs after the branch policy, and the push is written only when both allow every update.",
|
|
37
|
+
examples: [{ refs: [{
|
|
38
|
+
ref: "refs/heads/main",
|
|
39
|
+
decision: "deny",
|
|
40
|
+
reason: "files over 10 MiB are not accepted: video.mp4"
|
|
41
|
+
}, {
|
|
42
|
+
ref: "refs/heads/feature/x",
|
|
43
|
+
decision: "allow"
|
|
44
|
+
}] }]
|
|
45
|
+
});
|
|
46
|
+
export { PushPolicyNeeds, PushPolicyResult, PushRefDecision };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=push-policy-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-policy-result.js","names":[],"sources":["../../src/proxy/push-policy-result.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\nimport { RefDecisionAllow, RefDecisionDeny } from './policy-result.ts';\n\n/** What a push policy asks the gateway to compute before it is called. */\nexport const PushPolicyNeeds = z\n .object({\n changedPaths: z\n .boolean()\n .describe(\n 'true to be given, for every update, the commits it brings with the paths each changes (PushPolicyUpdate.commits). That means buffering and reading the pushed pack and reading trees from storage, bounded by SmartHttpConfig.maxPushPolicyPackBytes, maxPushPolicyObjectBytes, maxPushPolicyReads and maxChangedPaths; a push past a bound is refused as uncheckable. false to decide from the ref updates alone, before the pack is read (`commits` is then null).',\n ),\n })\n .strict()\n .meta({\n id: 'PushPolicyNeeds',\n title: 'Push policy needs',\n description:\n 'What PushPolicy.needs() returns for a push: whether check() needs the changed paths of every update.',\n examples: [{ changedPaths: true }],\n });\n\n/** What a push policy needs, inferred from {@link PushPolicyNeeds}. */\nexport type PushPolicyNeeds = z.infer<typeof PushPolicyNeeds>;\n\n/** A push policy's verdict on one ref update: allow or deny. */\nexport const PushRefDecision = z.discriminatedUnion('decision', [RefDecisionAllow, RefDecisionDeny]).meta({\n id: 'PushRefDecision',\n title: 'Push ref decision',\n description: 'The push policy verdict on one ref update: allow it, or deny it with a reason git shows.',\n examples: [\n { ref: 'refs/heads/main', decision: 'deny', reason: 'generated/ is written by the build pipeline' },\n ],\n});\n\n/** A push policy's verdict on one update, inferred from {@link PushRefDecision}. */\nexport type PushRefDecision = z.infer<typeof PushRefDecision>;\n\n/** What PushPolicy.check() returns. */\nexport const PushPolicyResult = z\n .object({\n refs: z\n .array(PushRefDecision)\n .max(10_000)\n .superRefine((decisions, ctx) => {\n const seen = new Set<string>();\n decisions.forEach((decision, index) => {\n if (seen.has(decision.ref)) {\n ctx.addIssue({\n code: 'custom',\n message: `the ref ${decision.ref} has more than one decision; a push policy result names each ref once`,\n path: [index, 'ref'],\n });\n }\n seen.add(decision.ref);\n });\n })\n .describe(\n 'One decision per update the policy was given, each ref named at most once. An update without a decision is refused, and a push is written only when every update is allowed; otherwise each refused ref is reported with its reason and the rest as \"not updated: another update in this push was refused\".',\n ),\n })\n .strict()\n .meta({\n id: 'PushPolicyResult',\n title: 'Push policy result',\n description:\n 'The push policy verdict on every ref update of one push. It runs after the branch policy, and the push is written only when both allow every update.',\n examples: [\n {\n refs: [\n {\n ref: 'refs/heads/main',\n decision: 'deny',\n reason: 'files over 10 MiB are not accepted: video.mp4',\n },\n { ref: 'refs/heads/feature/x', decision: 'allow' },\n ],\n },\n ],\n });\n\n/** A push policy verdict, inferred from {@link PushPolicyResult}. */\nexport type PushPolicyResult = z.infer<typeof PushPolicyResult>;\n/** A push policy verdict as a policy may write it, inferred from {@link PushPolicyResult}. */\nexport type PushPolicyResultInput = z.input<typeof PushPolicyResult>;\n"],"mappings":";;;;AAMA,MAAa,kBAAkB,EAC5B,OAAO,EACN,cAAc,EACX,QAAQ,CAAC,CACT,SACC,scACF,EACJ,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CAAC,EAAE,cAAc,KAAK,CAAC;AACnC,CAAC;;AAMH,MAAa,kBAAkB,EAAE,mBAAmB,YAAY,CAAC,kBAAkB,eAAe,CAAC,CAAC,CAAC,KAAK;CACxG,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CACR;EAAE,KAAK;EAAmB,UAAU;EAAQ,QAAQ;CAA8C,CACpG;AACF,CAAC;;AAMD,MAAa,mBAAmB,EAC7B,OAAO,EACN,MAAM,EACH,MAAM,eAAe,CAAC,CACtB,IAAI,GAAM,CAAC,CACX,aAAa,WAAW,QAAQ;CAC/B,MAAM,uBAAO,IAAI,IAAY;CAC7B,UAAU,SAAS,UAAU,UAAU;EACrC,IAAI,KAAK,IAAI,SAAS,GAAG,GACvB,IAAI,SAAS;GACX,MAAM;GACN,SAAS,WAAW,SAAS,IAAI;GACjC,MAAM,CAAC,OAAO,KAAK;EACrB,CAAC;EAEH,KAAK,IAAI,SAAS,GAAG;CACvB,CAAC;AACH,CAAC,CAAC,CACD,SACC,+SACF,EACJ,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR,EACE,MAAM,CACJ;EACE,KAAK;EACL,UAAU;EACV,QAAQ;CACV,GACA;EAAE,KAAK;EAAwB,UAAU;CAAQ,CACnD,EACF,CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** One file a pushed commit adds, changes or removes. */
|
|
3
|
+
export declare const ChangedPath: z.ZodObject<{
|
|
4
|
+
path: z.ZodString;
|
|
5
|
+
change: z.ZodEnum<{
|
|
6
|
+
added: "added";
|
|
7
|
+
deleted: "deleted";
|
|
8
|
+
modified: "modified";
|
|
9
|
+
}>;
|
|
10
|
+
oldMode: z.ZodNullable<z.ZodEnum<{
|
|
11
|
+
"040000": "040000";
|
|
12
|
+
100644: "100644";
|
|
13
|
+
100755: "100755";
|
|
14
|
+
120000: "120000";
|
|
15
|
+
160000: "160000";
|
|
16
|
+
}>>;
|
|
17
|
+
newMode: z.ZodNullable<z.ZodEnum<{
|
|
18
|
+
"040000": "040000";
|
|
19
|
+
100644: "100644";
|
|
20
|
+
100755: "100755";
|
|
21
|
+
120000: "120000";
|
|
22
|
+
160000: "160000";
|
|
23
|
+
}>>;
|
|
24
|
+
oldSha: z.ZodNullable<z.ZodString>;
|
|
25
|
+
newSha: z.ZodNullable<z.ZodString>;
|
|
26
|
+
size: z.ZodNullable<z.ZodInt>;
|
|
27
|
+
}, z.core.$strict>;
|
|
28
|
+
/** A changed path, inferred from {@link ChangedPath}. */
|
|
29
|
+
export type ChangedPath = z.infer<typeof ChangedPath>;
|
|
30
|
+
/** A commit a push brings that storage did not have, with the paths it changes. */
|
|
31
|
+
export declare const PushedCommit: z.ZodObject<{
|
|
32
|
+
sha: z.ZodString;
|
|
33
|
+
parents: z.ZodArray<z.ZodString>;
|
|
34
|
+
changes: z.ZodArray<z.ZodObject<{
|
|
35
|
+
path: z.ZodString;
|
|
36
|
+
change: z.ZodEnum<{
|
|
37
|
+
added: "added";
|
|
38
|
+
deleted: "deleted";
|
|
39
|
+
modified: "modified";
|
|
40
|
+
}>;
|
|
41
|
+
oldMode: z.ZodNullable<z.ZodEnum<{
|
|
42
|
+
"040000": "040000";
|
|
43
|
+
100644: "100644";
|
|
44
|
+
100755: "100755";
|
|
45
|
+
120000: "120000";
|
|
46
|
+
160000: "160000";
|
|
47
|
+
}>>;
|
|
48
|
+
newMode: z.ZodNullable<z.ZodEnum<{
|
|
49
|
+
"040000": "040000";
|
|
50
|
+
100644: "100644";
|
|
51
|
+
100755: "100755";
|
|
52
|
+
120000: "120000";
|
|
53
|
+
160000: "160000";
|
|
54
|
+
}>>;
|
|
55
|
+
oldSha: z.ZodNullable<z.ZodString>;
|
|
56
|
+
newSha: z.ZodNullable<z.ZodString>;
|
|
57
|
+
size: z.ZodNullable<z.ZodInt>;
|
|
58
|
+
}, z.core.$strict>>;
|
|
59
|
+
}, z.core.$strict>;
|
|
60
|
+
/** A pushed commit, inferred from {@link PushedCommit}. */
|
|
61
|
+
export type PushedCommit = z.infer<typeof PushedCommit>;
|
|
62
|
+
/** One ref update of a push, as a push policy sees it. */
|
|
63
|
+
export declare const PushPolicyUpdate: z.ZodObject<{
|
|
64
|
+
ref: z.ZodString;
|
|
65
|
+
oldSha: z.ZodString;
|
|
66
|
+
newSha: z.ZodString;
|
|
67
|
+
commits: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
68
|
+
sha: z.ZodString;
|
|
69
|
+
parents: z.ZodArray<z.ZodString>;
|
|
70
|
+
changes: z.ZodArray<z.ZodObject<{
|
|
71
|
+
path: z.ZodString;
|
|
72
|
+
change: z.ZodEnum<{
|
|
73
|
+
added: "added";
|
|
74
|
+
deleted: "deleted";
|
|
75
|
+
modified: "modified";
|
|
76
|
+
}>;
|
|
77
|
+
oldMode: z.ZodNullable<z.ZodEnum<{
|
|
78
|
+
"040000": "040000";
|
|
79
|
+
100644: "100644";
|
|
80
|
+
100755: "100755";
|
|
81
|
+
120000: "120000";
|
|
82
|
+
160000: "160000";
|
|
83
|
+
}>>;
|
|
84
|
+
newMode: z.ZodNullable<z.ZodEnum<{
|
|
85
|
+
"040000": "040000";
|
|
86
|
+
100644: "100644";
|
|
87
|
+
100755: "100755";
|
|
88
|
+
120000: "120000";
|
|
89
|
+
160000: "160000";
|
|
90
|
+
}>>;
|
|
91
|
+
oldSha: z.ZodNullable<z.ZodString>;
|
|
92
|
+
newSha: z.ZodNullable<z.ZodString>;
|
|
93
|
+
size: z.ZodNullable<z.ZodInt>;
|
|
94
|
+
}, z.core.$strict>>;
|
|
95
|
+
}, z.core.$strict>>>;
|
|
96
|
+
}, z.core.$strict>;
|
|
97
|
+
/** A ref update as a push policy sees it, inferred from {@link PushPolicyUpdate}. */
|
|
98
|
+
export type PushPolicyUpdate = z.infer<typeof PushPolicyUpdate>;
|
|
99
|
+
/** What a PushPolicy is asked to judge. */
|
|
100
|
+
export declare const PushPolicyInput: z.ZodObject<{
|
|
101
|
+
principal: z.ZodObject<{
|
|
102
|
+
subject: z.ZodString;
|
|
103
|
+
name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
104
|
+
email: z.ZodDefault<z.ZodNullable<z.ZodEmail>>;
|
|
105
|
+
roles: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
106
|
+
expiresAt: z.ZodDefault<z.ZodNullable<z.ZodISODateTime>>;
|
|
107
|
+
}, z.core.$strict>;
|
|
108
|
+
repo: z.ZodString;
|
|
109
|
+
updates: z.ZodArray<z.ZodObject<{
|
|
110
|
+
ref: z.ZodString;
|
|
111
|
+
oldSha: z.ZodString;
|
|
112
|
+
newSha: z.ZodString;
|
|
113
|
+
commits: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
114
|
+
sha: z.ZodString;
|
|
115
|
+
parents: z.ZodArray<z.ZodString>;
|
|
116
|
+
changes: z.ZodArray<z.ZodObject<{
|
|
117
|
+
path: z.ZodString;
|
|
118
|
+
change: z.ZodEnum<{
|
|
119
|
+
added: "added";
|
|
120
|
+
deleted: "deleted";
|
|
121
|
+
modified: "modified";
|
|
122
|
+
}>;
|
|
123
|
+
oldMode: z.ZodNullable<z.ZodEnum<{
|
|
124
|
+
"040000": "040000";
|
|
125
|
+
100644: "100644";
|
|
126
|
+
100755: "100755";
|
|
127
|
+
120000: "120000";
|
|
128
|
+
160000: "160000";
|
|
129
|
+
}>>;
|
|
130
|
+
newMode: z.ZodNullable<z.ZodEnum<{
|
|
131
|
+
"040000": "040000";
|
|
132
|
+
100644: "100644";
|
|
133
|
+
100755: "100755";
|
|
134
|
+
120000: "120000";
|
|
135
|
+
160000: "160000";
|
|
136
|
+
}>>;
|
|
137
|
+
oldSha: z.ZodNullable<z.ZodString>;
|
|
138
|
+
newSha: z.ZodNullable<z.ZodString>;
|
|
139
|
+
size: z.ZodNullable<z.ZodInt>;
|
|
140
|
+
}, z.core.$strict>>;
|
|
141
|
+
}, z.core.$strict>>>;
|
|
142
|
+
}, z.core.$strict>>;
|
|
143
|
+
}, z.core.$strict>;
|
|
144
|
+
/** A push policy's input, inferred from {@link PushPolicyInput}. */
|
|
145
|
+
export type PushPolicyInput = z.infer<typeof PushPolicyInput>;
|
|
146
|
+
//# sourceMappingURL=push-policy.d.ts.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { FullRefName, RepoName } from "../schemas/names.js";
|
|
2
|
+
import { Sha } from "../schemas/sha.js";
|
|
3
|
+
import { FileMode } from "../schemas/tree-entry.js";
|
|
4
|
+
import { Principal } from "./principal.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
// src/proxy/push-policy.ts
|
|
7
|
+
const EXAMPLE_OLD = "1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d";
|
|
8
|
+
const EXAMPLE_NEW = "8f3c2a9e1b7d4c6f0a5e2d9b8c7a6f5e4d3c2b1a";
|
|
9
|
+
const EXAMPLE_BLOB = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
|
|
10
|
+
/** One file a pushed commit adds, changes or removes. */
|
|
11
|
+
const ChangedPath = z.object({
|
|
12
|
+
path: z.string().min(1).max(4096).regex(/^[^\0]+$/).describe("The file's path from the repository root, \"/\"-separated, exactly as the tree names it (any bytes git allows except NUL, decoded as UTF-8); 1–4096 characters. Always a file, symlink or submodule, never a directory: a directory added or removed appears as each file in it."),
|
|
13
|
+
change: z.enum([
|
|
14
|
+
"added",
|
|
15
|
+
"modified",
|
|
16
|
+
"deleted"
|
|
17
|
+
]).meta({
|
|
18
|
+
description: "What the commit did to the path.",
|
|
19
|
+
enumDescriptions: {
|
|
20
|
+
added: "The path is new: no entry before (a file replacing a directory is added too).",
|
|
21
|
+
modified: "The path existed and its content or mode changed.",
|
|
22
|
+
deleted: "The path is gone (a directory replacing a file deletes the file)."
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
oldMode: FileMode.nullable().describe("The mode before the commit; null when the path was added."),
|
|
26
|
+
newMode: FileMode.nullable().describe("The mode after the commit; null when the path was deleted."),
|
|
27
|
+
oldSha: Sha.nullable().describe("The blob (or submodule commit) before the commit; null when added."),
|
|
28
|
+
newSha: Sha.nullable().describe("The blob (or submodule commit) after the commit; null when deleted."),
|
|
29
|
+
size: z.int().min(0).nullable().describe("Size in bytes of the new blob (for a symlink, of its target text); null when the path was deleted or is a submodule (mode 160000).")
|
|
30
|
+
}).strict().meta({
|
|
31
|
+
id: "ChangedPath",
|
|
32
|
+
title: "Changed path",
|
|
33
|
+
description: "One path a pushed commit changed, from comparing its tree with its parent's: the change, the modes and ids on both sides, and the new blob's size.",
|
|
34
|
+
examples: [{
|
|
35
|
+
path: "content/pages/about.md",
|
|
36
|
+
change: "modified",
|
|
37
|
+
oldMode: "100644",
|
|
38
|
+
newMode: "100644",
|
|
39
|
+
oldSha: EXAMPLE_BLOB,
|
|
40
|
+
newSha: EXAMPLE_OLD,
|
|
41
|
+
size: 1832
|
|
42
|
+
}]
|
|
43
|
+
});
|
|
44
|
+
/** A commit a push brings that storage did not have, with the paths it changes. */
|
|
45
|
+
const PushedCommit = z.object({
|
|
46
|
+
sha: Sha.describe("The commit id."),
|
|
47
|
+
parents: z.array(Sha.describe("A parent commit id.")).max(1e3).describe("Parent ids in order."),
|
|
48
|
+
changes: z.array(ChangedPath).max(1e5).describe("The paths the commit changes. Against its parent for an ordinary commit and against the empty tree for a root commit; for a merge, only the paths whose result differs from every parent (git's combined diff), since anything matching one parent came from that parent. Sorted by path.")
|
|
49
|
+
}).strict().meta({
|
|
50
|
+
id: "PushedCommit",
|
|
51
|
+
title: "Pushed commit",
|
|
52
|
+
description: "A commit new to the repository that a ref update brings (it is in the pushed pack), with the paths it changes.",
|
|
53
|
+
examples: [{
|
|
54
|
+
sha: EXAMPLE_NEW,
|
|
55
|
+
parents: [EXAMPLE_OLD],
|
|
56
|
+
changes: [{
|
|
57
|
+
path: "README.md",
|
|
58
|
+
change: "added",
|
|
59
|
+
oldMode: null,
|
|
60
|
+
newMode: "100644",
|
|
61
|
+
oldSha: null,
|
|
62
|
+
newSha: EXAMPLE_BLOB,
|
|
63
|
+
size: 0
|
|
64
|
+
}]
|
|
65
|
+
}]
|
|
66
|
+
});
|
|
67
|
+
/** One ref update of a push, as a push policy sees it. */
|
|
68
|
+
const PushPolicyUpdate = z.object({
|
|
69
|
+
ref: FullRefName.describe("The ref the update names, fully qualified."),
|
|
70
|
+
oldSha: Sha.describe("Id the ref names now; the all-zero id when the update creates the ref."),
|
|
71
|
+
newSha: Sha.describe("Id the ref will name; the all-zero id when the update deletes the ref."),
|
|
72
|
+
commits: z.array(PushedCommit).max(1e5).nullable().describe("The commits new to the repository that the update brings — those of the pushed pack reachable from `newSha` — newest first (breadth-first from `newSha`), each with its changed paths. Empty for a deletion, or when `newSha` is a commit storage already has. Null when the policy did not ask for changed paths (PushPolicyNeeds.changedPaths false).")
|
|
73
|
+
}).strict().meta({
|
|
74
|
+
id: "PushPolicyUpdate",
|
|
75
|
+
title: "Push policy update",
|
|
76
|
+
description: "One ref update of a push and, when the policy asked for them, the commits it brings.",
|
|
77
|
+
examples: [{
|
|
78
|
+
ref: "refs/heads/main",
|
|
79
|
+
oldSha: EXAMPLE_OLD,
|
|
80
|
+
newSha: EXAMPLE_NEW,
|
|
81
|
+
commits: null
|
|
82
|
+
}]
|
|
83
|
+
});
|
|
84
|
+
/** What a PushPolicy is asked to judge. */
|
|
85
|
+
const PushPolicyInput = z.object({
|
|
86
|
+
principal: Principal.describe("Who is pushing, as the Authenticator established it."),
|
|
87
|
+
repo: RepoName.describe("The repository pushed to."),
|
|
88
|
+
updates: z.array(PushPolicyUpdate).min(1).max(1e4).describe("Every update of the push, in the order the client sent them; all passed the branch policy.")
|
|
89
|
+
}).strict().meta({
|
|
90
|
+
id: "PushPolicyInput",
|
|
91
|
+
title: "Push policy input",
|
|
92
|
+
description: "What PushPolicy.check() is given: the principal, the repository and every ref update of a push the branch policy allowed, with changed paths when the policy asked for them.",
|
|
93
|
+
examples: [{
|
|
94
|
+
principal: {
|
|
95
|
+
subject: "alice",
|
|
96
|
+
name: null,
|
|
97
|
+
email: null,
|
|
98
|
+
roles: ["editor"],
|
|
99
|
+
expiresAt: null
|
|
100
|
+
},
|
|
101
|
+
repo: "acme-site",
|
|
102
|
+
updates: [{
|
|
103
|
+
ref: "refs/heads/main",
|
|
104
|
+
oldSha: EXAMPLE_OLD,
|
|
105
|
+
newSha: EXAMPLE_NEW,
|
|
106
|
+
commits: null
|
|
107
|
+
}]
|
|
108
|
+
}]
|
|
109
|
+
});
|
|
110
|
+
export { ChangedPath, PushPolicyInput, PushPolicyUpdate, PushedCommit };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=push-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-policy.js","names":[],"sources":["../../src/proxy/push-policy.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\nimport { FullRefName, RepoName } from '../schemas/names.ts';\nimport { Sha } from '../schemas/sha.ts';\nimport { FileMode } from '../schemas/tree-entry.ts';\nimport { Principal } from './principal.ts';\n\nconst EXAMPLE_OLD = '1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d';\nconst EXAMPLE_NEW = '8f3c2a9e1b7d4c6f0a5e2d9b8c7a6f5e4d3c2b1a';\nconst EXAMPLE_BLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391';\n\n/** One file a pushed commit adds, changes or removes. */\nexport const ChangedPath = z\n .object({\n path: z\n .string()\n .min(1)\n .max(4096)\n .regex(/^[^\\0]+$/)\n .describe(\n 'The file\\'s path from the repository root, \"/\"-separated, exactly as the tree names it (any bytes git allows except NUL, decoded as UTF-8); 1–4096 characters. Always a file, symlink or submodule, never a directory: a directory added or removed appears as each file in it.',\n ),\n change: z.enum(['added', 'modified', 'deleted']).meta({\n description: 'What the commit did to the path.',\n enumDescriptions: {\n added: 'The path is new: no entry before (a file replacing a directory is added too).',\n modified: 'The path existed and its content or mode changed.',\n deleted: 'The path is gone (a directory replacing a file deletes the file).',\n },\n }),\n oldMode: FileMode.nullable().describe('The mode before the commit; null when the path was added.'),\n newMode: FileMode.nullable().describe('The mode after the commit; null when the path was deleted.'),\n oldSha: Sha.nullable().describe('The blob (or submodule commit) before the commit; null when added.'),\n newSha: Sha.nullable().describe('The blob (or submodule commit) after the commit; null when deleted.'),\n size: z\n .int()\n .min(0)\n .nullable()\n .describe(\n 'Size in bytes of the new blob (for a symlink, of its target text); null when the path was deleted or is a submodule (mode 160000).',\n ),\n })\n .strict()\n .meta({\n id: 'ChangedPath',\n title: 'Changed path',\n description:\n \"One path a pushed commit changed, from comparing its tree with its parent's: the change, the modes and ids on both sides, and the new blob's size.\",\n examples: [\n {\n path: 'content/pages/about.md',\n change: 'modified',\n oldMode: '100644',\n newMode: '100644',\n oldSha: EXAMPLE_BLOB,\n newSha: EXAMPLE_OLD,\n size: 1832,\n },\n ],\n });\n\n/** A changed path, inferred from {@link ChangedPath}. */\nexport type ChangedPath = z.infer<typeof ChangedPath>;\n\n/** A commit a push brings that storage did not have, with the paths it changes. */\nexport const PushedCommit = z\n .object({\n sha: Sha.describe('The commit id.'),\n parents: z.array(Sha.describe('A parent commit id.')).max(1000).describe('Parent ids in order.'),\n changes: z\n .array(ChangedPath)\n .max(100_000)\n .describe(\n \"The paths the commit changes. Against its parent for an ordinary commit and against the empty tree for a root commit; for a merge, only the paths whose result differs from every parent (git's combined diff), since anything matching one parent came from that parent. Sorted by path.\",\n ),\n })\n .strict()\n .meta({\n id: 'PushedCommit',\n title: 'Pushed commit',\n description:\n 'A commit new to the repository that a ref update brings (it is in the pushed pack), with the paths it changes.',\n examples: [\n {\n sha: EXAMPLE_NEW,\n parents: [EXAMPLE_OLD],\n changes: [\n {\n path: 'README.md',\n change: 'added',\n oldMode: null,\n newMode: '100644',\n oldSha: null,\n newSha: EXAMPLE_BLOB,\n size: 0,\n },\n ],\n },\n ],\n });\n\n/** A pushed commit, inferred from {@link PushedCommit}. */\nexport type PushedCommit = z.infer<typeof PushedCommit>;\n\n/** One ref update of a push, as a push policy sees it. */\nexport const PushPolicyUpdate = z\n .object({\n ref: FullRefName.describe('The ref the update names, fully qualified.'),\n oldSha: Sha.describe('Id the ref names now; the all-zero id when the update creates the ref.'),\n newSha: Sha.describe('Id the ref will name; the all-zero id when the update deletes the ref.'),\n commits: z\n .array(PushedCommit)\n .max(100_000)\n .nullable()\n .describe(\n 'The commits new to the repository that the update brings — those of the pushed pack reachable from `newSha` — newest first (breadth-first from `newSha`), each with its changed paths. Empty for a deletion, or when `newSha` is a commit storage already has. Null when the policy did not ask for changed paths (PushPolicyNeeds.changedPaths false).',\n ),\n })\n .strict()\n .meta({\n id: 'PushPolicyUpdate',\n title: 'Push policy update',\n description: 'One ref update of a push and, when the policy asked for them, the commits it brings.',\n examples: [{ ref: 'refs/heads/main', oldSha: EXAMPLE_OLD, newSha: EXAMPLE_NEW, commits: null }],\n });\n\n/** A ref update as a push policy sees it, inferred from {@link PushPolicyUpdate}. */\nexport type PushPolicyUpdate = z.infer<typeof PushPolicyUpdate>;\n\n/** What a PushPolicy is asked to judge. */\nexport const PushPolicyInput = z\n .object({\n principal: Principal.describe('Who is pushing, as the Authenticator established it.'),\n repo: RepoName.describe('The repository pushed to.'),\n updates: z\n .array(PushPolicyUpdate)\n .min(1)\n .max(10_000)\n .describe('Every update of the push, in the order the client sent them; all passed the branch policy.'),\n })\n .strict()\n .meta({\n id: 'PushPolicyInput',\n title: 'Push policy input',\n description:\n 'What PushPolicy.check() is given: the principal, the repository and every ref update of a push the branch policy allowed, with changed paths when the policy asked for them.',\n examples: [\n {\n principal: { subject: 'alice', name: null, email: null, roles: ['editor'], expiresAt: null },\n repo: 'acme-site',\n updates: [{ ref: 'refs/heads/main', oldSha: EXAMPLE_OLD, newSha: EXAMPLE_NEW, commits: null }],\n },\n ],\n });\n\n/** A push policy's input, inferred from {@link PushPolicyInput}. */\nexport type PushPolicyInput = z.infer<typeof PushPolicyInput>;\n"],"mappings":";;;;;;AAQA,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,eAAe;;AAGrB,MAAa,cAAc,EACxB,OAAO;CACN,MAAM,EACH,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,IAAI,CAAC,CACT,MAAM,UAAU,CAAC,CACjB,SACC,kRACF;CACF,QAAQ,EAAE,KAAK;EAAC;EAAS;EAAY;CAAS,CAAC,CAAC,CAAC,KAAK;EACpD,aAAa;EACb,kBAAkB;GAChB,OAAO;GACP,UAAU;GACV,SAAS;EACX;CACF,CAAC;CACD,SAAS,SAAS,SAAS,CAAC,CAAC,SAAS,2DAA2D;CACjG,SAAS,SAAS,SAAS,CAAC,CAAC,SAAS,4DAA4D;CAClG,QAAQ,IAAI,SAAS,CAAC,CAAC,SAAS,oEAAoE;CACpG,QAAQ,IAAI,SAAS,CAAC,CAAC,SAAS,qEAAqE;CACrG,MAAM,EACH,IAAI,CAAC,CACL,IAAI,CAAC,CAAC,CACN,SAAS,CAAC,CACV,SACC,oIACF;AACJ,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR;EACE,MAAM;EACN,QAAQ;EACR,SAAS;EACT,SAAS;EACT,QAAQ;EACR,QAAQ;EACR,MAAM;CACR,CACF;AACF,CAAC;;AAMH,MAAa,eAAe,EACzB,OAAO;CACN,KAAK,IAAI,SAAS,gBAAgB;CAClC,SAAS,EAAE,MAAM,IAAI,SAAS,qBAAqB,CAAC,CAAC,CAAC,IAAI,GAAI,CAAC,CAAC,SAAS,sBAAsB;CAC/F,SAAS,EACN,MAAM,WAAW,CAAC,CAClB,IAAI,GAAO,CAAC,CACZ,SACC,2RACF;AACJ,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR;EACE,KAAK;EACL,SAAS,CAAC,WAAW;EACrB,SAAS,CACP;GACE,MAAM;GACN,QAAQ;GACR,SAAS;GACT,SAAS;GACT,QAAQ;GACR,QAAQ;GACR,MAAM;EACR,CACF;CACF,CACF;AACF,CAAC;;AAMH,MAAa,mBAAmB,EAC7B,OAAO;CACN,KAAK,YAAY,SAAS,4CAA4C;CACtE,QAAQ,IAAI,SAAS,wEAAwE;CAC7F,QAAQ,IAAI,SAAS,wEAAwE;CAC7F,SAAS,EACN,MAAM,YAAY,CAAC,CACnB,IAAI,GAAO,CAAC,CACZ,SAAS,CAAC,CACV,SACC,yVACF;AACJ,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,KAAK;EAAmB,QAAQ;EAAa,QAAQ;EAAa,SAAS;CAAK,CAAC;AAChG,CAAC;;AAMH,MAAa,kBAAkB,EAC5B,OAAO;CACN,WAAW,UAAU,SAAS,sDAAsD;CACpF,MAAM,SAAS,SAAS,2BAA2B;CACnD,SAAS,EACN,MAAM,gBAAgB,CAAC,CACvB,IAAI,CAAC,CAAC,CACN,IAAI,GAAM,CAAC,CACX,SAAS,4FAA4F;AAC1G,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR;EACE,WAAW;GAAE,SAAS;GAAS,MAAM;GAAM,OAAO;GAAM,OAAO,CAAC,QAAQ;GAAG,WAAW;EAAK;EAC3F,MAAM;EACN,SAAS,CAAC;GAAE,KAAK;GAAmB,QAAQ;GAAa,QAAQ;GAAa,SAAS;EAAK,CAAC;CAC/F,CACF;AACF,CAAC"}
|