openapi_rs/common/
config.rs1use std::env;
2
3#[derive(Default, Debug)]
4pub struct OpenApiConfig {
5 pub app_key: String,
6 pub app_secret: String,
7 pub endpoint: String,
8 pub cloud_endpoint: String,
9 pub hpc_endpoint: String,
10 pub sync_endpoint: String,
11 pub user_id: String,
12 pub zone: String,
13}
14
15#[derive(Debug, Default)]
16pub enum EndpointType {
17 #[default]
18 Api,
19 Cloud,
20 Hpc,
21 Sync,
22}
23
24impl OpenApiConfig {
25 pub fn new() -> Self {
26 Self::default()
27 }
28
29 pub fn with_app_key(mut self, app_key: String) -> Self {
30 self.app_key = app_key;
31 self
32 }
33
34 pub fn with_app_secret(mut self, app_secret: String) -> Self {
35 self.app_secret = app_secret;
36 self
37 }
38
39 pub fn with_endpoint(mut self, endpoint: String) -> Self {
40 self.endpoint = endpoint;
41 self
42 }
43
44 pub fn with_cloud_endpoint(mut self, cloud_endpoint: String) -> Self {
45 self.cloud_endpoint = cloud_endpoint;
46 self
47 }
48
49 pub fn with_hpc_endpoint(mut self, hpc_endpoint: String) -> Self {
50 self.hpc_endpoint = hpc_endpoint;
51 self
52 }
53
54 pub fn with_user_id(mut self, user_id: String) -> Self {
55 self.user_id = user_id;
56 self
57 }
58
59 pub fn with_zone(mut self, zone: String) -> Self {
60 self.zone = zone;
61 self
62 }
63
64 pub fn load_from_env(&mut self) -> anyhow::Result<Self> {
65 Ok(Self {
66 app_key: env::var("OpenApiAppKey")?,
67 app_secret: env::var("OpenApiAppSecret")?,
68 endpoint: env::var("OpenApiEndpoint")?,
69 cloud_endpoint: env::var("OpenApiCloudEndpoint")?,
70 hpc_endpoint: env::var("OpenApiHpcEndpoint")?,
71 sync_endpoint: env::var("OpenApiSyncEndpoint")?,
72 user_id: env::var("OpenApiUserId")?,
73 zone: env::var("OpenApiZone")?,
74 })
75 }
76}