Beispiel #1
0
    def attach_to(app):

        r = BottleRoutes()

        @app.route(r.common_search, method=["GET"])
        def search(auth_user):
            pattern = request.params.get("q", None)
            ignore_case = request.params.get("ignorecase", True)
            if isinstance(ignore_case, str):
                ignore_case = False if 'false' == ignore_case.lower() else True
            search_service = SearchService(app.authorizer, app.server_store,
                                           auth_user)
            references = [
                repr(ref)
                for ref in search_service.search(pattern, ignore_case)
            ]
            return {"results": references}

        @app.route(r.common_search_packages, method=["GET"])
        @app.route(r.common_search_packages_revision, method=["GET"])
        def search_packages(name,
                            version,
                            username,
                            channel,
                            auth_user,
                            revision=None):
            query = request.params.get("q", None)
            search_service = SearchService(app.authorizer, app.server_store,
                                           auth_user)
            ref = ConanFileReference(name, version, username, channel,
                                     revision)
            info = search_service.search_packages(ref, query)
            return info
    def attach_to(self, app):

        r = BottleRoutes(self.route)

        @app.route('%s/search' % r.base_url, method=["GET"])
        def search(auth_user):
            pattern = request.params.get("q", None)
            ignorecase = request.params.get("ignorecase", True)
            if isinstance(ignorecase, str):
                ignorecase = False if 'false' == ignorecase.lower() else True
            search_service = SearchService(app.authorizer, app.server_store,
                                           auth_user)
            references = [
                str(ref) for ref in search_service.search(pattern, ignorecase)
            ]
            return {"results": references}

        @app.route('%s/search' % r.recipe, method=["GET"])
        def search_packages(name, version, username, channel, auth_user):
            query = request.params.get("q", None)
            search_service = SearchService(app.authorizer, app.server_store,
                                           auth_user)
            conan_reference = ConanFileReference(name, version, username,
                                                 channel)
            info = search_service.search_packages(conan_reference,
                                                  query,
                                                  v2_compatibility_mode=True)
            return info
Beispiel #3
0
    def attach_to(app):
        r = BottleRoutes()
        storage_path = app.server_store.store
        service = FileUploadDownloadService(app.updown_auth_manager,
                                            storage_path)

        @app.route(r.v1_updown_file, method=["GET"])
        def get(the_path):
            token = request.query.get("signature", None)
            file_path = service.get_file_path(the_path, token)
            # https://github.com/kennethreitz/requests/issues/1586
            return static_file(os.path.basename(file_path),
                               root=os.path.dirname(file_path),
                               mimetype=get_mime_type(file_path))

        @app.route(r.v1_updown_file, method=["PUT"])
        def put(the_path):
            token = request.query.get("signature", None)
            file_saver = ConanFileUpload(request.body,
                                         None,
                                         filename=os.path.basename(the_path),
                                         headers=request.headers)
            abs_path = os.path.abspath(
                os.path.join(storage_path, os.path.normpath(the_path)))
            # Body is a stringIO (generator)
            service.put_file(file_saver, abs_path, token,
                             request.content_length)
