示例#1
0
    def add_collaborator(self, account_id, domain, email):
        """
        Adds a collaborator for the domain in the account

        At the time of the add, a collaborator may or may not have a DNSimple account.

        In case the collaborator doesn't have a DNSimple account, the system will invite her/him to register to
        DNSimple first and then to accept the collaboration invitation.

        In the other case, she/he is automatically added to the domain as collaborator. She/he can decide to reject
        the invitation later.

        See https://developer.dnsimple.com/v2/domains/collaborators/#addDomainCollaborator

        :param account_id: int
            The account ID
        :param domain: int/str
            The domain name or id
        :param email: str
            The email of the collaborator to be added

        :return: dnsimple.Response
            The collaborator added to the domain in the account
        """
        response = self.client.post(
            f'/{account_id}/domains/{domain}/collaborators',
            data=json.dumps({'email': email}))
        return Response(response, Collaborator)
示例#2
0
    def list_template_records(self, account_id, template, sort=None, page=None, per_page=None):
        """
        Lists the records in the template

        See https://developer.dnsimple.com/v2/templates/records/#listTemplateRecords

        :param account_id: int
            The account id
        :param template: int/str
            The template id or sid
        :param sort: str
            Comma separated key-value pairs: the name of a field and the order criteria (asc for ascending and desc for
            descending).

            Possible sort criteria:
                - id: Sort template records by ID (i.e. 'id:asc')
                - name: Sort template records by name (i.e. 'name:desc')
                - content: Sort template records by content (i.e. 'content:asc')
                - type: Sort template records by type (i.e. 'type:desc')
        :param page: int
            The page to return (default: 1)
        :param per_page: int
            The number of entries to return per page (default: 30, maximum: 100)

        :return: dnsimple.Response
            The list of template records
        """
        response = self.client.get(f'/{account_id}/templates/{template}/records', sort=sort, page=page, per_page=per_page)
        return Response(response, TemplateRecord)
示例#3
0
    def list_services(self, sort=None, page=None, per_page=None):
        """
        List the available one-click services.

        See https://developer.dnsimple.com/v2/services/#listServices

        :param sort: str
            Comma separated key-value pairs: the name of a field and the order criteria (asc for ascending and desc for
            descending).

            Possible sort criteria:
                - id: Sort services by ID (i.e. 'id:asc')
                - sid: Sort services by sid (i.e. 'sid:desc')
        :param page: int
            The page to return (default: 1)
        :param per_page: int
            The number of entries to return per page (default: 30, maximum: 100)

        :return: dnsimple.Response
            The list of services in DNSimple
        """
        response = self.client.get('/services',
                                   sort=sort,
                                   page=page,
                                   per_page=per_page)
        return Response(response, Service)
示例#4
0
    def list_templates(self, account_id, sort=None, page=None, per_page=None):
        """
        Lists the templates in the account

        See https://developer.dnsimple.com/v2/templates/#listTemplates

        :param account_id: int
            The account id
        :param sort: str
            Comma separated key-value pairs: the name of a field and the order criteria (asc for ascending and desc for
            descending).

            Possible sort criteria:
                - id: Sort templates by ID (i.e. 'id:asc')
                - name: Sort templates by name (alphabetical order) (i.e. 'name:desc')
                - sid: Sort templates by sid (i.e. 'sid:asc')
        :param page: int
            The page to return (default: 1)
        :param per_page: int
            The number of entries to return per page (default: 30, maximum: 100)

        :return: dnsimple.Response
            The templates in the account
        """
        response = self.client.get(f'/{account_id}/templates', sort=sort, page=page, per_page=per_page)
        return Response(response, Template)
示例#5
0
    def create_domain_delegation_signer_record(self, account_id, domain,
                                               ds_input):
        """
        Create a delegation signer record

        You only need to create a delegation signer record manually if your domain is registered with DNSimple but
        hosted with another DNS provider that is signing your zone. To enable DNSSEC on a domain that is hosted with
        DNSimple, use the DNSSEC enable endpoint.

        See https://developer.dnsimple.com/v2/domains/dnssec/#createDomainDelegationSignerRecord

        :param account_id: int
            The account ID
        :param domain: int/str
            The domain name or id
        :param ds_input: DelegationsSignerRecordInput
            The delegation signer record input to create the delegation signer record

        :return: dnsimple.Response
            The newly created domain delegation signer record
        """
        response = self.client.post(
            f'/{account_id}/domains/{domain}/ds_records',
            data=ds_input.to_json())
        return Response(response, DelegationSignerRecord)
