]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_token.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 Red Hat, Inc
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
19 #include <boost/algorithm/string.hpp>
22 #include "common/ceph_json.h"
23 #include "common/Formatter.h"
24 #include "rgw/rgw_b64.h"
32 static constexpr auto type_name
= "RGW_TOKEN";
34 enum token_type
: uint32_t {
41 static enum token_type
to_type(const string
& s
) {
42 if (boost::iequals(s
, "ad"))
44 if (boost::iequals(s
, "ldap"))
46 if (boost::iequals(s
, "keystone"))
47 return TOKEN_KEYSTONE
;
51 static const char* from_type(enum token_type type
) {
71 virtual uint32_t version() const { return 1; };
74 return ((type
!= TOKEN_NONE
) &&
80 : type(TOKEN_NONE
) {};
82 RGWToken(enum token_type _type
, const std::string
& _id
,
83 const std::string
& _key
)
84 : type(_type
), id(_id
), key(_key
) {};
86 RGWToken(const string
& json
) {
88 p
.parse(json
.c_str(), json
.length());
89 JSONDecoder::decode_json(RGWToken::type_name
, *this, &p
);
92 void encode(bufferlist
& bl
) const {
93 uint32_t ver
= version();
94 string typestr
{from_type(type
)};
95 ENCODE_START(1, 1, bl
);
96 ::encode(type_name
, bl
);
98 ::encode(typestr
, bl
);
104 void decode(bufferlist::iterator
& bl
) {
110 ::decode(version
, bl
);
111 ::decode(typestr
, bl
);
112 type
= to_type(typestr
);
118 void dump(Formatter
* f
) const {
119 ::encode_json("version", uint32_t(version()), f
);
120 ::encode_json("type", from_type(type
), f
);
121 ::encode_json("id", id
, f
);
122 ::encode_json("key", key
, f
);
125 void encode_json(Formatter
* f
) {
126 RGWToken
& token
= *this;
127 f
->open_object_section(type_name
);
128 ::encode_json(type_name
, token
, f
);
132 void decode_json(JSONObj
* obj
) {
136 JSONDecoder::decode_json("version", version
, obj
);
137 JSONDecoder::decode_json("type", typestr
, obj
);
138 type
= to_type(typestr
);
139 JSONDecoder::decode_json("id", id
, obj
);
140 JSONDecoder::decode_json("key", key
, obj
);
143 std::string
encode_json_base64(Formatter
* f
) {
145 std::ostringstream os
;
147 return to_base64(std::move(os
.str()));
150 friend inline ostream
& operator<<(ostream
& os
, const RGWToken
& token
);
152 virtual ~RGWToken() {};
154 WRITE_CLASS_ENCODER(RGWToken
)
156 inline ostream
& operator<<(ostream
& os
, const RGWToken
& token
)
159 << " type=" << RGWToken::from_type(token
.type
)
160 << " id=" << token
.id
161 << " key=" << token
.key
166 } /* namespace rgw */
168 #endif /* RGW_TOKEN_H */