Exemple #1
0
 def _write_as_topos(self):
     for topo_id, as_topo, base in srv_iter(self.topo_dicts,
                                            self.args.output_dir,
                                            common=True):
         path = os.path.join(base, TOPO_FILE)
         contents_json = json.dumps(self.topo_dicts[topo_id],
                                    default=json_default,
                                    indent=2)
         write_file(path, contents_json + '\n')
Exemple #2
0
    def _write_master_keys(self, topo_dicts):
        """
        Write AS master keys.
        """
        master_keys = {}
        for topo_id, as_topo, base in srv_iter(
                topo_dicts, self.args.output_dir, common=True):

            master_keys.setdefault(topo_id, self._gen_master_keys())
            write_file(get_master_key_file_path(base, MASTER_KEY_0),
                       base64.b64encode(master_keys[topo_id][0]).decode())
            write_file(get_master_key_file_path(base, MASTER_KEY_1),
                       base64.b64encode(master_keys[topo_id][1]).decode())
            # Confirm that keys parse correctly.
            assert get_master_key(base, MASTER_KEY_0) == master_keys[topo_id][0]
            assert get_master_key(base, MASTER_KEY_1) == master_keys[topo_id][1]
Exemple #3
0
 def _write_conf_policies(self, topo_dicts):
     """
     Write AS configurations and path policies.
     """
     as_confs = {}
     for topo_id, as_topo, base in srv_iter(
             topo_dicts, self.args.output_dir, common=True):
         as_confs.setdefault(topo_id, yaml.dump(
             self._gen_as_conf(as_topo), default_flow_style=False))
         conf_file = os.path.join(base, AS_CONF_FILE)
         write_file(conf_file, as_confs[topo_id])
         # Confirm that config parses cleanly.
         Config.from_file(conf_file)
         copy_file(self.args.path_policy,
                   os.path.join(base, PATH_POLICY_FILE))
     # Confirm that parser actually works on path policy file
     PathPolicy.from_file(self.args.path_policy)
Exemple #4
0
 def _copy_files(self, topo_dicts):
     cp = local['cp']
     # Copy the certs and key dir for all elements.
     for topo_id, as_topo, base in srv_iter(
             topo_dicts, self.args.output_dir, common=True):
         elem_dir = local.path(base)
         as_dir = elem_dir.dirname
         cp('-r', as_dir / 'certs', elem_dir / 'certs')
         cp('-r', as_dir / 'keys', elem_dir / 'keys')
         cp(as_dir.dirname.dirname // '*/trcs/*.trc', elem_dir / 'certs')
     # Copy the customers dir for all certificate servers.
     for topo_id, as_topo in topo_dicts.items():
         as_dir = local.path(topo_id.base_dir(self.args.output_dir))
         custom_dir = as_dir / 'customers'
         if not custom_dir.exists():
             continue
         for elem in as_topo["ControlService"]:
             cp('-r', as_dir / 'customers', as_dir / elem / 'customers')
Exemple #5
0
 def _write_trust_files(self, topo_dicts, cert_files):
     for topo_id, as_topo, base in srv_iter(topo_dicts,
                                            self.args.output_dir,
                                            common=True):
         for path, value in cert_files[topo_id].items():
             write_file(os.path.join(base, path), value + '\n')