HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/libcloud/dns/__pycache__/base.cpython-310.pyc
o

;j�C�@s�ddlZddlmZmZmZmZmZmZmZddl	m
Z
ddlmZddl
mZmZmZgd�ZGdd�d�ZGd	d
�d
�ZGdd�de�ZdS)
�N)�Any�Dict�List�Type�Union�Iterator�Optional)�__version__)�
RecordType)�
BaseDriver�
Connection�ConnectionUserAndKey)�Zone�Record�	DNSDriverc@s`eZdZdZ	ddd�Zdd�Zddd�Z				dd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)rz
    DNS zone.
    NcCs<|rt|�nd|_||_||_|pd|_||_|pi|_dS)a�
        :param id: Zone id.
        :type id: ``str``

        :param domain: The name of the domain.
        :type domain: ``str``

        :param type: Zone type (master, slave).
        :type type: ``str``

        :param ttl: Default TTL for records in this zone (in seconds).
        :type ttl: ``int``

        :param driver: DNSDriver instance.
        :type driver: :class:`DNSDriver`

        :param extra: (optional) Extra attributes (driver specific).
        :type extra: ``dict``
        N)�str�id�domain�type�ttl�driver�extra)�selfrrrrrr�r�E/opt/saltstack/salt/lib/python3.10/site-packages/libcloud/dns/base.py�__init__ s
z
Zone.__init__cC�|jj|d�S�N��zone)r�list_records�rrrrr C�zZone.list_recordscCs|jj|||||d�S)N)�namerr�datar)r�
create_record�rr#rr$rrrrr%GszZone.create_recordcC�|jj|||||d�S)N)rrrrr)r�update_zone�rrrrrrrr�updateK�zZone.updatecCrr)r�delete_zoner!rrr�deleteUr"zZone.deletecCrr)r�export_zone_to_bind_formatr!rrr�export_to_bind_formatYr"zZone.export_to_bind_formatcCs|jj||d�dS)N)r�	file_path)r�export_zone_to_bind_zone_file)rr0rrr�export_to_bind_zone_file]szZone.export_to_bind_zone_filecCsd�|j|j|jj�S)Nz*<Zone: domain={}, ttl={}, provider={} ...>)�formatrrrr#r!rrr�__repr__as
�z
Zone.__repr__�N�NNNN)�__name__�
__module__�__qualname__�__doc__rr r%r*r-r/r2r4rrrrrs
�#

�
rc@sHeZdZdZ		d
dd�Z				ddd�Zdd�Zd	d
�Zdd�ZdS)rz!
    Zone record / resource.
    Nc		CsD|rt|�nd|_||_||_||_||_||_||_|pi|_dS)a�
        :param id: Record id
        :type id: ``str``

        :param name: Hostname or FQDN.
        :type name: ``str``

        :param type: DNS record type (A, AAAA, ...).
        :type type: :class:`RecordType`

        :param data: Data for the record (depends on the record type).
        :type data: ``str``

        :param zone: Zone instance.
        :type zone: :class:`Zone`

        :param driver: DNSDriver instance.
        :type driver: :class:`DNSDriver`

        :param ttl: Record TTL.
        :type ttl: ``int``

        :param extra: (optional) Extra attributes (driver specific).
        :type extra: ``dict``
        N)	rrr#rr$rrrr)	rrr#rr$rrrrrrrros$zRecord.__init__cCr')N)�recordr#rr$r)r�
update_recordr&rrrr*�r+z
Record.updatecCr)N�r;)r�
delete_recordr!rrrr-�r"z
Record.deletecCs*|j}|dur	dS|��rt|�}|S|S)z�
        Return numeric ID for the provided record if the ID is a digit.

        This method is used for sorting the values when exporting Zone to a
        BIND format.
        N�)r�isdigit�int)r�	record_idZ
record_id_intrrr�_get_numeric_id�szRecord._get_numeric_idcCs8|jjr|jjn|jj}d||j|j|j|jj|jfS)NzE<Record: zone=%s, name=%s, type=%s, data=%s, provider=%s, ttl=%s ...>)rrrr#rr$rr�rrrrrr4�s�zRecord.__repr__)NNr6)	r7r8r9r:rr*r-rCr4rrrrrjs
�/
�
rcs�eZdZdZeZdZdZiZ				d)�fdd�	Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zd*dd�Z			d*dd�Zd+dd�Z	d+dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Z�ZS),rzj
    A base DNSDriver class to derive from

    This class is always subclassed by a specific driver.
    NTcs"t�jd|||||d�|��dS)aP
        :param    key: API key or username to used (required)
        :type     key: ``str``

        :param    secret: Secret password to be used (required)
        :type     secret: ``str``

        :param    secure: Whether to use HTTPS or HTTP. Note: Some providers
                only support HTTPS, and it is on by default.
        :type     secure: ``bool``

        :param    host: Override hostname used for connections.
        :type     host: ``str``

        :param    port: Override port used for connections.
        :type     port: ``int``

        :return: ``None``
        )�key�secret�secure�host�portNr)�superr)rrErFrGrHrI�kwargs��	__class__rrr�s"zDNSDriver.__init__cCst|j���S)z�
        Return a list of RecordType objects supported by the provider.

        :return: ``list`` of :class:`RecordType`
        )�list�RECORD_TYPE_MAP�keysr!rrr�list_record_types�szDNSDriver.list_record_typescC�td��)zu
        Return a generator to iterate over available zones.

        :rtype: ``generator`` of :class:`Zone`
        z-iterate_zones not implemented for this driver��NotImplementedErrorr!rrr�
iterate_zonesszDNSDriver.iterate_zonescCst|���S)zU
        Return a list of zones.

        :return: ``list`` of :class:`Zone`
        )rNrUr!rrr�
list_zones	szDNSDriver.list_zonescCrR)z�
        Return a generator to iterate over records for the provided zone.

        :param zone: Zone to list records for.
        :type zone: :class:`Zone`

        :rtype: ``generator`` of :class:`Record`
        z/iterate_records not implemented for this driverrSrDrrr�iterate_records�
zDNSDriver.iterate_recordscCst|�|��S)z�
        Return a list of records for the provided zone.

        :param zone: Zone to list records for.
        :type zone: :class:`Zone`

        :return: ``list`` of :class:`Record`
        )rNrWrDrrrr s
zDNSDriver.list_recordscCrR)z�
        Return a Zone instance.

        :param zone_id: ID of the required zone
        :type  zone_id: ``str``

        :rtype: :class:`Zone`
        z(get_zone not implemented for this driverrS)r�zone_idrrr�get_zone*rXzDNSDriver.get_zonecCrR)z�
        Return a Record instance.

        :param zone_id: ID of the required zone
        :type  zone_id: ``str``

        :param record_id: ID of the required record
        :type  record_id: ``str``

        :rtype: :class:`Record`
        z*get_record not implemented for this driverrS)rrYrBrrr�
get_record6s
zDNSDriver.get_record�mastercCrR)a�
        Create a new zone.

        :param domain: Zone domain name (e.g. example.com)
        :type domain: ``str``

        :param type: Zone type (master / slave).
        :type  type: ``str``

        :param ttl: TTL for new records. (optional)
        :type  ttl: ``int``

        :param extra: Extra attributes (driver specific). (optional)
        :type extra: ``dict``

        :rtype: :class:`Zone`
        z+create_zone not implemented for this driverrSr)rrr�create_zoneEszDNSDriver.create_zonecCrR)a�
        Update an existing zone.

        :param zone: Zone to update.
        :type  zone: :class:`Zone`

        :param domain: Zone domain name (e.g. example.com)
        :type  domain: ``str``

        :param type: Zone type (master / slave).
        :type  type: ``str``

        :param ttl: TTL for new records. (optional)
        :type  ttl: ``int``

        :param extra: Extra attributes (driver specific). (optional)
        :type  extra: ``dict``

        :rtype: :class:`Zone`
        z+update_zone not implemented for this driverrS)rrrrrrrrrr(ZszDNSDriver.update_zonecCrR)a�
        Create a new record.

        :param name: Record name without the domain name (e.g. www).
                     Note: If you want to create a record for a base domain
                     name, you should specify empty string ('') for this
                     argument.
        :type  name: ``str``

        :param zone: Zone where the requested record is created.
        :type  zone: :class:`Zone`

        :param type: DNS record type (A, AAAA, ...).
        :type  type: :class:`RecordType`

        :param data: Data for the record (depends on the record type).
        :type  data: ``str``

        :param extra: Extra attributes (driver specific). (optional)
        :type extra: ``dict``

        :rtype: :class:`Record`
        z-create_record not implemented for this driverrS)rr#rrr$rrrrr%yszDNSDriver.create_recordcCrR)a�
        Update an existing record.

        :param record: Record to update.
        :type  record: :class:`Record`

        :param name: Record name without the domain name (e.g. www).
                     Note: If you want to create a record for a base domain
                     name, you should specify empty string ('') for this
                     argument.
        :type  name: ``str``

        :param type: DNS record type (A, AAAA, ...).
        :type  type: :class:`RecordType`

        :param data: Data for the record (depends on the record type).
        :type  data: ``str``

        :param extra: (optional) Extra attributes (driver specific).
        :type  extra: ``dict``

        :rtype: :class:`Record`
        z-update_record not implemented for this driverrS)rr;r#rr$rrrrr<�szDNSDriver.update_recordcCrR)z�
        Delete a zone.

        Note: This will delete all the records belonging to this zone.

        :param zone: Zone to delete.
        :type  zone: :class:`Zone`

        :rtype: ``bool``
        z+delete_zone not implemented for this driverrSrDrrrr,�szDNSDriver.delete_zonecCrR)z�
        Delete a record.

        :param record: Record to delete.
        :type  record: :class:`Record`

        :rtype: ``bool``
        z-delete_record not implemented for this driverrS)rr;rrrr>�rXzDNSDriver.delete_recordc	Cs�|jdkr	td��g}|��}t|tjd�}tj���d�}t	|d�}|�
d|�|�
dj|jd��|�
d	j|j
d
��|D]
}|j|d�}|�
|�q@d�|�}|S)
z�
        Export Zone object to the BIND compatible format.

        :param zone: Zone to export.
        :type  zone: :class:`Zone`

        :return: Zone data in BIND compatible format.
        :rtype: ``str``
        r\z/You can only generate BIND out for master zones)rEz%Y-%m-%d %H:%M:%S)�version�datez4; Generated by Libcloud v%(version)s on %(date)s UTCz$ORIGIN {domain}.)rz$TTL {domain_ttl}
)Z
domain_ttlr=�
)r�
ValueErrorr �sortedrrC�datetime�utcnow�strftimer	�appendr3rr�_get_bind_record_line�join)	rr�lines�recordsr_�valuesr;�line�outputrrrr.�s


z$DNSDriver.export_zone_to_bind_formatcCsF|j|d�}t|d��}|�|�Wd�dS1swYdS)a
        Export Zone object to the BIND compatible format and write result to a
        file.

        :param zone: Zone to export.
        :type  zone: :class:`Zone`

        :param file_path: File path where the output will be saved.
        :type  file_path: ``str``
        r�wN)r.�open�write)rrr0�result�fprrrr1�s"�z'DNSDriver.export_zone_to_bind_zone_filecCsg}|jrdj|j|jjd�}n|jj}|d7}d|jvr"|jdn|jj}t|�}|j}|jt	j
t	jt	jt	j
t	jfvrJ|t|�ddkrJ|d7}|jt	jt	jfvrad|vra|�dd�}d	|}|jt	jt	jfvr}t|jd
�}||dt|j�||g}n
||dt|j�|g}d�|�}|S)
z�
        Generate BIND record line for the provided record.

        :param record: Record to generate the line for.
        :type  record: :class:`Record`

        :return: Bind compatible record line.
        :rtype: ``str``
        z{name}.{domain})r#r�.r�� �"z\"z"%s"�priority�IN�	)r#r3rrrrrr$rr
ZCNAMEZDNAMEZMXZPTRZSRV�lenZTXTZSPF�replacerh)rr;�partsr#rr$rwrlrrrrgs:��
zDNSDriver._get_bind_record_linecCs|��}tt|�}|S)z�
        Return a string representation of a DNS record type to a
        libcloud RecordType ENUM.

        :rtype: ``str``
        )�upper�getattrr
)r�stringZrecord_typerrr�_string_to_record_type8s
z DNSDriver._string_to_record_type)NTNN)r\NNr5)r7r8r9r:r
Z
connectionClsr#ZwebsiterOrrQrUrVrWr rZr[r]r(r%r<r,r>r.r1rgr��
__classcell__rrrLrr�s@�			

�
!
�!"6r)rc�typingrrrrrrrZlibcloudr	Zlibcloud.dns.typesr
Zlibcloud.common.baserrr
�__all__rrrrrrr�<module>s$O`