-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaws_es_proxy_py
65 lines (54 loc) · 2.25 KB
/
aws_es_proxy_py
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
#!/usr/bin/python3
import app
import config
import logging
from os import environ
from argparse import ArgumentParser
from boto3 import session
def _get_args():
parser = ArgumentParser()
required = parser.add_argument_group("required arguments")
parser.add_argument("-r", "--region", metavar="\b", default="eu-west-1",
help="AWS service region. Default is 'eu-west-1'")
parser.add_argument("-lh", "--host", metavar="\b",
help="Local host to listen on. Default: 127.0.0.1",
default="127.0.0.1")
parser.add_argument("-p", "--port", metavar="\b",
help="Local port to listen on. Default: 5000",
type=int, default=5000)
parser.add_argument("-d", "--debug", metavar="\b",
help="Debug mode for app. By default it turned off. " +
"Set one of the following values to turn it on: " +
"'yes', 'true', 'on', 'y', 't', '1'", default="false")
required.add_argument("-e", "--endpoint", metavar="\b", required=True,
help="AWS service domain endpoint.")
return parser.parse_args()
def main():
logging.basicConfig(level=logging.INFO)
logging.info("Proxy started")
args = _get_args()
config.aws_credentials = session.Session().get_credentials()
access_key = environ.get("AWS_ACCESS_KEY_ID")
secret_key = environ.get("AWS_SECRET_ACCESS_KEY")
if config.aws_credentials:
logging.info("Successfully loaded AWS credentials from %s" %
config.aws_credentials.method)
elif access_key and secret_key:
config.aws_credentials = session.Session(
aws_access_key_id=access_key,
aws_secret_access_key=secret_key
).get_credentials()
logging.info(
"Successfully loaded AWS credentials from environment variables"
)
else:
logging.error("No credential found")
exit(1)
config.is_debug = args.debug.lower() in ('yes', 'true', 't', 'y', '1')
config.app_host = args.host
config.app_port = args.port
config.aws_region = args.region
config.aws_endpoint = args.endpoint
app.start()
if __name__ == "__main__":
main()