Skip to main content

morax_api/config/
morax.rs

1// Copyright 2024 tison <wander4096@gmail.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use serde::Deserialize;
16use serde::Serialize;
17
18use crate::config::BrokerConfig;
19use crate::config::LogsConfig;
20use crate::config::MetaServiceConfig;
21use crate::config::RuntimeOptions;
22use crate::config::ServerConfig;
23use crate::config::StderrAppenderConfig;
24use crate::config::TelemetryConfig;
25use crate::property::S3StorageProperty;
26use crate::property::StorageProperty;
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(deny_unknown_fields)]
30pub struct Config {
31    pub server: ServerConfig,
32    pub telemetry: TelemetryConfig,
33    pub runtime: RuntimeOptions,
34}
35
36impl Default for Config {
37    fn default() -> Self {
38        Config {
39            server: ServerConfig {
40                broker: BrokerConfig {
41                    listen_addr: "0.0.0.0:8848".to_string(),
42                    advertise_addr: None,
43                },
44                meta: MetaServiceConfig {
45                    service_url: "postgres://morax:my_secret_password@127.0.0.1:5432/morax_meta"
46                        .to_string(),
47                },
48                default_storage: StorageProperty::S3(S3StorageProperty {
49                    bucket: "test-bucket".to_string(),
50                    region: "us-east-1".to_string(),
51                    prefix: "/".to_string(),
52                    endpoint: "http://127.0.0.1:9000".to_string(),
53                    access_key_id: "minioadmin".to_string(),
54                    secret_access_key: "minioadmin".to_string(),
55                    virtual_host_style: false,
56                }),
57            },
58            telemetry: TelemetryConfig {
59                logs: LogsConfig {
60                    stderr: Some(StderrAppenderConfig {
61                        filter: "DEBUG".to_string(),
62                    }),
63                },
64            },
65            runtime: RuntimeOptions::default(),
66        }
67    }
68}