@@ -45,22 +45,26 @@ aws::get_org_id() {
45
45
rollbar::fatal_trap \
46
46
" Dock-Init: Failed to Render Org Script" \
47
47
" Consule-Template was unable to realize the given template."
48
+ if [ -z ${AWS_ACCESS_KEY+x} ] || [ -z ${AWS_SECRET_KEY+x} ]; then
49
+ ORG_SCRIPT=$DOCK_INIT_BASE /util/get-org-id.sh
48
50
49
- ORG_SCRIPT=$DOCK_INIT_BASE /util/get-org-id.sh
51
+ local config=" $DOCK_INIT_BASE /consul-resources/template-config.hcl"
52
+ local template=" $DOCK_INIT_BASE "
53
+ template+=" /consul-resources/templates/get-org-tag.sh.ctmpl:$ORG_SCRIPT "
50
54
51
- local config=" $DOCK_INIT_BASE /consul-resources/template-config.hcl"
52
- local template=" $DOCK_INIT_BASE "
53
- template+=" /consul-resources/templates/get-org-tag.sh.ctmpl:$ORG_SCRIPT "
55
+ consul-template -config=" ${config} " -once -template=" ${template} "
54
56
55
- consul-template -config= " ${config} " -once -template= " ${template} "
57
+ rollbar::clear_trap
56
58
57
- rollbar::clear_trap
58
-
59
- # give amazon a chance to get the auth
60
- sleep 5
59
+ # give amazon a chance to get the auth
60
+ sleep 5
61
61
62
- # Attempt to fetch the org id from the tags via the fetch script
63
- backoff aws::fetch_org_id_from_tags
62
+ # Attempt to fetch the org id from the tags via the fetch script
63
+ backoff aws::fetch_org_id_from_tags
64
+ else
65
+ log::info " Taking aws creds from system"
66
+ backoff aws::get_org_id_onprem
67
+ fi
64
68
65
69
if [[ " $ORG_ID " == " " ]]; then
66
70
# this will print an error, so that's good
@@ -73,3 +77,36 @@ aws::get_org_id() {
73
77
74
78
log::info " Got Org ID: $ORG_ID "
75
79
}
80
+
81
+ aws::get_org_id_onprem () {
82
+ local attempt=${1}
83
+ log::info ' Attempting to get org id on prem'
84
+ data=' {"attempt":' " ${attempt} " ' }'
85
+
86
+ rollbar::warning_trap \
87
+ " Dock-Init: Cannot Fetch Org" \
88
+ " Attempting to get the Org Tag from AWS and failing." \
89
+ " $data "
90
+
91
+ EC2_HOME=/usr/local/ec2
92
+ export EC2_HOME
93
+
94
+ JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
95
+ export JAVA_HOME
96
+
97
+ local instance_id=$( ec2-metadata -i | awk ' {print $2}' )
98
+
99
+ # Note: this only works for us-.{4}-\d
100
+ local region=$( ec2-metadata --availability-zone | awk ' { where = match($2, /us\-.+\-[1|2]/); print substr($2, where, 9); }' )
101
+
102
+ ORG_ID=$( bash /usr/local/ec2/bin/ec2-describe-tags \
103
+ --aws-access-key=" ${AWS_ACCESS_KEY} " \
104
+ --aws-secret-key=" ${AWS_SECRET_KEY} " \
105
+ --filter " resource-type=instance" \
106
+ --filter " resource-id=${instance_id} " \
107
+ --filter " key=org" \
108
+ --region " ${region} " \
109
+ | awk ' {print $5}' )
110
+
111
+ export ORG_ID
112
+ }
0 commit comments