morax_api/property/
storage.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 std::fmt;
16
17use serde::Deserialize;
18use serde::Serialize;
19
20#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(deny_unknown_fields)]
22pub struct TopicProperty {
23    pub storage: StorageProperty,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(tag = "scheme")]
28#[serde(deny_unknown_fields)]
29pub enum StorageProperty {
30    #[serde(rename = "s3")]
31    S3(S3StorageProperty),
32}
33
34#[derive(Clone, Serialize, Deserialize)]
35#[serde(deny_unknown_fields)]
36pub struct S3StorageProperty {
37    /// Bucket name.
38    pub bucket: String,
39    /// Region name.
40    pub region: String,
41    /// URL prefix of table files, e.g. `/path/to/my/dir/`.
42    ///
43    /// Default to `/`
44    #[serde(default = "default_prefix")]
45    pub prefix: String,
46    /// URL of S3 endpoint, e.g. `https://s3.<region>.amazonaws.com`.
47    pub endpoint: String,
48    /// Access key ID.
49    pub access_key_id: String,
50    /// Secret access key.
51    pub secret_access_key: String,
52    /// Whether to enable virtual host style, so that API requests will be sent
53    /// in virtual host style instead of path style.
54    ///
55    /// Default to `true`
56    #[serde(default = "default_virtual_host_style")]
57    pub virtual_host_style: bool,
58}
59
60impl fmt::Debug for S3StorageProperty {
61    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62        f.debug_struct("S3Config")
63            .field("prefix", &self.prefix)
64            .field("bucket", &self.bucket)
65            .field("endpoint", &self.endpoint)
66            .field("region", &self.region)
67            .finish_non_exhaustive()
68    }
69}
70
71pub fn default_prefix() -> String {
72    "/".to_string()
73}
74
75pub const fn default_virtual_host_style() -> bool {
76    true
77}