]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_basic_types.cc
update sources to v12.1.0
[ceph.git] / ceph / src / rgw / rgw_basic_types.cc
CommitLineData
31f18b77
FG
1#include <iostream>
2#include <sstream>
3#include <string>
4
7c673cae
FG
5#include "rgw_basic_types.h"
6#include "common/ceph_json.h"
7
31f18b77
FG
8using std::string;
9using std::stringstream;
10
7c673cae
FG
11void decode_json_obj(rgw_user& val, JSONObj *obj)
12{
13 string s = obj->get_data();
14 val.from_str(s);
15}
16
17void 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}
31f18b77
FG
22
23namespace rgw {
24namespace auth {
25ostream& 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}
36string to_string(const Principal& p) {
37 stringstream s;
38 s << p;
39 return s.str();
40}
41}
42}