Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

Campaigns, devices, setup codes and challenges, in Postgres.

Implementations§

Source§

impl Store

Source

pub fn new(pool: PgPool) -> Self

A store in pool’s database.

Source

pub fn pool(&self) -> &PgPool

The database.

Source

pub async fn token_key(&self) -> Result<DeviceKey, ApiError>

The token signing key, created by whichever instance starts first.

Source

pub async fn create_campaign( &self, name: &str, edition: Edition, ) -> Result<Campaign, ApiError>

Creates a campaign.

Source

pub async fn campaign(&self, id: Uuid) -> Result<Campaign, ApiError>

A campaign by id.

Source

pub async fn delete_campaign( &self, id: Uuid, ) -> Result<Option<(Campaign, u64)>, ApiError>

Deletes a campaign with its devices, setup codes, pairings and login challenges, returning what it was; None if there’s no such campaign. Its devices can’t log in from then on.

Source

pub async fn new_setup_code( &self, campaign: Uuid, valid_for: Duration, ) -> Result<String, ApiError>

A fresh one-time code that lets a device make itself DM of campaign.

Source

pub async fn peek_setup_code( &self, code: &str, ) -> Result<Option<Uuid>, ApiError>

The campaign a setup code is for, without using it up.

Source

pub async fn take_setup_code( &self, executor: impl PgExecutor<'_>, code: &str, ) -> Result<Option<Uuid>, ApiError>

Uses up a setup code, returning its campaign if it was valid.

Source

pub async fn add_device( &self, executor: impl PgExecutor<'_>, cert: &SignedCert, ) -> Result<Device, ApiError>

Adds a device with its certificate, within the campaign’s limit.

Source

pub async fn export_campaign( &self, id: Uuid, ) -> Result<Option<AuthExport>, ApiError>

The campaign and its devices, to keep or move elsewhere; None if there’s no such campaign.

Source

pub async fn import_campaign( &self, export: &AuthExport, ) -> Result<u64, ApiError>

Takes in a campaign exported elsewhere, as it was, ids, keys and dates included; returns how many devices came with it. All or nothing, and not over a campaign that’s here already. Every certificate must be for the campaign and properly signed.

Source

pub async fn settings( &self, campaign: Uuid, ) -> Result<CampaignSettings, ApiError>

What was set for the campaign: by default, the services’ own limits, and changes allowed.

Source

pub async fn set_settings( &self, campaign: Uuid, settings: &CampaignSettings, ) -> Result<(), ApiError>

Sets what the campaign may keep and do; its devices’ tokens say so from their next login.

Source

pub async fn devices(&self, campaign: Uuid) -> Result<Vec<Device>, ApiError>

The campaign’s devices, revoked ones too.

Source

pub async fn revoke( &self, campaign: Uuid, key: PublicKey, ) -> Result<Device, ApiError>

Revokes a device. Refuses to revoke the campaign’s last DM device, which would leave nobody able to manage it.

Source

pub async fn add_service( &self, name: &str, key: PublicKey, ) -> Result<(), ApiError>

Lets a service log in to any campaign with key.

Source

pub async fn principal( &self, campaign: Uuid, key: PublicKey, ) -> Result<Option<(Principal, String)>, ApiError>

Who key is in campaign: an active device or a service.

Source

pub async fn create_challenge( &self, campaign: Uuid, key: PublicKey, server: PublicKey, valid_for: Duration, ) -> Result<Challenge, ApiError>

A challenge for a device of the campaign to sign.

Source

pub async fn take_challenge( &self, id: Uuid, ) -> Result<Option<IssuedChallenge>, ApiError>

Removes a challenge, returning it if it existed. Whoever gets it first wins, so each challenge is answered at most once.

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn set_request_id<M>( self, header_name: HeaderName, make_request_id: M, ) -> SetRequestId<Self, M>
where Self: Sized, M: MakeRequestId,

Add request id header and extension. Read more
§

fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>
where Self: Sized, M: MakeRequestId,

Add request id header and extension, using x-request-id as the header name. Read more
§

fn propagate_request_id( self, header_name: HeaderName, ) -> PropagateRequestId<Self>
where Self: Sized,

Propgate request ids from requests to responses. Read more
§

fn propagate_x_request_id(self) -> PropagateRequestId<Self>
where Self: Sized,

Propgate request ids from requests to responses, using x-request-id as the header name. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,