[MON] Adds check for 'insecure' vim config param in Openstack plugin
[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 os
30 import sys
31 import json
32 import logging
33
34 log = logging.getLogger(__name__)
35
36 class AccessCredentials():
37
38 def logtest(self):
39 log.info("Access credentials sourced for CloudWatch MON plugin")
40
41
42 def access_credential_calls(self,message):
43 try:
44 message = json.loads(message.value)['access_config']
45
46 AWS_KEY = message['user']
47 AWS_SECRET = message['password']
48 AWS_REGION = message['vim_tenant_name']
49
50 os.environ['AWS_ACCESS_KEY_ID'] = AWS_KEY
51 os.environ['AWS_SECRET_ACCESS_KEY'] = AWS_SECRET
52 os.environ['AWS_EC2_REGION'] = AWS_REGION
53
54
55 #aws_credentials.txt file to save the access credentials
56 cloudwatch_credentials = open("../../plugins/CloudWatch/cloudwatch_credentials.txt","w+")
57 cloudwatch_credentials.write("AWS_ACCESS_KEY_ID="+AWS_KEY+
58 "\nAWS_SECRET_ACCESS_KEY="+AWS_SECRET+
59 "\nAWS_EC2_REGION="+AWS_REGION)
60
61 #Closing the file
62 cloudwatch_credentials.close()
63 log.info("Access credentials sourced for CloudWatch MON plugin")
64
65 except Exception as e:
66 log.error("Access credentials not provided correctly: %s", str(e))
67