Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / rgw / rgw_basic_types.cc
1 #include <iostream>
2 #include <sstream>
3 #include <string>
4
5 #include "rgw_basic_types.h"
6 #include "common/ceph_json.h"
7
8 using std::string;
9 using std::stringstream;
10
11 void decode_json_obj(rgw_user& val, JSONObj *obj)
12 {
13   string s = obj->get_data();
14   val.from_str(s);
15 }
16
17 void encode_json(const char *name, const rgw_user& val, Formatter *f)
18 {
19   string s = val.to_str();
20   f->dump_string(name, s);
21 }
22
23 namespace rgw {
24 namespace auth {
25 ostream& operator <<(ostream& m, const Principal& p) {
26   if (p.is_wildcard()) {
27     return m << "*";
28   }
29
30   m << "arn:aws:iam:" << p.get_tenant() << ":";
31   if (p.is_tenant()) {
32     return m << "root";
33   }
34   return m << (p.is_user() ? "user/" : "role/") << p.get_id();
35 }
36 string to_string(const Principal& p) {
37   stringstream s;
38   s << p;
39   return s.str();
40 }
41 }
42 }