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
48        .get("ALIEN_DEPLOYMENT_TYPE")
49        .ok_or_else(|| {
50            AlienError::new(ErrorData::EnvironmentVariableMissing {
51                variable_name: "ALIEN_DEPLOYMENT_TYPE".to_string(),
52            })
53        })?;
54
55    deployment_type.parse().map_err(|_| {
56        AlienError::new(ErrorData::InvalidEnvironmentVariable {
57            variable_name: "ALIEN_DEPLOYMENT_TYPE".to_string(),
58            value: deployment_type.clone(),
59            reason: "Cannot parse the ALIEN_DEPLOYMENT_TYPE environment variable".to_string(),
60        })
61    })
62}
63
64/// Parse ALIEN_BINDINGS_MODE from environment variables.
65/// Defaults to Direct if not specified.
66pub fn get_bindings_mode_from_env(
67    env: &std::collections::HashMap<String, String>,
68) -> Result<BindingsMode> {
69    let mode_str = env
70        .get("ALIEN_BINDINGS_MODE")
71        .map(|s| s.as_str())
72        .unwrap_or("direct");
73
74    mode_str.parse().map_err(|reason: String| {
75        AlienError::new(ErrorData::InvalidEnvironmentVariable {
76            variable_name: "ALIEN_BINDINGS_MODE".to_string(),
77            value: mode_str.to_string(),
78            reason,
79        })
80    })
81}