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