Skip to main content

alien_bindings/
lib.rs

1use alien_error::AlienError;
2
3// Re-export core traits and types
4pub use alien_context::AlienContext;
5pub use alien_core::{BindingsMode, Platform};
6pub use error::{ErrorData, Result};
7pub use provider::BindingsProvider;
8pub use traits::{
9    ArtifactRegistry, ArtifactRegistryCredentials, ArtifactRegistryPermissions,
10    AwsServiceAccountInfo, AzureServiceAccountInfo, Binding, BindingsProviderApi, Build, Container,
11    Function, GcpServiceAccountInfo, ImpersonationRequest, Kv, Queue, RepositoryResponse,
12    ServiceAccount, ServiceAccountInfo, Storage, Vault,
13};
14pub use wait_until::{DrainConfig, DrainResponse, WaitUntil, WaitUntilContext};
15
16pub mod error;
17#[cfg(feature = "grpc")]
18pub mod grpc;
19pub mod providers;
20pub mod traits;
21// Re-export presigned types from alien-core
22pub mod presigned {
23    pub use alien_core::presigned::*;
24}
25pub mod alien_context;
26pub mod http_client;
27pub mod provider;
28
29mod wait_until;
30
31#[cfg(feature = "grpc")]
32pub use grpc::control;
33#[cfg(feature = "grpc")]
34pub use grpc::control_service::ControlGrpcServer;
35#[cfg(feature = "grpc")]
36pub use grpc::GrpcServerHandles;
37
38/// Gets the current platform from the ALIEN_DEPLOYMENT_TYPE environment variable.
39/// This is used by the runtime to determine which platform-specific implementations to use.
40pub fn get_current_platform() -> Result<Platform> {
41    let env_vars: std::collections::HashMap<String, String> = std::env::vars().collect();
42    get_platform_from_env(&env_vars)
43}
44
45/// Gets the platform from a HashMap of environment variables.
46pub fn get_platform_from_env(env: &std::collections::HashMap<String, String>) -> Result<Platform> {
47    let deployment_type = env.get("ALIEN_DEPLOYMENT_TYPE").ok_or_else(|| {
48        AlienError::new(ErrorData::EnvironmentVariableMissing {
49            variable_name: "ALIEN_DEPLOYMENT_TYPE".to_string(),
50        })
51    })?;
52
53    deployment_type.parse().map_err(|_| {
54        AlienError::new(ErrorData::InvalidEnvironmentVariable {
55            variable_name: "ALIEN_DEPLOYMENT_TYPE".to_string(),
56            value: deployment_type.clone(),
57            reason: "Cannot parse the ALIEN_DEPLOYMENT_TYPE environment variable".to_string(),
58        })
59    })
60}
61
62/// Parse ALIEN_BINDINGS_MODE from environment variables.
63/// Defaults to Direct if not specified.
64pub fn get_bindings_mode_from_env(
65    env: &std::collections::HashMap<String, String>,
66) -> Result<BindingsMode> {
67    let mode_str = env
68        .get("ALIEN_BINDINGS_MODE")
69        .map(|s| s.as_str())
70        .unwrap_or("direct");
71
72    mode_str.parse().map_err(|reason: String| {
73        AlienError::new(ErrorData::InvalidEnvironmentVariable {
74            variable_name: "ALIEN_BINDINGS_MODE".to_string(),
75            value: mode_str.to_string(),
76            reason,
77        })
78    })
79}