Beispiel #4
0
    def attach_to(self, app):

        r = BottleRoutes(self.route)

        @app.route(r.recipe, method="DELETE")
        def remove_recipe(name, version, username, channel, auth_user):
            """ Remove any existing conanfiles 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)

        @app.route('%s/delete' % r.packages, method="POST")
        def remove_packages(name, version, username, channel, auth_user):
            """ Remove any existing conanfiles or its packages created """
            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"])

        @app.route('%s/remove_files' % r.recipe, method="POST")
        def remove_recipe_files(name, version, username, channel, auth_user):
            """ Remove any existing conanfiles or its packages created """
            # 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)
Beispiel #5
0
    def attach_to(self, app):

        r = BottleRoutes()

        @app.route(r.common_authenticate, method=["GET"])
        def authenticate(http_basic_credentials):
            if not http_basic_credentials:
                raise AuthenticationException("Wrong user or password")

            user_service = UserService(app.authenticator,
                                       app.credentials_manager)

            token = user_service.authenticate(http_basic_credentials.user,
                                              http_basic_credentials.password)

            response.content_type = 'text/plain'
            return token

        @app.route(r.common_check_credentials, method=["GET"])
        def check_credentials(auth_user):
            """Just check if valid token. It not exception
            is raised from Bottle plugin"""
            if not auth_user:
                raise AuthenticationException("Logged user needed!")
            response.content_type = 'text/plain'
            return auth_user
Beispiel #6
0
    def attach_to(app):

        conan_service = ConanServiceV2(app.authorizer, app.server_store)
        r = BottleRoutes()

        @app.route(r.package_revision_files, method=["GET"])
        def get_package_file_list(name, version, username, channel, package_id,
                                  auth_user, revision, p_revision):
            pref = get_package_ref(name, version, username, channel,
                                   package_id, revision, p_revision)
            ret = conan_service.get_package_file_list(pref, auth_user)
            return ret

        @app.route(r.package_revision_file, method=["GET"])
        def get_package_file(name, version, username, channel, package_id,
                             the_path, auth_user, revision, p_revision):
            pref = get_package_ref(name, version, username, channel,
                                   package_id, revision, p_revision)
            file_generator = conan_service.get_package_file(
                pref, the_path, auth_user)
            return file_generator

        @app.route(r.package_revision_file, method=["PUT"])
        def upload_package_file(name, version, username, channel, package_id,
                                the_path, auth_user, revision, p_revision):

            if "X-Checksum-Deploy" in request.headers:
                raise NotFoundException("Non checksum storage")
            pref = get_package_ref(name, version, username, channel,
                                   package_id, revision, p_revision)
            conan_service.upload_package_file(request.body, request.headers,
                                              pref, the_path, auth_user)

        @app.route(r.recipe_revision_files, method=["GET"])
        def get_recipe_file_list(name, version, username, channel, auth_user,
                                 revision):
            ref = ConanFileReference(name, version, username, channel,
                                     revision)
            ret = conan_service.get_recipe_file_list(ref, auth_user)
            return ret

        @app.route(r.recipe_revision_file, method=["GET"])
        def get_recipe_file(name, version, username, channel, the_path,
                            auth_user, revision):
            ref = ConanFileReference(name, version, username, channel,
                                     revision)
            file_generator = conan_service.get_conanfile_file(
                ref, the_path, auth_user)
            return file_generator

        @app.route(r.recipe_revision_file, method=["PUT"])
        def upload_recipe_file(name, version, username, channel, the_path,
                               auth_user, revision):
            if "X-Checksum-Deploy" in request.headers:
                raise NotFoundException("Not a checksum storage")
            ref = ConanFileReference(name, version, username, channel,
                                     revision)
            conan_service.upload_recipe_file(request.body, request.headers,
                                             ref, the_path, auth_user)
Beispiel #7
0
    def attach_to(app):

        r = BottleRoutes()

        @app.route(r.recipe_revisions, method="GET")
        def get_recipe_revisions(name, version, username, channel, auth_user):
            """ Gets a JSON with the revisions for the specified recipe
            """
            conan_reference = ConanFileReference(name, version, username,
                                                 channel)
            conan_service = ConanServiceV2(app.authorizer, app.server_store)
            revs = conan_service.get_recipe_revisions(conan_reference,
                                                      auth_user)
            return _format_revs_return(revs)

        @app.route(r.recipe_latest, method="GET")
        def get_latest_recipe_revision(name, version, username, channel,
                                       auth_user):
            """ Gets a JSON with the revisions for the specified recipe
            """
            conan_reference = ConanFileReference(name, version, username,
                                                 channel)
            conan_service = ConanServiceV2(app.authorizer, app.server_store)
            rev = conan_service.get_latest_revision(conan_reference, auth_user)
            return _format_rev_return(rev)

        @app.route(r.package_revisions, method="GET")
        def get_package_revisions(name, version, username, channel, package_id,
                                  auth_user, revision):
            """ Get a JSON with the revisions for a specified RREV """
            package_reference = get_package_ref(name,
                                                version,
                                                username,
                                                channel,
                                                package_id,
                                                revision,
                                                p_revision=None)
            conan_service = ConanServiceV2(app.authorizer, app.server_store)
            revs = conan_service.get_package_revisions(package_reference,
                                                       auth_user)
            return _format_revs_return(revs)

        @app.route(r.package_revision_latest, method="GET")
        def get_latest_package_revision(name, version, username, channel,
                                        package_id, auth_user, revision):
            """ Gets a JSON with the revisions for the specified recipe
            """
            package_reference = get_package_ref(name,
                                                version,
                                                username,
                                                channel,
                                                package_id,
                                                revision,
                                                p_revision=None)
            conan_service = ConanServiceV2(app.authorizer, app.server_store)
            rev = conan_service.get_latest_package_revision(
                package_reference, auth_user)
            return _format_rev_return(rev)
Beispiel #8
0
    def attach_to(app):

        r = BottleRoutes()

        @app.route(r.recipe, method="DELETE")
        @app.route(r.recipe_revision, method="DELETE")
        def remove_recipe(name,
                          version,
                          username,
                          channel,
                          auth_user,
                          revision=None):
            """ Remove any existing conanfiles or its packages created.
            Will remove all revisions, packages and package revisions (parent folder) if no revision
            is passed
            """
            ref = ConanFileReference(name, version, username, channel,
                                     revision)
            conan_service = ConanService(app.authorizer, app.server_store,
                                         auth_user)
            conan_service.remove_conanfile(ref)

        @app.route(r.package_recipe_revision, method=["DELETE"])
        @app.route(r.package_revision, method=["DELETE"])
        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)

        @app.route(r.packages_revision, method="DELETE")
        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)
Beispiel #9
0
    def attach_to(app):
        r = BottleRoutes()

        @app.route(r.ping, method=["GET"])
        def ping():
            """
            Response OK. Useful to get server capabilities
            """
            response.headers['X-Conan-Server-Capabilities'] = ",".join(app.server_capabilities)
            return
Beispiel #10
0
    def attach_to(self, app):

        r = BottleRoutes(self.route)

        @app.route(r.recipe, method="DELETE")
        @app.route(r.recipe_revision, method="DELETE")
        def remove_recipe(name, version, username, channel, auth_user, revision=None):
            """ Remove any existing conanfiles or its packages created.
            Will remove all revisions, packages and package revisions (parent folder) if no revision
            is passed
            """
            ref = ConanFileReference(name, version, username, channel, revision)
            conan_service = ConanService(app.authorizer, app.server_store, auth_user)
            conan_service.remove_conanfile(ref)

        @app.route(r.package, method="DELETE")
        @app.route(r.package_recipe_revision, method=["DELETE"])
        @app.route(r.package_revision, method=["DELETE"])
        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
                - If PRev is NOT specified and RRev is NOT specified (package_url) it will remove
                  ALL the package revisions for the specified "package_id" for all the recipe
                  revisions (SAME AS V1)
             """
            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)

        @app.route(r.packages, method="DELETE")
        @app.route(r.packages_revision, method="DELETE")
        def remove_all_packages(name, version, username, channel, auth_user, revision=None):
            """ Remove a file from a recipe. The revision is mandatory, because it comes from
            the upload and the revision is mandatory in v2"""
            ref = ConanFileReference(name, version, username, channel, revision)
            conan_service = ConanService(app.authorizer, app.server_store, auth_user)
            conan_service.remove_all_packages(ref)
