Files
2026-08-15 07:13:00 +00:00

71 lines
2.2 KiB
Go

package api
import "net/url"
// Version is the API path prefix. It is a constant rather than a client option
// because the CLI and the server are released together; a mismatch is a bug,
// not a configuration.
const Version = "/api/v1"
// Path builders, shared so the client and the server's route table cannot drift
// apart. Every segment that comes from user input is escaped: a project named
// with a slash could otherwise rewrite the request into a different endpoint.
// (Project names are pattern-checked on creation, so this is defence in depth
// against a name that predates a stricter pattern.)
func PathProjects() string { return Version + "/projects" }
func PathProject(name string) string {
return Version + "/projects/" + url.PathEscape(name)
}
func PathProjectKeys(name string) string {
return PathProject(name) + "/keys"
}
func PathKeys() string { return Version + "/keys" }
func PathKey(id string) string {
return Version + "/keys/" + url.PathEscape(id)
}
func PathWhoAmI() string { return Version + "/whoami" }
func PathSystemInfo() string { return Version + "/system/info" }
func PathGC() string { return Version + "/gc" }
func PathFsck() string { return Version + "/fsck" }
func PathDeployments(project string) string {
return PathProject(project) + "/deployments"
}
func PathDeployment(project, id string) string {
return PathDeployments(project) + "/" + url.PathEscape(id)
}
func PathManifest(project, id string) string {
return PathDeployment(project, id) + "/manifest"
}
func PathFinalize(project, id string) string {
return PathDeployment(project, id) + "/finalize"
}
func PathActivate(project, id string) string {
return PathDeployment(project, id) + "/activate"
}
// PathBlob addresses a blob by lowercase hex digest. Blobs are global rather
// than per-project because the content-addressed store deduplicates across
// projects; see the security notes on the blob existence oracle.
func PathBlob(hexDigest string) string {
return Version + "/blobs/" + url.PathEscape(hexDigest)
}
// SiteURL returns where a project is served under path routing.
func SiteURL(base, project string) string {
return base + "/~" + url.PathEscape(project) + "/"
}