Skip to content

Commit

Permalink
adjust for deleted files and validate UUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
vortexing committed Dec 1, 2021
1 parent 0ef44f0 commit 5ca1fa3
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tgR.data
Type: Package
Title: Data Management Support for Fred Hutch Translational Genomics
Version: 0.0.2
Version: 0.0.3
Author: Amy Paguirigan
Maintainer: Amy Paguirigan <[email protected]>
Description: Supports the curation of scientific metadata associated with files stored
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(check_credentials)
export(commit_data_provenance)
export(delete_file_entries)
export(dropWhen)
export(get_all_deleted_files)
export(get_data_provenance)
export(get_dataset_annotations)
export(get_deleted_files)
Expand All @@ -13,4 +14,5 @@ export(mark_file_for_deletion)
export(set_credentials)
export(tag_and_commit_data_provenance)
export(tag_file)
export(validate_uuid)
importFrom(magrittr,"%>%")
1 change: 0 additions & 1 deletion R/delete_file_entries.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
delete_file_entries <- function(uuid = NULL) {
suppressMessages(check_credentials())
if(is.null(uuid)) {stop("Please provide uuid(s) for file entries to delete.")}
message("Deleting records cannot be undone. ")
formData <- list("token"=Sys.getenv("S3META"),
content='record',
action='delete',
Expand Down
46 changes: 42 additions & 4 deletions R/get_deleted_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ get_deleted_files <- function(bucket = NULL, prefix = NULL, DAG=NULL, file_type
format='csv',
type='flat',
csvDelimiter=',',
'fields[0]'='object_prefix',
'fields[1]'='bucket_name',
'fields[2]'='bucket_prefix',
'fields[3]'='deleted_object',
'fields[0]'='uuid',
'fields[1]'='object_prefix',
'fields[2]'='bucket_name',
'fields[3]'='bucket_prefix',
'fields[4]'='deleted_object',
'forms[0]'='data_provenance',
rawOrLabel='raw',
rawOrLabelHeaders='raw',
Expand All @@ -46,3 +47,40 @@ get_deleted_files <- function(bucket = NULL, prefix = NULL, DAG=NULL, file_type
} else {results <- data.frame()}
return(results)
}

#' Find all files that used to be in S3 that are marked for deletion of their data provenance
#'
#' @return A data frame containing metadata about all files marked for deletion of data provenance. Requesting data from a specific prefix can speed up the request.
#' @details Requires admin credentials.
#' @export


get_all_deleted_files <- function() {
check_credentials()
formData <- list("token"=Sys.getenv("S3META"),
content='record',
action='export',
format='csv',
type='flat',
csvDelimiter=',',
'fields[0]'='uuid',
'fields[1]'='object_prefix',
'fields[2]'='bucket_name',
'fields[3]'='bucket_prefix',
'fields[4]'='deleted_object',
'forms[0]'='data_provenance',
rawOrLabel='raw',
rawOrLabelHeaders='raw',
exportCheckboxLabel='false',
exportSurveyFields='false',
exportDataAccessGroups='true',
returnFormat='csv',
filterLogic="[deleted_object] = '1'"
)
results <- suppressMessages(httr::content(httr::POST(url = Sys.getenv("REDURI"), body = formData, encode = "form")))
message(paste0("Retrieved ", nrow(results), " records."))
if(nrow(results)>0) {
results <- results %>% dplyr::select(-dplyr::contains("_complete"))
} else {results <- data.frame()}
return(results)
}
33 changes: 33 additions & 0 deletions R/validate_uuid.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#' Checks to ensure a uuid is not already used
#'
#' @param uuid (Required) uuid you'd like to check
#' @return Returns NA if all uuids are valid, and an array of invalid uuids if any are invalid
#' @details Note: Only works for admin users.
#' @export
#'
validate_uuid <- function(uuid = NULL) {
if(is.null(uuid)) {stop("Please provide at least one uuid.")}
suppressMessages(check_credentials())
message("Checking for existing record(s) with the uuid(s) provided.")
logic <- paste0("[uuid] = '", paste(uuid, collapse = "' OR [uuid] = '"), "'")
formData <- list("token"=Sys.getenv("S3META"),
content='record',
action='export',
format='csv',
type='flat',
csvDelimiter=',',
'fields[0]'='uuid',
rawOrLabel='raw',
rawOrLabelHeaders='raw',
exportCheckboxLabel='false',
exportSurveyFields='false',
exportDataAccessGroups='false',
returnFormat='csv',
filterLogic=logic)
alreadyUsed <- suppressMessages(httr::content(
httr::POST(url = Sys.getenv("REDURI"),
body = formData, encode = "form", show_col_types = FALSE)))

if (nrow(alreadyUsed)>0) {result <- alreadyUsed$uuid} else {result <- NA}
return(result)
}
6 changes: 3 additions & 3 deletions docker/dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### vortexing/r_tgr.data:v0.0.2
### vortexing/r_tgr.data:v0.0.3
## Pull the R base image
FROM rocker/r-base:4.1.1
# Update
Expand All @@ -7,6 +7,6 @@ RUN apt-get install -y libssl-dev libxml2-dev libcurl4-openssl-dev
# Install required packages
RUN R -e "install.packages('remotes', dependencies = TRUE)"
# Install from github
RUN R -e "remotes::install_github('FredHutch/[email protected].2', dependencies = TRUE)"
RUN R -e "remotes::install_github('FredHutch/[email protected].3', dependencies = TRUE)"
# Override the R CMD for workflow managers
CMD ["/bin/bash"]
CMD ["/bin/bash"]
17 changes: 17 additions & 0 deletions man/get_all_deleted_files.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/validate_uuid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ca1fa3

Please sign in to comment.