-
Couldn't load subscription status.
- Fork 2
recipe: update env vars #27
base: main
Are you sure you want to change the base?
Conversation
| toc: true | ||
| --- | ||
|
|
||
| This recipe provides a method to update an environment variable used across a Posit Connect deployment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe motivate this with a use case? Like, everyone uses SOMETHING_TOKEN to store the service account key for some service, and you want to refresh that with a new value, so you need to find all content that uses that and set a new value.
|
|
||
| ## Ingredients | ||
|
|
||
| Running this recipe requires administrator privileges on Posit Connect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe note that you need admin privileges to update across all content, but that if you're just trying to edit your content, you don't need admin privileges.
| # get Server URL and API Key from the environment | ||
| CONNECT_SERVER <- Sys.getenv('CONNECT_SERVER') | ||
| CONNECT_API_KEY <-Sys.getenv('CONNECT_API_KEY') | ||
|
|
||
| # check if API Key is valid | ||
| if (is.null(CONNECT_API_KEY) || is.na(CONNECT_API_KEY) || nchar(CONNECT_API_KEY) == 0) { | ||
| stop("ERROR: valid CONNECT API key is required") | ||
| } | ||
|
|
||
| # check if Server URL is valid | ||
| if (is.null(CONNECT_SERVER) || is.na(CONNECT_SERVER) || nchar(CONNECT_SERVER) == 0) { | ||
| stop("ERROR: valid CONNECT server URL is required") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # get Server URL and API Key from the environment | |
| CONNECT_SERVER <- Sys.getenv('CONNECT_SERVER') | |
| CONNECT_API_KEY <-Sys.getenv('CONNECT_API_KEY') | |
| # check if API Key is valid | |
| if (is.null(CONNECT_API_KEY) || is.na(CONNECT_API_KEY) || nchar(CONNECT_API_KEY) == 0) { | |
| stop("ERROR: valid CONNECT API key is required") | |
| } | |
| # check if Server URL is valid | |
| if (is.null(CONNECT_SERVER) || is.na(CONNECT_SERVER) || nchar(CONNECT_SERVER) == 0) { | |
| stop("ERROR: valid CONNECT server URL is required") | |
| } |
connect() will validate this for you.
| client <- connectapi::connect() | ||
|
|
||
| content <- connectapi::get_content(client) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've done library(connectapi) so you don't need to ::.
| client <- connectapi::connect() | |
| content <- connectapi::get_content(client) | |
| client <- connect() | |
| content <- get_content(client) |
| library(dplyr) | ||
| library(tidyr) | ||
| library(glue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not appear that these packages are used.
| library(dplyr) | |
| library(tidyr) | |
| library(glue) |
| ## Ingredients | ||
|
|
||
| Running this recipe requires administrator privileges on Posit Connect. | ||
| You would need the following information in your environment to run this report: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| You would need the following information in your environment to run this report: | |
| You need the following information in your environment to run this report: |
| - CONNECT_SERVER | ||
| - CONNECT_API_KEY | ||
|
|
||
| Additionally, you would need to know the name of the environment variable to be updated and its new value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Additionally, you would need to know the name of the environment variable to be updated and its new value. | |
| Additionally, you need to know the name of the environment variable to be updated and its new value. |
|
|
||
| ## Method | ||
|
|
||
| The following script abstracts all Connect content and identifies if the content uses a specified environemnt variable, and then updates the variable with a specified value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The following script abstracts all Connect content and identifies if the content uses a specified environemnt variable, and then updates the variable with a specified value. | |
| The following script abstracts all Connect content, identifies if the content uses a specified environment variable, and then updates the variable with a specified value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default rendering of this recipe will change an environment variable for every piece of content on the server. This is irreversible and could have a big impact, especially if the target env var is something generic like "DB_PASSWORD."
I'd like the recipe to start from a place of first identifying content that has a given env var with certain filters, such as by tag or owner, and providing a "do you want to proceed y/n, this is irreversible" confirmation.
No description provided.