| 1 | // The web visibility of valley projects: who may read a project's plan |
| 2 | // graph and source on the web server a valley host publishes to. |
| 3 | // |
| 4 | // Two documents decide it, and both must say public. A project declares its |
| 5 | // own visibility in policy/web/ on its main. The instance repository's |
| 6 | // policy/web/ names the projects the instance lets the web read. A project |
| 7 | // is exported publicly only when its own declaration and the instance's |
| 8 | // both say public. A declaration that is missing, or that this schema |
| 9 | // refuses, means private. |
| 10 | // |
| 11 | // The instance repository is also a project, so its policy/web/ can carry |
| 12 | // both blocks: `instance` for what the instance allows, and `project` for |
| 13 | // the instance repository's own visibility. The publisher reads `instance` |
| 14 | // from the instance repository alone, and ignores it anywhere else. |
| 15 | // |
| 16 | // The declarations live in policy/web/, beside and not inside |
| 17 | // policy/instance/ and policy/project/. Those two directories are |
| 18 | // verification-policy layers, which schema/verification.cue closes to its |
| 19 | // own fields. |
| 20 | // |
| 21 | // Validate a declaration: |
| 22 | // cue vet -c schema/web.cue policy/web/*.cue |
| 23 | package web |
| 24 | |
| 25 | import "strings" |
| 26 | |
| 27 | // #Visibility is who may read a project on the web. public is anyone; |
| 28 | // private is no one. |
| 29 | #Visibility: "public" | "private" |
| 30 | |
| 31 | // #Declaration is one project's visibility. |
| 32 | #Declaration: { |
| 33 | visibility: #Visibility |
| 34 | } |
| 35 | |
| 36 | // #Name is a project's name, as schema/valley.cue names projects. |
| 37 | #Name: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$" & strings.MaxRunes(64) |
| 38 | |
| 39 | // project is what a repository declares of itself. |
| 40 | project?: #Declaration |
| 41 | |
| 42 | // instance is what the instance repository allows. |
| 43 | instance?: #Instance |
| 44 | |
| 45 | // #Instance names the projects the web may read, each with the visibility |
| 46 | // the instance allows it. A project it does not name is private. |
| 47 | #Instance: { |
| 48 | projects: [#Name]: #Declaration |
| 49 | } |
| 50 | |
| 51 | // A file's top level cannot be closed, so a stray top-level field, such as |
| 52 | // a `visibilty:` typo, conflicts with this sentinel and fails vet with an |
| 53 | // error naming the field. |
| 54 | [!="project" & !="instance"]: "INVALID: unknown top-level field; only \"project\" and \"instance\" are allowed" |