Skip to main content

alien_bindings/
lib.rs

1use alien_error::AlienError;
2
3// Re-export core traits and types
4pub use alien_core::{Platform, ENV_ALIEN_DEPLOYMENT_TYPE, ENV_OPERATOR_BASE_PLATFORM};
5pub use bindings::{Bindings, BoundQueue};
6pub use error::{ErrorData, Result};
7pub use provider::BindingsProvider;
8#[cfg(feature = "platform-sdk")]
9pub use remote::{RemoteBindings, RemoteStorage};
10pub use traits::{
11    ArtifactRegistry, ArtifactRegistryCredentials, ArtifactRegistryPermissions,
12    AwsServiceAccountInfo, AzureServiceAccountInfo, Binding, BindingsProviderApi, Build, Container,
13    GcpServiceAccountInfo, ImpersonationRequest, InvalidPostgresCaCertificates, Kv, Postgres,
14    PostgresConnectionParams, PostgresTlsPolicy, Queue, RegistryAuthMethod, RepositoryResponse,
15    ServiceAccount, ServiceAccountInfo, SslMode, Storage, Vault, Worker,
16};
17
18pub mod bindings;
19pub mod error;
20pub mod providers;
21pub mod traits;
22// Re-export presigned types from alien-core
23pub mod presigned {
24    pub use alien_core::presigned::*;
25}
26mod credential_source;
27pub mod http_client;
28pub mod provider;
29mod refreshing;
30#[cfg(feature = "platform-sdk")]
31mod remote;
32
33/// Gets the current platform from the ALIEN_DEPLOYMENT_TYPE environment variable.
34/// This is used by the runtime to determine which platform-specific implementations to use.
35pub fn get_current_platform() -> Result<Platform> {
36    let env_vars: std::collections::HashMap<String, String> = std::env::vars().collect();
37    get_platform_from_env(&env_vars)
38}
39
40/// Gets the platform from a HashMap of environment variables.
41pub fn get_platform_from_env(env: &std::collections::HashMap<String, String>) -> Result<Platform> {
42    let deployment_type = env.get(ENV_ALIEN_DEPLOYMENT_TYPE).ok_or_else(|| {
43        AlienError::new(ErrorData::EnvironmentVariableMissing {
44            variable_name: ENV_ALIEN_DEPLOYMENT_TYPE.to_string(),
45        })
46    })?;
47
48    deployment_type.parse().map_err(|_| {
49        AlienError::new(ErrorData::InvalidEnvironmentVariable {
50            variable_name: ENV_ALIEN_DEPLOYMENT_TYPE.to_string(),
51            value: deployment_type.clone(),
52            reason: "Cannot parse the ALIEN_DEPLOYMENT_TYPE environment variable".to_string(),
53        })
54    })
55}