renaming the toplevel geni/ package into sfa/
[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.method import Method
8 from sfa.util.parameter import Parameter, Mixed
9 from sfa.util.auth import Auth
10
11 class create_gid(Method):
12     """
13     Create a new GID. For MAs and SAs that are physically located on the
14     registry, this allows a owner/operator/PI to create a new GID and have it
15     signed by his respective authority.
16     
17     @param cred credential of caller
18     @param name hrn for new GID
19     @param uuid unique identifier for new GID
20     @param pkey_string public-key string (TODO: why is this a string and not a keypair object?)
21     
22     @return the string representation of a GID object
23     """
24
25     interfaces = ['registry']
26     
27     accepts = [
28         Parameter(str, "Credential string"),
29         Parameter(str, "Human readable name (hrn)"),
30         Mixed(Parameter(str, "Unique identifier for new GID (uuid)"),
31               Parameter(None, "Unique identifier (uuid) not specified")),   
32         Parameter(str, "public-key string")
33         ]
34
35     returns = Parameter(str, "String represeneation of a GID object")
36     
37     def call(self, cred, hrn, uuid, pubkey_str):
38         self.api.auth.check(cred, "getcredential")
39         self.api.auth.verify_object_belongs_to_me(hrn)
40         self.api.auth.verify_object_permission(hrn)
41
42         if uuid == None:
43             uuid = create_uuid()
44
45         pkey = Keypair()
46         pkey.load_pubkey_from_string(pubkey_str)
47         gid = self.api.auth.hierarchy.create_gid(hrn, uuid, pkey)
48
49         return gid.save_to_string(save_parents=True)