示例#6
0
    def exchange_authorization_for_token(self, code, client_id, client_secret,
                                         state, redirect_uri):
        """
        Exchange the short-lived authorization code for an access token
        you can use to authenticate your API calls.

        See https://developer.dnsimple.com/v2/oauth/

        :param code: str
            The authorization code, which can be used in the next step to retrieve a bearer token.
        :param client_id: str
            Client Id you received when the application was registered with DNSimple.
        :param client_secret: str
            Client Secret you received when the application was registered with DNSimple.
        :param state: str
            An unguessable random string. It is used to protect against cross-site request forgery
            attacks and it will be passed back to your redirect URI.
        :param redirect_uri: str
            Where to redirect the user after authorization has completed. This must be the exact
            URI registered or a subdirectory.
        :return: OAuthToken
            The OAuthToken object containing the access token to be used in subsequent calls to the API
        """
        response = self.client.post('/oauth/access_token',
                                    data={
                                        'code': code,
                                        'client_id': client_id,
                                        'client_secret': client_secret,
                                        'state': state,
                                        'redirect_uri': redirect_uri,
                                        'grant_type': 'authorization_code'
                                    })
        return Response(response, AccessToken)
示例#7
0
    def list_accounts(self):
        """
         Lists the accounts the current authenticated entity has access to.

        :return: dnsimple.Response
            The response containing the list of accounts.
        """
        response = self.client.get('/accounts')
        return Response(response, Account)
示例#8
0
    def whoami(self):
        """
        Retrieves the details about the current authenticated entity used to
        access the DNSimple API.

        :return: dnsimple.Response
            A response containing the details of the authenticated entity
        """
        response = self.client.get('/whoami')
        return Response(response, Whoami)
示例#9
0
    def setUp(self) -> None:
        responses.add(
            DNSimpleMockResponse(
                method=responses.GET,
                url='https://api.sandbox.dnsimple.com/v2/whoami',
                fixture_name='whoami/success-user'))

        self.http_response = requests.get(
            'https://api.sandbox.dnsimple.com/v2/whoami')
        self.dnsimple_response = Response(self.http_response, Whoami)
示例#10
0
    def get_tld_extended_attributes(self, tld):
        """
        Gets the extended attributes for a TLD

        See https://developer.dnsimple.com/v2/tlds/#getTldExtendedAttributes

        :param tld: str
            The TLD name

        :return: dnsimple.Response
            The TLDs extended attributes
        """
        response = self.client.get(f'/tlds/{tld}/extended_attributes')
        return Response(response, TldExtendedAttribute)
示例#11
0
    def get_service(self, service_id):
        """
        Gets the service with specified ID

        See https://developer.dnsimple.com/v2/services/#getService

        :param service_id: int
            The service id

        :return: dnsimple.Response
            The service requested
        """
        response = self.client.get(f'/services/{service_id}')
        return Response(response, Service)
示例#12
0
    def get_tld(self, tld):
        """
        Gets the details of a TLD

        See https://developer.dnsimple.com/v2/tlds/#getTld
        
        :param tld: str
            The TLD name

        :return: dnsimple.Response
            The TLD details
        """
        response = self.client.get(f'/tlds/{tld}')
        return Response(response, Tld)
示例#13
0
    def get_domain(self, account_id, domain):
        """
        Retrieves the details of an existing domain.

        See https://developer.dnsimple.com/v2/domains/#getDomain

        :param account_id: int
            The account ID
        :param domain: int/str
            The domain name or ID
        :return: dnsimple.Response
            The domain requested
        """
        response = self.client.get(f'/{account_id}/domains/{domain}')
        return Response(response, Domain)
