From bc3cbb84320b6cd1503a14db3b80cdeadf2e687b Mon Sep 17 00:00:00 2001 From: Hong Ooi Date: Tue, 26 Mar 2019 18:06:24 +1100 Subject: [PATCH] initial commit --- .Rbuildignore | 10 ++++++++++ .gitignore | 2 ++ DESCRIPTION | 29 ++++++++++++++++++++++++++++ LICENSE | 2 ++ LICENSE.md | 21 +++++++++++++++++++++ R/AzureKeyVault.R | 4 ++++ R/add_methods.R | 48 +++++++++++++++++++++++++++++++++++++++++++++++ R/az_vault.R | 10 ++++++++++ 8 files changed, 126 insertions(+) create mode 100644 .Rbuildignore create mode 100644 DESCRIPTION create mode 100644 LICENSE create mode 100644 LICENSE.md create mode 100644 R/AzureKeyVault.R create mode 100644 R/add_methods.R create mode 100644 R/az_vault.R diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..10b6f7d --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,10 @@ +^misc$ +^\.vs$ +\.sln$ +\.Rproj$ +\.Rxproj$ +^\.Rproj\.user$ +CONTRIBUTING.md +drat.sh +.travis.yml +^LICENSE\.md$ diff --git a/.gitignore b/.gitignore index 26fad6f..3192c1c 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ vignettes/*.pdf # Shiny token, see https://shiny.rstudio.com/articles/shinyapps.html rsconnect/ + +misc/ diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..e9ead98 --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,29 @@ +Package: AzureKeyVault +Title: Key and Secret Management in 'Azure' +Version: 2.0.1 +Authors@R: c( + person("Hong", "Ooi", , "hongooi@microsoft.com", role = c("aut", "cre")), + person("Microsoft", role="cph") + ) +Description: Manage keys, certificates and secrets in Microsoft's 'Key Vault' service: . +License: MIT + file LICENSE +URL: https://github.com/cloudyr/AzureKeyVault +BugReports: https://github.com/cloudyr/AzureKeyVault/issues +VignetteBuilder: knitr +Depends: + R (>= 3.3), +Imports: + utils, + parallel, + R6, + httr, + mime, + openssl + AzureRMR, + AzureAuth (>= 1.0.1) +Suggests: + knitr, + jsonlite, + testthat +Roxygen: list(markdown=TRUE) +RoxygenNote: 6.1.1 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0aece56 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2019 +COPYRIGHT HOLDER: Microsoft diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..16d86bf --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2019 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/R/AzureKeyVault.R b/R/AzureKeyVault.R new file mode 100644 index 0000000..c4e4851 --- /dev/null +++ b/R/AzureKeyVault.R @@ -0,0 +1,4 @@ +#' @import AzureRMR +NULL + +utils::globalVariables("self") diff --git a/R/add_methods.R b/R/add_methods.R new file mode 100644 index 0000000..5683c30 --- /dev/null +++ b/R/add_methods.R @@ -0,0 +1,48 @@ +add_methods <- function() +{ + ## extending AzureRMR classes + + AzureRMR::az_resource_group$set("public", "create_vault", overwrite=TRUE, + function(name, location=self$location, access=configure_vault_access(), sku="Standard", ...) + { + configure_vault_access=function() + { + creds <- decode_jwt(self$token$credentials$access_token) + tenant <- creds$tid + owner <- creds$oid + } + + props <- utils::modifyList( + list(accessPolicies=access, sku=list(family="A", name=sku)), + list(...) + ) + + AzureKeyVault::az_vault$new(self$token, self$subscription, self$name, + type="Microsoft.KeyVault/vaults", name=name, location=location, + properties=props, wait=wait) + }) + + + AzureRMR::az_resource_group$set("public", "get_vault", overwrite=TRUE, + function(name) + { + AzureKeyVault::az_vault$new(self$token, self$subscription, self$name, + type="Microsoft.KeyVault/vaults", name=name) + }) + + + AzureRMR::az_resource_group$set("public", "delete_vault", overwrite=TRUE, + function(name, confirm=TRUE, wait=FALSE) + { + self$get_vault(name)$delete(confirm=confirm, wait=wait) + }) + + + AzureRMR::az_subscription$set("public", "purge_vault", overwrite=TRUE, + function(name, location) + { + api_version=self$get_provider_api_version("Microsoft.KeyVault", "vaults") + op <- construct_path("providers/Microsoft.KeyVault/locations", location, "deletedVaults", name, "purge") + sub_op(op, api_version=api_version) + }) +} diff --git a/R/az_vault.R b/R/az_vault.R new file mode 100644 index 0000000..9a957de --- /dev/null +++ b/R/az_vault.R @@ -0,0 +1,10 @@ +az_vault=R6::R6Class("az_vault", inherit=AzureRMR::az_resource, + +public=list( + + update_access=function() + {}, + + get_vault_endpoint=function() + {} +))