#include "cls/user/cls_user_types.h"
+#include "rgw_account.h"
#include "rgw_basic_types.h"
#include "rgw_bucket.h"
#include "rgw_xml.h"
{
decode_json_obj(static_cast<std::string&>(id), obj);
}
+
+// rgw_owner variant
+rgw_owner parse_owner(const std::string& str)
+{
+ if (rgw::account::validate_id(str)) {
+ return rgw_account_id{str};
+ } else {
+ return rgw_user{str};
+ }
+}
+
+std::string to_string(const rgw_owner& o)
+{
+ struct visitor {
+ std::string operator()(const rgw_account_id& a) { return a; }
+ std::string operator()(const rgw_user& u) { return u.to_str(); }
+ };
+ return std::visit(visitor{}, o);
+}
+
+std::ostream& operator<<(std::ostream& out, const rgw_owner& o)
+{
+ struct visitor {
+ std::ostream& out;
+ std::ostream& operator()(const rgw_account_id& a) { return out << a; }
+ std::ostream& operator()(const rgw_user& u) { return out << u; }
+ };
+ return std::visit(visitor{out}, o);
+}
+
+void encode_json_impl(const char *name, const rgw_owner& o, ceph::Formatter *f)
+{
+ encode_json(name, to_string(o), f);
+}
+
+void decode_json_obj(rgw_owner& o, JSONObj *obj)
+{
+ std::string str;
+ decode_json_obj(str, obj);
+ o = parse_owner(str);
+}
#pragma once
+#include <iosfwd>
#include <string>
+#include <variant>
#include <fmt/format.h>
#include "common/dout.h"
static void generate_test_instances(std::list<rgw_user*>& o);
};
WRITE_CLASS_ENCODER(rgw_user)
+
+
+/// Resources are either owned by accounts, or by users or roles (represented as
+/// rgw_user) that don't belong to an account.
+///
+/// This variant is present in binary encoding formats, so existing types cannot
+/// be changed or removed. New types can only be added to the end.
+using rgw_owner = std::variant<rgw_user, rgw_account_id>;
+
+rgw_owner parse_owner(const std::string& str);
+std::string to_string(const rgw_owner& o);
+
+std::ostream& operator<<(std::ostream& out, const rgw_owner& o);
+
+void encode_json_impl(const char *name, const rgw_owner& o, ceph::Formatter *f);
+void decode_json_obj(rgw_owner& o, JSONObj *obj);