Exemple #1
0
    def _get_api(self):
        if self.remote_url not in self._cached_capabilities:
            tmp = RestV1Methods(self.remote_url, self.token,
                                self.custom_headers, self._output,
                                self.requester, self.verify_ssl,
                                self._put_headers)
            cap = tmp.server_capabilities()
            self._cached_capabilities[self.remote_url] = cap
            logger.debug("REST: Cached capabilities for the remote: %s" % cap)
            if not self._revisions_enabled and ONLY_V2 in cap:
                raise OnlyV2Available(self.remote_url)

        if self._revisions_enabled and REVISIONS in self._cached_capabilities.get(
                self.remote_url, []):
            checksum_deploy = CHECKSUM_DEPLOY in self._cached_capabilities.get(
                self.remote_url, [])
            return RestV2Methods(self.remote_url, self.token,
                                 self.custom_headers, self._output,
                                 self.requester, self.verify_ssl,
                                 self._put_headers, checksum_deploy)
        else:
            return RestV1Methods(self.remote_url, self.token,
                                 self.custom_headers, self._output,
                                 self.requester, self.verify_ssl,
                                 self._put_headers)
Exemple #2
0
    def _get_api(self):
        if self.remote_url not in self._cached_capabilities:
            tmp = RestV1Methods(self.remote_url, self.token,
                                self.custom_headers, self._output,
                                self.requester, self.verify_ssl,
                                self._put_headers)
            _, _, cap = tmp.server_info()
            self._cached_capabilities[self.remote_url] = cap

        if not self.block_v2 and REVISIONS in self._cached_capabilities[
                self.remote_url]:
            checksum_deploy = CHECKSUM_DEPLOY in self._cached_capabilities[
                self.remote_url]
            revisions_enabled = get_env("CONAN_CLIENT_REVISIONS_ENABLED",
                                        False)
            self.custom_headers[
                "V2_COMPATIBILITY_MODE"] = "1" if not revisions_enabled else "0"
            return RestV2Methods(self.remote_url, self.token,
                                 self.custom_headers, self._output,
                                 self.requester, self.verify_ssl,
                                 self._put_headers, checksum_deploy)
        else:
            return RestV1Methods(self.remote_url, self.token,
                                 self.custom_headers, self._output,
                                 self.requester, self.verify_ssl,
                                 self._put_headers)
Exemple #3
0
    def _get_api(self):
        if self.remote_url not in self._capabilities:
            tmp = RestV1Methods(self.remote_url, self.token,
                                self.custom_headers, self._output,
                                self.requester, self.verify_ssl,
                                self._put_headers)
            _, _, cap = tmp.server_info()
            self._capabilities[self.remote_url] = cap

        return RestV1Methods(self.remote_url, self.token, self.custom_headers,
                             self._output, self.requester, self.verify_ssl,
                             self._put_headers)
    def test_corrupted_manifest(self):
        remote_url = "http://some.url"
        pref = PackageReference.loads("lib/version@user/channel#rrev:123#prev")
        returned_files = {CONAN_MANIFEST: b"not expected content"}

        with patch.object(RestV1Methods, "_get_file_to_url_dict", return_value=None), \
             patch.object(RestV1Methods, "_download_files", return_value=returned_files):

            config = namedtuple("ConfigMock", "download_cache")(None)
            v1 = RestV1Methods(remote_url,
                               token=None,
                               custom_headers=None,
                               output=None,
                               requester=None,
                               config=config,
                               verify_ssl=None)
            with self.assertRaises(ConanException) as exc:
                v1.get_package_manifest(pref=pref)

            # Exception tells me about the originating error and the request I was doing.
            # It doesn't show the PREV because it is v1
            self.assertIn(
                "Error retrieving manifest file for package '{}'"
                " from remote ({})".format(pref, remote_url),
                str(exc.exception))
            self.assertIn("invalid literal for int() with base 10",
                          str(exc.exception))
Exemple #5
0
    def authenticate(self, user, password):
        api_v1 = RestV1Methods(self._remote_url, self._token,
                               self._custom_headers, self._output,
                               self._requester, self._verify_ssl,
                               self._artifacts_properties)

        if self._refresh_token and self._token:
            token, refresh_token = api_v1.refresh_token(
                self._token, self._refresh_token)
        else:
            try:
                # Check capabilities can raise also 401 until the new Artifactory is released
                oauth_capable = self._capable(OAUTH_TOKEN, user, password)
            except AuthenticationException:
                oauth_capable = False

            if oauth_capable:
                # Artifactory >= 6.13.X
                token, refresh_token = api_v1.authenticate_oauth(
                    user, password)
            else:
                token = api_v1.authenticate(user, password)
                refresh_token = None

        return token, refresh_token
Exemple #6
0
 def authenticate(self, user, password):
     apiv1 = RestV1Methods(self.remote_url, self.token, self.custom_headers,
                           self._output, self.requester, self.verify_ssl,
                           self._put_headers)
     # Use v1 for the auth because the "ping" could be also protected so we don't know if
     # we can use v2
     return apiv1.authenticate(user, password)
Exemple #7
0
 def _get_api(self):
     revisions = self._capable(REVISIONS)
     if self._revisions_enabled and revisions:
         checksum_deploy = self._capable(CHECKSUM_DEPLOY)
         return RestV2Methods(self.remote_url, self.token, self.custom_headers, self._output,
                              self.requester, self.verify_ssl, self._put_headers,
                              checksum_deploy)
     else:
         return RestV1Methods(self.remote_url, self.token, self.custom_headers, self._output,
                              self.requester, self.verify_ssl, self._put_headers)
