Struct Client

Source
pub struct Client<R, C, N>{ /* private fields */ }
Expand description

A client for a Warg registry.

Implementations§

Source§

impl<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage> Client<R, C, N>

Source

pub fn new( url: impl IntoUrl, registry: R, content: C, namespace_map: N, auth_token: Option<Secret<String>>, ignore_federation_hints: bool, disable_auto_accept_federation_hints: bool, disable_auto_package_init: bool, disable_interactive: bool, keyring_backend: Option<String>, keys: IndexSet<String>, ) -> ClientResult<Self>

Creates a new client for the given URL, registry storage, and content storage.

Source

pub fn url(&self) -> &RegistryUrl

Gets the URL of the client.

Source

pub fn registry(&self) -> &R

Gets the registry storage used by the client.

Source

pub fn content(&self) -> &C

Gets the content storage used by the client.

Source

pub fn namespace_map(&self) -> &N

Gets the namespace map

Source

pub async fn get_warg_registry( &self, namespace: &str, ) -> Result<Option<RegistryDomain>, ClientError>

Get warg registry domain.

Source

pub async fn store_namespace( &self, namespace: String, registry_domain: RegistryDomain, ) -> Result<()>

Stores namespace mapping in local storage

Source

pub async fn reset_namespaces(&self) -> Result<()>

Resets the namespace map

Source

pub async fn reset_registry(&self) -> ClientResult<()>

Reset client storage for the registry.

Source

pub async fn clear_content_cache(&self) -> ClientResult<()>

Clear client content cache.

Source

pub async fn lock_component(&self, info: &PackageInfo) -> ClientResult<Vec<u8>>

Locks component

Source

pub async fn bundle_component( &self, info: &PackageInfo, ) -> ClientResult<Vec<u8>>

Bundles component

Source

pub async fn publish(&self, signing_key: &PrivateKey) -> ClientResult<RecordId>

Submits the publish information in client storage.

If there’s no publishing information in client storage, an error is returned.

Returns the identifier of the record that was published.

Use wait_for_publish to wait for the record to transition to the published state.

Source

pub async fn sign_with_keyring_and_publish( &self, publish_info: Option<PublishInfo>, ) -> ClientResult<RecordId>

Submits the provided publish information or, if not provided, loads from client storage. Uses the keyring to retrieve a key and sign.

If there’s no publishing information in client storage, an error is returned.

Returns the identifier of the record that was published.

Use wait_for_publish to wait for the record to transition to the published state.

Source

pub async fn publish_with_info( &self, signing_key: &PrivateKey, publish_info: PublishInfo, ) -> ClientResult<RecordId>

Submits the provided publish information.

Any publish information in client storage is ignored.

Returns the identifier of the record that was published.

Use wait_for_publish to wait for the record to transition to the published state.

Source

pub async fn wait_for_publish( &self, package: &PackageName, record_id: &RecordId, interval: Duration, ) -> ClientResult<()>

Waits for a package record to transition to the published state.

The interval is the amount of time to wait between checks.

Returns an error if the package record was rejected.

Source

pub async fn update(&self) -> ClientResult<()>

Updates all package logs in client registry storage to the latest registry checkpoint.

Source

pub async fn download( &self, package: &PackageName, requirement: &VersionReq, ) -> Result<Option<PackageDownload>, ClientError>

Downloads the latest version of a package into client storage that satisfies the given version requirement.

If the requested package log is not present in client storage, it will be fetched from the registry first.

An error is returned if the package does not exist.

If a version satisfying the requirement does not exist, None is returned.

Returns the path within client storage of the package contents for the resolved version.

Source

pub async fn download_as_stream( &self, package: &PackageName, requirement: &VersionReq, ) -> Result<Option<(PackageDownloadInfo, impl Stream<Item = Result<Bytes>>)>, ClientError>

Downloads the latest version of a package.

If the requested package log is not present in client storage, it will be fetched from the registry first.

An error is returned if the package does not exist.

If a version satisfying the requirement does not exist, None is returned.

Source

pub async fn download_exact( &self, package: &PackageName, version: &Version, ) -> Result<PackageDownload, ClientError>

Downloads the specified version of a package into client storage.

If the requested package log is not present in client storage, it will be fetched from the registry first.

An error is returned if the package or version does not exist.

Returns the path within client storage of the package contents for the specified version.

Source

pub async fn download_exact_as_stream( &self, package: &PackageName, version: &Version, ) -> Result<(PackageDownloadInfo, impl Stream<Item = Result<Bytes>>), ClientError>

Downloads the specified version of a package.

If the requested package log is not present in client storage, it will be fetched from the registry first.

An error is returned if the package or version does not exist.

Source

pub async fn fetch_packages( &self, names: impl IntoIterator<Item = &PackageName>, ) -> Result<Vec<PackageInfo>, ClientError>

Fetches package logs without checking local storage first.

Source

pub async fn fetch_package( &self, name: &PackageName, ) -> Result<PackageInfo, ClientError>

Fetches the PackageInfo without checking local storage first.

Source

pub async fn package( &self, name: &PackageName, ) -> Result<PackageInfo, ClientError>

Retrieves the PackageInfo from local storage, if present, otherwise fetches from the registry.

Source§

impl Client<FileSystemRegistryStorage, FileSystemContentStorage, FileSystemNamespaceMapStorage>

Source

pub async fn try_new_with_config( registry: Option<&str>, config: &Config, auth_token: Option<Secret<String>>, ) -> Result<StorageLockResult<Self>, ClientError>

Attempts to create a client for the given registry URL.

If the URL is None, the home registry URL is used; if there is no home registry URL, an error is returned.

If a lock cannot be acquired for a storage directory, then NewClientResult::Blocked is returned with the path to the directory that could not be locked.

Source

pub async fn try_new_with_default_config( url: Option<&str>, ) -> Result<StorageLockResult<Self>, ClientError>

Attempts to create a client for the given registry URL.

If the URL is None, the home registry URL is used; if there is no home registry URL, an error is returned.

If a lock cannot be acquired for a storage directory, then NewClientResult::Blocked is returned with the path to the directory that could not be locked.

Same as calling try_new_with_config with Config::from_default_file()?.unwrap_or_default().

Source

pub async fn new_with_config( registry: Option<&str>, config: &Config, auth_token: Option<Secret<String>>, ) -> Result<Self, ClientError>

Creates a client for the given registry URL.

If the URL is None, the home registry URL is used; if there is no home registry URL, an error is returned.

This method blocks if storage locks cannot be acquired.

Source

pub async fn new_with_default_config( url: Option<&str>, ) -> Result<Self, ClientError>

Creates a client for the given registry URL.

If the URL is None, the home registry URL is used; if there is no home registry URL, an error is returned.

This method blocks if storage locks cannot be acquired.

Same as calling new_with_config with Config::from_default_file()?.unwrap_or_default().

Auto Trait Implementations§

§

impl<R, C, N> Freeze for Client<R, C, N>
where R: Freeze, C: Freeze, N: Freeze,

§

impl<R, C, N> !RefUnwindSafe for Client<R, C, N>

§

impl<R, C, N> Send for Client<R, C, N>

§

impl<R, C, N> Sync for Client<R, C, N>

§

impl<R, C, N> Unpin for Client<R, C, N>
where R: Unpin, C: Unpin, N: Unpin,

§

impl<R, C, N> !UnwindSafe for Client<R, C, N>

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

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

Source§

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

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

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

Source§

fn vzip(self) -> V

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

impl<T> ErasedDestructor for T
where T: 'static,