]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_basic_types.cc
import ceph 14.2.5
[ceph.git] / ceph / src / rgw / rgw_basic_types.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include <iostream>
5 #include <sstream>
6 #include <string>
7
8 #include "rgw_basic_types.h"
9 #include "rgw_xml.h"
10 #include "common/ceph_json.h"
11
12 using std::string;
13 using std::stringstream;
14
15 void decode_json_obj(rgw_user& val, JSONObj *obj)
16 {
17 val.from_str(obj->get_data());
18 }
19
20 void encode_json(const char *name, const rgw_user& val, Formatter *f)
21 {
22 f->dump_string(name, val.to_str());
23 }
24
25 void encode_xml(const char *name, const rgw_user& val, Formatter *f)
26 {
27 encode_xml(name, val.to_str(), f);
28 }
29
30 namespace rgw {
31 namespace auth {
32 ostream& operator <<(ostream& m, const Principal& p) {
33 if (p.is_wildcard()) {
34 return m << "*";
35 }
36
37 m << "arn:aws:iam:" << p.get_tenant() << ":";
38 if (p.is_tenant()) {
39 return m << "root";
40 }
41 return m << (p.is_user() ? "user/" : "role/") << p.get_id();
42 }
43 }
44 }