Skip to content

Commit

Permalink
[IMP] connector_dns: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
flotho committed Dec 26, 2022
1 parent 94f3d0a commit f400fdd
Show file tree
Hide file tree
Showing 45 changed files with 1,130 additions and 1,124 deletions.
2 changes: 0 additions & 2 deletions connector_dns/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Elico Corp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import backend
from . import connector
from . import models
from . import unit

37 changes: 17 additions & 20 deletions connector_dns/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Elico Corp
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'DNS connector',
'version': '8.0.1.0.0',
'category': 'Connector',
'depends': ['connector'],
'author': 'Elico Corp, '
'LasLabs, '
'Odoo Community Association (OCA)',
'license': 'AGPL-3',
'website': 'https://www.elico-corp.com',
'data': [
'views/dns_backend.xml',
'views/dns_record.xml',
'views/dns_zone.xml',
'views/dns_menu.xml',
'views/connector_config_settings.xml',
'data/dns_record_type.xml',
'security/dns.xml',
'security/ir.model.access.csv',
"name": "DNS connector",
"version": "8.0.1.0.0",
"category": "Connector",
"depends": ["connector"],
"author": "Elico Corp, " "LasLabs, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/infrastructure",
"data": [
"views/dns_backend.xml",
"views/dns_record.xml",
"views/dns_zone.xml",
"views/dns_menu.xml",
"views/connector_config_settings.xml",
"data/dns_record_type.xml",
"security/dns.xml",
"security/ir.model.access.csv",
],
'installable': True,
"installable": True,
}
3 changes: 1 addition & 2 deletions connector_dns/backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Elico Corp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import openerp.addons.connector.backend as backend

dns = backend.Backend('dns')
dns = backend.Backend("dns")
53 changes: 29 additions & 24 deletions connector_dns/connector.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Elico Corp
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api
from openerp.addons.connector.connector import Environment
from openerp import api, fields, models
from openerp.addons.connector.checkpoint import checkpoint
from openerp.addons.connector.connector import Environment


def get_environment(session, model_name, backend_id):
""" Create an environment to work with. """
backend_record = session.env['dns.backend'].browse(backend_id)
"""Create an environment to work with."""
backend_record = session.env["dns.backend"].browse(backend_id)
env = Environment(backend_record, session, model_name)
return env


class DNSBinding(models.AbstractModel):
""" Abstract Model for the Bindigs.
"""Abstract Model for the Bindigs.
All the models used as bindings between External System and Odoo
(``aws.dns.record``, ``aws.dns.zone``, ...) should ``_inherit`` it.
"""
_name = 'dns.binding'
_inherit = 'external.binding'
_description = 'DNS Binding (abstract)'

_name = "dns.binding"
_inherit = "external.binding"
_description = "DNS Binding (abstract)"

dns_backend_id = fields.Many2one(
comodel_name='dns.backend',
string='DNS Backend',
comodel_name="dns.backend",
string="DNS Backend",
store=True,
required=True,
ondelete='restrict',
default=lambda s: s._default_dns_backend_id()
ondelete="restrict",
default=lambda s: s._default_dns_backend_id(),
)
dns_id_external = fields.Char(
string='External ID',
help='ID of the record in external system.',
string="External ID",
help="ID of the record in external system.",
)
fail_date = fields.Datetime()

_sql_constraints = [
('backend_uniq', 'unique(dns_backend_id, dns_id_external)',
'A binding already exists with the same DNS External ID.'),
(
"backend_uniq",
"unique(dns_backend_id, dns_id_external)",
"A binding already exists with the same DNS External ID.",
),
]

@api.model
def _default_dns_backend_id(self):
return self.env['dns.backend'].search([
('is_default', '=', True),
('active', '=', True),
],
return self.env["dns.backend"].search(
[
("is_default", "=", True),
("active", "=", True),
],
limit=1,
)


def add_checkpoint(session, model_name, record_id, backend_id):
""" Add a row in the model ``connector.checkpoint`` for a record,
"""Add a row in the model ``connector.checkpoint`` for a record,
meaning it has to be reviewed by a user.
:param session: current session
:type session: :class:`openerp.addons.connector.session.ConnectorSession`
Expand All @@ -65,5 +69,6 @@ def add_checkpoint(session, model_name, record_id, backend_id):
:param backend_id: ID of the dnspod Backend
:type backend_id: int
"""
return checkpoint.add_checkpoint(session, model_name, record_id,
'dns.backend', backend_id)
return checkpoint.add_checkpoint(
session, model_name, record_id, "dns.backend", backend_id
)
16 changes: 7 additions & 9 deletions connector_dns/consumer.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from .unit.export_synchronizer import export_record
import logging

from .unit.export_synchronizer import export_record

import logging
_logger = logging.getLogger(__name__)


def delay_export(session, model_name, record_id, vals):
""" Delay a job which export a binding record.
"""Delay a job which export a binding record.
(A binding record being a ``dns.record.bind``,
``dns.zone.bind``, ...)
"""
if session.context.get('connector_no_export'):
if session.context.get("connector_no_export"):
return
fields = vals.keys()
export_record.delay(session, model_name, record_id, fields=fields)


def delay_export_all_bindings(session, model_name, record_id, vals):
""" Delay a job which export all the bindings of a record.
"""Delay a job which export all the bindings of a record.
In this case, it is called on records of normal models and will delay
the export for all the bindings.
"""
if session.context.get('connector_no_export'):
if session.context.get("connector_no_export"):
return
record = session.env[model_name].browse(record_id)
fields = vals.keys()
for binding in record.dns_bind_ids:
export_record.delay(session, binding._model._name, binding.id,
fields=fields)
export_record.delay(session, binding._model._name, binding.id, fields=fields)
114 changes: 60 additions & 54 deletions connector_dns/data/dns_record_type.xml
Original file line number Diff line number Diff line change
@@ -1,137 +1,143 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<openerp>
<data noupdate="1">

