Skip to content

Commit

Permalink
feat: promote toggles script (#3639)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Apr 28, 2023
1 parent b18d625 commit 116db8f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions scripts/promote.sh
@@ -0,0 +1,52 @@
#!/bin/bash

# Source Unleash instance
SOURCE_URL=""
SOURCE_API_TOKEN=""
SOURCE_ENV="production"
SOURCE_TAG="exported"

# Target Unleash instance
TARGET_URL=""
TARGET_API_TOKEN=""
TARGET_PROJECT="DemoImport"
TARGET_ENV="production"

export_data() {
curl -s -w "\n%{http_code}" -X POST "$SOURCE_URL" \
-H "Authorization: $SOURCE_API_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"tag\": \"$SOURCE_TAG\", \"environment\": \"$SOURCE_ENV\"}"
}

import_data() {
data="$1"
response=$(curl -s -w "\n%{http_code}" -X POST "$TARGET_URL" \
-H "Authorization: $TARGET_API_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"project\": \"$TARGET_PROJECT\", \"environment\": \"$TARGET_ENV\", \"data\": $data}")

http_code=$(echo "$response" | awk 'END{print}')

if ! [[ $http_code -ge 200 && $http_code -lt 300 ]]; then
status_message=$(echo "$response" | awk 'NR==1{print}')
echo "Error: Import failed with $http_code $status_message"
exit 1
fi
}

echo "Exporting data from source API: ${SOURCE_URL}, tag: ${SOURCE_TAG}, environment: ${SOURCE_ENV}"
response=$(export_data)
http_code=$(echo "$response" | awk 'END{print}')
if [[ $http_code -ge 200 && $http_code -lt 300 ]]; then
data=$(echo "$response" | awk 'NR>1{print line} {line=$0}')
echo "Data exported successfully."
else
status_message=$(echo "$response" | awk 'NR==1{print}')
echo "Error: Export failed with $http_code $status_message"
exit 1
fi

echo "Importing data to target API: ${TARGET_URL}, project: ${TARGET_PROJECT}, environment: ${TARGET_ENV}"
import_data "$data"
echo "Data imported successfully."
Expand Up @@ -39,6 +39,7 @@ export class ImportTogglesStore implements IImportTogglesStore {
featureNames: string[],
environment: string,
): Promise<boolean> {
if (featureNames.length === 0) return true;
const result = await this.db.raw(
'SELECT EXISTS (SELECT 1 FROM feature_strategies WHERE environment = ? and feature_name in (' +
featureNames.map(() => '?').join(',') +
Expand Down

0 comments on commit 116db8f

Please sign in to comment.