From 7d6b41d17de90d51c986b9099f1ec87527081997 Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Mon, 8 Apr 2024 16:06:07 -0700 Subject: [PATCH] vpc code: fix misspelled fxn name, better error handling, more tests for vpc fxn --- R/vpc_security_groups.R | 5 ++-- man/aws_vpc_sec_group_rules.Rd | 2 +- man/aws_vpc_security_group.Rd | 2 +- man/aws_vpc_security_group_create.Rd | 2 +- man/aws_vpc_security_group_ingress.Rd | 2 +- man/aws_vpc_security_groups.Rd | 2 +- man/aws_vpc_sg_with_ingresss.Rd | 33 --------------------------- tests/testthat/test-vpc.R | 29 +++++++++++++++++++++++ 8 files changed, 37 insertions(+), 40 deletions(-) delete mode 100644 man/aws_vpc_sg_with_ingresss.Rd diff --git a/R/vpc_security_groups.R b/R/vpc_security_groups.R index 023b7b4..a05f6fd 100644 --- a/R/vpc_security_groups.R +++ b/R/vpc_security_groups.R @@ -8,7 +8,7 @@ #' and [aws_vpc_security_group_ingress()] #' @family security groups #' @return (character) security group ID -aws_vpc_sg_with_ingresss <- function(engine) { +aws_vpc_sg_with_ingress <- function(engine) { sg <- aws_vpc_security_group_create( name = glue("{engine}-{paste0(sample(1:9, size = 4), collapse = '')}"), engine = engine @@ -39,6 +39,7 @@ security_group_handler <- function(ids, engine) { sgsdf <- jsonlite::fromJSON( jsonlite::toJSON(sgs$SecurityGroups, auto_unbox = TRUE) ) + if (is_empty(sgsdf)) sgsdf <- tibble(IpPermissions = list()) port_df <- dplyr::filter( sgsdf, @@ -56,7 +57,7 @@ security_group_handler <- function(ids, engine) { "Creating security group with access for ", "{.strong {engine}} and port {.strong {port}}" )) - trysg <- tryCatch(aws_vpc_sg_with_ingresss(engine), + trysg <- tryCatch(aws_vpc_sg_with_ingress(engine), error = function(e) e ) if (rlang::is_error(trysg)) { diff --git a/man/aws_vpc_sec_group_rules.Rd b/man/aws_vpc_sec_group_rules.Rd index 2e6b213..057329c 100644 --- a/man/aws_vpc_sec_group_rules.Rd +++ b/man/aws_vpc_sec_group_rules.Rd @@ -39,6 +39,6 @@ Other security groups: \code{\link{aws_vpc_security_group_ingress}()}, \code{\link{aws_vpc_security_groups}()}, \code{\link{aws_vpc_security_group}()}, -\code{\link{aws_vpc_sg_with_ingresss}()} +\code{\link{aws_vpc_sg_with_ingress}()} } \concept{security groups} diff --git a/man/aws_vpc_security_group.Rd b/man/aws_vpc_security_group.Rd index ef040cb..bccb694 100644 --- a/man/aws_vpc_security_group.Rd +++ b/man/aws_vpc_security_group.Rd @@ -37,6 +37,6 @@ Other security groups: \code{\link{aws_vpc_security_group_create}()}, \code{\link{aws_vpc_security_group_ingress}()}, \code{\link{aws_vpc_security_groups}()}, -\code{\link{aws_vpc_sg_with_ingresss}()} +\code{\link{aws_vpc_sg_with_ingress}()} } \concept{security groups} diff --git a/man/aws_vpc_security_group_create.Rd b/man/aws_vpc_security_group_create.Rd index a6ebc84..227456f 100644 --- a/man/aws_vpc_security_group_create.Rd +++ b/man/aws_vpc_security_group_create.Rd @@ -74,6 +74,6 @@ Other security groups: \code{\link{aws_vpc_security_group_ingress}()}, \code{\link{aws_vpc_security_groups}()}, \code{\link{aws_vpc_security_group}()}, -\code{\link{aws_vpc_sg_with_ingresss}()} +\code{\link{aws_vpc_sg_with_ingress}()} } \concept{security groups} diff --git a/man/aws_vpc_security_group_ingress.Rd b/man/aws_vpc_security_group_ingress.Rd index 93a60a5..7996383 100644 --- a/man/aws_vpc_security_group_ingress.Rd +++ b/man/aws_vpc_security_group_ingress.Rd @@ -47,6 +47,6 @@ Other security groups: \code{\link{aws_vpc_security_group_create}()}, \code{\link{aws_vpc_security_groups}()}, \code{\link{aws_vpc_security_group}()}, -\code{\link{aws_vpc_sg_with_ingresss}()} +\code{\link{aws_vpc_sg_with_ingress}()} } \concept{security groups} diff --git a/man/aws_vpc_security_groups.Rd b/man/aws_vpc_security_groups.Rd index 58a7467..106ab01 100644 --- a/man/aws_vpc_security_groups.Rd +++ b/man/aws_vpc_security_groups.Rd @@ -27,6 +27,6 @@ Other security groups: \code{\link{aws_vpc_security_group_create}()}, \code{\link{aws_vpc_security_group_ingress}()}, \code{\link{aws_vpc_security_group}()}, -\code{\link{aws_vpc_sg_with_ingresss}()} +\code{\link{aws_vpc_sg_with_ingress}()} } \concept{security groups} diff --git a/man/aws_vpc_sg_with_ingresss.Rd b/man/aws_vpc_sg_with_ingresss.Rd deleted file mode 100644 index 5b45b00..0000000 --- a/man/aws_vpc_sg_with_ingresss.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vpc_security_groups.R -\name{aws_vpc_sg_with_ingresss} -\alias{aws_vpc_sg_with_ingresss} -\title{Get a security group with one ingress rule based on the engine} -\usage{ -aws_vpc_sg_with_ingresss(engine) -} -\arguments{ -\item{engine}{(character) The engine to use. default: "mariadb". required. -one of: mariadb, mysql, postgres, or redshift} -} -\value{ -(character) security group ID -} -\description{ -Get a security group with one ingress rule based on the engine -} -\details{ -Adds an ingress rule specific to the \code{engine} supplied (port -changes based on the engine), and your IP address. To create your own -security group and ingress rules see \code{\link[=aws_vpc_security_group_create]{aws_vpc_security_group_create()}} -and \code{\link[=aws_vpc_security_group_ingress]{aws_vpc_security_group_ingress()}} -} -\seealso{ -Other security groups: -\code{\link{aws_vpc_sec_group_rules}()}, -\code{\link{aws_vpc_security_group_create}()}, -\code{\link{aws_vpc_security_group_ingress}()}, -\code{\link{aws_vpc_security_groups}()}, -\code{\link{aws_vpc_security_group}()} -} -\concept{security groups} diff --git a/tests/testthat/test-vpc.R b/tests/testthat/test-vpc.R index 7759208..001f1ab 100644 --- a/tests/testthat/test-vpc.R +++ b/tests/testthat/test-vpc.R @@ -124,5 +124,34 @@ test_that("aws_vpc_security_group_ingress", { expect_match(out$SecurityGroupRules[[1]]$GroupId, "sg-") }) +test_that("aws_vpc_sg_with_ingress", { + expect_error(aws_vpc_sg_with_ingress()) + + res <- aws_vpc_sg_with_ingress("mariadb") + expect_type(res, "character") + expect_match(res, "sg-") + + out <- aws_vpc_security_group(res) + expect_type(out, "list") + expect_length(out$SecurityGroups, 1) + expect_match(out$SecurityGroups[[1]]$GroupName, "mariadb-") + + res_mysql <- aws_vpc_sg_with_ingress("mysql") + out_mysql <- aws_vpc_security_group(res_mysql) + expect_match(out_mysql$SecurityGroups[[1]]$GroupName, "mysql-") +}) + +test_that("security_group_handler", { + # missing `id` param + expect_error(security_group_handler()) + # if `id` given and not `NULL`, returns itself + an_id <- 123 + expect_equal(security_group_handler(an_id), an_id) + # if `id` given and IS `NULL`, errors b/c `engine` missing + expect_error(security_group_handler(NULL)) + # if `id` given, engine value not supported + expect_error(security_group_handler(NULL, engine = "asdff")) +}) + # cleanup Sys.unsetenv("AWS_PROFILE")