Beispiel #11
0
    def attach_to(self, app):

        r = BottleRoutes(self.route)

        @app.route(r.v1_recipe_digest, method=["GET"])
        def get_conan_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)
            reference = ConanFileReference(name, version, username, channel)
            urls = conan_service.get_conanfile_download_urls(
                reference, [CONAN_MANIFEST])
            if not urls:
                raise NotFoundException("No digest found")
            return urls

        @app.route(r.v1_package_digest, method=["GET"])
        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)
            reference = ConanFileReference(name, version, username, channel)
            package_reference = PackageReference(reference, package_id)

            urls = conan_service.get_package_download_urls(
                package_reference, [CONAN_MANIFEST])
            if not urls:
                raise NotFoundException("No digest found")
            urls_norm = {
                filename.replace("\\", "/"): url
                for filename, url in urls.items()
            }
            return urls_norm

        @app.route(r.recipe, method=["GET"])
        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)
            reference = ConanFileReference(name, version, username, channel)
            snapshot = conan_service.get_recipe_snapshot(reference)
            snapshot_norm = {
                filename.replace("\\", "/"): the_md5
                for filename, the_md5 in snapshot.items()
            }
            return snapshot_norm

        @app.route(r.package, method=["GET"])
        def get_package_snapshot(name, version, username, channel, package_id,
                                 auth_user):
            """
            Get a dictionary with all files and their each md5s
            """
            conan_service = ConanService(app.authorizer, app.server_store,
                                         auth_user)
            reference = ConanFileReference(name, version, username, channel)
            package_reference = PackageReference(reference, package_id)
            snapshot = conan_service.get_package_snapshot(package_reference)
            snapshot_norm = {
                filename.replace("\\", "/"): the_md5
                for filename, the_md5 in snapshot.items()
            }
            return snapshot_norm

        @app.route(r.v1_recipe_download_urls, method=["GET"])
        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)
            reference = ConanFileReference(name, version, username, channel)
            urls = conan_service.get_conanfile_download_urls(reference)
            urls_norm = {
                filename.replace("\\", "/"): url
                for filename, url in urls.items()
            }
            return urls_norm

        @app.route(r.v1_package_download_urls, method=["GET"])
        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)
            reference = ConanFileReference(name, version, username, channel)
            package_reference = PackageReference(reference, package_id)
            urls = conan_service.get_package_download_urls(package_reference)
            urls_norm = {
                filename.replace("\\", "/"): url
                for filename, url in urls.items()
            }
            return urls_norm

        @app.route(r.v1_recipe_upload_urls, method=["POST"])
        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)
            reference = 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(
                reference, filesizes)
            urls_norm = {
                filename.replace("\\", "/"): url
                for filename, url in urls.items()
            }
            app.server_store.update_last_revision(reference)
            return urls_norm

        @app.route(r.v1_package_upload_urls, method=["POST"])
        def get_package_upload_urls(name, version, username, channel,
                                    package_id, auth_user):
            """
            Get a dict with all files and the upload url
            """
            conan_service = ConanService(app.authorizer, app.server_store,
                                         auth_user)
            reference = ConanFileReference(name, version, username, channel,
                                           DEFAULT_REVISION_V1)
            package_reference = PackageReference(reference, package_id,
                                                 DEFAULT_REVISION_V1)

            reader = codecs.getreader("utf-8")
            filesizes = json.load(reader(request.body))
            urls = conan_service.get_package_upload_urls(
                package_reference, filesizes)
            urls_norm = {
                filename.replace("\\", "/"): url
                for filename, url in urls.items()
            }
            app.server_store.update_last_package_revision(package_reference)
            return urls_norm