dos2unix'ed
[sfa.git] / sfa / trust / credential_legacy.py
index dc02941..b5fc449 100644 (file)
@@ -1,3 +1,25 @@
+#----------------------------------------------------------------------
+# Copyright (c) 2008 Board of Trustees, Princeton University
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and/or hardware specification (the "Work") to
+# deal in the Work without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Work, and to permit persons to whom the Work
+# is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Work.
+#
+# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS 
+# IN THE WORK.
+#----------------------------------------------------------------------
 ##
 # Implements SFA Credentials
 #
 # certificate that stores a tuple of parameters.
 ##
 
-### $Id: credential.py 17477 2010-03-25 16:49:34Z jkarlin $
-### $URL: svn+ssh://svn.planet-lab.org/svn/sfa/branches/geni-api/sfa/trust/credential.py $
 
 import xmlrpclib
 
+from sfa.util.faults import MissingDelegateBit, ChildRightsNotSubsetOfParent
 from sfa.trust.certificate import Certificate
-from sfa.trust.rights import *
-from sfa.trust.gid import *
-from sfa.util.faults import *
+from sfa.trust.gid import GID
 
 ##
 # Credential is a tuple:
@@ -110,16 +129,16 @@ class CredentialLegacy(Certificate):
     ##
     # set the privileges
     #
-    # @param privs either a comma-separated list of privileges of a RightList object
+    # @param privs either a comma-separated list of privileges of a Rights object
 
     def set_privileges(self, privs):
         if isinstance(privs, str):
-            self.privileges = RightList(string = privs)
+            self.privileges = Rights(string = privs)
         else:
             self.privileges = privs
 
     ##
-    # return the privileges as a RightList object
+    # return the privileges as a Rights object
 
     def get_privileges(self):
         if not self.privileges:
@@ -176,7 +195,7 @@ class CredentialLegacy(Certificate):
 
         privStr = dict.get("privileges", None)
         if privStr:
-            self.privileges = RightList(string = privStr)
+            self.privileges = Rights(string = privStr)
         else:
             self.privileges = None
 
@@ -223,24 +242,29 @@ class CredentialLegacy(Certificate):
     #
     # @param dump_parents If true, also dump the parent certificates
 
-    def dump(self, dump_parents=False):
-        print "CREDENTIAL", self.get_subject()
+    def dump(self, *args, **kwargs):
+        print self.dump_string(*args,**kwargs)
+
+    def dump_string(self, dump_parents=False):
+        result=""
+        result += "CREDENTIAL %s\n" % self.get_subject()
 
-        print "      privs:", self.get_privileges().save_to_string()
+        result += "      privs: %s\n" % self.get_privileges().save_to_string()
 
-        print "  gidCaller:"
         gidCaller = self.get_gid_caller()
         if gidCaller:
+            result += "  gidCaller:\n"
             gidCaller.dump(8, dump_parents)
 
-        print "  gidObject:"
         gidObject = self.get_gid_object()
         if gidObject:
-            gidObject.dump(8, dump_parents)
+            result += "  gidObject:\n"
+            result += gidObject.dump_string(8, dump_parents)
 
-        print "   delegate:", self.get_delegate()
+        result += "   delegate: %s" % self.get_delegate()
 
         if self.parent and dump_parents:
-           print "PARENT",
-           self.parent.dump(dump_parents)
+            result += "PARENT\n"
+            result += self.parent.dump_string(dump_parents)
 
+        return result