Esempio n. 1
0
 def remove_packages(name, version, username, channel, auth_user):
     ref = ConanFileReference(name, version, username, channel)
     conan_service = ConanService(app.authorizer, app.server_store,
                                  auth_user)
     reader = codecs.getreader("utf-8")
     payload = json.load(reader(request.body))
     conan_service.remove_packages(ref, payload["package_ids"])
Esempio n. 2
0
    def setUp(self):
        self.ref = ConanFileReference.loads("openssl/2.0.3@lasote/testing#%s" % DEFAULT_REVISION_V1)

        self.pref = PackageReference(self.ref, "123123123", DEFAULT_REVISION_V1)
        self.tmp_dir = temp_folder()

        read_perms = [("*/*@*/*", "*")]
        write_perms = []
        authorizer = BasicAuthorizer(read_perms, write_perms)

        self.fake_url = "http://url"
        updown_auth_manager = JWTUpDownAuthManager("secret", timedelta(seconds=200))
        adapter = ServerDiskAdapter(self.fake_url, self.tmp_dir, updown_auth_manager)
        self.server_store = ServerStore(storage_adapter=adapter)
        self.service = ConanService(authorizer, self.server_store, "lasote")
        self.search_service = SearchService(authorizer, self.server_store, "lasote")

        files = hello_source_files("test")
        save_files(self.server_store.export(self.ref), files)
        self.server_store.update_last_revision(self.ref)
        self.conan_digest = FileTreeManifest.create(self.server_store.export(self.ref))
        conan_digest_path = os.path.join(self.server_store.export(self.ref), CONAN_MANIFEST)
        save(conan_digest_path, str(self.conan_digest))

        files = hello_source_files("package")
        save_files(self.server_store.package(self.pref), files)
Esempio n. 3
0
 def remove_recipe(name, version, username, channel, auth_user):
     """ Remove any existing recipes or its packages created.
     Will remove all revisions, packages and package revisions (parent folder)"""
     ref = ConanFileReference(name, version, username, channel)
     conan_service = ConanService(app.authorizer, app.server_store,
                                  auth_user)
     conan_service.remove_conanfile(ref)
Esempio n. 4
0
 def remove_all_packages(name,
                         version,
                         username,
                         channel,
                         auth_user,
                         revision=None):
     """ Remove all packages from a RREV"""
     ref = ConanFileReference(name, version, username, channel,
                              revision)
     conan_service = ConanService(app.authorizer, app.server_store,
                                  auth_user)
     conan_service.remove_all_packages(ref)
Esempio n. 5
0
 def get_recipe_snapshot(name, version, username, channel, auth_user):
     """
     Get a dictionary with all files and their each md5s
     """
     conan_service = ConanService(app.authorizer, app.server_store,
                                  auth_user)
     ref = ConanFileReference(name, version, username, channel)
     snapshot = conan_service.get_recipe_snapshot(ref)
     snapshot_norm = {
         filename.replace("\\", "/"): the_md5
         for filename, the_md5 in snapshot.items()
     }
     return snapshot_norm
Esempio n. 6
0
 def get_recipe_manifest_url(name, version, username, channel,
                             auth_user):
     """
     Get a dict with all files and the download url
     """
     conan_service = ConanService(app.authorizer, app.server_store,
                                  auth_user)
     ref = ConanFileReference(name, version, username, channel)
     urls = conan_service.get_conanfile_download_urls(
         ref, [CONAN_MANIFEST])
     if not urls:
         raise RecipeNotFoundException(ref)
     return urls
Esempio n. 7
0
 def remove_recipe_files(name, version, username, channel, auth_user):
     # The remove files is a part of the upload process, where the revision in v1 will
     # always be DEFAULT_REVISION_V1
     revision = DEFAULT_REVISION_V1
     ref = ConanFileReference(name, version, username, channel,
                              revision)
     conan_service = ConanService(app.authorizer, app.server_store,
                                  auth_user)
     reader = codecs.getreader("utf-8")
     payload = json.load(reader(request.body))
     files = [
         os.path.normpath(filename) for filename in payload["files"]
     ]
     conan_service.remove_conanfile_files(ref, files)