示例#14
0
    def create_template(self, account_id, template_attributes):
        """
        Creates a template in the account

        See https://developer.dnsimple.com/v2/templates/#createTemplate

        :param account_id: int
            The account id
        :param template_attributes: dnsimple.struct.Template
            The template attributes
        :return: dnsimple.Response
            The newly created template
        """
        response = self.client.post(f'/{account_id}/templates', data=template_attributes.to_json())
        return Response(response, Template)
    def enable_vanity_name_servers(self, account_id, domain):
        """
        Enables Vanity Name Servers for the domain

        See https://developer.dnsimple.com/v2/vanity/#enableVanityNameServers

        :param account_id: int
            The account id
        :param domain: int/str
            The domain name or id
        :return: dnsimple.Response
            The vanity name server list
        """
        response = self.client.put(f'/{account_id}/vanity/{domain}')
        return Response(response, VanityNameServer)
示例#16
0
    def disable_dnssec(self, account_id, domain):
        """
        Disable DNSSEC for the domain in the account.

        See https://developer.dnsimple.com/v2/domains/dnssec/#disableDomainDnssec

        :param account_id: int
            The account ID
        :param domain: int/str
            The domain name or id

        :return: dnsimple.Response
            An empty response
        """
        response = self.client.delete(f'/{account_id}/domains/{domain}/dnssec')
        return Response(response)
示例#17
0
    def list_collaborators(self, account_id, domain):
        """
        List collaborators for the domain in the account.

        See https://developer.dnsimple.com/v2/domains/collaborators/#listDomainCollaborators

        :param account_id: int
            The account ID
        :param domain: int/str
            The domain name or id
        :return: dnsimple.Response
            A list of collaborators for the domain in the account
        """
        response = self.client.get(
            f'/{account_id}/domains/{domain}/collaborators')
        return Response(response, Collaborator)
示例#18
0
    def get_zone_file(self, account_id, zone):
        """
        Gets a zone file from the account

        See https://developer.dnsimple.com/v2/zones/#getZoneFile

        :param account_id: int
            The account ID
        :param zone: str
            The zone name

        :return: dnsimple.Response
            The zone file requested
        """
        response = self.client.get(f'/{account_id}/zones/{zone}/file')
        return Response(response, ZoneFile)
示例#19
0
    def create_domain(self, account_id, domain_name):
        """
        Creates a domain in the account.

        See https://developer.dnsimple.com/v2/domains/#create

        :param account_id: int
            The account ID
        :param domain_name: str
            The name of the domain
        :return: dnsimple.Response
            The newly created domain
        """
        response = self.client.post(f'/{account_id}/domains',
                                    data=json.dumps({'name': domain_name}))
        return Response(response, Domain)
示例#20
0
    def create_contact(self, account_id, contact):
        """
        Creates a new contact in the account

        See https://developer.dnsimple.com/v2/contacts/#createContact
        
        :param account_id: int
            The account id
        :param contact: dnsimple.struct.Contact
            The contact to be created

        :return: dnsimple.Response
            The newly created contact
        """
        response = self.client.post(f'/{account_id}/contacts', data=contact.to_json())
        return Response(response, Contact)
示例#21
0
    def reject_push(self, account_id, push_id):
        """
        Reject a push for the target account

        See: https://developer.dnsimple.com/v2/domains/pushes/#rejectPush

        :param account_id: int
            The account ID
        :param push_id: int
            Then push ID

        :return: dnsimple.Response
            An empty response
        """
        response = self.client.delete(f'/{account_id}/pushes/{push_id}')
        return Response(response)
示例#22
0
    def get_contact(self, account_id, contact_id):
        """
        Gets a contact from the account

        See https://developer.dnsimple.com/v2/contacts/#getContact

        :param account_id: int
            Then account id
        :param contact_id: int
            The contact id

        :return: dnsimple.Response
            The contact
        """
        response = self.client.get(f'/{account_id}/contacts/{contact_id}')
        return Response(response, Contact)
示例#23
0
    def get_template(self, account_id, template):
        """
        Gets the template with the specified id or sid

        See https://developer.dnsimple.com/v2/templates/#getTemplate

        :param account_id: int
            The account id
        :param template: int/str
            The template sid or id

        :return: dnsimple.Response
            The template requested
        """
        response = self.client.get(f'/{account_id}/templates/{template}')
        return Response(response, Template)
