Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

Conversation

@gsingh91
Copy link
Contributor

No description provided.

@gsingh91 gsingh91 self-assigned this Apr 11, 2024
@gsingh91 gsingh91 linked an issue Apr 11, 2024 that may be closed by this pull request
toc: true
---

This recipe provides a method to update an environment variable used across a Posit Connect deployment.
Copy link
Contributor

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.
Copy link
Contributor

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.

Comment on lines +44 to +56
# 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")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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.

Comment on lines +59 to +61
client <- connectapi::connect()

content <- connectapi::get_content(client)
Copy link
Contributor

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 ::.

Suggested change
client <- connectapi::connect()
content <- connectapi::get_content(client)
client <- connect()
content <- get_content(client)

Comment on lines +40 to +42
library(dplyr)
library(tidyr)
library(glue)
Copy link
Contributor

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.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Collaborator

@kmasiello kmasiello left a 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.

@kmasiello kmasiello added the blocked Extra attention is needed label May 7, 2024
@nealrichardson nealrichardson removed the blocked Extra attention is needed label Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recipe: find all content that uses a given env var

5 participants