Skip to content

Commit

Permalink
Add Search and Redis configuration, add /heartbeat, panic + cors hand…
Browse files Browse the repository at this point in the history
…lers
  • Loading branch information
auguwu committed Jul 15, 2023
1 parent 0f75082 commit 4ca64e5
Show file tree
Hide file tree
Showing 19 changed files with 1,100 additions and 23 deletions.
463 changes: 462 additions & 1 deletion Cargo.bzl.lock

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rust_project(
deps = [
"//crates/common:charted_common",
"@crate_index//:aws-sdk-s3",
"@crate_index//:base64",
"@crate_index//:clap",
"@crate_index//:eyre",
"@crate_index//:lazy_static",
Expand Down
1 change: 1 addition & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ remi-s3 = { version = "0.2.1", features = ["serde"] }
aws-sdk-s3 = "0.28.0"
paste = "1.0.13"
merge-struct = "0.1.0"
base64 = "0.21.2"
72 changes: 72 additions & 0 deletions crates/config/src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,75 @@
// 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 crate::{make_config, var, SecureSetting, SecureSettingError};
use charted_common::TRUTHY_REGEX;

make_config! {
/// Configuration to create a Redis connection pool
RedisConfig {
#[serde(default, skip_serializing_if = "Option::is_none")]
master_name: Option<String> {
default: None;
env_value: var!("CHARTED_REDIS_SENTINEL_MASTER_NAME", is_optional: true);
};

#[serde(default, skip_serializing_if = "Option::is_none")]
password: Option<String> {
default: None;
env_value: var!("CHARTED_REDIS_PASSWORDS", is_optional: true);
};

#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub hosts: Vec<String> {
default: default_redis_hosts();
env_value: var!("CHARTED_REDIS_HOSTS", {
or_else: default_redis_hosts();
mapper: |val| val.split(',').map(|f| f.to_string()).collect::<Vec<_>>();
});
};

#[serde(default = "default_tls")]
pub tls: bool {
default: default_tls();
env_value: var!("CHARTED_REDIS_TLS_ENABLE", {
or_else: default_tls();
mapper: |val| TRUTHY_REGEX.is_match(val.as_str());
});
};

#[serde(default = "default_db")]
pub db: u8 {
default: default_db();
env_value: var!("CHARTED_REDIS_DB", to: u8, or_else: default_db());
};
}
}

impl RedisConfig {
pub fn password(&self) -> Result<Option<String>, SecureSettingError> {
match self.password.clone() {
Some(password) => SecureSetting::new("redis.password".into()).load_optional(password.as_str()),
None => Ok(None),
}
}

pub fn master_name(&self) -> Result<Option<String>, SecureSettingError> {
match self.password.clone() {
Some(password) => SecureSetting::new("redis.master_name".into()).load_optional(password.as_str()),
None => Ok(None),
}
}
}

fn default_redis_hosts() -> Vec<String> {
vec!["redis://localhost:6379".into()]
}

fn default_tls() -> bool {
false
}

fn default_db() -> u8 {
2
}
Loading

0 comments on commit 4ca64e5

Please sign in to comment.