-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrator.sh
executable file
·53 lines (45 loc) · 1.08 KB
/
migrator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Parse command line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--namespace)
namespace="$2"
shift
;;
--json-in)
json_file="$2"
shift
;;
*)
echo "Unknown parameter passed: $1"
exit 1
;;
esac
shift
done
# Check if --namespace parameter is provided
if [ -z "$namespace" ]; then
echo "Please provide a namespace using the --namespace parameter."
exit 1
fi
# Check if --json-in parameter is provided
if [ -z "$json_file" ]; then
echo "Please provide input JSON file name using the --json-in parameter."
exit 1
fi
# Read JSON content from file
json_input=$(cat "$json_file")
# Use jq to convert JSON to YAML
yaml_content=$(echo "$json_input" | jq -r --arg ns "$namespace" '
[{
name: $ns,
accounts: [.db.entries[] | {
name: "\(.issuer) \(.name)",
token: .info.secret
}]
}]' | yq eval -P)
# Remove single quotes from name in accounts
yaml_content=$(echo "$yaml_content" | sed "s/'//g")
# Print the result
echo "$yaml_content" > output.yml
echo "YAML file generated: output.yml"