]>
git.proxmox.com Git - ceph.git/blob - 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 ft=cpp
8 #include "cls/user/cls_user_types.h"
10 #include "rgw_basic_types.h"
12 #include "common/ceph_json.h"
15 using std::stringstream
;
17 void decode_json_obj(rgw_user
& val
, JSONObj
*obj
)
19 val
.from_str(obj
->get_data());
22 void encode_json(const char *name
, const rgw_user
& val
, Formatter
*f
)
24 f
->dump_string(name
, val
.to_str());
27 void encode_xml(const char *name
, const rgw_user
& val
, Formatter
*f
)
29 encode_xml(name
, val
.to_str(), f
);
32 rgw_bucket::rgw_bucket(const rgw_user
& u
, const cls_user_bucket
& b
) :
36 bucket_id(b
.bucket_id
),
37 explicit_placement(b
.explicit_placement
.data_pool
,
38 b
.explicit_placement
.data_extra_pool
,
39 b
.explicit_placement
.index_pool
)
43 void rgw_bucket::convert(cls_user_bucket
*b
) const
47 b
->bucket_id
= bucket_id
;
48 b
->explicit_placement
.data_pool
= explicit_placement
.data_pool
.to_str();
49 b
->explicit_placement
.data_extra_pool
= explicit_placement
.data_extra_pool
.to_str();
50 b
->explicit_placement
.index_pool
= explicit_placement
.index_pool
.to_str();
53 std::string
rgw_bucket::get_key(char tenant_delim
, char id_delim
, size_t reserve
) const
55 const size_t max_len
= tenant
.size() + sizeof(tenant_delim
) +
56 name
.size() + sizeof(id_delim
) + bucket_id
.size() + reserve
;
60 if (!tenant
.empty() && tenant_delim
) {
62 key
.append(1, tenant_delim
);
65 if (!bucket_id
.empty() && id_delim
) {
66 key
.append(1, id_delim
);
67 key
.append(bucket_id
);
72 std::string
rgw_bucket_shard::get_key(char tenant_delim
, char id_delim
,
73 char shard_delim
) const
75 static constexpr size_t shard_len
{12}; // ":4294967295\0"
76 auto key
= bucket
.get_key(tenant_delim
, id_delim
, shard_len
);
77 if (shard_id
>= 0 && shard_delim
) {
78 key
.append(1, shard_delim
);
79 key
.append(std::to_string(shard_id
));
84 void encode_json_impl(const char *name
, const rgw_zone_id
& zid
, Formatter
*f
)
86 encode_json(name
, zid
.id
, f
);
89 void decode_json_obj(rgw_zone_id
& zid
, JSONObj
*obj
)
91 decode_json_obj(zid
.id
, obj
);
96 ostream
& operator <<(ostream
& m
, const Principal
& p
) {
97 if (p
.is_wildcard()) {
101 m
<< "arn:aws:iam:" << p
.get_tenant() << ":";
105 return m
<< (p
.is_user() ? "user/" : "role/") << p
.get_id();