<record id="type_a" model="dns.record.type">
<field name="name">IPv4 Address</field>
<field name="code">A</field>
<field name="help">IPv4 address. Enter multiple addresses
<field name="help">IPv4 address. Enter multiple addresses
on separate lines.
Example:
192.0.2.235
Example:
192.0.2.235
198.51.100.234
</field>
<field name="validate_regex">^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\n?)+$</field>
<field
name="validate_regex"
>^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\n?)+$</field>
</record>

<record id="type_aaaa" model="dns.record.type">
<field name="name">IPv6 Address</field>
<field name="code">AAAA</field>
<field name="help">IPv6 address. Enter multiple addresses
<field name="help">IPv6 address. Enter multiple addresses
on separate lines.
Example:
2001:0db8:85a3:0:0:8a2e:0370:7334
Example:
2001:0db8:85a3:0:0:8a2e:0370:7334
fe80:0:0:0:202:b3ff:fe1e:8329
</field>
<field name="validate_regex">^((?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}\n?)+$</field>
</record>

<record id="type_cname" model="dns.record.type">
<field name="name">Canonical Name</field>
<field name="code">CNAME</field>
<field name="help">The domain name that you want to
resolve to instead of the value in the
<field name="help">The domain name that you want to
resolve to instead of the value in the
Name field.
Example:
Example:
www.example.com
</field>
<field name="validate_regex">^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$</field>
</record>

<record id="type_mx" model="dns.record.type">
<field name="name">Mail Exchange</field>
<field name="code">MX</field>
<field name="help">A priority and a domain name that
specifies a mail server. Enter multiple
<field name="help">A priority and a domain name that
specifies a mail server. Enter multiple
values on separate lines.
Format:
[priority] [mail server host name]
Example:
10 mailserver.example.com.
Format:
[priority] [mail server host name]
Example:
10 mailserver.example.com.
20 mailserver2.example.com.
</field>
<field name="validate_regex">^([12]?\d ([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\n)+$</field>
<field
name="validate_regex"
>^([12]?\d ([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\n)+$</field>
</record>

<record id="type_txt" model="dns.record.type">
<field name="name">Text</field>
<field name="code">TXT</field>
<field name="help">A text record.
Enter multiple values on separate lines.
Enclose text in quotation marks.
Example:
"Sample Text Entries"
Example:
"Sample Text Entries"
"Enclose entries in quotation marks"
</field>
<field name="validate_regex">^(".*"\n)+$</field>
</record>

<record id="type_ptr" model="dns.record.type">
<field name="name">Pointer</field>
<field name="code">PTR</field>
<field name="help">The domain name that you want to return.
Example:
Example:
www.example.com
</field>
<field name="validate_regex">^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$</field>
</record>

<record id="type_srv" model="dns.record.type">
<field name="name">Service Locator</field>
<field name="code">SRV</field>
<field name="help">A SRV record. For information about SRV
record format, refer to the applicable
documentation. Enter multiple values
<field name="help">A SRV record. For information about SRV
record format, refer to the applicable
documentation. Enter multiple values
on separate lines.
Format:
Format:
[priority] [weight] [port] [server host name]
Example:
1 10 5269 xmpp-server.example.com.
Example:
1 10 5269 xmpp-server.example.com.
2 12 5060 sip-server.example.com.
</field>
<field name="validate_regex">^(\d+ \d+ \d+ ([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\n)+$</field>
<field
name="validate_regex"
>^(\d+ \d+ \d+ ([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\n)+$</field>
</record>

<record id="type_spf" model="dns.record.type">
<field name="name">Sender Policy Framework</field>
<field name="code">SPF</field>
<field name="help">An SPF record. For information about SPF
record format, refer to the applicable
documentation. Enter multiple values
on separate lines. Enclose values in
<field name="help">An SPF record. For information about SPF
record format, refer to the applicable
documentation. Enter multiple values
on separate lines. Enclose values in
quotation marks.
Example:
Example:
"v=spf1 ip4:192.168.0.1/16-all"
</field>
<field name="validate_regex">.*</field>
</record>

<record id="type_naptr" model="dns.record.type">
<field name="name">Name Authority Pointer</field>
<field name="code">NAPTR</field>
<field name="help">An NAPTR record. For information about NAPTR
record format, refer to the applicable
documentation. Enter multiple values
<field name="help">An NAPTR record. For information about NAPTR
record format, refer to the applicable
documentation. Enter multiple values
on separate lines.
Format:
Format:
[order] [preference] [flags] [services] [regexp] [replacement]
Example:
100 100 "U" "" "!^.*$!sip:info@bar.example.com!" .
Example:
100 100 "U" "" "!^.*$!sip:info@bar.example.com!" .
10 100 "S" "SIP+D2U" "" foo.example.com.
</field>
<field name="validate_regex">.*</field>
</record>

<record id="type_ns" model="dns.record.type">
<field name="name">Name Server</field>
<field name="code">A</field>
<field name="help">The domain name of a name server.
Enter multiple name servers on
<field name="help">The domain name of a name server.
Enter multiple name servers on
separate lines.
Example:
ns1.amazon.com
ns2.amazon.org
ns3.amazon.net
Example:
ns1.amazon.com
ns2.amazon.org
ns3.amazon.net
ns4.amazon.co.uk
</field>
<field name="validate_regex">^(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\n)+$</field>
Expand Down
Loading

0 comments on commit f400fdd

Please sign in to comment.