-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path.profile_montecarlo
More file actions
141 lines (122 loc) · 5.47 KB
/
.profile_montecarlo
File metadata and controls
141 lines (122 loc) · 5.47 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# .profile_montecarlo
# tailscale_tunnel_path
export PATH="/usr/local/bin:$PATH"
mc() {
echo $'\e[48;5;75m\e[1m\e[38;5;231m \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m /$$ /$$ /$$$$$$ \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m | $$$ /$$$ /$$__ $$ \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m | $$$$ /$$$$| $$ \\__/ \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m | $$ $$/$$ $$| $$ \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m | $$ $$$| $$| $$ \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m | $$\\ $ | $$| $$ $$ \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m | $$ \\/ | $$| $$$$$$/ \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m |__/ |__/ \\______/ \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m \e[0m'
echo $'\e[48;5;75m\e[1m\e[38;5;231m \e[0m'
}
fql() {
fa "$(echo "$1" | snake)"
}
_enter_virtualenv_dir() {
if [[ -n $CONDA_DEFAULT_ENV ]]; then
mamba deactivate
elif [[ -n $VIRTUAL_ENV ]]; then
deactivate
fi
local venv_dir="$1"
# shellcheck disable=SC1091
source "$venv_dir/bin/activate"
export LIBRARY_PATH="/opt/homebrew/opt/openssl@1.1/lib"
}
_exit_virtualenv_dir() {
if type deactivate >/dev/null 2>&1; then
deactivate
unset LIBRARY_PATH
mamba activate
fi
}
_enter_virtualenv_for_montecarlo() {
if [[ $PWD == *"/montecarlo/"* && $OLDPWD != *"/montecarlo/"* ]] ||
[[ $PWD == *"/montecarlo/saas-serverless/"* && $OLDPWD != *"/montecarlo/saas-serverless/"* ]]; then
if [[ -d env ]]; then
_enter_virtualenv_dir env
elif [[ -d venv ]]; then
_enter_virtualenv_dir venv
elif [[ -d .venv ]]; then
_enter_virtualenv_dir .venv
fi
elif [[ $PWD != *"/montecarlo/"* && $OLDPWD == *"/montecarlo/"* ]] ||
[[ $PWD != *"/montecarlo/saas-serverless/"* && $OLDPWD == *"/montecarlo/saas-serverless/"* ]]; then
if type deactivate >/dev/null 2>&1; then
_exit_virtualenv_dir
fi
fi
}
if [[ -n $ZSH_VERSION ]]; then
if [[ ${chpwd_functions[*]} != *_enter_virtualenv_for_montecarlo* ]]; then
chpwd_functions+=("_enter_virtualenv_for_montecarlo")
fi
fi
# Okta profile variables (profiles are defined in ~/.okta-aws) needed for scripts
export OKTA_PROFILE_AUDIT=audit
export OKTA_PROFILE_CUST_1=cust-1
export OKTA_PROFILE_CUST_2=cust-2
export OKTA_PROFILE_DEV=dev
export OKTA_PROFILE_DEV_CAAS_1=dev-caas-1
export OKTA_PROFILE_DEV_COLLECTOR_1=dev-collector-1
export OKTA_PROFILE_DEV_SECURITY=dev-security
export OKTA_PROFILE_LOG_ARCHIVE=log-archive
export OKTA_PROFILE_MARKETPLACE=marketplace
export OKTA_PROFILE_MR_SANDBOX=mr-sandbox
export OKTA_PROFILE_PROD=prod
export OKTA_PROFILE_PROD_CAAS_1=prod-caas-1
export OKTA_PROFILE_PROD_COLLECTOR_1=prod-collector-1
export OKTA_PROFILE_ROOT=root
export OKTA_PROFILE_SANDBOX=sandbox
export OKTA_PROFILE_TADATA=tadata
generateCredentials() {
profile_name=$1
cache_path="$HOME/.aws/cli/cache"
cache_file=$(ls -t "$cache_path" | head -n 1 | tr -d "\n")
aws_access_key_id=$(cat "$cache_path"/"$cache_file" | jq -r '.Credentials.AccessKeyId')
aws_secret_access_key=$(cat "$cache_path"/"$cache_file" | jq -r '.Credentials.SecretAccessKey')
aws_session_token=$(cat "$cache_path"/"$cache_file" | jq -r '.Credentials.SessionToken')
echo -e "[${profile_name}]\naws_access_key_id = $aws_access_key_id\naws_secret_access_key = $aws_secret_access_key\naws_session_token = $aws_session_token" >~/.aws/credentials
}
function aws-profile-switch() {
unset AWS_PROFILE
aws sts get-caller-identity --profile "$1" >/dev/null 2>&1
if [ $? -eq 0 ]; then
export AWS_PROFILE=$1
else
aws sso login --sso-session mc-okta && export AWS_PROFILE=$1
fi
if [ $? -ne 0 ]; then
echo -e "AWS SSO login failed, please try again"
else
# hack to generate ~/.aws/cli/cache/*.json
aws sts get-caller-identity --profile "$1" >/dev/null 2>&1
generateCredentials "$AWS_PROFILE"
fi
}
# Okta AWS Admin aliases
alias audit="aws-profile-switch ${OKTA_PROFILE_AUDIT}"
alias cust-1="aws-profile-switch ${OKTA_PROFILE_CUST_1}"
alias cust-2="aws-profile-switch ${OKTA_PROFILE_CUST_2}"
alias dev="aws-profile-switch ${OKTA_PROFILE_DEV}"
alias dev-caas-1="aws-profile-switch ${OKTA_PROFILE_DEV_CAAS_1}"
alias dev-collector-1="aws-profile-switch ${OKTA_PROFILE_DEV_COLLECTOR_1}"
alias dev-security="aws-profile-switch ${OKTA_PROFILE_DEV_SECURITY}"
alias log-archive="aws-profile-switch ${OKTA_PROFILE_LOG_ARCHIVE}"
alias marketplace="aws-profile-switch ${OKTA_PROFILE_MARKETPLACE}"
alias mr-sandbox="aws-profile-switch ${OKTA_PROFILE_MR_SANDBOX}"
alias prod="aws-profile-switch ${OKTA_PROFILE_PROD}"
alias prod-caas-1="aws-profile-switch ${OKTA_PROFILE_PROD_CAAS_1}"
alias prod-collector-1="aws-profile-switch ${OKTA_PROFILE_PROD_COLLECTOR_1}"
alias root="aws-profile-switch ${OKTA_PROFILE_ROOT}"
alias sandbox="aws-profile-switch ${OKTA_PROFILE_SANDBOX}"
alias tadata="aws-profile-switch ${OKTA_PROFILE_TADATA}"
alias aws-refresh-token="aws sso logout && aws sso login"