-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathconfig.hpp
More file actions
66 lines (56 loc) · 1.9 KB
/
config.hpp
File metadata and controls
66 lines (56 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Unless explicitly stated otherwise all files in this repository are
// dual-licensed under the Apache-2.0 License or BSD-3-Clause License.
//
// This product includes software developed at Datadog
// (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
#pragma once
#include <optional>
#include <spdlog/spdlog.h>
#include <string_view>
#include <unordered_map>
namespace dds::config {
// TODO: Rename to ArgConfig or ArgParser?
// Perhaps make this a "singleton"
class config {
public:
explicit config(
const std::function<std::optional<std::string_view>(std::string_view)>
&fn);
[[nodiscard]] std::string_view socket_file_path() const
{
return kv_.at(env_socket_file_path);
}
[[nodiscard]] bool is_abstract_socket() const
{
std::string_view const sfp = socket_file_path();
if (sfp.empty()) {
return false;
}
return sfp[0] == '@';
}
[[nodiscard]] std::string_view lock_file_path() const
{
return kv_.at(env_lock_file_path);
}
[[nodiscard]] std::string_view log_file_path() const
{
return kv_.at(env_log_file_path);
}
[[nodiscard]] spdlog::level::level_enum log_level() const
{
return spdlog::level::from_str(std::string{kv_.at(env_log_level)});
}
protected:
static const std::unordered_map<std::string_view, std::string_view>
defaults;
std::unordered_map<std::string_view, std::string_view> kv_{defaults};
static constexpr std::string_view env_socket_file_path =
"_DD_SIDECAR_APPSEC_SOCKET_FILE_PATH";
static constexpr std::string_view env_lock_file_path =
"_DD_SIDECAR_APPSEC_LOCK_FILE_PATH";
static constexpr std::string_view env_log_file_path =
"_DD_SIDECAR_APPSEC_LOG_FILE_PATH";
static constexpr std::string_view env_log_level =
"_DD_SIDECAR_APPSEC_LOG_LEVEL";
};
} // namespace dds::config