]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: print dict-like IAM Policy element as a dict
authorKefu Chai <kchai@redhat.com>
Thu, 16 Nov 2017 04:34:58 +0000 (12:34 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 16 Nov 2017 05:08:57 +0000 (13:08 +0800)
so they are printed like
{ Hello: World, Goodbye: [ Cruel, World ] }
instead of
[ Hello: World, Goodbye: [ Cruel, World ] ]

also, all of the print_dict() caller sites are protected by
`if (!foo.empty())`, so no need to check for empty.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/rgw/rgw_iam_policy.cc

index 1d9e2e53666c1377f893b30a562cd1e4ce63f911..dd11af883dd5e039fc9b4a42598e6032d0aa4330 100644 (file)
@@ -1193,6 +1193,15 @@ ostream& print_array(ostream& m, Iterator begin, Iterator end) {
   }
   return m;
 }
+
+template<typename Iterator>
+ostream& print_dict(ostream& m, Iterator begin, Iterator end) {
+  m << "{ ";
+  std::copy(begin, end, ceph::make_ostream_joiner(m, ", "));
+  m << " }";
+  return m;
+}
+
 }
 
 ostream& operator <<(ostream& m, const Condition& c) {
@@ -1433,12 +1442,12 @@ ostream& operator <<(ostream& m, const Statement& s) {
   }
   if (!s.princ.empty()) {
     m << "Principal: ";
-    print_array(m, s.princ.cbegin(), s.princ.cend());
+    print_dict(m, s.princ.cbegin(), s.princ.cend());
     m << ", ";
   }
   if (!s.noprinc.empty()) {
     m << "NotPrincipal: ";
-    print_array(m, s.noprinc.cbegin(), s.noprinc.cend());
+    print_dict(m, s.noprinc.cbegin(), s.noprinc.cend());
     m << ", ";
   }
 
@@ -1492,7 +1501,7 @@ ostream& operator <<(ostream& m, const Statement& s) {
 
   if (!s.conditions.empty()) {
     m << "Condition: ";
-    print_array(m, s.conditions.cbegin(), s.conditions.cend());
+    print_dict(m, s.conditions.cbegin(), s.conditions.cend());
   }
 
   return m << " }";