Struct patchify::server::Axum

source ·
#[non_exhaustive]
pub struct Axum;
Expand description

Endpoint handlers for use with the Axum web framework.

This struct contains ready-made handlers for use with the Axum web framework. These handlers call the methods on the Core struct, and provide a convenient way to add the functionality to an existing Axum-based application API.

Note the following:

  1. The methods on the Core struct require Core to be instantiated. The instance should be wrapped in an Arc and added to the Axum router as an extension, to be extracted by the handlers.
  2. The handlers are static methods, and stateless, and obtain their state by extracting the Core instance from the request extensions.

It is not intended that this struct should be instantiated, and so the ability to do so is not provided.

§Examples

let config = Config { /* ... */ };
let core   = Arc::new(Core::new(config));
let app    = Router::new()
    .route("/api/latest",            get(Axum::get_latest_version))
    .route("/api/hashes/:version",   get(Axum::get_hash_for_version))
    .route("/api/releases/:version", get(Axum::get_release_file))
    .layer(Extension(core))
;

Implementations§

source§

impl Axum

source

pub async fn get_latest_version( __arg0: Extension<Arc<Core>> ) -> impl IntoResponse

Latest version number of the application.

This handler returns a response containing the latest version number of the application, as per the configured version list.

It does not include the SHA256 hash, to keep the response size to a minimum.

§Parameters
  • core - The core server instance.
source

pub async fn get_hash_for_version( __arg0: Extension<Arc<Core>>, __arg1: Path<Version> ) -> impl IntoResponse

SHA256 hash for a given version of the application.

This function checks the configured version list and returns the matching SHA256 hash for the specified version of the application.

§Parameters
  • core - The core server instance.
  • version - The version of the application to retrieve the hash for.
§Errors
  • A 400 Bad Request status will be returned if the version format is invalid.
  • A 404 Not Found status will be returned if the specified version does not exist.
source

pub async fn get_release_file( __arg0: Extension<Arc<Core>>, __arg1: Path<Version> ) -> impl IntoResponse

Release file for a given version of the application.

This function returns the release file for the specified version of the application, as per the configured version list. It will stream the file if it is large.

§Parameters
  • core - The core server instance.
  • version - The version of the application to retrieve the release file for.
§Errors
  • A 400 Bad Request status will be returned if the version format is invalid.
  • A 404 Not Found status will be returned if the specified version does not exist.
  • A 500 Internal Server Error status will be returned if the file is missing or cannot be read. In this situation a message to this effect will be provided — this is useful for testing the endpoint directly, but in a production environment it would be sensible to strip it out rather than show it to an end user.
source

pub fn sign_response(key: &SigningKey, response: Response) -> Response

Signs a response by adding a signature header.

This function accepts a Response and signs it by adding an X-Signature header. The signature is generated against the response body using the server’s private key.

Note that this function is only suitable for use with responses that contain a fully-known body, as the complete body data needs to be used to generate the signature. It is therefore not suitable for use with streaming responses, as the entire body must be known in advance in order to be signed. As large files are often streamed, the implication is that these should be unsigned, with their authenticity verified by other means.

The pattern used by this library is that release file downloads are not signed, allowing them to be streamed if they are large, with a SHA256 hash being available separately for verification. The response containing the hash is signed, so the hash can be verified as authentic.

§Parameters
  • key - The server’s private key.
  • response - The Response to sign.

Trait Implementations§

source§

impl Clone for Axum

source§

fn clone(&self) -> Axum

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Axum

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Copy for Axum

Auto Trait Implementations§

§

impl Freeze for Axum

§

impl RefUnwindSafe for Axum

§

impl Send for Axum

§

impl Sync for Axum

§

impl Unpin for Axum

§

impl UnwindSafe for Axum

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn from_ref(input: &T) -> T

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

impl<T> Instrument for T

source§

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

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

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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.
source§

impl<T> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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