Esempio n. 1
0
def test_generic_urlparse():
    url = 'https://assible.com/blog'
    parts = urlparse(url)
    generic_parts = generic_urlparse(parts)
    assert generic_parts.as_list() == list(parts)

    assert urlunparse(generic_parts.as_list()) == url
Esempio n. 2
0
    def fetch_role_related(self, related, role_id):
        """
        Fetch the list of related items for the given role.
        The url comes from the 'related' field of the role.
        """

        results = []
        try:
            url = _urljoin(self.api_server, self.available_api_versions['v1'],
                           "roles", role_id, related, "?page_size=50")
            data = self._call_galaxy(url)
            results = data['results']
            done = (data.get('next_link', None) is None)

            # https://github.com/assible/assible/issues/64355
            # api_server contains part of the API path but next_link includes the /api part so strip it out.
            url_info = urlparse(self.api_server)
            base_url = "%s://%s/" % (url_info.scheme, url_info.netloc)

            while not done:
                url = _urljoin(base_url, data['next_link'])
                data = self._call_galaxy(url)
                results += data['results']
                done = (data.get('next_link', None) is None)
        except Exception as e:
            display.warning(
                "Unable to retrieve role (id=%s) data (%s), but this is not fatal so we continue: %s"
                % (role_id, related, to_text(e)))
        return results
Esempio n. 3
0
def test_generic_urlparse_no_netloc_no_host():
    url = '/blog'
    parts = list(urlparse(url))
    generic_parts = generic_urlparse(parts)
    assert generic_parts.username is None
    assert generic_parts.password is None
    assert generic_parts.port is None
    assert generic_parts.hostname == ''
Esempio n. 4
0
def test_generic_urlparse_netloc():
    url = 'https://assible.com:443/blog'
    parts = urlparse(url)
    generic_parts = generic_urlparse(parts)
    assert generic_parts.hostname == parts.hostname
    assert generic_parts.hostname == 'assible.com'
    assert generic_parts.port == 443
    assert urlunparse(generic_parts.as_list()) == url
Esempio n. 5
0
def update_tls_hostname(result):
    if result['tls_hostname'] is None:
        # get default machine name from the url
        parsed_url = urlparse(result['docker_host'])
        if ':' in parsed_url.netloc:
            result['tls_hostname'] = parsed_url.netloc[:parsed_url.netloc.
                                                       rindex(':')]
        else:
            result['tls_hostname'] = parsed_url
Esempio n. 6
0
def test_generic_urlparse_no_netloc():
    url = 'https://*****:*****@assible.com:443/blog'
    parts = list(urlparse(url))
    generic_parts = generic_urlparse(parts)
    assert generic_parts.hostname == 'assible.com'
    assert generic_parts.port == 443
    assert generic_parts.username == 'user'
    assert generic_parts.password == 'passwd'
    assert urlunparse(generic_parts.as_list()) == url
Esempio n. 7
0
    def get_collection_versions(self, namespace, name):
        """
        Gets a list of available versions for a collection on a Galaxy server.

        :param namespace: The collection namespace.
        :param name: The collection name.
        :return: A list of versions that are available.
        """
        relative_link = False
        if 'v3' in self.available_api_versions:
            api_path = self.available_api_versions['v3']
            pagination_path = ['links', 'next']
            relative_link = True  # AH pagination results are relative an not an absolute URI.
        else:
            api_path = self.available_api_versions['v2']
            pagination_path = ['next']

        n_url = _urljoin(self.api_server, api_path, 'collections', namespace,
                         name, 'versions', '/')

        error_context_msg = 'Error when getting available collection versions for %s.%s from %s (%s)' \
                            % (namespace, name, self.name, self.api_server)
        data = self._call_galaxy(n_url, error_context_msg=error_context_msg)

        if 'data' in data:
            # v3 automation-hub is the only known API that uses `data`
            # since v3 pulp_assible does not, we cannot rely on version
            # to indicate which key to use
            results_key = 'data'
        else:
            results_key = 'results'

        versions = []
        while True:
            versions += [v['version'] for v in data[results_key]]

            next_link = data
            for path in pagination_path:
                next_link = next_link.get(path, {})

            if not next_link:
                break
            elif relative_link:
                # TODO: This assumes the pagination result is relative to the root server. Will need to be verified
                # with someone who knows the AH API.
                next_link = n_url.replace(urlparse(n_url).path, next_link)

            data = self._call_galaxy(to_native(next_link,
                                               errors='surrogate_or_strict'),
                                     error_context_msg=error_context_msg)

        return versions
Esempio n. 8
0
def get_s3_client(module, aws_connect_kwargs, location, ceph, s3_url):
    if s3_url and ceph:  # TODO - test this
        ceph = urlparse(s3_url)
        params = dict(module=module,
                      conn_type='client',
                      resource='s3',
                      use_ssl=ceph.scheme == 'https',
                      region=location,
                      endpoint=s3_url,
                      **aws_connect_kwargs)
    elif is_fakes3(s3_url):
        fakes3 = urlparse(s3_url)
        port = fakes3.port
        if fakes3.scheme == 'fakes3s':
            protocol = "https"
            if port is None:
                port = 443
        else:
            protocol = "http"
            if port is None:
                port = 80
        params = dict(module=module,
                      conn_type='client',
                      resource='s3',
                      region=location,
                      endpoint="%s://%s:%s" %
                      (protocol, fakes3.hostname, to_text(port)),
                      use_ssl=fakes3.scheme == 'fakes3s',
                      **aws_connect_kwargs)
    else:
        params = dict(module=module,
                      conn_type='client',
                      resource='s3',
                      region=location,
                      endpoint=s3_url,
                      **aws_connect_kwargs)
    return boto3_conn(**params)
Esempio n. 9
0
def is_fakes3(s3_url):
    """ Return True if s3_url has scheme fakes3:// """
    if s3_url is not None:
        return urlparse(s3_url).scheme in ('fakes3', 'fakes3s')
    else:
        return False
Esempio n. 10
0
def test_generic_urlparse_no_netloc_no_auth():
    url = 'https://assible.com:443/blog'
    parts = list(urlparse(url))
    generic_parts = generic_urlparse(parts)
    assert generic_parts.username is None
    assert generic_parts.password is None