def __load_variables(self): """ Load extra variables, specified in the .mercury_config file. """ for key in Configuration.get_all_keys("vars"): self.variables[key] = Configuration.get("vars", key)
def trust(self, certificate, peer): """ Add the certificate to the SSL Known Hosts in the Configuration file, so we will always trust this host in future. """ Configuration.set("ssl-known-hosts", "%s|%d" % peer, self.digest(certificate))
def enable(cls, path): """ Re-add a Mercury module repository to the collection, that was created manually or has previously been removed with #disable(). """ if cls.looks_like_repo(path): Configuration.set('repositories', path, path) else: raise UnknownRepository(path)
def disable(cls, path): """ Remove a Mercury module repository from the collection, but leave the file system intact. """ if cls.is_repo(path): Configuration.delete('repositories', path) else: raise UnknownRepository(path)
def delete(cls, url): """ Removes a Mercury remote, with the specified URL. """ if cls.get(url) != None: Configuration.delete('remotes', url) return True else: raise UnknownRemote(url)
def all(cls): """ Returns all known Mercury remotes. If the [remotes] section does not exist in the configuration file, we create it and add a default repository. """ if not Configuration.has_section('remotes'): cls.create("https://raw.github.com/mwrlabs/mercury-modules/repository/") return Configuration.get_all_values('remotes')
def create(cls, url): """ Create a new Mercury remote, with the specified URL. If the URL already exists, no remote will be created. """ if cls.get(url) == None: Configuration.set('remotes', url, url) return True else: return False
def all(cls): """ Returns all known Mercury remotes. If the [remotes] section does not exist in the configuration file, we create it and add a default repository. """ if not Configuration.has_section('remotes'): cls.create( "https://raw.github.com/mwrlabs/mercury-modules/repository/") return Configuration.get_all_values('remotes')
def provision(self, path): """ Provision new CA Key Material. This will overwrite any existing CA. """ self.authority.create_ca() Configuration.set("ssl", "ca_path", path) fs.write(self.ca_certificate_path(), ca.CA.certificate_to_pem(self.authority.ca_cert)) fs.write(self.__ca_key_path(), ca.CA.pkey_to_pem(self.authority.ca_key)) return True
def get(cls, url): """ Get an instance of Remote, initialised with the remote settings. """ url = Configuration.get('remotes', url) if url != None: return cls(url) else: return None
def ca_path(self, skip_default=False): """ Get the path to the CA Key Material, as defined by the configuration file. """ ca_path = Configuration.get("ssl", "ca_path") if ca_path == None and skip_default == False: ca_path = os.path.join(os.path.dirname(__file__), "embedded_ca") return ca_path
def all(cls): """ Returns all known Mercury repositories. """ return Configuration.get_all_values('repositories')
def trusted_certificate_for(self, peer): """ Fetches the trusted certificate for a peer. """ return Configuration.get("ssl-known-hosts", "%s|%d" % peer)