Title: | Provides utility functions to the container-template repository |
---|---|
Description: | Provides functions for uploading and emailing documents. |
Authors: | Collin Schwantes [aut, cre] , Noam Ross [aut] , EcoHealth Alliance [cph] |
Maintainer: | Collin Schwantes <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9007 |
Built: | 2024-10-26 02:55:00 UTC |
Source: | https://github.com/ecohealthalliance/containerTemplateUtils |
Providing a key that is a folder and path that is a folder will result in
the whole folder being copied to the path location. If you supply "" to key,
the whole bucket will be downloaded. Use copy_s3_dir_structure
to copy the
bucket "directory" structure.
aws_s3_download( path, bucket, key, copy_s3_dir_structure = FALSE, check = TRUE, error = FALSE )
aws_s3_download( path, bucket, key, copy_s3_dir_structure = FALSE, check = TRUE, error = FALSE )
path |
String. Path to download location. Could be a folder or specific file(s) |
bucket |
The name of the bucket to be downloaded from |
key |
The key or name for the file or folder to be download from the bucket. Should end with "/" for folders. Use "" to download whole bucket. |
copy_s3_dir_structure |
Logical. Should the structure of the S3 bucket be recreated as sub directories to the path argument? |
check |
Whether to check if the exact file already exists in the download location and skip downloading. Defaults to TRUE |
error |
Whether error out if the file is missing, folder is empty, or system environment variables are missing. Otherwise a message will print but an empty list will be returned. |
A list, each element having the key, etag (hash), and path of downloaded files
When uploading folders, the subdirectory structure will be preserved. To upload files from a folder without preserving the directory structure, pass a vector of file paths to the path argument.
aws_s3_upload( path, bucket, key = basename(path), prefix = "", check = TRUE, error = FALSE, file_type = "guess" )
aws_s3_upload( path, bucket, key = basename(path), prefix = "", check = TRUE, error = FALSE, file_type = "guess" )
path |
String. The path to the file(s) or folder(s) to be uploaded |
bucket |
String. The name of the bucket to be uploaded to |
key |
String. The "path" of the file(s) or folder(s) in the AWS bucket. Should end with "/" for folders. Use "" (an empty string) to upload files in folder without top-level folder. |
prefix |
String. A prefix to prepend to the file or folder keys. Generally should end with "/" |
check |
Logical. Whether to check if the exact file already exists in the bucket and skip uploading. Defaults to TRUE |
error |
Logical. Whether error out if the file is missing, folder is empty, or system environment variables are missing. Otherwise a message will print but an empty list will be returned. |
file_type |
String. Provide a file type from |
If you would like the change the directory structure, pass in a vector of file paths and a corresponding vector of keys.
A list, each element being having the key and etag (hash) of uploaded files
## Not run: # Upload a single file to a specific location in the bucket. # this will take the readme.md file and place in the exact location # specified by the key and prefix. Notice the key ends in a file # extension. containerTemplateUtils::aws_s3_upload(path = "README.md", key = "test/key/param/readme.md", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # A vector of paths with a matching vector of keys # will also result in exact placement. paths <- list.files("R",full.names = TRUE ) file_names <- basename(paths) keys <- sprintf("%s/%s","example_dir",file_names) containerTemplateUtils::aws_s3_upload(path = paths, key = keys, error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "example_dir/<file_name>" # Supplying a single file path and key with no file extension will # result in the key being treated as a directory and the file being placed # in that directory. containerTemplateUtils::aws_s3_upload(path = "R/utils-aws-upload.R", key = "test/key/param", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws key will be "test/key/param/utils-aws-upload.R" # Supplying a single file path and no key argument will result in the file # being uploaded to the top level directory of the bucket. containerTemplateUtils::aws_s3_upload(path = "R/utils-aws-upload.R", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws key will be "./utils-aws-upload.R" # If the path argument is a folder, the key argument should also be a folder. # Files from the folder will be uploaded into that directory. containerTemplateUtils::aws_s3_upload(path = "R/", key = "test/upload_folder/", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "test/upload_nested_folder/<files from R/>" # If the path argument is a folder with sub-directories, the structure of # the sub-directories will be preserved. dir.create("example_with_sub_dirs") dir.create("example_with_sub_dirs/sub_dir") file.create("example_with_sub_dirs/sub_dir/test.txt") containerTemplateUtils::aws_s3_upload(path = "example_with_sub_dirs/", key = "test/upload_nested_folder/", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws key will be "test/upload_nested_folder/example_with_sub_dirs/sub_dir/test.txt" # If the path argument is a folder and no key argument is supplied, # the local directory structure will be copied to the S3 bucket. containerTemplateUtils::aws_s3_upload(path = "example_with_sub_dirs/", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "R/<files from R/>" # If the path argument is a folder and key is an empty string, then only # the files from the folder will be uploaded. containerTemplateUtils::aws_s3_upload(path = "R/", key = "", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "./<files from R/>" # The prefix argument can be used to add a directory to the beginning of # a path in the AWS bucket.This can be used with files or folders. containerTemplateUtils::aws_s3_upload(path = "R/", key = "example_r_scripts", error = TRUE, prefix = "my_example_prefix", bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "my_example_prefix/example_r_scripts/<files from R/>" # This can be useful if you're using version control # systems like git and would like to organize files by branch library(gert) git_prefix <- gert::git_branch() containerTemplateUtils::aws_s3_upload(path = "R/", key = "", error = TRUE, prefix = git_prefix, bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "<current GIT branch>/<files from R/>" ## End(Not run)
## Not run: # Upload a single file to a specific location in the bucket. # this will take the readme.md file and place in the exact location # specified by the key and prefix. Notice the key ends in a file # extension. containerTemplateUtils::aws_s3_upload(path = "README.md", key = "test/key/param/readme.md", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # A vector of paths with a matching vector of keys # will also result in exact placement. paths <- list.files("R",full.names = TRUE ) file_names <- basename(paths) keys <- sprintf("%s/%s","example_dir",file_names) containerTemplateUtils::aws_s3_upload(path = paths, key = keys, error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "example_dir/<file_name>" # Supplying a single file path and key with no file extension will # result in the key being treated as a directory and the file being placed # in that directory. containerTemplateUtils::aws_s3_upload(path = "R/utils-aws-upload.R", key = "test/key/param", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws key will be "test/key/param/utils-aws-upload.R" # Supplying a single file path and no key argument will result in the file # being uploaded to the top level directory of the bucket. containerTemplateUtils::aws_s3_upload(path = "R/utils-aws-upload.R", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws key will be "./utils-aws-upload.R" # If the path argument is a folder, the key argument should also be a folder. # Files from the folder will be uploaded into that directory. containerTemplateUtils::aws_s3_upload(path = "R/", key = "test/upload_folder/", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "test/upload_nested_folder/<files from R/>" # If the path argument is a folder with sub-directories, the structure of # the sub-directories will be preserved. dir.create("example_with_sub_dirs") dir.create("example_with_sub_dirs/sub_dir") file.create("example_with_sub_dirs/sub_dir/test.txt") containerTemplateUtils::aws_s3_upload(path = "example_with_sub_dirs/", key = "test/upload_nested_folder/", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws key will be "test/upload_nested_folder/example_with_sub_dirs/sub_dir/test.txt" # If the path argument is a folder and no key argument is supplied, # the local directory structure will be copied to the S3 bucket. containerTemplateUtils::aws_s3_upload(path = "example_with_sub_dirs/", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "R/<files from R/>" # If the path argument is a folder and key is an empty string, then only # the files from the folder will be uploaded. containerTemplateUtils::aws_s3_upload(path = "R/", key = "", error = TRUE, bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "./<files from R/>" # The prefix argument can be used to add a directory to the beginning of # a path in the AWS bucket.This can be used with files or folders. containerTemplateUtils::aws_s3_upload(path = "R/", key = "example_r_scripts", error = TRUE, prefix = "my_example_prefix", bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "my_example_prefix/example_r_scripts/<files from R/>" # This can be useful if you're using version control # systems like git and would like to organize files by branch library(gert) git_prefix <- gert::git_branch() containerTemplateUtils::aws_s3_upload(path = "R/", key = "", error = TRUE, prefix = git_prefix, bucket =Sys.getenv("AWS_BUCKET")) # aws keys will be "<current GIT branch>/<files from R/>" ## End(Not run)
Adds information about the git branch to the file path.
create_git_prefix( branch = gert::git_branch(), path = "", ignore_if_main = TRUE )
create_git_prefix( branch = gert::git_branch(), path = "", ignore_if_main = TRUE )
branch |
String. Current branch of repo. |
path |
String. Folder where file should be uploaded. If an empty string is provided (default), the path argument will be ignored. |
ignore_if_main |
Logical. No prefixed added to files on main branch. |
String. Prefix for the file path.
# create_git_prefix(branch = gert::git_branch(), # path= "example", # ignore_if_main=TRUE) # "refs/head/current/branch/example"
# create_git_prefix(branch = gert::git_branch(), # path= "example", # ignore_if_main=TRUE) # "refs/head/current/branch/example"
Get html report files
get_file_paths(tar_obj, pattern, ...)
get_file_paths(tar_obj, pattern, ...)
tar_obj |
a tar_render object or other target object that contains file paths |
pattern |
string. regex pattern to match desired file paths |
... |
additional tar_render or other target objects |
a list of file paths
Create urls for items stored on EHA secure sites
make_eha_secure_url(url_domain = Sys.getenv("URL_PREFIX"), remote_path)
make_eha_secure_url(url_domain = Sys.getenv("URL_PREFIX"), remote_path)
url_domain |
String. Resource name on eha secure |
remote_path |
String. What is the path to the resource on remote site. For AWS this will be the item key. |
string. URL for resource
Send email alerts to updated automation reports
send_email_update( to, from = "[email protected]", project_name, attach = FALSE, test = FALSE, path = "outputs", pattern = "\\.html" )
send_email_update( to, from = "[email protected]", project_name, attach = FALSE, test = FALSE, path = "outputs", pattern = "\\.html" )
to |
A vector of email addresses serving as primary recipients for the message. |
from |
The email address of the sender. |
project_name |
String. Name of the project to use in email subject and body text. |
attach |
Logical. Should reports be attached to email? Default is FALSE. If TRUE, all HTML reports found in "outputs" folder will be attached to email. |
test |
Logical. Is this an email alert for testing automation reports? Default is FALSE. If TRUE, subject includes test and upload path will include the current git branch in the file path (e.g. https://project.secure.eha.io/refs/fix/missing_documentation/file.txt) |
path |
String. Name of folder or file path for attachment items |
pattern |
String. Regex pattern to select specific files in path. |
Invisible. Update email sent to list of recipients in to
browseVignettes("blastula")
Send email alerts to updated automation reports
send_email_update_tar( to, from = "[email protected]", project_name, use_hyperlinks = FALSE, hyperlinks_text = NULL, hyperlinks_url = NULL, attach = FALSE, attachment_paths, test = FALSE, additional_body_text = "" )
send_email_update_tar( to, from = "[email protected]", project_name, use_hyperlinks = FALSE, hyperlinks_text = NULL, hyperlinks_url = NULL, attach = FALSE, attachment_paths, test = FALSE, additional_body_text = "" )
to |
A vector of email addresses serving as primary recipients for the message. |
from |
The email address of the sender. |
project_name |
String. Name of the project to use in email subject and body text. |
use_hyperlinks |
Logical. If TRUE, a hyperlink using the file name or custom text is provided instead of the the full url of the report. |
hyperlinks_text |
String. NULL, hyperlink will be Current_ReportBasename eg Current_MyMarkdownReport.html. If a string or vector of strings are provided those will be used for the text in the hyperlink. |
hyperlinks_url |
String. Url to used in the hyperlink or as raw text to link to file. |
attach |
Logical. Should reports be attached to email? Default is FALSE. If TRUE, specify local files using the attachment_paths argument. |
attachment_paths |
String. Local file paths to be attachemed to the email. |
test |
Logical. Is this an email alert for testing automation reports? Default is FALSE. If TRUE, subject includes test and upload path will include the current git branch in the file path (e.g. https://project.secure.eha.io/refs/fix/missing_documentation/file.txt) |
additional_body_text |
String. Any additional text to be included in the body. This text is added to the end of the email body. You can use markdown to format the text. |
Invisible. Update email sent to list of recipients in to
browseVignettes("blastula")