<commit_before>from ovh import Client
from .base import Provider as BaseProvider

def ProviderParser(subparser):
    subparser.description = '''
        OVH Provider requires a token with full rights on /domain/*.
        It can be generated for your OVH account on the following URL: 
        https://api.ovh.com/createToken/index.cgi?GET=/domain/*&PUT=/domain/*&POST=/domain/*&DELETE=/domain/*'''
    subparser.add_argument('--auth-entrypoint', help='specify the OVH entrypoint', choices=['ovh-eu', 'ovh-ca', 'soyoustart-eu', 'soyoustart-ca', 'kimsufi-eu', 'kimsufi-ca'])
    subparser.add_argument('--auth-application-key', help='specify the application key')
    subparser.add_argument('--auth-application-secret', help='specify the application secret')
    subparser.add_argument('--auth-consumer-key', help='specify the consumer key')

class Provider(BaseProvider):

    def __init__(self, options, engine_overrides=None):
        super(Provider, self).__init__(options, engine_overrides)
        self.ovh_client = Client(
            endpoint=options['auth_entrypoint'],
            application_key=options['auth_application_key'],
            application_secret=options['auth_application_secret'],
            consumer_key=options['auth_consumer_key']
        )

    def authenticate(self):
        domain = self.options['domain']

        domains = self.ovh_client.get('/domain/zone')
        if domain not in domains:
            raise Exception('Domain {0} not found'.format(domain))

        status = self.ovh_client.get('/domain/zone/{0}/status'.format(domain))
        if not status['isDeployed']:
            raise Exception('Zone {0} is not deployed'.format(domain))

    def create_record(self, type, name, content):
        domain = self.options['domain']

        config = {
            'fieldType': type,
            'subDomain': self._relative_name(name),
            'target': content
        }

        self.ovh_client.post('/domain/zone/{0}/record'.format(domain), **config)
        self.ovh_client.post('/domain/zone/{0}/refresh'.format(domain))

        return True

    def list_records(self, type=None, name=None, content=None):
        domain = self.options['domain']
        records = []

        config = {}
        if type:
            config['fieldType'] = type
        if name:
            config['subDomain'] = self._relative_name(name)

        record_ids = self.ovh_client.get('/domain/zone/{0}/record'.format(domain), **config)

        for record_id in record_ids:
            raw = self.ovh_client.get('/domain/zone/{0}/record/{1}'.format(domain, record_id))
            records.append({
                'type': raw['fieldType'],
                'name': raw['subDomain'],
                'ttl': raw['ttl'],
                'content': raw['target'],
                'id': raw['id']
            })

        if content:
            records = [record for record in records if record['content'].lower() == content.lower()]

        return records

    def update_record(self, identifier, type=None, name=None, content=None):
        domain = self.options['domain']

        config = {}
        if name:
            config['subDomain'] = self._relative_name(name)
        if content:
            config['target'] = content

        self.ovh_client.put('/domain/zone/{0}/record/{1}'.format(domain, identifier), **config)
        self.ovh_client.post('/domain/zone/{0}/refresh'.format(domain))

        return True

    def delete_record(self, identifier=None, type=None, name=None, content=None):
        domain = self.options['domain']

        if not identifier:
            records = self.list_records(type, name, content)
            if len(records) == 1:
                identifier = records[0]['id']
            else:
                raise Exception('Record identifier could not be found')

        self.ovh_client.delete('/domain/zone/{0}/record/{1}'.format(domain, identifier))
        self.ovh_client.post('/domain/zone/{0}/refresh'.format(domain))
<commit_msg>Use getter<commit_after>from ovh import Client
from .base import Provider as BaseProvider

def ProviderParser(subparser):
    subparser.description = '''
        OVH Provider requires a token with full rights on /domain/*.
        It can be generated for your OVH account on the following URL: 
        https://api.ovh.com/createToken/index.cgi?GET=/domain/*&PUT=/domain/*&POST=/domain/*&DELETE=/domain/*'''
    subparser.add_argument('--auth-entrypoint', help='specify the OVH entrypoint', choices=['ovh-eu', 'ovh-ca', 'soyoustart-eu', 'soyoustart-ca', 'kimsufi-eu', 'kimsufi-ca'])
    subparser.add_argument('--auth-application-key', help='specify the application key')
    subparser.add_argument('--auth-application-secret', help='specify the application secret')
    subparser.add_argument('--auth-consumer-key', help='specify the consumer key')

class Provider(BaseProvider):

    def __init__(self, options, engine_overrides=None):
        super(Provider, self).__init__(options, engine_overrides)
        print(self.options)
        self.ovh_client = Client(
            endpoint=self.options.get('auth_entrypoint'),
            application_key=self.options.get('auth_application_key'),
            application_secret=self.options.get('auth_application_secret'),
            consumer_key=self.options.get('auth_consumer_key')
        )

    def authenticate(self):
        domain = self.options.get('domain')

        domains = self.ovh_client.get('/domain/zone')
        if domain not in domains:
            raise Exception('Domain {0} not found'.format(domain))

        status = self.ovh_client.get('/domain/zone/{0}/status'.format(domain))
        if not status['isDeployed']:
            raise Exception('Zone {0} is not deployed'.format(domain))

    def create_record(self, type, name, content):
        domain = self.options.get('domain')

        config = {
            'fieldType': type,
            'subDomain': self._relative_name(name),
            'target': content
        }

        self.ovh_client.post('/domain/zone/{0}/record'.format(domain), **config)
        self.ovh_client.post('/domain/zone/{0}/refresh'.format(domain))

        return True

    def list_records(self, type=None, name=None, content=None):
        domain = self.options.get('domain')
        records = []

        config = {}
        if type:
            config['fieldType'] = type
        if name:
            config['subDomain'] = self._relative_name(name)

        record_ids = self.ovh_client.get('/domain/zone/{0}/record'.format(domain), **config)

        for record_id in record_ids:
            raw = self.ovh_client.get('/domain/zone/{0}/record/{1}'.format(domain, record_id))
            records.append({
                'type': raw['fieldType'],
                'name': raw['subDomain'],
                'ttl': raw['ttl'],
                'content': raw['target'],
                'id': raw['id']
            })

        if content:
            records = [record for record in records if record['content'].lower() == content.lower()]

        return records

    def update_record(self, identifier, type=None, name=None, content=None):
        domain = self.options.get('domain')

        config = {}
        if name:
            config['subDomain'] = self._relative_name(name)
        if content:
            config['target'] = content

        self.ovh_client.put('/domain/zone/{0}/record/{1}'.format(domain, identifier), **config)
        self.ovh_client.post('/domain/zone/{0}/refresh'.format(domain))

        return True

    def delete_record(self, identifier=None, type=None, name=None, content=None):
        domain = self.options.get('domain')

        if not identifier:
            records = self.list_records(type, name, content)
            if len(records) == 1:
                identifier = records[0]['id']
            else:
                raise Exception('Record identifier could not be found')

        self.ovh_client.delete('/domain/zone/{0}/record/{1}'.format(domain, identifier))
        self.ovh_client.post('/domain/zone/{0}/refresh'.format(domain))

{'fraction_non_alphanumeric': 0.14319277853344875, 'fraction_numerical': 0.003956967973290466, 'mean_word_length': 2.612326931665922, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6578624', 'n_tokens_mistral': 2325, 'n_tokens_neox': 2240, 'n_words': 458}