-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path038-admin-proxy-create-template.sh
More file actions
executable file
·60 lines (49 loc) · 2.27 KB
/
038-admin-proxy-create-template.sh
File metadata and controls
executable file
·60 lines (49 loc) · 2.27 KB
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
54
55
56
57
58
59
60
#!/bin/bash
# Resource: Proxy Configuration(Under Administration)
# This is the first script to generate template files without credentials
# The first script will generate template files under the folder: proxy/template.
# Then users need to fill in the missing fields such as CA, credentials.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
DATA_DIR="$SCRIPT_DIR"/data/proxy
TEMPLATE_DIR=template
credential_type_json_template='{"type":{"kind":"Credential","version":"v1alpha1","package":"vmware.tanzu.manage.v1alpha1.account.credential.Credential"}}'
proxy_data_json_template='{"httpUserName": "","httpPassword": "","httpsUserName": "","httpsPassword": "","proxyCABundle": ""}'
if [ ! -d $DATA_DIR ]; then
echo "Nothing to do without directory $DATA_DIR, please backup data first"
exit 0
fi
if [ ! -d $DATA_DIR/$TEMPLATE_DIR ]; then
mkdir -p $DATA_DIR/$TEMPLATE_DIR
fi
echo "Generate proxy configuration template yaml files"
proxyList=$(cat $DATA_DIR/proxies.yaml | yq eval -o=json - | jq -c '.credentials[]')
while IFS= read -r proxy; do
name=$(echo "$proxy" | jq -r '.fullName.name // ""')
echo "$proxy" | \
jq 'del(.fullName.orgId, .meta.parentReferences, .meta.annotations."x-customer-domain", .type, .status)' | \
jq --argjson typeJson "$credential_type_json_template" '. += $typeJson' | \
jq --argjson new_data "$proxy_data_json_template" '.spec.data.keyValue.data = $new_data' | \
yq eval -P - > "$DATA_DIR/$TEMPLATE_DIR/${name}.yaml"
done <<< "$proxyList"
echo '''
Template examples:
1.Spec Format for Proxy
##################################################################
spec:
capability: PROXY_CONFIG
data:
keyValue:
data:
httpUserName: "<base64 string>"
httpPassword: "<base64 string>"
httpsUserName: "<base64 string>"
httpsPassword: "<base64 string>"
proxyCABundle: "<base64 string>"
type: SECRET_TYPE_UNSPECIFIED
meta:
provider: PROVIDER_UNSPECIFIED
temporaryCredentialSupport: false
'''
echo "##################################################################"
echo "The generated template files are without credentials."
echo "You need to go to the dir: data/proxy/template to fill the missing field values for each template file before execute the import script."