Esempio n. 8
0
 def get_conanfile_download_urls(name, version, username, channel,
                                 auth_user):
     """
     Get a dict with all files and the download url
     """
     conan_service = ConanService(app.authorizer, app.server_store,
                                  auth_user)
     ref = ConanFileReference(name, version, username, channel)
     try:
         urls = conan_service.get_conanfile_download_urls(ref)
     except NotFoundException:
         raise RecipeNotFoundException(ref)
     urls_norm = {
         filename.replace("\\", "/"): url
         for filename, url in urls.items()
     }
     return urls_norm
Esempio n. 9
0
 def get_conanfile_upload_urls(name, version, username, channel,
                               auth_user):
     """
     Get a dict with all files and the upload url
     """
     conan_service = ConanService(app.authorizer, app.server_store,
                                  auth_user)
     ref = ConanFileReference(name, version, username, channel,
                              DEFAULT_REVISION_V1)
     reader = codecs.getreader("utf-8")
     filesizes = json.load(reader(request.body))
     urls = conan_service.get_conanfile_upload_urls(ref, filesizes)
     urls_norm = {
         filename.replace("\\", "/"): url
         for filename, url in urls.items()
     }
     app.server_store.update_last_revision(ref)
     return urls_norm
Esempio n. 10
0
 def remove_package(name,
                    version,
                    username,
                    channel,
                    package_id,
                    auth_user,
                    revision=None,
                    p_revision=None):
     """ - If both RRev and PRev are specified, it will remove the specific package revision
           of the specific recipe revision.
         - If PRev is NOT specified but RRev is specified (package_recipe_revision_url)
           it will remove all the package revisions
      """
     pref = get_package_ref(name, version, username, channel,
                            package_id, revision, p_revision)
     conan_service = ConanService(app.authorizer, app.server_store,
                                  auth_user)
     conan_service.remove_package(pref)
Esempio n. 11
0
        def get_package_manifest_url(name, version, username, channel,
                                     package_id, auth_user):
            """
            Get a dict with all files and the download url
            """
            conan_service = ConanService(app.authorizer, app.server_store,
                                         auth_user)
            ref = ConanFileReference(name, version, username, channel)
            pref = PackageReference(ref, package_id)

            urls = conan_service.get_package_download_urls(
                pref, [CONAN_MANIFEST])
            if not urls:
                raise PackageNotFoundException(pref)
            urls_norm = {
                filename.replace("\\", "/"): url
                for filename, url in urls.items()
            }
            return urls_norm
Esempio n. 12
0
        def get_package_download_urls(name, version, username, channel,
                                      package_id, auth_user):
            """
            Get a dict with all packages files and the download url for each one
            """
            conan_service = ConanService(app.authorizer, app.server_store,
                                         auth_user)
            ref = ConanFileReference(name, version, username, channel)
            pref = PackageReference(ref, package_id)
            try:
                urls = conan_service.get_package_download_urls(pref)
            except NotFoundException:
                raise PackageNotFoundException(pref)

            urls_norm = {
                filename.replace("\\", "/"): url
                for filename, url in urls.items()
            }
            return urls_norm