Exemple #8
0
 def _capable(self, capability):
     capabilities = self._cached_capabilities.get(self.remote_url)
     if capabilities is None:
         tmp = RestV1Methods(self.remote_url, self.token, self.custom_headers, self._output,
                             self.requester, self.verify_ssl, self._put_headers)
         capabilities = tmp.server_capabilities()
         self._cached_capabilities[self.remote_url] = capabilities
         logger.debug("REST: Cached capabilities for the remote: %s" % capabilities)
         if not self._revisions_enabled and ONLY_V2 in capabilities:
             raise OnlyV2Available(self.remote_url)
     return capability in capabilities
Exemple #9
0
    def _get_api(self):
        if self.remote_url not in self._capabilities:
            tmp = RestV1Methods(self.remote_url, self.token,
                                self.custom_headers, self._output,
                                self.requester, self.verify_ssl,
                                self._put_headers)
            _, _, cap = tmp.server_info()
            self._capabilities[self.remote_url] = cap

        # FIXME: ONLY CONNECT TO APIV2 THE CLIENT WHEN THE PROTOCOL IS STABLE
        # from conans import API_V2, CHECKSUM_DEPLOY
        # from conans.client.rest.rest_client_v2 import RestV2Methods
        #if API_V2 in self._capabilities[self.remote_url]:
        #    checksum_deploy = CHECKSUM_DEPLOY in self._capabilities[self.remote_url]
        #    return RestV2Methods(self.remote_url, self.token, self.custom_headers, self._output,
        #                         self.requester, self.verify_ssl, self._put_headers,
        #                         checksum_deploy)
        #else:
        return RestV1Methods(self.remote_url, self.token, self.custom_headers,
                             self._output, self.requester, self.verify_ssl,
                             self._put_headers)
Exemple #10
0
    def _get_api(self):
        if self.remote_url not in self._capabilities:
            tmp = RestV1Methods(self.remote_url, self.token,
                                self.custom_headers, self._output,
                                self.requester, self.verify_ssl,
                                self._put_headers)
            _, _, cap = tmp.server_info()
            self._capabilities[self.remote_url] = cap

        if API_V2 in self._capabilities[self.remote_url]:
            checksum_deploy = CHECKSUM_DEPLOY in self._capabilities[
                self.remote_url]
            return RestV2Methods(self.remote_url, self.token,
                                 self.custom_headers, self._output,
                                 self.requester, self.verify_ssl,
                                 self._put_headers, checksum_deploy)
        else:
            return RestV1Methods(self.remote_url, self.token,
                                 self.custom_headers, self._output,
                                 self.requester, self.verify_ssl,
                                 self._put_headers)
Exemple #11
0
 def _capable(self, capability, user=None, password=None):
     capabilities = self._cached_capabilities.get(self._remote_url)
     if capabilities is None:
         tmp = RestV1Methods(self._remote_url, self._token,
                             self._custom_headers, self._output,
                             self._requester, self._config,
                             self._verify_ssl, self._artifacts_properties)
         capabilities = tmp.server_capabilities(user, password)
         self._cached_capabilities[self._remote_url] = capabilities
         logger.debug("REST: Cached capabilities for the remote: %s" %
                      capabilities)
         if not self._revisions_enabled and ONLY_V2 in capabilities:
             raise OnlyV2Available(self._remote_url)
     return capability in capabilities
Exemple #12
0
    def _get_api(self):
        if self.remote_url not in self._cached_capabilities:
            tmp = RestV1Methods(self.remote_url, self.token,
                                self.custom_headers, self._output,
                                self.requester, self.verify_ssl,
                                self._put_headers)
            _, _, cap = tmp.server_info()
            self._cached_capabilities[self.remote_url] = cap
            if not self._revisions_enabled and ONLY_V2 in cap:
                raise OnlyV2Available(self.remote_url)

        if self._revisions_enabled and REVISIONS in self._cached_capabilities[
                self.remote_url]:
            checksum_deploy = CHECKSUM_DEPLOY in self._cached_capabilities[
                self.remote_url]
            return RestV2Methods(self.remote_url, self.token,
                                 self.custom_headers, self._output,
                                 self.requester, self.verify_ssl,
                                 self._put_headers, checksum_deploy)
        else:
            return RestV1Methods(self.remote_url, self.token,
                                 self.custom_headers, self._output,
                                 self.requester, self.verify_ssl,
                                 self._put_headers)
Exemple #13
0
 def _get_api(self):
     revisions = self._capable(REVISIONS)
     matrix_params = self._capable(MATRIX_PARAMS)
     if self._revisions_enabled and revisions:
         checksum_deploy = self._capable(CHECKSUM_DEPLOY)
         return RestV2Methods(self._remote_url, self._token,
                              self._custom_headers, self._output,
                              self._requester, self._verify_ssl,
                              self._artifacts_properties, checksum_deploy,
                              matrix_params)
     else:
         return RestV1Methods(self._remote_url, self._token,
                              self._custom_headers, self._output,
                              self._requester, self._verify_ssl,
                              self._artifacts_properties, matrix_params)
Exemple #14
0
    def authenticate(self, user, password):
        api_v1 = RestV1Methods(self.remote_url, self.token, self.custom_headers, self._output,
                               self.requester, self.verify_ssl, self._put_headers)

        if self.refresh_token and self.token:
            token, refresh_token = api_v1.refresh_token(self.token, self.refresh_token)
        else:
            if OAUTH_TOKEN in self._cached_capabilities.get(self.remote_url, []):
                # Artifactory >= 6.13.X
                token, refresh_token = api_v1.authenticate_oauth(user, password)
            else:
                token = api_v1.authenticate(user, password)
                refresh_token = None

        return token, refresh_token