generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Utilities | ||
|
||
This folder contains some utilities for the project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<# | ||
.SYNOPSIS | ||
This script is an environment generator for backend. | ||
.DESCRIPTION | ||
This script sets up the necessary environment variables and configurations required for the backend system to function properly. | ||
.EXAMPLE | ||
# To run this script, use the following command: | ||
# .\env-gen.ps1 " | ||
#> | ||
$file_path = "$PSScriptRoot/../backend/.env" | ||
|
||
# Log in to OpenShift | ||
Start-Process "oc" -Wait -ArgumentList "login --server=https://api.silver.devops.gov.bc.ca:6443 --web" | ||
|
||
|
||
#switch to dev, | ||
oc project d37bb7-dev | ||
|
||
# Get the secret data | ||
$secretData = oc get secret nr-oracle-service -n d37bb7-dev -o json | ConvertFrom-Json | ||
|
||
# Decode the secret data and create the .env file | ||
$envContent = "" | ||
foreach ($key in $secretData.data.PSObject.Properties.Name) { | ||
if ($key -eq "apiKey") { | ||
$decodedValue = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secretData.data.$key)) | ||
$envContent += "NR_ORACLE_SERVICE_KEY=$decodedValue`n" | ||
} | ||
} | ||
$envContent += "NR_ORACLE_SERVICE_URL=http://localhost:9080`n" | ||
$envContent += "OMRR_AUTHZ_DOCS_FLAG=true`n" | ||
$envContent += "OMRR_APP_STATUS_FLAG=flase" | ||
# Write the content to the output file | ||
$envContent | Out-File -FilePath "$file_path" -Encoding utf8 | ||
|
||
|
||
Write-Host "Environment file created at $file_path" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
# Set file path relative to script location | ||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
FILE_PATH="${SCRIPT_DIR}/../backend/.env" | ||
echo "Creating environment file at $FILE_PATH" | ||
# Log in to OpenShift | ||
oc login --server=https://api.silver.devops.gov.bc.ca:6443 --web | ||
|
||
# Switch to dev project | ||
oc project d37bb7-dev | ||
|
||
# Get the secret data and process with jq | ||
SECRET_DATA=$(oc get secret nr-oracle-service -n d37bb7-dev -o json) | ||
|
||
# Initialize env content | ||
ENV_CONTENT="" | ||
|
||
# Extract and decode apiKey | ||
API_KEY=$(echo "$SECRET_DATA" | jq -r '.data.apiKey' | base64 -d) | ||
ENV_CONTENT="NR_ORACLE_SERVICE_KEY=$API_KEY | ||
NR_ORACLE_SERVICE_URL=http://localhost:9080 | ||
OMRR_AUTHZ_DOCS_FLAG=true | ||
OMRR_APP_STATUS_FLAG=flase" | ||
|
||
# Write content to .env file | ||
echo "$ENV_CONTENT" > "$FILE_PATH" | ||
|
||
echo "Environment file created at $FILE_PATH" |