-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
g3-tls-ticket: add redis source and config
- Loading branch information
Showing
22 changed files
with
618 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2024 ByteDance and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
use std::path::Path; | ||
|
||
use anyhow::{anyhow, Context}; | ||
use yaml_rust::Yaml; | ||
|
||
use super::RedisClientConfigBuilder; | ||
|
||
impl RedisClientConfigBuilder { | ||
pub fn set_yaml_kv( | ||
&mut self, | ||
k: &str, | ||
v: &Yaml, | ||
lookup_dir: Option<&Path>, | ||
) -> anyhow::Result<()> { | ||
match k { | ||
"addr" | "address" => { | ||
let addr = g3_yaml::value::as_upstream_addr(v, crate::REDIS_DEFAULT_PORT) | ||
.context(format!("invalid upstream address value for key {k}"))?; | ||
self.set_addr(addr); | ||
Ok(()) | ||
} | ||
"tls" | "tls_client" => { | ||
let tls = g3_yaml::value::as_rustls_client_config_builder(v, lookup_dir).context( | ||
format!("invalid rustls tls client config value for key {k}"), | ||
)?; | ||
self.set_tls_client(tls); | ||
Ok(()) | ||
} | ||
"tls_name" => { | ||
let name = g3_yaml::value::as_rustls_server_name(v) | ||
.context(format!("invalid rustls server name value for key {k}"))?; | ||
self.set_tls_name(name); | ||
Ok(()) | ||
} | ||
"db" => { | ||
let db = | ||
g3_yaml::value::as_i64(v).context(format!("invalid int value for key {k}"))?; | ||
self.set_db(db); | ||
Ok(()) | ||
} | ||
"username" => { | ||
let username = g3_yaml::value::as_string(v)?; | ||
self.set_username(username); | ||
Ok(()) | ||
} | ||
"password" => { | ||
let password = g3_yaml::value::as_string(v)?; | ||
self.set_password(password); | ||
Ok(()) | ||
} | ||
"connect_timeout" => { | ||
let timeout = g3_yaml::humanize::as_duration(v) | ||
.context(format!("invalid humanize duration value for key {k}"))?; | ||
self.set_connect_timeout(timeout); | ||
Ok(()) | ||
} | ||
"response_timeout" | "read_timeout" => { | ||
let timeout = g3_yaml::humanize::as_duration(v) | ||
.context(format!("invalid humanize duration value for key {k}"))?; | ||
self.set_response_timeout(timeout); | ||
Ok(()) | ||
} | ||
_ => Err(anyhow!("invalid key {}", k)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2024 ByteDance and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
use std::path::Path; | ||
|
||
use anyhow::{anyhow, Context}; | ||
use yaml_rust::Yaml; | ||
|
||
use super::TlsTicketConfig; | ||
use crate::source::TicketSourceConfig; | ||
|
||
impl TlsTicketConfig { | ||
pub fn parse_yaml(value: &Yaml, lookup_dir: Option<&Path>) -> anyhow::Result<Self> { | ||
if let Yaml::Hash(map) = value { | ||
let mut config = TlsTicketConfig::default(); | ||
g3_yaml::foreach_kv(map, |k, v| match g3_yaml::key::normalize(k).as_str() { | ||
"check_interval" => { | ||
config.check_interval = g3_yaml::humanize::as_duration(v) | ||
.context(format!("invalid humanize duration value for key {k}"))?; | ||
Ok(()) | ||
} | ||
"local_lifetime" => { | ||
config.local_lifetime = g3_yaml::value::as_u32(v)?; | ||
Ok(()) | ||
} | ||
"source" => { | ||
let source = TicketSourceConfig::parse_yaml(v, lookup_dir).context(format!( | ||
"invalid remote tls ticket source config for key {k}" | ||
))?; | ||
config.remote_source = Some(source); | ||
Ok(()) | ||
} | ||
_ => Err(anyhow!("invalid key {k}")), | ||
})?; | ||
Ok(config) | ||
} else { | ||
Err(anyhow!( | ||
"yaml value type for 'tls ticket config' should be 'map'" | ||
)) | ||
} | ||
} | ||
} |
Oops, something went wrong.