示例#24
0
    def delete_webhook(self, account_id, webhook):
        """
        Deletes a webhook from the account

        See https://developer.dnsimple.com/v2/webhooks/#deleteWebhook

        :param account_id: int
            The account id
        :param webhook: int/str
            The webhook id

        :return: dnsimple.Response
            An empty response
        """
        response = self.client.delete(f'/{account_id}/webhooks/{webhook}')
        return Response(response)
示例#25
0
    def delete_contact(self, account_id, contact_id):
        """
        Deletes a contact from the account

        See https://developer.dnsimple.com/v2/contacts/#deleteContact

        :param account_id: int
            The account id
        :param contact_id: int
            The contact id

        :return: dnsimple.Response
            An empty response
        """
        response = self.client.delete(f'/{account_id}/contacts/{contact_id}')
        return Response(response)
示例#26
0
    def get_webhook(self, account_id, webhook):
        """
        Gets a webhook from the account

        See https://developer.dnsimple.com/v2/webhooks/#getWebhook

        :param account_id: int
            The account id
        :param webhook: int/str
            The webhook id

        :return: dnsimple.Response
            The webhook
        """
        response = self.client.get(f'/{account_id}/webhooks/{webhook}')
        return Response(response, Webhook)
示例#27
0
    def get_dnssec(self, account_id, domain):
        """
        Get the status of DNSSEC, indicating whether it is currently enabled or disabled.

        See https://developer.dnsimple.com/v2/domains/dnssec/#getDomainDnssec

        :param account_id: int
            The account ID
        :param domain: int/str
            The domain name or id

        :return: dnsimple.Response
            The DNSSEC status requested
        """
        response = self.client.get(f'/{account_id}/domains/{domain}/dnssec')
        return Response(response, Dnssec)
    def disable_vanity_name_servers(self, account_id, domain):
        """
        Disables Vanity Name Servers for the domain

        See https://developer.dnsimple.com/v2/vanity/#disableVanityNameServers

        :param account_id: int
            The account id
        :param domain: int/str
            The domain name or id

        :return: dnsimple.Response
            An empty response
        """
        response = self.client.delete(f'/{account_id}/vanity/{domain}')
        return Response(response)
示例#29
0
    def renew_whois_privacy(self, account_id, domain):
        """
        Renew WHOIS privacy

        See https://developer.dnsimple.com/v2/registrar/whois-privacy/#renewWhoisPrivacy

        :param account_id: int
            The account ID
        :param domain: int/str
            The domain name or id

        :return: dnsimple.Response
            The whois privacy renewal
        """
        response = self.client.post(
            f'/{account_id}/registrar/domains/{domain}/whois_privacy')
        return Response(response, WhoisPrivacyRenewal)
示例#30
0
    def list_records(self,
                     account_id,
                     zone,
                     filter=None,
                     sort=None,
                     page=None,
                     per_page=None):
        """
        Lists the zone records in the account

        See https://developer.dnsimple.com/v2/zones/records/#listZoneRecords

        :param account_id: int
            The account ID
        :param zone: str
            The zone name
        :param sort: str
            Comma separated key-value pairs: the name of a field and the order criteria (asc for ascending and desc for
            descending).

            Possible sort criteria:
                - id: Sort records by ID (i.e. 'id:asc')
                - name: Sort records by name (i.e. 'name:desc')
                - content: Sort records by content (i.e. 'content:asc')
                - type: Sort records by type (i.e. 'type:asc')
        :param filter: dict
            Makes it possible to ask only for the exact subset of data that you you’re looking for.

            Possible filters:
                - name_like: Only include records where the name contains the given string (i.e.{'name_like':'example'})
                - name: Only include records with name equal to the given string (i.e. {'name': 'example.com'})
                - type: Only include records with the record type equal to the given string (i.e. {'type': 'SOA'})
        :param page: int
            The page to return (default: 1)
        :param per_page: int
            The number of entries to return per page (default: 30, maximum: 100)

        :return: dnsimple.Response
            The list of zone records in the account
        """
        response = self.client.get(f'/{account_id}/zones/{zone}/records',
                                   filter=filter,
                                   sort=sort,
                                   page=page,
                                   per_page=per_page)
        return Response(response, ZoneRecord)