added support for urn name format. urn is the default name format used over the wire
[sfa.git] / sfa / methods / create_gid.py
1 ### $Id$
2 ### $URL$
3
4 from sfa.trust.certificate import Keypair 
5
6 from sfa.util.faults import *
7 from sfa.util.namespace import *
8 from sfa.util.method import Method
9 from sfa.util.parameter import Parameter, Mixed
10 from sfa.trust.gid import create_uuid
11 from sfa.trust.auth import Auth
12
13 class create_gid(Method):
14     """
15     Create a new GID. For MAs and SAs that are physically located on the
16     registry, this allows a owner/operator/PI to create a new GID and have it
17     signed by his respective authority.
18     
19     @param cred credential of caller
20     @param name hrn for new GID
21     @param uuid unique identifier for new GID
22     @param pkey_string public-key string (TODO: why is this a string and not a keypair object?)
23     
24     @return the string representation of a GID object
25     """
26
27     interfaces = ['registry']
28     
29     accepts = [
30         Parameter(str, "Credential string"),
31         Parameter(str, "Human readable name (hrn or urn)"),
32         Mixed(Parameter(str, "Unique identifier for new GID (uuid)"),
33               Parameter(None, "Unique identifier (uuid) not specified")),   
34         Parameter(str, "public-key string")
35         ]
36
37     returns = Parameter(str, "String represeneation of a GID object")
38     
39     def call(self, cred, xrn, uuid, pubkey_str):
40         
41         # convert urn to hrn     
42         hrn, type = hrn_to_urn(xrn) 
43
44         # validate the credential
45         self.api.auth.check(cred, "getcredential")
46         self.api.auth.verify_object_belongs_to_me(hrn)
47         self.api.auth.verify_object_permission(hrn)
48
49         if uuid == None:
50             uuid = create_uuid()
51
52         pkey = Keypair()
53         pkey.load_pubkey_from_string(pubkey_str)
54         gid = self.api.auth.hierarchy.create_gid(xrn, uuid, pkey)
55
56         return gid.save_to_string(save_parents=True)