Skip to content

Commit

Permalink
Return string from cloud_config.
Browse files Browse the repository at this point in the history
Because yaml drops comments. #46
  • Loading branch information
hadley committed Oct 21, 2014
1 parent 317297f commit d4647f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion R/cloud_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
#'
#' @param name Name of template
#' @inheritParams droplet_create
#' @return A string. (Can't return yaml because the \code{yaml} package
#' strips off comments, and the first comment is extremely important.)
#' @export
#' @keywords internal
#' @examples
#' \donttest{
#' cat(cloud_config("ubuntu"))
#' }
cloud_config <- function(name, ssh_keys = NULL) {
path <- system.file("cloudconfig", paste0(name, ".yaml"),
package = "analogsea")
Expand All @@ -22,5 +28,7 @@ cloud_config <- function(name, ssh_keys = NULL) {

config$users[[1]]$`ssh-authorized-keys` <- public

config
# Convert back to string and restore comment
text <- yaml::as.yaml(config)
paste0("#cloud-config\n", text)
}
3 changes: 1 addition & 2 deletions R/droplet-actions.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ droplet_create <- function(name = random_name(),
call. = FALSE)
}

config <- cloud_config(cloud_config, ssh_keys)
user_data <- yaml::as.yaml(config)
user_data <- cloud_config(cloud_config, ssh_keys)
}

res <- do_POST('droplets',
Expand Down
9 changes: 9 additions & 0 deletions man/cloud_config.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ with the corresponding private key will be able to log in to the droplet.
See \code{\link{keys}()} for a list of the keys that you've added.
Default: NULL.}
}
\value{
A string. (Can't return yaml because the \code{yaml} package
strips off comments, and the first comment is extremely important.)
}
\description{
This takes a template stored in \code{inst/cloudconfig} and inserts
ssh_keys into the first user.
}
\examples{
\donttest{
cat(cloud_config("ubuntu"))
}
}
\keyword{internal}

0 comments on commit d4647f5

Please sign in to comment.