2 # Geni Registry Wrapper
4 # This wrapper implements the Geni Registry.
6 # There are several items that need to be done before starting the registry.
8 # 1) Update util/config.py to match the parameters of your PLC installation.
10 # 2) Import the existing planetlab database, creating the
11 # appropriate geni records. This is done by running the "import.py" tool.
13 # 3) Create a "trusted_roots" directory and place the certificate of the root
14 # authority in that directory. Given the defaults in import.py, this certificate
15 # would be named "planetlab.gid". For example,
17 # mkdir trusted_roots; cp authorities/planetlab.gid trusted_roots/
27 from geniserver import *
29 from trustedroot import *
30 from hierarchy import *
33 from genitable import *
34 from geniticket import *
37 # Convert geni fields to PLC fields for use when registering up updating
38 # registry record in the PLC database
40 # @params type type of record (user, slice, ...)
41 # @params hrn human readable name
42 # @params geni_fields dictionary of geni fields
43 # @params pl_fields dictionary of PLC fields (output)
45 def geni_fields_to_pl_fields(type, hrn, geni_fields, pl_fields):
47 if not "email" in pl_fields:
48 if not "email" in geni_fields:
49 raise MissingGeniInfo("email")
50 pl_fields["email"] = geni_fields["email"]
52 if not "first_name" in pl_fields:
53 pl_fields["first_name"] = "geni"
55 if not "last_name" in pl_fields:
56 pl_fields["last_name"] = hrn
59 if not "instantiation" in pl_fields:
60 pl_fields["instantiation"] = "plc-instantiated"
61 if not "name" in pl_fields:
62 pl_fields["name"] = hrn_to_pl_slicename(hrn)
63 if not "max_nodes" in pl_fields:
64 pl_fields["max_nodes"] = 10
67 if not "hostname" in pl_fields:
68 if not "dns" in geni_fields:
69 raise MissingGeniInfo("dns")
70 pl_fields["hostname"] = geni_fields["dns"]
72 if not "model" in pl_fields:
73 pl_fields["model"] = "geni"
76 pl_fields["login_base"] = hrn_to_pl_login_base(hrn)
78 if not "name" in pl_fields:
79 pl_fields["name"] = hrn
81 if not "abbreviated_name" in pl_fields:
82 pl_fields["abbreviated_name"] = hrn
84 if not "enabled" in pl_fields:
85 pl_fields["enabled"] = True
87 if not "is_public" in pl_fields:
88 pl_fields["is_public"] = True
91 # Registry is a GeniServer that serves registry requests. It also serves
92 # component and slice operations that are implemented on the registry
93 # due to SFA engineering decisions
96 class Registry(GeniServer):
98 # Create a new registry object.
100 # @param ip the ip address to listen on
101 # @param port the port to listen on
102 # @param key_file private key filename of registry
103 # @param cert_file certificate filename containing public key (could be a GID file)
105 def __init__(self, ip, port, key_file, cert_file):
106 GeniServer.__init__(self, ip, port, key_file, cert_file)
108 # get PL account settings from config module
109 self.pl_auth = get_pl_auth()
111 # connect to planetlab
112 if "Url" in self.pl_auth:
113 self.connect_remote_shell()
115 self.connect_local_shell()
118 # Connect to a remote shell via XMLRPC
120 def connect_remote_shell(self):
122 self.shell = remoteshell.RemoteShell()
125 # Connect to a local shell via local API functions
127 def connect_local_shell(self):
129 self.shell = PLC.Shell.Shell(globals = globals())
132 # Register the server RPCs for the registry
134 def register_functions(self):
135 GeniServer.register_functions(self)
137 self.server.register_function(self.create_gid)
138 self.server.register_function(self.get_self_credential)
139 self.server.register_function(self.get_credential)
140 self.server.register_function(self.get_gid)
141 self.server.register_function(self.register)
142 self.server.register_function(self.remove)
143 self.server.register_function(self.update)
144 self.server.register_function(self.list)
145 self.server.register_function(self.resolve)
146 # component interface
147 self.server.register_function(self.get_ticket)
150 # Given an authority name, return the information for that authority. This
151 # is basically a stub that calls the hierarchy module.
153 # @param auth_hrn human readable name of authority
155 def get_auth_info(self, auth_hrn):
156 return AuthHierarchy.get_auth_info(auth_hrn)
159 # Given an authority name, return the database table for that authority. If
160 # the database table does not exist, then one will be automatically
163 # @param auth_name human readable name of authority
165 def get_auth_table(self, auth_name):
166 auth_info = self.get_auth_info(auth_name)
168 table = GeniTable(hrn=auth_name,
169 cninfo=auth_info.get_dbinfo())
171 # if the table doesn't exist, then it means we haven't put any records
172 # into this authority yet.
174 if not table.exists():
175 report.trace("Registry: creating table for authority " + auth_name)
181 # Verify that an authority belongs to this registry. This is basically left
182 # up to the implementation of the hierarchy module. If the specified name
183 # does not belong to this registry, an exception is thrown indicating the
184 # caller should contact someone else.
186 # @param auth_name human readable name of authority
188 def verify_auth_belongs_to_me(self, name):
189 # get_auth_info will throw an exception if the authority does not
191 self.get_auth_info(name)
194 # Verify that an object belongs to this registry. By extension, this implies
195 # that the authority that owns the object belongs to this registry. If the
196 # object does not belong to this registry, then an exception is thrown.
198 # @param name human readable name of object
200 def verify_object_belongs_to_me(self, name):
201 auth_name = get_authority(name)
203 # the root authority belongs to the registry by default?
204 # TODO: is this true?
206 self.verify_auth_belongs_to_me(auth_name)
209 # Verify that the object_gid that was specified in the credential allows
210 # permission to the object 'name'. This is done by a simple prefix test.
211 # For example, an object_gid for planetlab.us.arizona would match the
212 # objects planetlab.us.arizona.slice1 and planetlab.us.arizona.
214 # @param name human readable name to test
216 def verify_object_permission(self, name):
217 object_hrn = self.object_gid.get_hrn()
218 if object_hrn == name:
220 if name.startswith(object_hrn + "."):
222 raise PermissionError(name)
225 # Fill in the planetlab-specific fields of a Geni record. This involves
226 # calling the appropriate PLC methods to retrieve the database record for
229 # PLC data is filled into the pl_info field of the record.
231 # @param record record to fill in fields (in/out param)
233 def fill_record_pl_info(self, record):
234 type = record.get_type()
235 pointer = record.get_pointer()
237 # records with pointer==-1 do not have plc info associated with them.
238 # for example, the top level authority records which are
239 # authorities, but not PL "sites"
243 if (type == "sa") or (type == "ma"):
244 pl_res = self.shell.GetSites(self.pl_auth, [pointer])
245 elif (type == "slice"):
246 pl_res = self.shell.GetSlices(self.pl_auth, [pointer])
247 elif (type == "user"):
248 pl_res = self.shell.GetPersons(self.pl_auth, [pointer])
249 elif (type == "node"):
250 pl_res = self.shell.GetNodes(self.pl_auth, [pointer])
252 raise UnknownGeniType(type)
255 # the planetlab record no longer exists
256 # TODO: delete the geni record ?
257 raise PlanetLabRecordDoesNotExist(record.get_name())
259 record.set_pl_info(pl_res[0])
262 # Look up user records given PLC user-ids. This is used as part of the
263 # process for reverse-mapping PLC records into Geni records.
265 # @param auth_table database table for the authority that holds the user records
266 # @param user_id_list list of user ids
267 # @param role either "*" or a string describing the role to look for ("pi", "user", ...)
269 # TODO: This function currently only searches one authority because it would
270 # be inefficient to brute-force search all authorities for a user id. The
271 # solution would likely be to implement a reverse mapping of user-id to
274 def lookup_users(self, auth_table, user_id_list, role="*"):
276 for person_id in user_id_list:
277 user_records = auth_table.find("user", person_id, "pointer")
278 for user_record in user_records:
279 self.fill_record_info(user_record)
281 user_roles = user_record.get_pl_info().get("roles")
282 if (role=="*") or (role in user_roles):
283 record_list.append(user_record.get_name())
287 # Fill in the geni-specific fields of the record.
289 # Note: It is assumed the fill_record_pl_info() has already been performed
292 def fill_record_geni_info(self, record):
294 type = record.get_type()
296 if (type == "slice"):
297 auth_table = self.get_auth_table(get_authority(record.get_name()))
298 person_ids = record.pl_info.get("person_ids", [])
299 researchers = self.lookup_users(auth_table, person_ids)
300 geni_info['researcher'] = researchers
303 auth_table = self.get_auth_table(record.get_name())
304 person_ids = record.pl_info.get("person_ids", [])
305 pis = self.lookup_users(auth_table, person_ids, "pi")
306 geni_info['pi'] = pis
307 # TODO: OrganizationName
310 auth_table = self.get_auth_table(record.get_name())
311 person_ids = record.pl_info.get("person_ids", [])
312 operators = self.lookup_users(auth_table, person_ids, "tech")
313 geni_info['operator'] = operators
314 # TODO: OrganizationName
316 auth_table = self.get_auth_table(record.get_name())
317 person_ids = record.pl_info.get("person_ids", [])
318 owners = self.lookup_users(auth_table, person_ids, "admin")
319 geni_info['owner'] = owners
321 elif (type == "node"):
322 geni_info['dns'] = record.pl_info.get("hostname", "")
323 # TODO: URI, LatLong, IP, DNS
325 elif (type == "user"):
326 geni_info['email'] = record.pl_info.get("email", "")
327 # TODO: PostalAddress, Phone
329 record.set_geni_info(geni_info)
332 # Given a Geni record, fill in the PLC-specific and Geni-specific fields
335 def fill_record_info(self, record):
336 self.fill_record_pl_info(record)
337 self.fill_record_geni_info(record)
342 # Register an object with the registry. In addition to being stored in the
343 # Geni database, the appropriate records will also be created in the
346 # @param cred credential string
347 # @param record_dict dictionary containing record fields
349 def register(self, cred, record_dict):
350 self.decode_authentication(cred, "register")
352 record = GeniRecord(dict = record_dict)
353 type = record.get_type()
354 name = record.get_name()
356 auth_name = get_authority(name)
357 self.verify_object_permission(auth_name)
358 auth_info = self.get_auth_info(auth_name)
359 table = self.get_auth_table(auth_name)
363 # check if record already exists
364 existing_records = table.resolve(type, name)
366 raise ExistingRecord(name)
368 if (type == "sa") or (type=="ma"):
370 if not AuthHierarchy.auth_exists(name):
371 AuthHierarchy.create_auth(name)
373 # authorities are special since they are managed by the registry
374 # rather than by the caller. We create our own GID for the
375 # authority rather than relying on the caller to supply one.
377 # get the GID from the newly created authority
378 child_auth_info = self.get_auth_info(name)
379 gid = auth_info.get_gid_object()
380 record.set_gid(gid.save_to_string(save_parents=True))
382 geni_fields = record.get_geni_info()
383 site_fields = record.get_pl_info()
385 # if registering a sa, see if a ma already exists
386 # if registering a ma, see if a sa already exists
388 other_rec = table.resolve("ma", record.get_name())
390 other_rec = table.resolve("sa", record.get_name())
393 print "linking ma and sa to the same plc site"
394 pointer = other_rec[0].get_pointer()
396 geni_fields_to_pl_fields(type, name, geni_fields, site_fields)
397 print "adding site with fields", site_fields
398 pointer = self.shell.AddSite(self.pl_auth, site_fields)
400 record.set_pointer(pointer)
402 elif (type == "slice"):
403 geni_fields = record.get_geni_info()
404 slice_fields = record.get_pl_info()
406 geni_fields_to_pl_fields(type, name, geni_fields, slice_fields)
408 pointer = self.shell.AddSlice(self.pl_auth, slice_fields)
409 record.set_pointer(pointer)
411 elif (type == "user"):
412 geni_fields = record.get_geni_info()
413 user_fields = record.get_pl_info()
415 geni_fields_to_pl_fields(type, name, geni_fields, user_fields)
417 pointer = self.shell.AddPerson(self.pl_auth, user_fields)
418 record.set_pointer(pointer)
420 elif (type == "node"):
421 geni_fields = record.get_geni_info()
422 node_fields = record.get_pl_info()
424 geni_fields_to_pl_fields(type, name, geni_fields, node_fields)
426 login_base = hrn_to_pl_login_base(auth_name)
428 print "calling addnode with", login_base, node_fields
429 pointer = self.shell.AddNode(self.pl_auth, login_base, node_fields)
430 record.set_pointer(pointer)
433 raise UnknownGeniType(type)
437 return record.get_gid_object().save_to_string(save_parents=True)
442 # Remove an object from the registry. If the object represents a PLC object,
443 # then the PLC records will also be removed.
445 # @param cred credential string
446 # @param record_dict dictionary containing record fields. The only relevant
447 # fields of the record are 'name' and 'type', which are used to lookup
448 # the current copy of the record in the Geni database, to make sure
449 # that the appopriate record is removed.
451 def remove(self, cred, record_dict):
452 self.decode_authentication(cred, "remove")
454 record = GeniRecord(dict = record_dict)
455 type = record.get_type()
457 self.verify_object_permission(record.get_name())
459 auth_name = get_authority(record.get_name())
460 table = self.get_auth_table(auth_name)
462 # let's not trust that the caller has a well-formed record (a forged
463 # pointer field could be a disaster), so look it up ourselves
464 record_list = table.resolve(type, record.get_name())
466 raise RecordNotFound(name)
467 record = record_list[0]
471 self.shell.DeletePerson(self.pl_auth, record.get_pointer())
472 elif type == "slice":
473 self.shell.DeleteSlice(self.pl_auth, record.get_pointer())
475 self.shell.DeleteNode(self.pl_auth, record.get_pointer())
476 elif (type == "sa") or (type == "ma"):
478 other_rec = table.resolve("ma", record.get_name())
480 other_rec = table.resolve("sa", record.get_name())
483 # sa and ma both map to a site, so if we are deleting one
484 # but the other still exists, then do not delete the site
485 print "not removing site", record.get_name(), "because either sa or ma still exists"
488 print "removing site", record.get_name()
489 self.shell.DeleteSite(self.pl_auth, record.get_pointer())
491 raise UnknownGeniType(type)
500 # Update an object in the registry. Currently, this only updates the
501 # PLC information associated with the record. The Geni fields (name, type,
504 # The record is expected to have the pl_info field filled in with the data
505 # that should be updated.
507 # TODO: The geni_info member of the record should be parsed and the pl_info
508 # adjusted as necessary (add/remove users from a slice, etc)
510 # @param cred credential string specifying rights of the caller
511 # @param record a record dictionary to be updated
513 def update(self, cred, record_dict):
514 self.decode_authentication(cred, "update")
516 record = GeniRecord(dict = record_dict)
517 type = record.get_type()
519 self.verify_object_permission(record.get_name())
521 auth_name = get_authority(record.get_name())
522 table = self.get_auth_table(auth_name)
524 # make sure the record exists
525 existing_record_list = table.resolve(type, record.get_name())
526 if not existing_record_list:
527 raise RecordNotFound(record.get_name())
529 existing_record = existing_record_list[0]
530 pointer = existing_record.get_pointer()
532 # update the PLC information that was specified with the record
534 if (type == "sa") or (type == "ma"):
535 self.shell.UpdateSite(self.pl_auth, pointer, record.get_pl_info())
537 elif type == "slice":
538 self.shell.UpdateSlice(self.pl_auth, pointer, record.get_pl_info())
541 self.shell.UpdatePerson(self.pl_auth, pointer, record.get_pl_info())
544 self.shell.UpdateNode(self.pl_auth, pointer, record.get_pl_info())
547 raise UnknownGeniType(type)
550 # List the records in an authority. The objectGID in the supplied credential
551 # should name the authority that will be listed.
553 # TODO: List doesn't take an hrn and uses the hrn contained in the
554 # objectGid of the credential. Does this mean the only way to list an
555 # authority is by having a credential for that authority?
557 # @param cred credential string specifying rights of the caller
559 # @return list of record dictionaries
560 def list(self, cred):
561 self.decode_authentication(cred, "list")
563 auth_name = self.object_gid.get_hrn()
564 table = self.get_auth_table(auth_name)
566 records = table.list()
569 for record in records:
571 self.fill_record_info(record)
572 good_records.append(record)
573 except PlanetLabRecordDoesNotExist:
574 # silently drop the ones that are missing in PL.
575 # is this the right thing to do?
576 report.error("ignoring geni record " + record.get_name() + " because pl record does not exist")
580 for record in good_records:
581 dicts.append(record.as_dict())
588 # Resolve a record. This is an internal version of the Resolve API call
589 # and returns records in record object format rather than dictionaries
590 # that may be sent over XMLRPC.
592 # @param type type of record to resolve (user | sa | ma | slice | node)
593 # @param name human readable name of object
594 # @param must_exist if True, throw an exception if no records are found
596 # @return a list of record objects, or an empty list []
598 def resolve_raw(self, type, name, must_exist=True):
599 auth_name = get_authority(name)
601 table = self.get_auth_table(auth_name)
603 records = table.resolve(type, name)
605 if (not records) and must_exist:
606 raise RecordNotFound(name)
609 for record in records:
611 self.fill_record_info(record)
612 good_records.append(record)
613 except PlanetLabRecordDoesNotExist:
614 # silently drop the ones that are missing in PL.
615 # is this the right thing to do?
616 report.error("ignoring geni record " + record.get_name() + " because pl record does not exist")
624 # This is a wrapper around resolve_raw that converts records objects into
625 # dictionaries before returning them to the user.
627 # @param cred credential string authorizing the caller
628 # @param name human readable name to resolve
630 # @return a list of record dictionaries, or an empty list
632 def resolve(self, cred, name):
633 self.decode_authentication(cred, "resolve")
635 records = self.resolve_raw("*", name)
637 for record in records:
638 dicts.append(record.as_dict())
645 # Retrieve the GID for an object. This function looks up a record in the
646 # registry and returns the GID of the record if it exists.
647 # TODO: Is this function needed? It's a shortcut for Resolve()
649 # @param name hrn to look up
651 # @return the string representation of a GID object
653 def get_gid(self, name):
654 self.verify_object_belongs_to_me(name)
655 records = self.resolve_raw("*", name)
657 for record in records:
658 gid = record.get_gid()
659 gid_string_list.append(gid.save_to_string(save_parents=True))
660 return gid_string_list
663 # Determine tje rights that an object should have. The rights are entirely
664 # dependent on the type of the object. For example, users automatically
665 # get "refresh", "resolve", and "info".
667 # @param type the type of the object (user | sa | ma | slice | node)
668 # @param name human readable name of the object (not used at this time)
670 # @return RightList object containing rights
672 def determine_rights(self, type, name):
675 # rights seem to be somewhat redundant with the type of the credential.
676 # For example, a "sa" credential implies the authority right, because
677 # a sa credential cannot be issued to a user who is not an owner of
688 elif type == "slice":
693 elif type == "component":
699 # GENI API: Get_self_credential
701 # Get_self_credential a degenerate version of get_credential used by a
702 # client to get his initial credential when he doesn't have one. This is
703 # the same as get_credential(..., cred=None,...).
705 # The registry ensures that the client is the principal that is named by
706 # (type, name) by comparing the public key in the record's GID to the
707 # private key used to encrypt the client-side of the HTTPS connection. Thus
708 # it is impossible for one principal to retrieve another principal's
709 # credential without having the appropriate private key.
711 # @param type type of object (user | slice | sa | ma | node
712 # @param name human readable name of object
714 # @return the string representation of a credential object
716 def get_self_credential(self, type, name):
717 self.verify_object_belongs_to_me(name)
719 auth_hrn = get_authority(name)
720 auth_info = self.get_auth_info(auth_hrn)
722 # find a record that matches
723 records = self.resolve_raw(type, name, must_exist=True)
726 gid = record.get_gid_object()
727 peer_cert = self.server.peer_cert
728 if not peer_cert.is_pubkey(gid.get_pubkey()):
729 raise ConnectionKeyGIDMismatch(gid.get_subject())
731 # create the credential
732 gid = record.get_gid_object()
733 cred = Credential(subject = gid.get_subject())
734 cred.set_gid_caller(gid)
735 cred.set_gid_object(gid)
736 cred.set_issuer(key=auth_info.get_pkey_object(), subject=auth_hrn)
737 cred.set_pubkey(gid.get_pubkey())
739 rl = self.determine_rights(type, name)
740 cred.set_privileges(rl)
742 cred.set_parent(AuthHierarchy.get_auth_cred(auth_hrn))
747 return cred.save_to_string(save_parents=True)
750 # GENI API: Get_credential
752 # Retrieve a credential for an object.
754 # If cred==None, then the behavior reverts to get_self_credential()
756 # @param cred credential object specifying rights of the caller
757 # @param type type of object (user | slice | sa | ma | node)
758 # @param name human readable name of object
760 # @return the string representation of a credental object
762 def get_credential(self, cred, type, name):
764 return get_self_credential(self, type, name)
766 self.decode_authentication(cred, "getcredential")
768 self.verify_object_belongs_to_me(name)
770 auth_hrn = get_authority(name)
771 auth_info = self.get_auth_info(auth_hrn)
773 records = self.resolve_raw(type, name, must_exist=True)
776 # TODO: Check permission that self.client_cred can access the object
778 object_gid = record.get_gid_object()
779 new_cred = Credential(subject = object_gid.get_subject())
780 new_cred.set_gid_caller(self.client_gid)
781 new_cred.set_gid_object(object_gid)
782 new_cred.set_issuer(key=auth_info.get_pkey_object(), subject=auth_hrn)
783 new_cred.set_pubkey(object_gid.get_pubkey())
785 rl = self.determine_rights(type, name)
786 new_cred.set_privileges(rl)
788 new_cred.set_parent(AuthHierarchy.get_auth_cred(auth_hrn))
793 return new_cred.save_to_string(save_parents=True)
796 # GENI_API: Create_gid
798 # Create a new GID. For MAs and SAs that are physically located on the
799 # registry, this allows a owner/operator/PI to create a new GID and have it
800 # signed by his respective authority.
802 # @param cred credential of caller
803 # @param name hrn for new GID
804 # @param uuid unique identifier for new GID
805 # @param pkey_string public-key string (TODO: why is this a string and not a keypair object?)
807 # @return the string representation of a GID object
809 def create_gid(self, cred, name, uuid, pubkey_str):
810 self.decode_authentication(cred, "getcredential")
812 self.verify_object_belongs_to_me(name)
814 self.verify_object_permission(name)
820 pkey.load_pubkey_from_string(pubkey_str)
821 gid = AuthHierarchy.create_gid(name, uuid, pkey)
823 return gid.save_to_string(save_parents=True)
825 # ------------------------------------------------------------------------
826 # Component Interface
829 # Convert a PLC record into the slice information that will be stored in
830 # a ticket. There are two parts to this information: attributes and
833 # Attributes are non-resource items, such as keys and the initscript
834 # Rspec is a set of resource specifications
836 # @param record a record object
838 # @return a tuple (attrs, rspec) of dictionaries
840 def record_to_slice_info(self, record):
842 # get the user keys from the slice
844 persons = self.shell.GetPersons(self.pl_auth, record.pl_info['person_ids'])
845 for person in persons:
846 person_keys = self.shell.GetKeys(self.pl_auth, person["key_ids"])
847 for person_key in person_keys:
848 keys = keys + [person_key['key']]
851 attributes['name'] = record.pl_info['name']
852 attributes['keys'] = keys
853 attributes['instantiation'] = record.pl_info['instantiation']
854 attributes['vref'] = 'default'
855 attributes['timestamp'] = time.time()
859 # get the PLC attributes and separate them into slice attributes and
862 filter['slice_id'] = record.pl_info['slice_id']
863 plc_attrs = self.shell.GetSliceAttributes(self.pl_auth, filter)
864 for attr in plc_attrs:
867 # initscripts: lookup the contents of the initscript and store it
868 # in the ticket attributes
869 if (name == "initscript"):
870 filter={'name': attr['value']}
871 initscripts = self.shell.GetInitScripts(self.pl_auth, filter)
873 attributes['initscript'] = initscripts[0]['script']
875 rspec[name] = attr['value']
877 return (attributes, rspec)
880 # GENI API: get_ticket
882 # Retrieve a ticket. This operation is currently implemented on the
883 # registry (see SFA, engineering decisions), and is not implemented on
886 # The ticket is filled in with information from the PLC database. This
887 # information includes resources, and attributes such as user keys and
890 # @param cred credential string
891 # @param name name of the slice to retrieve a ticket for
892 # @param rspec resource specification dictionary
894 # @return the string representation of a ticket object
896 def get_ticket(self, cred, name, rspec):
897 self.decode_authentication(cred, "getticket")
899 self.verify_object_belongs_to_me(name)
901 self.verify_object_permission(name)
903 # XXX much of this code looks like get_credential... are they so similar
904 # that they should be combined?
906 auth_hrn = get_authority(name)
907 auth_info = self.get_auth_info(auth_hrn)
909 records = self.resolve_raw("slice", name, must_exist=True)
912 object_gid = record.get_gid_object()
913 new_ticket = Ticket(subject = object_gid.get_subject())
914 new_ticket.set_gid_caller(self.client_gid)
915 new_ticket.set_gid_object(object_gid)
916 new_ticket.set_issuer(key=auth_info.get_pkey_object(), subject=auth_hrn)
917 new_ticket.set_pubkey(object_gid.get_pubkey())
919 self.fill_record_info(record)
921 (attributes, rspec) = self.record_to_slice_info(record)
923 new_ticket.set_attributes(attributes)
924 new_ticket.set_rspec(rspec)
926 new_ticket.set_parent(AuthHierarchy.get_auth_ticket(auth_hrn))
931 return new_ticket.save_to_string(save_parents=True)
934 if __name__ == "__main__":
938 key_file = "server.key"
939 cert_file = "server.cert"
941 # if no key is specified, then make one up
942 if (not os.path.exists(key_file)) or (not os.path.exists(cert_file)):
943 key = Keypair(create=True)
944 key.save_to_file(key_file)
946 cert = Certificate(subject="registry")
947 cert.set_issuer(key=key, subject="registry")
950 cert.save_to_file(cert_file)
952 AuthHierarchy = Hierarchy()
954 TrustedRoots = TrustedRootList()
956 s = Registry("", 12345, key_file, cert_file)
957 s.trusted_cert_list = TrustedRoots.get_list()