pub struct Store { /* private fields */ }Expand description
The SQLite database, and every query the server makes against it.
Implementations§
Source§impl Store
impl Store
Sourcepub fn create_enrollment(
&self,
e: &NewEnrollment<'_>,
max_pending: usize,
max_per_address: usize,
) -> Result<Created>
pub fn create_enrollment( &self, e: &NewEnrollment<'_>, max_pending: usize, max_per_address: usize, ) -> Result<Created>
Stores a pending enrolment, unless its code is in use by another
one still waiting, max_pending are waiting already, or
max_per_address from its address are.
Sourcepub fn poll_enrollment(
&self,
enrollment_id: &str,
now: OffsetDateTime,
interval: Duration,
) -> Result<Poll>
pub fn poll_enrollment( &self, enrollment_id: &str, now: OffsetDateTime, interval: Duration, ) -> Result<Poll>
Answers a machine’s poll, and records when it asked.
A poll sooner than interval after the last one is told to slow
down. A second of slack keeps a client that sleeps exactly the
interval from being told so because its previous request spent a
moment in flight.
Sourcepub fn approve_enrollment(
&self,
user_code: &str,
device_id: &str,
scope: &str,
now: &str,
expected_fingerprint: Option<&str>,
) -> Result<Decision<Device>>
pub fn approve_enrollment( &self, user_code: &str, device_id: &str, scope: &str, now: &str, expected_fingerprint: Option<&str>, ) -> Result<Decision<Device>>
Approves the enrolment waiting with user_code, making it device
device_id. When expected_fingerprint is given, the code’s key
must have exactly that fingerprint.
Sourcepub fn deny_enrollment(
&self,
user_code: &str,
now: &str,
) -> Result<Decision<String>>
pub fn deny_enrollment( &self, user_code: &str, now: &str, ) -> Result<Decision<String>>
Denies the enrolment waiting with user_code, answering with the
name it asked for.
Sourcepub fn pending_enrollment(
&self,
user_code: &str,
now: &str,
) -> Result<Decision<Waiting>>
pub fn pending_enrollment( &self, user_code: &str, now: &str, ) -> Result<Decision<Waiting>>
What the enrolment waiting with user_code asked for, judged the
way approving it would be, so a lookup and the approval after it
never disagree about whether the code is still good.
Sourcepub fn insert_device(
&self,
d: &NewDevice<'_>,
max_for_key: Option<u32>,
) -> Result<Inserted>
pub fn insert_device( &self, d: &NewDevice<'_>, max_for_key: Option<u32>, ) -> Result<Inserted>
Stores a device, unless an unrevoked one has its name or, when
max_for_key is given, its authkey already has that many
unrevoked devices. Both are checked under the lock the insert holds.
Sourcepub fn revoke_device(&self, id: &str, now: &str) -> Result<Option<Device>>
pub fn revoke_device(&self, id: &str, now: &str) -> Result<Option<Device>>
Revokes a device. Revoking one already revoked keeps the first
time. None when there is no such device.
Sourcepub fn touch_device(&self, id: &str, now: &str) -> Result<()>
pub fn touch_device(&self, id: &str, now: &str) -> Result<()>
Records that a device was just seen.
Sourcepub fn insert_authkey(&self, k: &NewAuthkey<'_>) -> Result<Authkey>
pub fn insert_authkey(&self, k: &NewAuthkey<'_>) -> Result<Authkey>
Stores an authkey’s hash and details.
Sourcepub fn authkey_by_hash(&self, key_sha256: &str) -> Result<Option<Authkey>>
pub fn authkey_by_hash(&self, key_sha256: &str) -> Result<Option<Authkey>>
The authkey whose SHA-256 is key_sha256, in any state.
Source§impl Store
impl Store
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Opens (creating if needed) the database at path.
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
An in-memory database, for tests.
Sourcepub fn get(
&self,
project_key: &str,
file_path: &str,
) -> Result<Option<Existing>>
pub fn get( &self, project_key: &str, file_path: &str, ) -> Result<Option<Existing>>
Reads one row.
Sourcepub fn upsert(
&self,
project_key: &str,
file_path: &str,
content: &str,
source_env: &str,
updated_at: &str,
) -> Result<()>
pub fn upsert( &self, project_key: &str, file_path: &str, content: &str, source_env: &str, updated_at: &str, ) -> Result<()>
Writes content, clearing any tombstone.
Sourcepub fn tombstone(
&self,
project_key: &str,
file_path: &str,
source_env: &str,
updated_at: &str,
) -> Result<()>
pub fn tombstone( &self, project_key: &str, file_path: &str, source_env: &str, updated_at: &str, ) -> Result<()>
Marks a file deleted while deliberately leaving its content in
place: a mistaken delete stays recoverable at the database level,
even though nothing in the app surfaces an undo yet. Store::list
withholds the content so a pull can’t resurrect it.
Sourcepub fn list(&self, project_key: &str) -> Result<Vec<File>>
pub fn list(&self, project_key: &str) -> Result<Vec<File>>
Every file for a project, tombstones included so a pulling client knows what to remove locally — but with the deleted content withheld.
Sourcepub fn last_sync_at(&self) -> Result<String>
pub fn last_sync_at(&self) -> Result<String>
The most recent write across all projects, for /health. Empty when
nothing has ever been synced.
Sourcepub fn admin_stats(&self) -> Result<(Vec<ProjectStats>, AdminTotals)>
pub fn admin_stats(&self) -> Result<(Vec<ProjectStats>, AdminTotals)>
Aggregates per project for the admin page.
Auto Trait Implementations§
impl !Freeze for Store
impl RefUnwindSafe for Store
impl Send for Store
impl Sync for Store
impl Unpin for Store
impl UnsafeUnpin for Store
impl UnwindSafe for Store
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more