How to use dnsimple - 10 common examples

To help you get started, we’ve selected a few dnsimple examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onlyhavecans / dnsimple-python / tests / fixtures.py View on Github external
def client():
    return DNSimple(
        api_token = os.getenv('DNSIMPLE_API_TOKEN'),
        sandbox   = True
    )
github onlyhavecans / dnsimple-python / tests / test_auth.py View on Github external
def test_basic_authentication_raises_no_exceptions(self):
        client = DNSimple(
            email=os.getenv('DNSIMPLE_EMAIL'),
            password=os.getenv('DNSIMPLE_PASSWORD'),
            sandbox=True
        )

        client.domains()
github onlyhavecans / dnsimple-python / tests / test_auth.py View on Github external
def test_authentication_with_invalid_credentials_raises(self):
        with pytest.raises(DNSimpleException) as exception:
            client = DNSimple(email='user@host.com', password='bogus')
            client.domains()

        assert 'Authentication failed' in str(exception.value)
github onlyhavecans / dnsimple-python / tests / test_auth.py View on Github external
def test_authentication_with_invalid_credentials_raises(self):
        with pytest.raises(DNSimpleException) as exception:
            client = DNSimple(email='user@host.com', password='bogus')
            client.domains()

        assert 'Authentication failed' in str(exception.value)
github onlyhavecans / dnsimple-python / tests / test_domains.py View on Github external
# Test deleting by ID
        response = client.delete(domain['domain']['id'])

        assert isinstance(response, dict)
        assert len(response) == 0
        assert len(client.domains()) == (domain_count - 2)

        # Ensure deleting non-existent domain by name fails
        with pytest.raises(DNSimpleException) as exception:
            client.delete('unknown.domain')

        assert "Domain `unknown.domain` not found" in str(exception.value)

        # Ensure deleting non-existent domain by ID fails
        with pytest.raises(DNSimpleException) as exception:
            client.delete(9999)

        assert "Domain `9999` not found" in str(exception.value)
github onlyhavecans / dnsimple-python / tests / test_domains.py View on Github external
def test_check_domain(self, client):
        # Ensure invalid domain names cause errors
        with pytest.raises(DNSimpleException) as exception:
            client.check('add.test')

        assert "TLD .TEST is invalid or not supported" in str(exception.value)

        # Check a domain name that is not available
        status = client.check('google.com')

        assert not status['available']

        status = client.check('dnsimple-python-available-domain.com')

        assert status['available']
github onlyhavecans / dnsimple-python / tests / test_records.py View on Github external
def test_find_record(self, domain, client, token_client):
        www = self.find_record(client, domain, 'www')

        # Test finding by record ID
        assert www
        assert client.record(domain['domain']['id'], www['record']['id']) == www
        assert token_client.record(domain['domain']['id'], www['record']['id']) == www

        # Test that finding a non-existent record fails
        with pytest.raises(DNSimpleException) as exception:
            client.record(domain['domain']['id'], 999999)

        assert 'Record `999999` not found' in str(exception.value)
github onlyhavecans / dnsimple-python / tests / test_records.py View on Github external
assert isinstance(record, dict)

        assert record['record']['name']    == 'www'
        assert record['record']['content'] == domain['domain']['name']

        record = token_client.add_record(domain['domain']['id'], {
            'record_type': 'CNAME',
            'name':        'token-cname',
            'content':     'token.{0}'.format(domain['domain']['name'])
        })

        assert record['record']['name'] == 'token-cname'

        # Test adding without parameters causes an error
        with pytest.raises(DNSimpleException) as exception:
            client.add_record(domain['domain']['name'], {})

        assert 'Validation failed' in str(exception.value)

        assert self.record_count(client, domain) == (start_record_count + 4)
github onlyhavecans / dnsimple-python / tests / test_auth.py View on Github external
def test_authentication_with_no_credentials_raises(self):
        with pytest.raises(DNSimpleAuthException) as exception:
            client = DNSimple()

        assert 'insufficient authentication details provided.' in str(exception.value)
github ansible / ansible / lib / ansible / modules / net_tools / dnsimple.py View on Github external
domain = module.params.get('domain')
    record = module.params.get('record')
    record_ids = module.params.get('record_ids')
    record_type = module.params.get('type')
    ttl = module.params.get('ttl')
    value = module.params.get('value')
    priority = module.params.get('priority')
    state = module.params.get('state')
    is_solo = module.params.get('solo')

    if account_email and account_api_token:
        client = DNSimple(email=account_email, api_token=account_api_token)
    elif os.environ.get('DNSIMPLE_EMAIL') and os.environ.get('DNSIMPLE_API_TOKEN'):
        client = DNSimple(email=os.environ.get('DNSIMPLE_EMAIL'), api_token=os.environ.get('DNSIMPLE_API_TOKEN'))
    else:
        client = DNSimple()

    try:
        # Let's figure out what operation we want to do

        # No domain, return a list
        if not domain:
            domains = client.domains()
            module.exit_json(changed=False, result=[d['domain'] for d in domains])

        # Domain & No record
        if domain and record is None and not record_ids:
            domains = [d['domain'] for d in client.domains()]
            if domain.isdigit():
                dr = next((d for d in domains if d['id'] == int(domain)), None)
            else:
                dr = next((d for d in domains if d['name'] == domain), None)