pub struct PolicyStore { /* private fields */ }Expand description
Read and write per-repository policy documents.
Cheap to clone; every clone reads and writes the same document.
Implementations§
Source§impl PolicyStore
impl PolicyStore
Sourcepub fn new(store: Arc<dyn ControlStore>) -> Result<Self>
pub fn new(store: Arc<dyn ControlStore>) -> Result<Self>
Open the policy document held in store (the server’s control store).
Sourcepub fn history(&self) -> Result<Vec<DocVersion>>
pub fn history(&self) -> Result<Vec<DocVersion>>
Every version this document has ever had, oldest first (the certificate-identity plan).
Policy history is not a nicety. “Who turned the signature requirement off, and when” is the question that gets asked after the fact, and a configuration store with no history cannot answer it.
Sourcepub fn get(&self, repo: &RepoRef) -> Result<Option<String>>
pub fn get(&self, repo: &RepoRef) -> Result<Option<String>>
The policy document for repo, or None if none was ever stored.
None is not an empty policy, and the caller must not turn it into
one silently: it means nobody has configured this repository, which is
the state where every well-formed push is served. gunnar-server logs
that distinction at open time rather than inferring it.
Sourcepub fn set(&self, repo: &RepoRef, document: &str) -> Result<()>
pub fn set(&self, repo: &RepoRef, document: &str) -> Result<()>
Store document as repo’s policy, replacing whatever was there.
The bytes are not parsed here; see the module docs. What is checked is
that they are not empty — an empty document is the one value that would
read back as “a policy exists and it configures nothing”, which is
indistinguishable from a write that lost its content. Removing a policy
is PolicyStore::remove, and it says so.
Sourcepub fn remove(&self, repo: &RepoRef) -> Result<bool>
pub fn remove(&self, repo: &RepoRef) -> Result<bool>
Delete repo’s policy, reporting whether there was one.
The boolean is the difference between “the policy is gone” and “there was nothing to delete”, and a caller that collapsed them could report a successful removal of a rule that never existed.