alien-bindings 3.3.1

Alien direct in-process resource bindings
Documentation
use alien_error::AlienError;

// Re-export core traits and types
pub use alien_core::{Platform, ENV_ALIEN_DEPLOYMENT_TYPE, ENV_OPERATOR_BASE_PLATFORM};
pub use bindings::{Bindings, BoundQueue};
pub use error::{ErrorData, Result};
pub use provider::BindingsProvider;
#[cfg(feature = "platform-sdk")]
pub use remote::{RemoteBindings, RemoteStorage};
pub use traits::{
    ArtifactRegistry, ArtifactRegistryCredentials, ArtifactRegistryPermissions,
    AwsServiceAccountInfo, AzureServiceAccountInfo, Binding, BindingsProviderApi, Build, Container,
    GcpServiceAccountInfo, ImpersonationRequest, InvalidPostgresCaCertificates, Kv, Postgres,
    PostgresConnectionParams, PostgresTlsPolicy, Queue, RegistryAuthMethod, RepositoryResponse,
    ServiceAccount, ServiceAccountInfo, SslMode, Storage, Vault, Worker,
};

pub mod bindings;
pub mod error;
pub mod providers;
pub mod traits;
// Re-export presigned types from alien-core
pub mod presigned {
    pub use alien_core::presigned::*;
}
mod credential_source;
pub mod http_client;
pub mod provider;
mod refreshing;
#[cfg(feature = "platform-sdk")]
mod remote;

/// Gets the current platform from the ALIEN_DEPLOYMENT_TYPE environment variable.
/// This is used by the runtime to determine which platform-specific implementations to use.
pub fn get_current_platform() -> Result<Platform> {
    let env_vars: std::collections::HashMap<String, String> = std::env::vars().collect();
    get_platform_from_env(&env_vars)
}

/// Gets the platform from a HashMap of environment variables.
pub fn get_platform_from_env(env: &std::collections::HashMap<String, String>) -> Result<Platform> {
    let deployment_type = env.get(ENV_ALIEN_DEPLOYMENT_TYPE).ok_or_else(|| {
        AlienError::new(ErrorData::EnvironmentVariableMissing {
            variable_name: ENV_ALIEN_DEPLOYMENT_TYPE.to_string(),
        })
    })?;

    deployment_type.parse().map_err(|_| {
        AlienError::new(ErrorData::InvalidEnvironmentVariable {
            variable_name: ENV_ALIEN_DEPLOYMENT_TYPE.to_string(),
            value: deployment_type.clone(),
            reason: "Cannot parse the ALIEN_DEPLOYMENT_TYPE environment variable".to_string(),
        })
    })
}