Skip to content

Commit

Permalink
1st code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hongooi73 committed Aug 3, 2019
1 parent 74be229 commit 56dac69
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 14 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
^\.Rproj\.user$
.travis.yml
CONTRIBUTING.md
CODE_OF_CONDUCT.md
drat.sh
^LICENSE\.md$
azure-pipelines.yml
27 changes: 13 additions & 14 deletions README.md → CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
23 changes: 23 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Package: AzureVMmetadata
Title: Interface to Azure virtual machine instance metadata
Version: 0.0.1
Authors@R: c(
person("Hong", "Ooi", , "[email protected]", role = c("aut", "cre")),
person("Microsoft", role="cph")
)
Description: A simple interface to the instance metadata inside a virtual machine running in Microsoft's 'Azure' cloud. Part of the 'AzureR' family of packages.
URL: https://github.com/Azure/AzureVMmetadata https://github.com/Azure/AzureR
BugReports: https://github.com/Azure/AzureVMmetadata/issues
License: MIT + file LICENSE
VignetteBuilder: knitr
Depends:
R (>= 3.3)
Imports:
openssl,
httr (>= 1.3)
Suggests:
knitr,
testthat,
AzureAuth
Roxygen: list(markdown=TRUE)
RoxygenNote: 6.1.1
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(attested)
export(in_azure_vm)
export(instance)
export(update_attested_metadata)
export(update_instance_metadata)
92 changes: 92 additions & 0 deletions R/AzureVMmetadata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
host <- httr::parse_url("http://169.254.169.254")
inst_api_version <- "2019-02-01"
att_api_version <- "2018-10-01"
ev_api_version <- "2017-11-01"


#' @export
instance <- new.env()

#' @export
attested <- new.env()

#' @export
events <- new.env()


#' @export
update_instance_metadata <- function()
{
host$path <- "metadata/instance"
host$query <- list(`api-version`=att_api_version)
res <- try(httr::GET(host, httr::add_headers(metadata=TRUE)), silent=TRUE)

if(!inherits(res, "response") || res$status_code > 299)
return(NULL)

inst <- httr::content(res)
for(x in names(inst))
instance[[x]] <- inst[[x]]
invisible(inst)
}


#' @export
update_attested_metadata <- function(nonce=NULL)
{
host$path <- "metadata/attested/document"
host$query <- list(`api-version`=att_api_version)
res <- try(httr::GET(host, httr::add_headers(metadata=TRUE, nonce=nonce)), silent=TRUE)

if(!inherits(res, "response") || res$status_code > 299)
return(NULL)

att <- httr::content(res)
for(x in names(att))
attested[[x]] <- att[[x]]
invisible(att)
}


#' @export
update_scheduled_events <- function()
{
host$path <- "metadata/scheduledevents"
host$query <- list(`api-version`=ev_api_version)
res <- try(httr::GET(host, httr::add_headers(metadata=TRUE)), silent=TRUE)

if(!inherits(res, "response") || res$status_code > 299)
return(NULL)

ev <- httr::content(res)
for(x in names(ev))
events[[x]] <- ev[[x]]
invisible(ev)
}



#' @export
get_vm_cert <- function()
{
if(is.null(attested$signature))
return(NULL)

openssl::read_p7b(openssl::base64_decode(attested$signature))[[1]]
}


#' @export
in_azure_vm <- function()
{
obj <- try(httr::GET(host), silent=TRUE)
inherits(obj, "response") && httr::status_code(obj) == 400
}


.onLoad <- function(libname, pkgname)
{
update_instance_metadata()
update_attested_metadata()
}

0 comments on commit 56dac69

Please sign in to comment.