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