8c110ab36d9869218ec0cab0536ef77bb2d2a9b8
[osm/MON.git] / osm_mon / plugins / CloudWatch / access_credentials.py
1 ##
2 # Copyright 2017 xFlow Research Pvt. Ltd
3 # This file is part of MON module
4 # All Rights Reserved.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
16 # under the License.
17 #
18 # For those usages not covered by the Apache License, Version 2.0 please
19 # contact with: usman.javaid@xflowresearch.com
20 ##
21
22 """
23 Access credentials class implements all the methods to store the access credentials for AWS
24 """
25
26 __author__ = "Usman Javaid"
27 __date__ = "20-December-2017"
28
29 import json
30 import logging
31 import os
32
33 log = logging.getLogger(__name__)
34
35
36 class AccessCredentials():
37
38 def logtest(self):
39 log.info("Access credentials sourced for CloudWatch MON plugin")
40
41 def access_credential_calls(self, message):
42 try:
43 message = json.loads(message.value)['access_config']
44
45 AWS_KEY = message['user']
46 AWS_SECRET = message['password']
47 AWS_REGION = message['vim_tenant_name']
48
49 os.environ['AWS_ACCESS_KEY_ID'] = AWS_KEY
50 os.environ['AWS_SECRET_ACCESS_KEY'] = AWS_SECRET
51 os.environ['AWS_EC2_REGION'] = AWS_REGION
52
53 # aws_credentials.txt file to save the access credentials
54 cloudwatch_credentials = open("../../plugins/CloudWatch/cloudwatch_credentials.txt", "w+")
55 cloudwatch_credentials.write("AWS_ACCESS_KEY_ID=" + AWS_KEY +
56 "\nAWS_SECRET_ACCESS_KEY=" + AWS_SECRET +
57 "\nAWS_EC2_REGION=" + AWS_REGION)
58
59 # Closing the file
60 cloudwatch_credentials.close()
61 log.info("Access credentials sourced for CloudWatch MON plugin")
62
63 except Exception as e:
64 log.error("Access credentials not provided correctly: %s", str(e))