Struct freta::Client

source ·
pub struct Client { /* private fields */ }
Expand description

Freta Client

Implementations§

source§

impl Client

source

pub async fn new() -> Result<Self>

Create a new client for the Freta service

Errors

This function will return an error if creating the backend REST API client fails

source

pub async fn with_config(config: Config) -> Result<Self>

Create a new client for the Freta service with a configuration

Errors

This function will return an error if creating the backend REST API client fails

source

pub async fn logout() -> Result<()>

logout of the service

Errors

This function will return an error if deleting the authentication cache fails

source

pub async fn user_config_get(&self) -> Result<UserConfig>

Retrieve user configuration settings

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to get their configuration
source

pub async fn user_config_update( &self, eula_accepted: Option<String>, include_samples: bool ) -> Result<UserConfigUpdateResponse>

Update user configuration settings

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to update their configuration
source

pub async fn eula(&self) -> Result<Bytes>

Get the latest EULA required to use the service

Note, all API requests to the service will return the EULA as part of the error in the HTTP Error response if the EULA has not been accepted.

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
source

pub async fn info(&self) -> Result<Info>

Retrieve information about the service

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to get the service information
source

pub fn images_list( &self, image_id: Option<ImageId>, owner_id: Option<OwnerId>, state: Option<ImageState>, include_samples: bool ) -> Pin<Box<impl Stream<Item = Result<Image, Error>> + Send + '_>>

List available images

Example
use futures::StreamExt;
let mut stream = client.images_list(None, None, None, true);
while let Some(image) = stream.next().await {
    let image = image?;
    println!("{image:?}");
}
Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission
source

pub async fn images_create<T, K, V>( &self, format: ImageFormat, tags: T ) -> Result<Image>where T: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

Create a new image entry

The resulting Image.image_url is a time-limited SAS URL that can be used to upload a memory snapshot to Freta via tools such as azcopy

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to create images.
source

pub async fn images_upload<P, T, K, V>( &self, format: ImageFormat, tags: T, path: P ) -> Result<Image>where P: AsRef<Path>, T: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

Create and upload an image to Freta

Errors

This function will return an error in the following cases:

  1. Creating the image in Freta fails
  2. Uploading the blob to Azure Storage fails
source

pub async fn images_get(&self, image_id: ImageId) -> Result<Image>

Get information on an image

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to read the specified image
source

pub async fn images_delete( &self, image_id: ImageId ) -> Result<ImageDeleteResponse>

Delete an image

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to delete the specified image
source

pub async fn images_update<T, K, V>( &self, image_id: ImageId, tags: Option<T>, shareable: Option<bool> ) -> Result<Image>where T: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

Update metadata for an image

If tags is not None, then the tags are overwritten. If shareable is not None, then the shareable value is overwritten.

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to update metadata for the specified image
source

pub async fn images_reanalyze( &self, image_id: ImageId ) -> Result<ImageReanalyzeResponse>

Reanalyze an image

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to reanalyze the specified image
source

pub async fn images_download<P>( &self, image_id: ImageId, output: P ) -> Result<()>where P: AsRef<Path>,

Download an image to a file

NOTE: The service only allows downloading images that have been analyzed successfully.

Errors

This function will return an error in the follow cases:

  1. The user does not have permission to access the specified image
  2. The image was not successfully analyzed
  3. Downloading the image fails
Example
client.images_download(image_id, "/tmp/image.lime").await?;
source

pub fn artifacts_list( &self, image_id: ImageId ) -> Pin<Box<impl Stream<Item = Result<String, Error>> + Send + '_>>

List the artifacts extracted from the image

Errors

This function will return an error in the follow cases:

  1. Getting the artifacts SAS URL for the image fails
  2. Listing the blobs from the Azure Storage fails
Example
use futures::StreamExt;
let mut stream = client.artifacts_list(image_id);
while let Some(entry) = stream.next().await {
    let entry = entry?;
    println!("{entry}");
}
source

