]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_env.cc
import quincy 17.2.0
[ceph.git] / ceph / src / rgw / rgw_env.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #include "rgw_common.h"
5 #include "rgw_log.h"
6
7 #include <string>
8 #include <map>
9 #include "include/ceph_assert.h"
10 #include "rgw_crypt_sanitize.h"
11
12 #define dout_context g_ceph_context
13 #define dout_subsys ceph_subsys_rgw
14
15 using namespace std;
16
17 void RGWEnv::init(CephContext *cct)
18 {
19 conf.init(cct);
20 }
21
22 void RGWEnv::set(std::string name, std::string val)
23 {
24 env_map[std::move(name)] = std::move(val);
25 }
26
27 void RGWEnv::init(CephContext *cct, char **envp)
28 {
29 const char *p;
30
31 env_map.clear();
32
33 for (int i=0; (p = envp[i]); ++i) {
34 string s(p);
35 int pos = s.find('=');
36 if (pos <= 0) // should never be 0
37 continue;
38 string name = s.substr(0, pos);
39 string val = s.substr(pos + 1);
40 env_map[name] = val;
41 }
42
43 init(cct);
44 }
45
46 const char *rgw_conf_get(const map<string, string, ltstr_nocase>& conf_map, const char *name, const char *def_val)
47 {
48 auto iter = conf_map.find(name);
49 if (iter == conf_map.end())
50 return def_val;
51
52 return iter->second.c_str();
53 }
54
55 const char *RGWEnv::get(const char *name, const char *def_val) const
56 {
57 return rgw_conf_get(env_map, name, def_val);
58 }
59
60 int rgw_conf_get_int(const map<string, string, ltstr_nocase>& conf_map, const char *name, int def_val)
61 {
62 auto iter = conf_map.find(name);
63 if (iter == conf_map.end())
64 return def_val;
65
66 const char *s = iter->second.c_str();
67 return atoi(s);
68 }
69
70 int RGWEnv::get_int(const char *name, int def_val) const
71 {
72 return rgw_conf_get_int(env_map, name, def_val);
73 }
74
75 bool rgw_conf_get_bool(const map<string, string, ltstr_nocase>& conf_map, const char *name, bool def_val)
76 {
77 auto iter = conf_map.find(name);
78 if (iter == conf_map.end())
79 return def_val;
80
81 const char *s = iter->second.c_str();
82 return rgw_str_to_bool(s, def_val);
83 }
84
85 bool RGWEnv::get_bool(const char *name, bool def_val)
86 {
87 return rgw_conf_get_bool(env_map, name, def_val);
88 }
89
90 size_t RGWEnv::get_size(const char *name, size_t def_val) const
91 {
92 const auto iter = env_map.find(name);
93 if (iter == env_map.end())
94 return def_val;
95
96 size_t sz;
97 try{
98 sz = stoull(iter->second);
99 } catch(...){
100 /* it is very unlikely that we'll ever encounter out_of_range, but let's
101 return the default eitherway */
102 sz = def_val;
103 }
104
105 return sz;
106 }
107
108 bool RGWEnv::exists(const char *name) const
109 {
110 return env_map.find(name)!= env_map.end();
111 }
112
113 bool RGWEnv::exists_prefix(const char *prefix) const
114 {
115 if (env_map.empty() || prefix == NULL)
116 return false;
117
118 const auto iter = env_map.lower_bound(prefix);
119 if (iter == env_map.end())
120 return false;
121
122 return (strncmp(iter->first.c_str(), prefix, strlen(prefix)) == 0);
123 }
124
125 void RGWEnv::remove(const char *name)
126 {
127 map<string, string, ltstr_nocase>::iterator iter = env_map.find(name);
128 if (iter != env_map.end())
129 env_map.erase(iter);
130 }
131
132 void RGWConf::init(CephContext *cct)
133 {
134 enable_ops_log = cct->_conf->rgw_enable_ops_log;
135 enable_usage_log = cct->_conf->rgw_enable_usage_log;
136
137 defer_to_bucket_acls = 0; // default
138 if (cct->_conf->rgw_defer_to_bucket_acls == "recurse") {
139 defer_to_bucket_acls = RGW_DEFER_TO_BUCKET_ACLS_RECURSE;
140 } else if (cct->_conf->rgw_defer_to_bucket_acls == "full_control") {
141 defer_to_bucket_acls = RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL;
142 }
143 }