Esempio n. 13
0
class ConanServiceTest(unittest.TestCase):

    def setUp(self):
        self.ref = ConanFileReference.loads("openssl/2.0.3@lasote/testing#%s" % DEFAULT_REVISION_V1)

        self.pref = PackageReference(self.ref, "123123123", DEFAULT_REVISION_V1)
        self.tmp_dir = temp_folder()

        read_perms = [("*/*@*/*", "*")]
        write_perms = []
        authorizer = BasicAuthorizer(read_perms, write_perms)

        self.fake_url = "http://url"
        updown_auth_manager = JWTUpDownAuthManager("secret", timedelta(seconds=200))
        adapter = ServerDiskAdapter(self.fake_url, self.tmp_dir, updown_auth_manager)
        self.server_store = ServerStore(storage_adapter=adapter)
        self.service = ConanService(authorizer, self.server_store, "lasote")
        self.search_service = SearchService(authorizer, self.server_store, "lasote")

        files = hello_source_files("test")
        save_files(self.server_store.export(self.ref), files)
        self.server_store.update_last_revision(self.ref)
        self.conan_digest = FileTreeManifest.create(self.server_store.export(self.ref))
        conan_digest_path = os.path.join(self.server_store.export(self.ref), CONAN_MANIFEST)
        save(conan_digest_path, str(self.conan_digest))

        files = hello_source_files("package")
        save_files(self.server_store.package(self.pref), files)

    def test_get_recipe_snapshot(self):
        snap = self.service.get_recipe_snapshot(self.ref)
        base_path = self.server_store.export(self.ref)

        snap_expected = {'hello.cpp': md5sum(os.path.join(base_path, "hello.cpp")),
                         'conanmanifest.txt': md5sum(os.path.join(base_path, "conanmanifest.txt")),
                         'executable': md5sum(os.path.join(base_path, "executable")),
                         'main.cpp':  md5sum(os.path.join(base_path, "main.cpp")),
                         'CMakeLists.txt':  md5sum(os.path.join(base_path, "CMakeLists.txt")),
                         'hellotest.h':  md5sum(os.path.join(base_path, "hellotest.h"))}

        self.assertEquals(snap, snap_expected)

    def test_get_conanfile_download_urls(self):
        urls = self.service.get_conanfile_download_urls(self.ref)
        # Remove parameters
        urls = {name: url.split("?signature")[0] for name, url in urls.items()}

        def fake_url_build(filename):
            return (self.fake_url + "/"
                    + self.ref.dir_repr()
                    + "/" + self.ref.revision
                    + "/export/" + filename)

        expected_urls = {'CMakeLists.txt': fake_url_build('CMakeLists.txt'),
                         'conanmanifest.txt': fake_url_build('conanmanifest.txt'),
                         'executable': fake_url_build('executable'),
                         'hello.cpp': fake_url_build('hello.cpp'),
                         'hellotest.h': fake_url_build('hellotest.h'),
                         'main.cpp': fake_url_build('main.cpp')}
        self.assertEquals(urls, expected_urls)

    def test_get_package_download_urls(self):
        urls = self.service.get_package_download_urls(self.pref)
        # Remove parameters
        urls = {name: url.split("?signature")[0] for name, url in urls.items()}

        def fake_url_build(filename):
            return (self.fake_url
                    + "/" + self.pref.ref.dir_repr()
                    + "/" + self.pref.ref.revision
                    + "/package/" + self.pref.id
                    + "/" + self.pref.revision
                    + "/" + filename)

        expected_urls = {'CMakeLists.txt': fake_url_build('CMakeLists.txt'),
                         'executable': fake_url_build('executable'),
                         'hello.cpp': fake_url_build('hello.cpp'),
                         'hellopackage.h': fake_url_build('hellopackage.h'),
                         'main.cpp': fake_url_build('main.cpp')}
        self.assertEquals(urls, expected_urls)

    def test_get_conanfile_upload_urls(self):
        urls = self.service.get_conanfile_upload_urls(self.ref,
                                                      {"conanfile.py": 23,
                                                       "conanmanifest.txt": 24})
        # Remove parameters
        urls = {name: url.split("?signature")[0] for name, url in urls.items()}

        def fake_url_build(filename):
            return (self.fake_url
                    + "/" + self.ref.dir_repr()
                    + "/" + self.ref.revision
                    + "/export/" + filename)

        expected_urls = {'conanfile.py': fake_url_build('conanfile.py'),
                         'conanmanifest.txt': fake_url_build('conanmanifest.txt')}
        self.assertEquals(urls, expected_urls)

    def test_get_package_upload_urls(self):
        urls = self.service.get_package_upload_urls(self.pref, {"uno.lib": 23, "dos.dll": 24})
        # Remove parameters
        urls = {name: url.split("?signature")[0] for name, url in urls.items()}

        def fake_url_build(filename):
            return (self.fake_url
                    + "/" + self.pref.ref.dir_repr()
                    + "/" + self.pref.ref.revision
                    + "/package/" + self.pref.id
                    + "/" + self.pref.revision
                    + "/" + filename)

        expected_urls = {'uno.lib': fake_url_build('uno.lib'),
                         'dos.dll': fake_url_build('dos.dll')}
        self.assertEquals(urls, expected_urls)

    def test_search(self):
        """ check the dict is returned by get_packages_info service
        """
        # Creating and saving conans, packages, and conans.vars
        ref2 = ConanFileReference("openssl", "3.0", "lasote", "stable", DEFAULT_REVISION_V1)
        ref3 = ConanFileReference("Assimp", "1.10", "fenix", "stable", DEFAULT_REVISION_V1)
        ref4 = ConanFileReference("assimpFake", "0.1", "phil", "stable", DEFAULT_REVISION_V1)

        pref2 = PackageReference(ref2, "12345587754", DEFAULT_REVISION_V1)
        pref3 = PackageReference(ref3, "77777777777", DEFAULT_REVISION_V1)

        conan_vars = """
[options]
    use_Qt=%s
"""
        conan_vars1 = conan_vars % "True"
        conan_vars2 = conan_vars % "False"
        conan_vars3 = conan_vars % "True"

        save_files(self.server_store.package(self.pref), {CONANINFO: conan_vars1})
        self.server_store.update_last_package_revision(self.pref)
        save_files(self.server_store.package(pref2), {CONANINFO: conan_vars2})
        self.server_store.update_last_package_revision(pref2)
        save_files(self.server_store.package(pref3), {CONANINFO: conan_vars3})
        self.server_store.update_last_package_revision(pref3)

        save_files(self.server_store.export(ref4), {"dummy.txt": "//"})

        info = self.search_service.search()
        expected = [ref3, ref4, self.ref, ref2]
        self.assertEqual(expected, info)

        info = self.search_service.search(pattern="Assimp*", ignorecase=False)
        self.assertEqual(info, [ref3.copy_clear_rev()])

        info = self.search_service.search_packages(ref2, None)
        self.assertEqual(info, {'12345587754': {'full_requires': [],
                                                'options': {'use_Qt': 'False'},
                                                'settings': {},
                                                'recipe_hash': None}})

        info = self.search_service.search_packages(ref3, None)
        self.assertEqual(info, {'77777777777': {'full_requires': [],
                                                'options': {'use_Qt': 'True'},
                                                'settings': {},
                                                'recipe_hash': None}})

    def remove_test(self):
        ref2 = ConanFileReference("OpenCV", "3.0", "lasote", "stable", DEFAULT_REVISION_V1)
        ref3 = ConanFileReference("Assimp", "1.10", "lasote", "stable", DEFAULT_REVISION_V1)

        pref2 = PackageReference(ref2, "12345587754", DEFAULT_REVISION_V1)
        pref3 = PackageReference(ref3, "77777777777", DEFAULT_REVISION_V1)

        save_files(self.server_store.export(ref2), {"fake.txt": "//fake"})
        self.server_store.update_last_revision(ref2)
        save_files(self.server_store.package(pref2), {"fake.txt": "//fake"})
        self.server_store.update_last_package_revision(pref2)
        save_files(self.server_store.package(pref3), {"fake.txt": "//fake"})
        self.server_store.update_last_package_revision(pref3)

        # Delete all the conans folder
        self.service.remove_conanfile(self.ref)
        conan_path = self.server_store.conan(self.ref)
        self.assertFalse(os.path.exists(conan_path))

        # Delete one package
        self.service.remove_packages(ref3, ["77777777777"])
        pref = PackageReference(ref3, '77777777777')
        package_folder_3 = self.server_store.package_revisions_root(pref)
        self.assertFalse(os.path.exists(package_folder_3))

        # Raise an exception
        self.assertRaises(NotFoundException,
                          self.service.remove_conanfile,
                          ConanFileReference("Fake", "1.0", "lasote", "stable"))