Skip to content

Commit

Permalink
Merge pull request #1255 from adorsys/env-var-sub-for-json-array
Browse files Browse the repository at this point in the history
doc for env var sub in a json array
  • Loading branch information
Motouom authored Jan 16, 2025
2 parents 2c2263a + 75e6fe0 commit 834b0cb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions docs/config/environmental-variable-substitution-for-json-array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## Environment Variable Substitution for JSON Arrays
This document provides a step-by-step guide on importing environment variables into JSON arrays using the Keycloak Config CLI.

### Prerequisites
- Ensure you have dotenv installed and configured in your environment.
- Have a Keycloak Config CLI setup ready for performing realm imports.
### Steps to Perform Import of Environment Variables
- Step 1: Configure the .env File

Create or update your .env file to include the necessary environment variables. For example:

```bash
CLIENT_WEBAPP_REDIRECT_URIS="https://app1.example.com/callback","https://app2.example.com/callback","https://app3.example.com/callback"
```
This environment variable contains a comma-separated list of redirect URIs.

- Step 2: Prepare the JSON Configuration File

Include the environment variable reference in your JSON configuration file. For example:

```json
{
"enabled": true,
"realm": "realmWithClient",
"clients": [
{
"clientId": "my-client",
"redirectUris": ["$(env:CLIENT_WEBAPP_REDIRECT_URIS)"]
}
]
}
```
Here, the `$(env:CLIENT_WEBAPP_REDIRECT_URIS)` syntax indicates that the value should be replaced with the corresponding environment variable.

- Step 3: Execute the Import Command

Use the dotenv command together with the import command to load the .env file and execute the Keycloak Config CLI import:

```bach
dotenv -e /PATH/TO/THE/.env kc-cli import --file /PATH/TO/CONFIG.JSON
```
Replace /PATH/TO/THE/.env with the full path to your .env file and /PATH/TO/CONFIG.JSON with the path to your JSON configuration file.

- Step 4: Enable Variable Substitution

Set the IMPORT_VARSUBSTITUTION_ENABLED environment variable to true to activate variable substitution:

```
export IMPORT_VARSUBSTITUTION_ENABLED=true
```
Ensure this environment variable is set in your shell or runtime environment before performing the import.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ nav:
- Adding Multiple post.logout.redirect.uris: config/addind-multiple-post-logout-redirect-uris.md
- Minimal Configurations From exported JSON: config/minimal-configuration.md
- Authenticator configuration: config/Authenticator-Configuration.md
- Environment Variable Substitution for JSON Arrays: config/environmental-variable-substitution-for-json-array.md


markdown_extensions:
Expand Down

0 comments on commit 834b0cb

Please sign in to comment.