Skip to content

Commit

Permalink
Creation of new projects is now an administrator task.
Browse files Browse the repository at this point in the history
Uploads can only be performed to existing projects. This aligns with the
gypsum philosophy and is necessary to have more control over disk usage.
  • Loading branch information
LTLA committed Apr 9, 2024
1 parent ee6968c commit 14bdb96
Show file tree
Hide file tree
Showing 53 changed files with 295 additions and 228 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gobbler
Version: 0.1.0
Date: 2024-02-13
Version: 0.1.1
Date: 2024-04-09
Title: Interface to the gobbler service
Description:
Friendly interface to the gobbler service.
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(allocateUploadDirectory)
export(approveProbation)
export(checkHealth)
export(cloneVersion)
export(createProject)
export(fetchLatest)
export(fetchManifest)
export(fetchPermissions)
Expand Down
3 changes: 2 additions & 1 deletion R/approveProbation.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
#' @author Aaron Lun
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # to start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up an upload.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' removeAsset("test", "probation", info$staging) # clean out any existing entry
#' res <- uploadDirectory("test", "probation", "v1", src,
#' staging=info$staging, probation=TRUE)
#' fetchSummary("test", "probation", "v1", registry=info$registry)
Expand Down
3 changes: 2 additions & 1 deletion R/cloneVersion.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up an upload.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' removeAsset("test", "simple", info$staging) # clean out any existing entry
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#'
#' # Creating a clone.
Expand Down
47 changes: 47 additions & 0 deletions R/createProject.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#' Create a project
#'
#' Create a new project in the registry.
#'
#' @param project String containing the project to remove.
#' @param owners Character vector containing the user IDs for owners of this project.
#' This defaults to the current user.
#' @param uploaders List specifying the authorized uploaders for this project.
#' See the \code{uploaders} field in the \code{\link{fetchPermissions}} return value for the expected format.
#' @param staging String containing the path to the staging directory.
#'
#' @return \code{NULL} is invisibly returned if the project was successfully created.
#'
#' @author Aaron Lun
#'
#' @seealso
#' \code{\link{uploadDirectory}}, to upload a new version of an asset to an existing project.
#'
#' \code{\link{removeProject}}, to remove a project respectively.
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", staging=info$staging) # start with a clean slate.
#'
#' # Creating our new project.
#' createProject("test", staging=info$staging)
#' listProjects(registry=info$registry)
#'
#' @export
createProject <- function(project, staging, owners=NULL, uploaders=NULL) {
req <- list(project=project)

permissions <- list()
if (!is.null(owners)) {
permissions$owners <- as.list(owners)
}
if (!is.null(uploaders)) {
permissions$uploaders <- sanitize_uploaders(uploaders)
}
if (length(permissions)) {
req$permissions <- permissions
}

chosen <- dump_request(staging, "create_project", req)
wait_response(staging, chosen)
invisible(NULL)
}
3 changes: 2 additions & 1 deletion R/fetchLatest.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up a few uploads.
#' src <- allocateUploadDirectory(info$staging)
#' removeAsset("test", "simple", info$staging) # clean out existing entries
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#' res <- uploadDirectory("test", "simple", "v2", src, staging=info$staging)
#'
Expand Down
3 changes: 2 additions & 1 deletion R/fetchManifest.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up an upload.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' dir.create(file.path(src, "whee"))
#' write(file=file.path(src, "whee", "blah"), "stuff")
#' removeAsset("test", "simple", info$staging) # clean out any existing entry
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#'
#' # Obtaining the manifest for this version.
Expand Down
8 changes: 3 additions & 5 deletions R/fetchPermissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#'
#' # Mocking up an upload.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' removeProject("test", info$staging) # clean out any existing entry
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging,
#' # Mocking up a project.upload.
#' createProject("test", info$staging,
#' uploaders=list(list(id="urmom", until=Sys.time() + 1000)))
#'
#' # Fetching the permissions.
Expand Down
3 changes: 2 additions & 1 deletion R/fetchSummary.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up an upload.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' removeAsset("test", "simple", info$staging) # clean out any existing entry
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#'
#' # Obtain a summary for this version.
Expand Down
3 changes: 2 additions & 1 deletion R/fetchUsage.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up an upload.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' write(file=file.path(src, "whee"), "stuff")
#' removeProject("test", info$staging) # clean out any existing entry
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#'
#' # Obtaining the project usage.
Expand Down
3 changes: 2 additions & 1 deletion R/listAssets.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up a few uploads.
#' src <- allocateUploadDirectory(info$staging)
#' removeProject("test", info$staging) # clean out existing entries
#' for (ass in c("simple", "more-simple", "even-more-simple")) {
#' uploadDirectory("test", ass, "v1", src, staging=info$staging)
#' }
Expand Down
3 changes: 2 additions & 1 deletion R/listFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up an upload.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' dir.create(file.path(src, "whee"))
#' write(file=file.path(src, "whee", "blah"), "stuff")
#' write(file=file.path(src, "whee2"), "more-stuff")
#' removeAsset("test", "simple", info$staging) # clean out any existing entry
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#'
#' # List files, with or without a prefix.
Expand Down
15 changes: 8 additions & 7 deletions R/listProjects.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
#'
#' @examples
#' info <- startGobbler()
#'
#' # Mocking up a few uploads.
#' src <- allocateUploadDirectory(info$staging)
#' for (proj in c("test", "more-tests", "even-more-tests")) {
#' removeProject(proj, info$staging) # clean out any existing entry
#' uploadDirectory(proj, "simple", "v1", src, staging=info$staging)
#' }
#' removeProject("test", info$staging) # clean out any existing entries
#' removeProject("more-test", info$staging)
#' removeProject("even-more-test", info$staging)
#'
#' # Now mocking up the creation of some projects.
#' createProject("test", info$staging)
#' createProject("more-test", info$staging)
#' createProject("even-more-test", info$staging)
#'
#' # Listing out the projects.
#' listProjects(info$registry)
Expand Down
3 changes: 2 additions & 1 deletion R/listVersions.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start from a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up a few uploads.
#' src <- allocateUploadDirectory(info$staging)
#' removeAsset("test", "simple", info$staging) # clean out existing entries
#' for (v in c("v1", "v2")) {
#' uploadDirectory("test", "simple", v, src, staging=info$staging)
#' }
Expand Down
3 changes: 2 additions & 1 deletion R/refreshLatest.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start from a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up a few uploads.
#' src <- allocateUploadDirectory(info$staging)
#' removeAsset("test", "simple", info$staging) # clean out existing entries
#' for (v in c("v1", "v2")) {
#' uploadDirectory("test", "simple", v, src, staging=info$staging)
#' }
Expand Down
3 changes: 2 additions & 1 deletion R/refreshUsage.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up an upload.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' write(file=file.path(src, "whee"), "stuff")
#' removeProject("test", info$staging) # clean out existing entries
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#'
#' # Messing with the project usage:
Expand Down
3 changes: 2 additions & 1 deletion R/rejectProbation.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
#' @author Aaron Lun
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up an upload.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' removeAsset("test", "probation", info$staging) # clean out any existing entry
#' res <- uploadDirectory("test", "probation", "v1", src,
#' staging=info$staging, probation=TRUE)
#' listVersions("test", "probation", registry=info$registry)
Expand Down
12 changes: 6 additions & 6 deletions R/removeAsset.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up an asset if it doesn't already exist.
#' if (!file.exists(file.path(info$registry, "test", "simple"))) {
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#' }
#' # Mocking up an asset so we have something to remove.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#' listAssets("test", registry=info$registry)
#'
#' # Removing the asset.
Expand Down
13 changes: 6 additions & 7 deletions R/removeProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
#' @seealso
#' \code{\link{removeAsset}} and \code{\link{removeVersion}}, to remove assets and versions respectively.
#'
#' \code{\link{createProject}}, to create a project.
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#'
#' # Mocking a project if it doesn't already exist.
#' if (file.exists(file.path(info$registry, "test"))) {
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#' }
#' # Mocking up a project so we have something to delete.
#' createProject("test", info$staging)
#' listProjects(registry=info$registry)
#'
#' # Removing the asset.
#' # Removing the project.
#' removeProject("test", staging=info$staging)
#' listProjects(registry=info$registry)
#'
Expand Down
10 changes: 5 additions & 5 deletions R/removeVersion.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up a version if it doesn't already exist.
#' if (!file.exists(versionPath(info$registry, "test", "simple", "v1"))) {
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#' }
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#' listVersions("test", "simple", registry=info$registry)
#'
#' # Removing the version.
Expand Down
5 changes: 4 additions & 1 deletion R/setPermissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
#' @seealso
#' \code{\link{fetchPermissions}}, to fetch the permissions.
#'
#' \code{\link{createProject}}, to set permissions during project creation.
#'
#' @return \code{NULL} is invisibly returned upon successful setting of the permissions.
#'
#' @examples
#' info <- startGobbler()
#' removeProject("test", info$staging) # start with a clean slate.
#' createProject("test", info$staging)
#'
#' # Mocking up an upload.
#' src <- allocateUploadDirectory(info$staging)
#' write(file=file.path(src, "foo"), "BAR")
#' removeProject("test", info$staging) # cleaning out any existing entry
#' res <- uploadDirectory("test", "simple", "v1", src, staging=info$staging)
#' fetchPermissions("test", registry=info$registry)
#'
Expand Down
Loading

0 comments on commit 14bdb96

Please sign in to comment.