Пример #1
0
    def __init__(self, dns_id: str = None, zone_id: str = None):
        if (dns_id or zone_id) and not (dns_id and zone_id):
            raise exceptions.ConfigException(
                'You have to set both dns_id and zone_id! Only one does not make sense.'
            )

        self.cf = CloudFlare.CloudFlare()
        self.dns_id = dns_id
        self.zone_id = zone_id
Пример #2
0
    def __init__(self, path):  # type: (pathlib.Path) -> None
        if not path.exists():
            raise exceptions.ConfigException('The config was not found on this path! {}'.format(path))

        data = toml.load(path)
        logger.debug(f'Loaded configuration:\n{pprint.pformat(data)}')
        self.data, self.repos = self._load_data(data)

        self.loaded_path = path
        self._ipfs = None
Пример #3
0
        def _recursive_check(data, schema):
            if isinstance(schema, set):
                schema = dict.fromkeys(schema, None)

            for mandatory_key, value in schema.items():
                if mandatory_key not in data:
                    raise exceptions.ConfigException('\'{}\' is required configuration!'.format(mandatory_key))

                # Lets recurrently checked nested options
                if value is not None:
                    _recursive_check(data[mandatory_key], value)
Пример #4
0
    def update_dns(self, cid: str):
        if not self.dns_id or not self.zone_id:
            raise exceptions.ConfigException(
                'dns_id and zone_id not set. Not possible to update DNS!')

        try:
            self.cf.user.tokens.verify()
        except CloudFlare.exceptions.CloudFlareAPIError:
            raise exceptions.PublishingException(
                'CloudFlare access not configured!')

        logger.info('Publishing new CID to CloudFlare DNSLink')

        record = self.cf.zones.dns_records.get(self.zone_id, self.dns_id)
        record['content'] = f'dnslink={cid}'
        self.cf.zones.dns_records.put(self.zone_id, self.dns_id, data=record)
Пример #5
0
 def _verify_data(self, data):
     if not data.get('host') or not data.get('port'):
         raise exceptions.ConfigException('\'host\' and \'port\' are required items in configuration file!')