-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathcfn-test-create-inputs.sh
executable file
·76 lines (61 loc) · 2.41 KB
/
cfn-test-create-inputs.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Copyright 2023 MongoDB Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#!/usr/bin/env bash
# cfn-test-create-inputs.sh
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# cfn-test-create-inputs.sh
#
# This tool generates json files in the inputs/ for `cfn test`.
#
set -euo pipefail
function usage {
echo "usage:$0 <project_name>"
}
if [ "$#" -ne 1 ]; then usage; fi
if [[ "$*" == help ]]; then usage; fi
rm -rf inputs
mkdir inputs
#create apikey
org_id="$MONGODB_ATLAS_ORG_ID"
api_key_id=$(atlas organizations apikeys create --desc "cfn-boto-key-${CFN_TEST_TAG}" --role ORG_MEMBER --output json | jq -r '.id')
#create team
team_name="cfn-boto-team-${CFN_TEST_TAG}"
user_name=$(atlas organizations users list --output json | jq -r '.results[0].emailAddress')
echo "${user_name}"
team_id=$(atlas teams describe --name "$team_name" --output json | jq -r ".id") || echo ""
if [ -z "$team_id" ]; then
team_id=$(atlas team create "${team_name}" --username "${user_name}" --orgId "${org_id}" --output json | jq -r '.id')
fi
name="${1}"
jq --arg org "$MONGODB_ATLAS_ORG_ID" \
--arg name "$name" \
--arg key_id "$api_key_id" \
--arg team_id "$team_id" \
'.OrgId?|=$org |.Name?|=$name | .ProjectApiKeys[0].Key?|=$key_id | .ProjectTeams[0].TeamId?|=$team_id' \
"$(dirname "$0")/inputs_1_create.template.json" >"inputs/inputs_1_create.json"
jq --arg org "$MONGODB_ATLAS_ORG_ID" \
--arg name "${name}-update" \
--arg key_id "$api_key_id" \
--arg team_id "$team_id" \
'.OrgId?|=$org | .Name?|=$name | .ProjectApiKeys[0].Key?|=$key_id | .ProjectTeams[0].TeamId?|=$team_id' \
"$(dirname "$0")/inputs_1_update.template.json" >"inputs/inputs_1_update.json"
jq --arg org "${org_id}" \
--arg name "${name}-tags" \
'.OrgId?|=$org |.Name?|=$name' \
"test/inputs_2_create.template.json" >"inputs/inputs_2_create.json"
jq --arg org "${org_id}" \
--arg name "${name}"-tags \
'.OrgId?|=$org |.Name?|=$name' \
"test/inputs_2_update.template.json" >"inputs/inputs_2_update.json"
ls -l inputs