initial code repo
[stor4nfv.git] / src / ceph / src / rgw / rgw_basic_types.cc
diff --git a/src/ceph/src/rgw/rgw_basic_types.cc b/src/ceph/src/rgw/rgw_basic_types.cc
new file mode 100644 (file)
index 0000000..c16d920
--- /dev/null
@@ -0,0 +1,42 @@
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#include "rgw_basic_types.h"
+#include "common/ceph_json.h"
+
+using std::string;
+using std::stringstream;
+
+void decode_json_obj(rgw_user& val, JSONObj *obj)
+{
+  string s = obj->get_data();
+  val.from_str(s);
+}
+
+void encode_json(const char *name, const rgw_user& val, Formatter *f)
+{
+  string s = val.to_str();
+  f->dump_string(name, s);
+}
+
+namespace rgw {
+namespace auth {
+ostream& operator <<(ostream& m, const Principal& p) {
+  if (p.is_wildcard()) {
+    return m << "*";
+  }
+
+  m << "arn:aws:iam:" << p.get_tenant() << ":";
+  if (p.is_tenant()) {
+    return m << "root";
+  }
+  return m << (p.is_user() ? "user/" : "role/") << p.get_id();
+}
+string to_string(const Principal& p) {
+  stringstream s;
+  s << p;
+  return s.str();
+}
+}
+}