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