Exemplo n.º 1
0
 def __call__(self, data: str):
     try:
         url = URL(data)
     except ValueError:
         raise ValidationError(_("URL cannot be parsed"),
                               code="parse_error")
     if url.has_query_param('db'):
         if not url.query_param('db').isdigit():
             raise ValidationError(_("Invalid port specified"),
                                   code="invalid_port")
     if url.scheme() == "unix":
         if url.host():
             raise ValidationError(
                 _("Hostname not supported for unix domain sockets"),
                 code="unix_domain_socket_hostname")
         if url.port():
             raise ValidationError(
                 _("Port not supported for unix domain sockets"),
                 code="unix_domain_socket_port")
         if not url.path():
             raise ValidationError(
                 _("No path specified for unix domain socket"),
                 code="unix_domain_socket_path")
     if url.scheme() in ("redis", "redis+tls"):
         if not url.host():
             raise ValidationError(_("No host specified"),
                                   code="host_missing")
Exemplo n.º 2
0
 def test_remove_port(self):
     url = URL('https://example.com/hello?x=100')
     new = url.port('')
     self.assertEqual('https://example.com/hello?x=100', str(new))
Exemplo n.º 3
0
    # Do some sanity checks on the config
    requiredAttribs = [
        'serviceName', 'package', 'components', 'configurations'
    ]
    for attrib in requiredAttribs:
        if not attrib in service_config:
            log.error("Invalid configuration. Missing required attribute '%s'",
                      attrib)
            sys.exit(3)

    log.info('Installing service: %s on ambari host: %s',
             service_config['serviceName'], args.ambari_host)
    ambari_host_uri = URL(args.ambari_host)
    ambari_client = Ambari(ambari_host_uri.host(),
                           port=ambari_host_uri.port(),
                           protocol=ambari_host_uri.scheme(),
                           username=args.username,
                           password=args.password,
                           identifier='hdiapps')
    # If this is being invoked from outside the cluster, we must fixup the href references contained within the responses
    ambari_client.client.request_params['hooks'] = dict(
        response=shared_lib.Fixup(ambari_host_uri).fixup)
    # Assume we only have 1 cluster managed by this Ambari installation
    cluster = ambari_client.clusters.next()
    log.debug('Cluster: %s, href: %s', cluster.cluster_name, cluster._href)

    # Pull in any extra dynamic configuration
    if args.extra_config:
        try:
            extra_config = json.loads(args.extra_config)
        service_config = config_request.json()
        log.debug('Service config: %s', service_config)
    except:
        log.error("Invalid configuration URI", exc_info=True)
        sys.exit(2)

    # Do some sanity checks on the config
    requiredAttribs = ['serviceName', 'package', 'components', 'configurations']
    for attrib in requiredAttribs:
        if not attrib in service_config:
            log.error("Invalid configuration. Missing required attribute '%s'", attrib)
            sys.exit(3)

    log.info('Installing service: %s on ambari host: %s', service_config['serviceName'], args.ambari_host)
    ambari_host_uri = URL(args.ambari_host)
    ambari_client = Ambari(ambari_host_uri.host(), port=ambari_host_uri.port(), protocol=ambari_host_uri.scheme(), username=args.username, password=args.password, identifier='hdiapps')
    # If this is being invoked from outside the cluster, we must fixup the href references contained within the responses
    ambari_client.client.request_params['hooks'] = dict(response=shared_lib.Fixup(ambari_host_uri).fixup)
    # Assume we only have 1 cluster managed by this Ambari installation 
    cluster = ambari_client.clusters.next()
    log.debug('Cluster: %s, href: %s', cluster.cluster_name, cluster._href)

    # Pull in any extra dynamic configuration
    if args.extra_config:
        try:
            extra_config = json.loads(args.extra_config)
            log.debug('Applying dynamic service configuration specified on command-line: %s', extra_config)
        except:
            log.warning('Extra configuration specified by the -x argument could not be parsed as JSON. The value was \'%s\'. Details: ', args.extra_config, exc_info=True)
            extra_config = {}    
    else:
Exemplo n.º 5
0
                   query='q=google')
print(argument_url)
print(argument_url.as_string())
inline_url = URL().scheme('https').domain('www.google.com').path(
    'search').query_param('q', 'google')
print(inline_url)
print(inline_url.as_string())

u = URL('postgres://*****:*****@localhost:1234/test?ssl=true')
print(u.scheme())
print(u.host())
print(u.domain())
print(u.username())
print(u.password())
print(u.netloc())
print(u.port())
print(u.path())
print(u.query())
print(u.path_segments())
print(u.query_param('ssl'))
print(u.query_param('ssl', as_list=True))
print(u.query_params())
print(u.has_query_param('ssl'))
print(u.subdomains())

u = URL.from_string('https://github.com/minwook-shin')
print(u.path_segment(0))

new_url = u.add_path_segment('minwook-shin.github.com')
print(new_url.as_string())
Exemplo n.º 6
0
 def test_remove_port(self):
     url = URL('https://example.com/hello?x=100')
     new = url.port('')
     self.assertEqual('https://example.com/hello?x=100', str(new))