pub async fn artifacts_get<N>( &self, image_id: ImageId, name: N ) -> Result<Vec<u8>>where N: Into<String>,

Get an artifact extracted from the image

Errors

This function will return an error in the follow cases:

  1. Getting the artifacts SAS URL for the image fails
  2. Getting the artifact fails
Example
let report = client.artifacts_get(image_id, "report.json").await?;
source

pub async fn artifacts_download<P, N>( &self, image_id: ImageId, name: N, output: P ) -> Result<()>where P: AsRef<Path>, N: Into<String>,

Download an artifact extracted from the image to a file

Errors

This function will return an error in the follow cases:

  1. Getting the artifacts SAS URL for the image fails
  2. Downloading the artifact fails
Example
client
    .artifacts_download(image_id, "report.json", "/tmp/report.json")
    .await?;
source

pub async fn images_monitor(&self, image_id: ImageId) -> Result<Image>

Monitor the ongoing state of an image until the analysis has completed.

Errors

This function will return an error in the following cases:

  1. Getting the image fails
  2. The image analysis state gets to Failed or is not recognized
Example
client.images_monitor(image_id).await?;
source

pub fn webhooks_list( &self ) -> Pin<Box<impl Stream<Item = Result<Webhook, Error>> + Send + '_>>

List the configured webhooks

Errors

This function will return an error in the follow cases:

  1. The connection to the Service fails
  2. The user does not have permission to get their webhooks
Example
let mut stream = client.webhooks_list();
while let Some(entry) = stream.next().await {
    let entry = entry?;
    println!("{:?}", entry);
}
source

pub async fn webhook_get(&self, webhook_id: WebhookId) -> Result<Webhook>

Get information on a webhook

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to read the specified webhook
source

pub async fn webhook_delete( &self, webhook_id: WebhookId ) -> Result<WebhookBoolResponse>

Delete a webhook

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to delete the specified webhook
source

pub async fn webhook_update<S>( &self, webhook_id: WebhookId, url: Url, event_types: BTreeSet<WebhookEventType>, hmac_token: Option<S> ) -> Result<Webhook>where S: Into<Secret>,

Update a webhook

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to update the specified webhook
source

pub async fn webhook_ping(&self, webhook_id: WebhookId) -> Result<Bytes>

Ping a webhook

This generates a synthetic event for a given webhook to test that it works as expected without having to analyze an image.

Note: This service provides the raw response from the Freta service to enable the developers of webhook receivers to validate their HMAC calculation works as expected.

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to update the specified webhook
source

pub async fn webhook_resend( &self, webhook_id: WebhookId, webhook_event_id: WebhookEventId ) -> Result<WebhookEvent>

Resend a webhook event

This resends a specific event to the webhook.

Note: If the event already pending being sent to the webhook endpoint, this will be a NOOP.

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to resend the specified webhook event
source

pub async fn webhook_create<S>( &self, url: Url, event_types: BTreeSet<WebhookEventType>, hmac_token: Option<S> ) -> Result<Webhook>where S: Into<Secret>,

Create a webhook

Errors

This function will return an error in the following conditions:

  1. The connection to the Service fails
  2. The user does not have permission to create a webhook
source

pub fn webhooks_logs( &self, webhook_id: WebhookId ) -> Pin<Box<impl Stream<Item = Result<WebhookLog, Error>> + Send + '_>>

List the logs for a specific webhook

Errors

This function will return an error in the follow cases:

  1. The connection to the Service fails
  2. The user does not have permission to get their webhooks
Example
let mut stream = client.webhooks_logs(webhook_id);
while let Some(entry) = stream.next().await {
    let entry = entry?;
    println!("{entry:?}");
}

Trait Implementations§

source§

impl Debug for Client

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
§

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

§

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
§

impl<T> Captures<'_> for Twhere T: ?Sized,

§

impl<T, __> MentionsTy<__> for Twhere T: ?Sized, __: ?Sized,