diff --git a/README.md b/README.md index dba5a33f..76a80d0f 100644 --- a/README.md +++ b/README.md @@ -163,8 +163,10 @@ The HTTP API, under `/api/v1`, puts records in batches, if the changes they revise are where the client saw them, and fetches them by id, walks snapshots for the trees and blobs a client lacks (the only way files leave a server), in parts of at most 64 MiB each way, compares the records of -changes, lists statements, revisions, targets and their logs, lands -changes and targets, and streams +changes, lists statements, +revisions, targets and their logs, lists the directories and reads the +files of a target's tip or any revision, without its history, issues +scoped tokens, lands changes and targets, and streams events by long-poll: `GET /api/v1/repos//events?cursor=&wait=30s` answers as soon as there are events after the cursor, with a JSON batch, the next cursor, and the diff --git a/apps/origin-src/src/http.rs b/apps/origin-src/src/http.rs index afe28959..6cbc94b7 100644 --- a/apps/origin-src/src/http.rs +++ b/apps/origin-src/src/http.rs @@ -18,9 +18,10 @@ use origin_shared::ChangeId; use origin_shared::Head; use origin_shared::access::{InvalidToken, Rights}; use origin_shared::api::{ - Annotation, ApiError, ErrorCode, EventsQuery, FetchRecords, FetchSnapshot, Inventory, - InventoryRequest, IssuedToken, LandRequest, Landings, LogEntry, LogQuery, MORE, NewTarget, - PutQuery, RepoName, RepoSummary, Revisions, StatementsQuery, Stored, TargetInfo, TokenRequest, + Annotation, ApiError, BrowseQuery, ErrorCode, EventsQuery, FetchRecords, FetchSnapshot, + Inventory, InventoryRequest, IssuedToken, LandRequest, Landings, Listing, LogEntry, LogQuery, + MORE, NewTarget, PutQuery, RepoName, RepoSummary, Revisions, StatementsQuery, Stored, + TargetInfo, TokenRequest, }; use origin_shared::event::Page; use origin_shared::landing::Pending; @@ -70,6 +71,8 @@ impl Api { .routes(routes!(events)) .routes(routes!(whoami)) .routes(routes!(issue_token)) + .routes(routes!(tree)) + .routes(routes!(file)) .routes(routes!(openapi_document)) } @@ -574,6 +577,63 @@ async fn issue_token( .map(Json) } +/// Lists a directory of a snapshot: a target's tip, or a revision's or an +/// acceptance's. Withheld entries keep their place. +#[utoipa::path( + get, + path = "/api/v1/repos/{repo}/tree", + operation_id = "tree", + params(("repo" = String, Path, description = "The repository"), BrowseQuery), + responses( + (status = 200, description = "The directory's entries", body = Listing), + (status = 400, description = "The path is a file, or the record has no snapshot", body = ApiError), + (status = 403, description = "The caller reads nothing under the path", body = ApiError), + (status = 404, description = "The repository, the target, the record or the path does not exist", body = ApiError) + ) +)] +async fn tree( + repos: Repos, + Path(repo): Path, + caller: Caller, + Query(query): Query, +) -> Result, HttpError> { + call(repos, repo, caller, move |service, caller| { + service.tree(caller, &query) + }) + .await + .map(Json) +} + +/// Reads a file of a snapshot, as `tree` finds it. +#[utoipa::path( + get, + path = "/api/v1/repos/{repo}/file", + operation_id = "file", + params(("repo" = String, Path, description = "The repository"), BrowseQuery), + responses( + (status = 200, description = "The file's content", content_type = "application/octet-stream", body = Binary), + (status = 400, description = "The path is a directory, or the record has no snapshot", body = ApiError), + (status = 403, description = "The caller may not read the file", body = ApiError), + (status = 404, description = "The repository, the target, the record or the path does not exist", body = ApiError) + ) +)] +async fn file( + repos: Repos, + Path(repo): Path, + caller: Caller, + Query(query): Query, +) -> Result { + let content = call(repos, repo, caller, move |service, caller| { + service.file(caller, &query) + }) + .await?; + Ok(( + [(header::CONTENT_TYPE, "application/octet-stream")], + content, + ) + .into_response()) +} + /// The OpenAPI document of this API. #[utoipa::path( get, diff --git a/apps/origin-src/src/permissions.rs b/apps/origin-src/src/permissions.rs index c25db54a..80e4af49 100644 --- a/apps/origin-src/src/permissions.rs +++ b/apps/origin-src/src/permissions.rs @@ -144,6 +144,9 @@ pub enum Forbidden { /// The owner has no principal to issue a token for. #[error("only a signed-in caller gets a token, for themselves")] NoPrincipal, + /// A path the caller may not read. + #[error("you may not read `{0}`")] + Read(RepoPath), /// A token's scope reaches beyond its issuer's rights. #[error("a token may only narrow your rights, which don't include `{0}`")] Scope(Capability), diff --git a/apps/origin-src/src/remote.rs b/apps/origin-src/src/remote.rs index 1093f7a1..180e2be0 100644 --- a/apps/origin-src/src/remote.rs +++ b/apps/origin-src/src/remote.rs @@ -14,9 +14,9 @@ use origin_client::Client; use origin_shared::Head; use origin_shared::access::Rights; use origin_shared::api::{ - ErrorCode, EventsQuery, FetchRecords, FetchSnapshot, Inventory, InventoryRequest, IssuedToken, - LandRequest, Landings, LogEntry, LogQuery, NewTarget, PutQuery, RepoName, Stored, TargetInfo, - TokenRequest, + BrowseQuery, ErrorCode, EventsQuery, FetchRecords, FetchSnapshot, Inventory, InventoryRequest, + IssuedToken, LandRequest, Landings, Listing, LogEntry, LogQuery, NewTarget, PutQuery, RepoName, + Stored, TargetInfo, TokenRequest, }; use origin_shared::event::Page; use origin_shared::landing::Pending; @@ -99,6 +99,10 @@ calls! { /// Issues a token acting for the user, with a narrower scope. fn issue_token(request: &TokenRequest) -> IssuedToken = issue_token(request), issue_token(request); + /// Lists a directory of a snapshot. + fn tree(query: &BrowseQuery) -> Listing = tree(query), tree(query); + /// Reads a file of a snapshot. + fn file(query: &BrowseQuery) -> Vec = file(query), file(query); } impl Remote { diff --git a/apps/origin-src/src/service.rs b/apps/origin-src/src/service.rs index 090ee59d..a4a85b3e 100644 --- a/apps/origin-src/src/service.rs +++ b/apps/origin-src/src/service.rs @@ -29,9 +29,9 @@ use std::time::Duration; use origin_platform::Native; use origin_shared::access::{PathAccess, Rights, Token}; use origin_shared::api::{ - Annotation, ErrorCode, EventsQuery, Expected, FetchSnapshot, Inventory, InventoryRequest, - IssuedToken, LandRequest, Landings, LogEntry, LogQuery, NewTarget, RevisionEntry, Revisions, - Stored, TargetInfo, TokenRequest, + Annotation, At, BrowseQuery, ErrorCode, EventsQuery, Expected, FetchSnapshot, Inventory, + InventoryRequest, IssuedToken, LandRequest, Landings, Listed, Listing, LogEntry, LogQuery, + NewTarget, RevisionEntry, Revisions, Stored, TargetInfo, TokenRequest, }; use origin_shared::event::{EventKind, Filter, Page}; use origin_shared::landing::{Pending, Proposal}; @@ -39,7 +39,7 @@ use origin_shared::object::DecodeError; use origin_shared::pack::{Pack, Packer, Part}; use origin_shared::{ AcceptanceId, Base, ChangeId, Head, Kind, NodeKey, Object, ObjectId, ObjectKind, Principal, - PrincipalName, RecordId, RepoPath, Statement, StatementId, TargetName, TreeId, + PrincipalName, RecordId, RepoPath, Statement, StatementId, TargetName, TreeEntry, TreeId, }; use crate::annotations::{AnnotateError, Annotations}; @@ -50,6 +50,7 @@ use crate::permissions::{Forbidden, Reader}; use crate::policy::{Policy, PolicyError}; use crate::queue::{LandError, Queue}; use crate::store::{Store, StoreError}; +use crate::tree::Snapshots; /// A node: its name, and the key it signs acceptances with as the /// authority of the targets its repositories' policies name it for. A @@ -450,6 +451,89 @@ impl OriginService { Ok(Some(&rights.paths)) } + /// What `query` names, a directory or file of a snapshot the caller + /// sees, the snapshot, and what it withholds from the caller. + fn browse( + &self, + caller: &Caller, + query: &BrowseQuery, + ) -> Result<(Option, TreeId, TreeEntry), ServiceError> { + let rights = self.rights(caller)?; + let record = match &query.at { + At::Target(target) => { + let head = self + .store + .head(target)? + .ok_or_else(|| ServiceError::UnknownTarget(target.clone()))?; + RecordId::Acceptance(head.acceptance) + } + &At::Record(record) => record, + }; + let snapshot = self.snapshot_of(&mut Reader::new(&self.store, &rights.paths), record)?; + let withheld = self.filter(&rights, record)?.cloned(); + let entry = Snapshots::new(&self.store) + .entry_at(snapshot, &query.path)? + .ok_or_else(|| ServiceError::NoSuchPath(query.path.clone()))?; + if withheld + .as_ref() + .is_some_and(|access| !access.reads_entry(&query.path, &entry)) + { + return Err(Forbidden::Read(query.path.clone()).into()); + } + Ok((withheld, snapshot, entry)) + } + + /// Lists a directory of a snapshot: of a target's tip, or of a revision + /// or an acceptance the caller sees. Entries whose content is withheld + /// from the caller keep their place, marked. + /// + /// # Errors + /// + /// Fails if the target or record doesn't exist or isn't seen, the path + /// isn't a directory, the caller reads nothing under it, or a tree + /// cannot be read. + pub fn tree(&self, caller: &Caller, query: &BrowseQuery) -> Result { + let (withheld, snapshot, entry) = self.browse(caller, query)?; + let tree = entry + .subtree() + .ok_or_else(|| ServiceError::NotADirectory(query.path.clone()))?; + let entries = self + .store + .get(tree)? + .iter() + .map(|(name, &entry)| Listed { + name: name.clone(), + kind: entry.kind, + id: entry.id, + withheld: withheld + .as_ref() + .is_some_and(|access| !access.reads_entry(&query.path.join(name), &entry)), + }) + .collect(); + Ok(Listing { + snapshot, + path: query.path.clone(), + entries, + }) + } + + /// The content of a file of a snapshot, as [`OriginService::tree`] + /// finds it, which the caller must read. + /// + /// # Errors + /// + /// Fails like [`OriginService::tree`], or if the path isn't a file. + pub fn file(&self, caller: &Caller, query: &BrowseQuery) -> Result, ServiceError> { + let (_, _, entry) = self.browse(caller, query)?; + if entry.kind.is_tree() { + return Err(ServiceError::NotAFile(query.path.clone())); + } + Ok(self + .store + .try_blob(entry.id)? + .ok_or(StoreError::NotFound(entry.id))?) + } + /// What the repository holds of each change that the caller sees: its /// revisions and heads, and the statements about them, by id. A change /// it never heard of has none. @@ -1072,6 +1156,15 @@ pub enum ServiceError { /// A snapshot was asked of a record that has none. #[error("{0} has no snapshot: name a revision or an acceptance")] NotASnapshot(RecordId), + /// A snapshot has nothing at a path. + #[error("nothing is at `{0}`")] + NoSuchPath(RepoPath), + /// A path listed is a file. + #[error("`{0}` is not a directory")] + NotADirectory(RepoPath), + /// A path read is a directory. + #[error("`{0}` is not a file")] + NotAFile(RepoPath), /// An object put refers to one as an object of another kind: a /// snapshot that isn't a tree, a file that is one, a description that /// isn't an attachment. @@ -1156,10 +1249,13 @@ impl ServiceError { | Self::UnknownChange(_) | Self::UnknownTarget(_) | Self::UnknownSnapshot(_) - | Self::UnknownRecord(_) => ErrorCode::NotFound, + | Self::UnknownRecord(_) + | Self::NoSuchPath(_) => ErrorCode::NotFound, Self::NoTarget | Self::NotARecord(_) | Self::NotASnapshot(_) + | Self::NotADirectory(_) + | Self::NotAFile(_) | Self::WrongKind { .. } | Self::Malformed { .. } | Self::Acceptance(_) diff --git a/apps/origin-src/tests/http.rs b/apps/origin-src/tests/http.rs index 517925db..7c23562b 100644 --- a/apps/origin-src/tests/http.rs +++ b/apps/origin-src/tests/http.rs @@ -8,8 +8,8 @@ use std::time::{Duration, Instant}; use origin_client::{Client, Error, Repo}; use origin_shared::api::{ - ErrorCode, EventsQuery, Expected, FetchRecords, FetchSnapshot, InventoryRequest, LandRequest, - List, LogQuery, NewTarget, PutQuery, RepoName, StatementsQuery, TokenRequest, + BrowseQuery, ErrorCode, EventsQuery, Expected, FetchRecords, FetchSnapshot, InventoryRequest, + LandRequest, List, LogQuery, NewTarget, PutQuery, RepoName, StatementsQuery, TokenRequest, }; use origin_shared::event::EventKind; use origin_shared::landing::{Blocked, Landing, Proposal}; @@ -869,6 +869,69 @@ async fn tells_callers_what_they_may_do_and_issues_narrower_tokens() { assert_eq!(code(error), ErrorCode::Forbidden); } +#[tokio::test] +async fn browses_snapshots_without_their_history() { + let server = Server::start().await; + let made = land_on_strict( + &server, + 1, + &[ + ("README.md", "hello"), + ("secrets/key", "hunter2"), + ("src/lib.rs", "fn a() {}"), + ], + ) + .await; + let at = |at: &str, path: &str| BrowseQuery { + at: at.parse().unwrap(), + path: RepoPath::new(path).unwrap(), + }; + let root = server.strict.tree(&at("main", "/")).await.unwrap(); + let names: Vec<_> = root + .entries + .iter() + .map(|entry| (entry.name.as_str(), entry.kind, entry.withheld)) + .collect(); + assert_eq!( + names, + [ + ("README.md", EntryKind::File, false), + ("secrets", EntryKind::Tree, false), + ("src", EntryKind::Tree, false), + ] + ); + let revision = format!("revision:{}", made.id); + assert_eq!( + server + .strict + .file(&at(&revision, "secrets/key")) + .await + .unwrap(), + b"hunter2" + ); + + // Others see that the secret is there, but not what it is. + let anonymous = &server.anonymous; + let root = anonymous.tree(&at("main", "")).await.unwrap(); + assert!(root.entries[1].withheld, "{root:?}"); + assert_eq!( + anonymous.file(&at("main", "README.md")).await.unwrap(), + b"hello" + ); + for path in ["secrets/key", "secrets"] { + let error = anonymous.file(&at("main", path)).await.unwrap_err(); + assert_eq!(code(error), ErrorCode::Forbidden, "{path}"); + } + let error = anonymous.tree(&at("main", "secrets")).await.unwrap_err(); + assert_eq!(code(error), ErrorCode::Forbidden); + let error = anonymous.tree(&at("main", "README.md")).await.unwrap_err(); + assert_eq!(code(error), ErrorCode::BadRequest); + let error = anonymous.file(&at("main", "missing")).await.unwrap_err(); + assert_eq!(code(error), ErrorCode::NotFound); + let error = anonymous.tree(&at("nowhere", "")).await.unwrap_err(); + assert_eq!(code(error), ErrorCode::NotFound); +} + #[tokio::test] async fn reads_only_what_the_caller_may() { let server = Server::start().await; diff --git a/crates/origin-client/src/lib.rs b/crates/origin-client/src/lib.rs index bc3bb024..c815c350 100644 --- a/crates/origin-client/src/lib.rs +++ b/crates/origin-client/src/lib.rs @@ -20,9 +20,10 @@ use origin_shared::access::Rights; use origin_shared::api::{ - Annotation, ApiError, EventsQuery, FetchRecords, FetchSnapshot, Inventory, InventoryRequest, - IssuedToken, LandRequest, Landings, LogEntry, LogQuery, MORE, NewTarget, PutQuery, RepoName, - RepoSummary, Revisions, StatementsQuery, Stored, TargetInfo, TokenRequest, + Annotation, ApiError, BrowseQuery, EventsQuery, FetchRecords, FetchSnapshot, Inventory, + InventoryRequest, IssuedToken, LandRequest, Landings, Listing, LogEntry, LogQuery, MORE, + NewTarget, PutQuery, RepoName, RepoSummary, Revisions, StatementsQuery, Stored, TargetInfo, + TokenRequest, }; use origin_shared::event::Page; use origin_shared::landing::Pending; @@ -116,6 +117,11 @@ endpoints! { /// Issues a token acting for the caller, with a narrower scope. fn issue_token(request: &TokenRequest) -> IssuedToken = POST "tokens", json(request) => json; + /// Lists a directory of a target's tip, or of a revision's or an + /// acceptance's snapshot. + fn tree(query: &BrowseQuery) -> Listing = GET "tree", query(query) => json; + /// Reads a file of a snapshot, as `tree` finds it. + fn file(query: &BrowseQuery) -> Vec = GET "file", query(query) => bytes; } } @@ -228,6 +234,10 @@ impl Response { let pack = Pack::decode(&self.0.bytes().await?)?; Ok(Part { pack, more }) } + + async fn bytes(self) -> Result, Error> { + Ok(self.0.bytes().await?.to_vec()) + } } /// A failed request. diff --git a/crates/origin-shared/src/api.rs b/crates/origin-shared/src/api.rs index 33b04b8b..475c0f75 100644 --- a/crates/origin-shared/src/api.rs +++ b/crates/origin-shared/src/api.rs @@ -12,8 +12,9 @@ use crate::landing::{Landing, Proposal}; use crate::policy::{KindPattern, Requirement}; use crate::text::Period; use crate::{ - Acceptance, AcceptanceId, ChangeId, Head, ObjectId, Principal, PrincipalName, RecordId, - RepoPath, Revision, RevisionId, Statement, StatementId, TargetName, TreeId, + Acceptance, AcceptanceId, ChangeId, EntryKind, EntryName, Head, ObjectId, Principal, + PrincipalName, RecordId, RepoPath, Revision, RevisionId, Statement, StatementId, TargetName, + TreeId, }; /// The name of a repository on a server: ASCII letters, digits, `.`, `_` @@ -439,6 +440,82 @@ pub struct IssuedToken { pub expires: u64, } +/// A snapshot to browse: a target's tip, `main`, or a record's, +/// `revision:` or `acceptance:`. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum At { + /// The tip of a target. + Target(TargetName), + /// The snapshot of a revision or an acceptance. + Record(RecordId), +} + +impl FromStr for At { + type Err = String; + + fn from_str(input: &str) -> Result { + if input.contains(':') { + input + .parse() + .map(Self::Record) + .map_err(|error: crate::ParseIdError| error.to_string()) + } else { + input + .parse() + .map(Self::Target) + .map_err(|error: crate::InvalidName| error.to_string()) + } + } +} + +impl fmt::Display for At { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Target(target) => target.fmt(f), + Self::Record(record) => record.fmt(f), + } + } +} + +/// Asks for a directory or a file of a snapshot. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoParams)] +#[into_params(parameter_in = Query)] +pub struct BrowseQuery { + /// The snapshot: a target, such as `main`, or `revision:` or + /// `acceptance:`. + #[param(value_type = String)] + pub at: At, + /// The directory or file: the root by default. + #[serde(default)] + #[param(value_type = Option)] + pub path: RepoPath, +} + +/// A directory of a snapshot. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)] +pub struct Listing { + /// The snapshot's root tree. + pub snapshot: TreeId, + /// The directory. + pub path: RepoPath, + /// Its entries, sorted by name. + pub entries: Vec, +} + +/// An entry of a [`Listing`]. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)] +pub struct Listed { + /// Its name. + pub name: EntryName, + /// A file, an executable, a symlink or a directory. + pub kind: EntryKind, + /// Its object. + pub id: ObjectId, + /// Whether its content is withheld from the caller: it keeps its + /// place, but can't be read. + pub withheld: bool, +} + /// What went wrong with a request. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)] pub struct ApiError { diff --git a/crates/origin-shared/src/object/tree.rs b/crates/origin-shared/src/object/tree.rs index c33226fd..043ec2d2 100644 --- a/crates/origin-shared/src/object/tree.rs +++ b/crates/origin-shared/src/object/tree.rs @@ -96,6 +96,20 @@ impl fmt::Display for EntryKind { } } +impl std::str::FromStr for EntryKind { + type Err = String; + + fn from_str(kind: &str) -> Result { + match kind { + "file" => Ok(Self::File), + "executable" => Ok(Self::Executable), + "symlink" => Ok(Self::Symlink), + "directory" => Ok(Self::Tree), + _ => Err(format!("invalid entry kind `{kind}`")), + } + } +} + /// One entry of a tree. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct TreeEntry { diff --git a/crates/origin-shared/src/text.rs b/crates/origin-shared/src/text.rs index c41a7c13..b8490596 100644 --- a/crates/origin-shared/src/text.rs +++ b/crates/origin-shared/src/text.rs @@ -10,11 +10,12 @@ use utoipa::openapi::RefOr; use utoipa::openapi::schema::{ObjectBuilder, Schema, Type}; use crate::access::{Capability, Targets}; +use crate::api::At; use crate::policy::{KindPattern, Principals}; use crate::{ - AcceptanceId, AttachmentId, BlobId, ChangeId, Digest, EntryName, Kind, NodePublicKey, ObjectId, - Principal, PrincipalName, RecordId, RepoPath, RevisionId, StatementId, TargetId, TargetName, - TreeId, Verdict, + AcceptanceId, AttachmentId, BlobId, ChangeId, Digest, EntryKind, EntryName, Kind, + NodePublicKey, ObjectId, Principal, PrincipalName, RecordId, RepoPath, RevisionId, StatementId, + TargetId, TargetName, TreeId, Verdict, }; /// Serializes each type as the string it displays as, deserializes it by @@ -76,6 +77,8 @@ as_text! { Period => "30s"; Capability => "write src"; Targets => "main"; + At => "main"; + EntryKind => "file"; } /// A length of time, written as a whole number of seconds (`s`), minutes diff --git a/docs/openapi.json b/docs/openapi.json index a018e732..5b2b9587 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -265,6 +265,83 @@ } } }, + "/api/v1/repos/{repo}/file": { + "get": { + "summary": "Reads a file of a snapshot, as `tree` finds it.", + "operationId": "file", + "parameters": [ + { + "name": "repo", + "in": "path", + "description": "The repository", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "at", + "in": "query", + "description": "The snapshot: a target, such as `main`, or `revision:` or\n`acceptance:`.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "path", + "in": "query", + "description": "The directory or file: the root by default.", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The file's content", + "content": { + "application/octet-stream": { + "schema": { + "$ref": "#/components/schemas/Binary" + } + } + } + }, + "400": { + "description": "The path is a directory, or the record has no snapshot", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + }, + "403": { + "description": "The caller may not read the file", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + }, + "404": { + "description": "The repository, the target, the record or the path does not exist", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + } + } + } + }, "/api/v1/repos/{repo}/land": { "post": { "summary": "Submits a change, or a target's tip, to a target's landing queue, run\nby this server.", @@ -861,6 +938,83 @@ } } }, + "/api/v1/repos/{repo}/tree": { + "get": { + "summary": "Lists a directory of a snapshot: a target's tip, or a revision's or an\nacceptance's. Withheld entries keep their place.", + "operationId": "tree", + "parameters": [ + { + "name": "repo", + "in": "path", + "description": "The repository", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "at", + "in": "query", + "description": "The snapshot: a target, such as `main`, or `revision:` or\n`acceptance:`.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "path", + "in": "query", + "description": "The directory or file: the root by default.", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The directory's entries", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Listing" + } + } + } + }, + "400": { + "description": "The path is a file, or the record has no snapshot", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + }, + "403": { + "description": "The caller reads nothing under the path", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + }, + "404": { + "description": "The repository, the target, the record or the path does not exist", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + } + } + } + }, "/api/v1/repos/{repo}/whoami": { "get": { "summary": "Tells the caller who they are and what they may do in the repository.", @@ -1163,6 +1317,18 @@ "48fc721fbbc172e0925fa27af1671de225ba927134802998b10a1568a188652b" ] }, + "EntryKind": { + "type": "string", + "examples": [ + "file" + ] + }, + "EntryName": { + "type": "string", + "examples": [ + "main.rs" + ] + }, "ErrorCode": { "type": "string", "description": "The kind of an [`ApiError`].", @@ -1649,6 +1815,60 @@ "write" ] }, + "Listed": { + "type": "object", + "description": "An entry of a [`Listing`].", + "required": [ + "name", + "kind", + "id", + "withheld" + ], + "properties": { + "id": { + "$ref": "#/components/schemas/ObjectId", + "description": "Its object." + }, + "kind": { + "$ref": "#/components/schemas/EntryKind", + "description": "A file, an executable, a symlink or a directory." + }, + "name": { + "$ref": "#/components/schemas/EntryName", + "description": "Its name." + }, + "withheld": { + "type": "boolean", + "description": "Whether its content is withheld from the caller: it keeps its\nplace, but can't be read." + } + } + }, + "Listing": { + "type": "object", + "description": "A directory of a snapshot.", + "required": [ + "snapshot", + "path", + "entries" + ], + "properties": { + "entries": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Listed" + }, + "description": "Its entries, sorted by name." + }, + "path": { + "$ref": "#/components/schemas/RepoPath", + "description": "The directory." + }, + "snapshot": { + "$ref": "#/components/schemas/TreeId", + "description": "The snapshot's root tree." + } + } + }, "LogEntry": { "type": "object", "description": "One acceptance of a target's log.",