-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.rs
More file actions
125 lines (109 loc) · 3.83 KB
/
Copy pathconfig.rs
File metadata and controls
125 lines (109 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use code0_flow::flow_config::environment::Environment;
use code0_flow::flow_config::mode::Mode;
/// Service Configuration
/// This configuration holds the setup for every Adapter.
/// If your Adapter needs more configuration, implement the `LoadConfig` trait.
pub struct AdapterConfig {
/// Service Environment
pub environment: Environment,
/// STATIC:
/// The service will start with no Sagittarius in mind.
/// No Aquila connection will be established.
///
/// DYNAMIC:
/// The service will start with Sagittarius in mind.
/// Aquila connection will be established.
pub mode: Mode,
/// NATS URL
///
/// URL of the NATS server to connect to.
pub nats_url: String,
/// NATS Bucket
///
/// Name of the NATS bucket to use.
pub nats_bucket: String,
/// GRPC Port
///
/// Port on which the adapter's Health Service server will listen.
pub grpc_port: u16,
/// GRPC Host
///
/// Host on which the adapter's Health Service server will listen.
pub grpc_host: String,
/// Aquila URL
///
/// URL of the Aquila server to connect to.
pub aquila_url: String,
/// Aquila Token
///
/// Token used to authenticate with Aquila.
pub aquila_token: String,
/// Definition Path
///
/// Path to the root definition folder.
pub definition_path: String,
/// Is Monitored
///
/// If true the Adapter will expose a grpc health service server.
pub with_health_service: bool,
/// Variant
///
/// The Variant of Draco. E.g. Http, Cron...
pub draco_variant: String,
/// Adapter Status Update Interval Seconds
///
/// Interval for runtime status heartbeat updates while the adapter is running.
/// Set to 0 to disable periodic heartbeat updates.
pub adapter_status_update_interval_seconds: u64,
}
impl AdapterConfig {
pub fn from_env() -> Self {
let nats_url = code0_flow::flow_config::env_with_default(
"NATS_URL",
String::from("nats://localhost:4222"),
);
let nats_bucket =
code0_flow::flow_config::env_with_default("NATS_BUCKET", String::from("flow_store"));
let grpc_port = code0_flow::flow_config::env_with_default("GRPC_PORT", 50051);
let grpc_host =
code0_flow::flow_config::env_with_default("GRPC_HOST", String::from("localhost"));
let aquila_url = code0_flow::flow_config::env_with_default(
"AQUILA_URL",
String::from("grpc://localhost:50051"),
);
let aquila_token =
code0_flow::flow_config::env_with_default("AQUILA_TOKEN", String::from("token"));
let environment =
code0_flow::flow_config::env_with_default("ENVIRONMENT", Environment::Development);
let mode = code0_flow::flow_config::env_with_default("MODE", Mode::STATIC);
let definition_path = code0_flow::flow_config::env_with_default(
"DEFINITION_PATH",
String::from("./definition"),
);
let with_health_service =
code0_flow::flow_config::env_with_default("WITH_HEALTH_SERVICE", false);
let draco_variant =
code0_flow::flow_config::env_with_default("DRACO_VARIANT", String::from("None"));
let adapter_status_update_interval_seconds = code0_flow::flow_config::env_with_default(
"ADAPTER_STATUS_UPDATE_INTERVAL_SECONDS",
30_u64,
);
Self {
environment,
nats_bucket,
mode,
nats_url,
grpc_port,
grpc_host,
aquila_url,
aquila_token,
definition_path,
with_health_service,
draco_variant,
adapter_status_update_interval_seconds,
}
}
pub fn is_static(&self) -> bool {
self.mode == Mode::STATIC
}
}