sett 0.4.0

Rust port of sett (data compression, encryption and transfer tool).
Documentation
//! Portal API response types.

use serde::Deserialize;

#[cfg(feature = "auth")]
use serde::Serialize;

#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
/// Check package response from the Portal API.
pub struct CheckPackage {
    /// The project code of the package.
    ///
    /// It is derived from the `transfer_id` field of the package metadata.
    pub project_code: String,
}

#[derive(Deserialize, Debug)]
/// Error response from the Portal API when checking a package.
pub(super) struct PortalError {
    /// The error message.
    pub(super) detail: String,
}

#[cfg(feature = "auth")]
/// S3 connection info as returned by the Portal API.
///
/// This struct is used as an intermediary step, and avoids having to write
/// a custom deserializer for [`ConnectionInfo`].
///
/// [`ConnectionInfo`]: crate::remote::s3::ConnectionInfo
#[derive(Deserialize)]
pub(super) struct S3ConnectionInfoRaw {
    access_key_id: String,
    secret_access_key: String,
    session_token: String,
    endpoint: String,
    bucket: String,
    expiration: chrono::DateTime<chrono::Utc>,
}

#[cfg(feature = "auth")]
impl From<S3ConnectionInfoRaw> for crate::remote::s3::ConnectionInfo {
    fn from(value: S3ConnectionInfoRaw) -> Self {
        crate::remote::s3::ConnectionInfo {
            endpoint: value.endpoint,
            bucket: value.bucket,
            credentials: crate::remote::s3::Credentials::new(
                value.access_key_id,
                value.secret_access_key,
                Some(value.session_token),
                Some(value.expiration.into()),
            ),
        }
    }
}

#[cfg(feature = "auth")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all(deserialize = "SCREAMING_SNAKE_CASE"))]
/// Possible statuses for a data transfer request on Portal.
pub enum DataTransferStatus {
    /// The data transfer is undergoing the approval process.
    Initial,
    /// The data transfer has been approved by all parties and ready to be
    /// performed.
    Authorized,
    /// The data transfer has been rejected by at least one the parties and will
    /// not be performed.
    Unauthorized,
    /// The data transfer is expired and cannot be performed.
    Expired,
}

#[cfg(feature = "auth")]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
/// Portal's representation of data transfer request.
pub struct DataTransfer {
    /// Unique ID.
    pub id: u32,
    /// Name of the data provider sending the data.
    pub data_provider_name: String,
    /// Name of the project receiving the data.
    pub project_name: String,
    /// Current status of the data transfer request.
    pub status: DataTransferStatus,
}