Completed
Push — master ( 699989...d91a4b )
by Andrii
14:03
created

heppy.modules.domain.render_auth_info()   A

Complexity

Conditions 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 5
rs 9.4285
1
from collections import OrderedDict
2
3
from ..Module import Module
4
5
class domain(Module):
6
    opmap = {
7
        'greeting':     'descend',
8
        'infData':      'descend',
9
        'chkData':      'descend',
10
        'creData':      'descend',
11
        'ns':           'descend',
12
        'authInfo':     'descend',
13
        'name':         'set',
14
        'roid':         'set',
15
        'clID':         'set',
16
        'crID':         'set',
17
        'upID':         'set',
18
        'crDate':       'set',
19
        'upDate':       'set',
20
        'exDate':       'set',
21
        'trDate':       'set',
22
        'pw':           'set',
23
        'registrant':   'set',
24
    }
25
26
### RESPONSE parsing
27
28
    def parse_cd(self, response, tag):
29
        name    = response.find(tag, 'domain:name')
30
        reason  = response.find(tag, 'domain:reason')
31
        response.addto('avails', {name.text.lower(): name.attrib['avail']})
32
        if reason is not None:
33
            response.addto('reasons', {name.text.lower(): reason.text})
34
35
    def parse_status(self, response, tag):
36
        response.addpair('statuses', tag.attrib['s'])
37
38
    def parse_hostObj(self, response, tag):
39
        response.addpair('nss', tag.text.lower())
40
41
    def parse_host(self, response, tag):
42
        response.addpair('hosts', tag.text.lower())
43
44
    def parse_contact(self, response, tag):
45
        response.set(tag.attrib['type'], tag.text)
46
47
### REQUEST rendering
48
49
    def render_check(self, request):
50
        command = self.render_command(request, 'check')
51
        for name in request.get('names').itervalues():
52
            request.sub(command, 'domain:name', {}, name)
53
54
    def render_info(self, request):
55
        hosts = request.get('hosts', 'all')
56
        command = self.render_command_fields(request, 'info', {'name': {'hosts': hosts}})
57
        if request.has('pw'):
58
            self.render_auth_info(request, command)
59
60
    def render_auth_info(self, request, command, pw = None):
61
        if pw is None:
62
            pw = request.get('pw', '')
63
        authInfo = request.sub(command, 'domain:authInfo')
64
        request.sub(authInfo, 'domain:pw', {}, pw)
65
66
    def render_create(self, request):
67
        command = self.render_command_fields(request, 'create', OrderedDict([
68
            ('name', {}),
69
            ('period', {'unit': 'y'}),
70
        ]))
71
        if request.get('registrant'):
72
            request.sub(command, 'domain:registrant', {}, request.get('registrant'))
73
        for type in ('admin', 'tech', 'billing'):
74
            if request.get(type):
75
                request.sub(command, 'domain:contact', {'type': type}, request.get(type))
76
        self.render_auth_info(request, command)
77
78
    def render_delete(self, request):
79
        self.render_command_fields(request, 'delete')
80
81
    def render_renew(self, request):
82
        self.render_command_fields(request, 'renew', OrderedDict([
83
            ('name', {}),
84
            ('curExpDate', {}),
85
            ('period', {'unit': 'y'}),
86
        ]))
87
88
    def render_update(self, request):
89
        command = self.render_command_fields(request, 'update')
90