~mthaddon/charm-haproxy/jammy

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: Barry Price
  • Date: 2019-03-21 11:33:58 UTC
  • mto: This revision was merged to the branch mainline in revision 125.
  • Revision ID: barry.price@canonical.com-20190321113358-k267w7vbnf20qmbq
Linting fixes, bzr ignore .venv dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
218
218
    haproxy_config = load_haproxy_config(haproxy_config_file)
219
219
    if haproxy_config is None:
220
220
        return None
221
 
    m = re.search("stats auth\s+(\w+):(\w+)", haproxy_config)
 
221
    m = re.search(r"stats auth\s+(\w+):(\w+)", haproxy_config)
222
222
    if m is not None:
223
223
        return m.group(2)
224
224
    else:
246
246
    if haproxy_config is None:
247
247
        return ()
248
248
    listen_stanzas = re.findall(
249
 
        "listen\s+([^\s]+)\s+([^:]+):(.*)",
 
249
        r"listen\s+([^\s]+)\s+([^:]+):(.*)",
250
250
        haproxy_config)
251
251
    # Match bind stanzas like:
252
252
    #
254
254
    # bind 2001:db8::1:80
255
255
    # bind 1.2.3.4:123 ssl crt /foo/bar
256
256
    bind_stanzas = re.findall(
257
 
        "\s+bind\s+([a-fA-F0-9\.:\*]+):(\d+).*\n\s+default_backend\s+([^\s]+)",
 
257
        r"\s+bind\s+([a-fA-F0-9\.:\*]+):(\d+).*\n\s+default_backend\s+([^\s]+)",
258
258
        haproxy_config, re.M)
259
259
    return (tuple(((service, addr, int(port))
260
260
                   for service, addr, port in listen_stanzas)) +
454
454
    monitoring_config.append("http-request deny unless allowed_cidr")
455
455
    monitoring_config.append("stats enable")
456
456
    monitoring_config.append("stats uri /")
457
 
    monitoring_config.append("stats realm Haproxy\ Statistics")
 
457
    monitoring_config.append("stats realm Haproxy\ Statistics")  # noqa: W605
458
458
    monitoring_config.append("stats auth %s:%s" %
459
459
                             (config_data['monitoring_username'],
460
460
                              monitoring_password))
1269
1269
                # to turn it into a string for comparison
1270
1270
                component_addr = octet_parser(name.getComponent())
1271
1271
                cert_addresses.add(str(component_addr))
1272
 
        except:
 
1272
        except Exception:
1273
1273
            pass
1274
1274
    if cert_addresses != unit_addresses:
1275
1275
        log('subjAltName: Cert (%s) != Unit (%s), assuming stale' % (
1289
1289
    """
1290
1290
    try:
1291
1291
        import ipaddress
 
1292
 
1292
1293
        def ipaddress_parser(octet):
1293
1294
            return str(ipaddress.ip_address(str(octet)))
1294
1295
        return ipaddress_parser
1295
1296
    except ImportError:
1296
1297
        import ipaddr
 
1298
 
1297
1299
        def trusty_ipaddress_parser(octet):
1298
1300
            return str(ipaddr.IPAddress(ipaddr.Bytes(str(octet))))
1299
1301
        return trusty_ipaddress_parser
1405
1407
        print("Unknown hook")
1406
1408
        sys.exit(1)
1407
1409
 
 
1410
 
1408
1411
if __name__ == "__main__":
1409
1412
    hook_name = os.path.basename(sys.argv[0])
1410
1413
    # Also support being invoked directly with hook as argument name.