
    Vh$                         d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ  ej                  d      5  d dlmZmZ d	d	d	       d
 Zd Zd Zd Zd Zd Zedk(  r e        y	y	# 1 sw Y   )xY w)    )absolute_importdivisionprint_functiona  
module: dnsimple_info

short_description: Pull basic info from DNSimple API

version_added: "4.2.0"

description: Retrieve existing records and domains from DNSimple API.

extends_documentation_fragment:
  - community.general.attributes
  - community.general.attributes.info_module

options:
  name:
    description:
      - The domain name to retrieve info from.
      - Will return all associated records for this domain if specified.
      - If not specified, will return all domains associated with the account ID.
    type: str

  account_id:
    description: The account ID to query.
    required: true
    type: str

  api_key:
    description: The API key to use.
    required: true
    type: str

  record:
    description:
      - The record to find.
      - If specified, only this record will be returned instead of all records.
    required: false
    type: str

  sandbox:
    description: Whether or not to use sandbox environment.
    required: false
    default: false
    type: bool

author:
  - Edward Hilgendorf (@edhilgendorf)
a  
- name: Get all domains from an account
  community.general.dnsimple_info:
    account_id: "1234"
    api_key: "1234"

- name: Get all records from a domain
  community.general.dnsimple_info:
    name: "example.com"
    account_id: "1234"
    api_key: "1234"

- name: Get all info from a matching record
  community.general.dnsimple_info:
    name: "example.com"
    record: "subdomain"
    account_id: "1234"
    api_key: "1234"
al  
dnsimple_domain_info:
  description: Returns a list of dictionaries of all domains associated with the supplied account ID.
  type: list
  elements: dict
  returned: success when O(name) is not specified
  sample:
    - account_id: 1234
      created_at: '2021-10-16T21:25:42Z'
      id: 123456
      last_transferred_at:
      name: example.com
      reverse: false
      secondary: false
      updated_at: '2021-11-10T20:22:50Z'
  contains:
    account_id:
      description: The account ID.
      type: int
    created_at:
      description: When the domain entry was created.
      type: str
    id:
      description: ID of the entry.
      type: int
    last_transferred_at:
      description: Date the domain was transferred, or empty if not.
      type: str
    name:
      description: Name of the record.
      type: str
    reverse:
      description: Whether or not it is a reverse zone record.
      type: bool
    updated_at:
      description: When the domain entry was updated.
      type: str

dnsimple_records_info:
  description: Returns a list of dictionaries with all records for the domain supplied.
  type: list
  elements: dict
  returned: success when O(name) is specified, but O(record) is not
  sample:
    - content: ns1.dnsimple.com admin.dnsimple.com
      created_at: '2021-10-16T19:07:34Z'
      id: 12345
      name: 'catheadbiscuit'
      parent_id:
      priority:
      regions:
        - global
      system_record: true
      ttl: 3600
      type: SOA
      updated_at: '2021-11-15T23:55:51Z'
      zone_id: example.com
  contains:
    content:
      description: Content of the returned record.
      type: str
    created_at:
      description: When the domain entry was created.
      type: str
    id:
      description: ID of the entry.
      type: int
    name:
      description: Name of the record.
      type: str
    parent_id:
      description: Parent record or null.
      type: int
    priority:
      description: Priority setting of the record.
      type: str
    regions:
      description: List of regions where the record is available.
      type: list
    system_record:
      description: Whether or not it is a system record.
      type: bool
    ttl:
      description: Record TTL.
      type: int
    type:
      description: Record type.
      type: str
    updated_at:
      description: When the domain entry was updated.
      type: str
    zone_id:
      description: ID of the zone that the record is associated with.
      type: str
dnsimple_record_info:
  description: Returns a list of dictionaries that match the record supplied.
  returned: success when O(name) and O(record) are specified
  type: list
  elements: dict
  sample:
    - content: 1.2.3.4
      created_at: '2021-11-15T23:55:51Z'
      id: 123456
      name: catheadbiscuit
      parent_id:
      priority:
      regions:
        - global
      system_record: false
      ttl: 3600
      type: A
      updated_at: '2021-11-15T23:55:51Z'
      zone_id: example.com
  contains:
    content:
      description: Content of the returned record.
      type: str
    created_at:
      description: When the domain entry was created.
      type: str
    id:
      description: ID of the entry.
      type: int
    name:
      description: Name of the record.
      type: str
    parent_id:
      description: Parent record or null.
      type: int
    priority:
      description: Priority setting of the record.
      type: str
    regions:
      description: List of regions where the record is available.
      type: list
    system_record:
      description: Whether or not it is a system record.
      type: bool
    ttl:
      description: Record TTL.
      type: int
    type:
      description: Record type.
      type: str
    updated_at:
      description: When the domain entry was updated.
      type: str
    zone_id:
      description: ID of the zone that the record is associated with.
      type: str
)AnsibleModule)depsrequests)RequestSessionNc                     ddj                  |      d}|rdnd}dj                  ||       }t        ||      }|j                         }|S )	Nzapplication/jsonz
Bearer {0})AcceptAuthorizationz.sandbox z.https://api{sandbox}.dnsimple.com/v2/{account})sandboxaccount)urlheaders)formatr	   prepare)r   key
is_sandboxr   r   r   reqprepped_requests           s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/dnsimple_info.py	build_urlr      sV    + , 3 3C 8:G&jBG
:
A
A'[b
A
cC
c7
+CkkmO    c                    |j                   }t               j                  |      }d|j                         vr| j	                  d       |j                         d   }|j                         d   d   }d}||k  rR|dz   }dj                  ||      |_         t               j                  |      }||j                         d   z   }||k  rR|S )N
paginationz1API Call failed, check ID, key and sandbox valuesdatatotal_pages   z{url}&page={page})r   page)r   r
   sendjson	fail_jsonr   )modulerequest_objectbase_urlresponser   r   r!   new_resultss           r   iterate_datar*      s    !!Hy~~n-H8==?*LM==?6"D--/,/>KD

ax077H47Pinn^4k&&(00	 
 Kr   c                     |j                   dz   | j                  d   z   dz   | j                  d   z   dc|_         |_        t        | |      S )N/zones/namez/records?name=recordGETr   paramsmethodr*   dnsimple_modreq_objs     r   record_infor6     si    ")++	"9L<O<OPV<W"WZj"jmy  nA  nA  BJ  nK  #K  MRGKg..r   c                 x    |j                   dz   | j                  d   z   dz   dc|_         |_        t        | |      S )Nr,   r-   z/records?per_page=100r/   r0   r3   s     r   domain_infor8     s@    ")++	"9L<O<OPV<W"WZq"qsxGKg..r   c                 R    |j                   dz   dc|_         |_        t        | |      S )Nz/zones/?per_page=100r/   )r   r2   r*   r3   s     r   account_infor:     s)    ")++0F"FGKg..r   c                     dddddddddddddddddd} d	di}t        | d
      }|j                  }t        |d   |d   |d         }t        j                  |       |d   rz|d   ru|d   r'|d   r"t        ||      |d<    |j                  di | y |d   r"t        ||      |d<    |j                  di | y t        ||      |d<    |j                  di | y |j                  d       y )NTstr)requiredtype)r=   r>   no_logFbool)r=   r>   default)
account_idapi_keyr-   r.   r   changed)argument_specsupports_check_moderB   rC   r   r-   r.   dnsimple_record_infodnsimple_records_infodnsimple_domain_infoz$Need at least account_id and api_key)msg )
r   r1   r   r   validater6   	exit_jsonr8   r:   r$   )fieldsresultr%   r1   r   s        r   mainrP     s<    $(7 $etD"E2$e4 %v%HF 	5F  F
 ]]F
F<(9%9%'C 	MM& ly 1&>fX.-8-EF)*F&v& F^.9&#.FF*+F&v& .:&#-FF)*F&v&CDr   __main__)
__future__r   r   r   r>   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   :ansible_collections.community.general.plugins.module_utilsr   declarer   r	   r
   r   r*   r6   r8   r:   rP   __name__rK   r   r   <module>r[      s    C B.`(V
p 5 KT\\* *)*&/
/
/
+E\ zF }* *s   	A""A+