2 # Copyright 2017 xFlow Research Pvt. Ltd
3 # This file is part of MON module
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
18 # For those usages not covered by the Apache License, Version 2.0 please
19 # contact with: usman.javaid@xflowresearch.com
23 Access credentials class implements all the methods to store the access credentials for AWS
26 __author__
= "Usman Javaid"
27 __date__
= "20-December-2017"
33 log
= logging
.getLogger(__name__
)
36 class AccessCredentials():
39 log
.info("Access credentials sourced for CloudWatch MON plugin")
41 def access_credential_calls(self
, message
):
43 message
= json
.loads(message
.value
)['access_config']
45 AWS_KEY
= message
['user']
46 AWS_SECRET
= message
['password']
47 AWS_REGION
= message
['vim_tenant_name']
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
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
)
60 cloudwatch_credentials
.close()
61 log
.info("Access credentials sourced for CloudWatch MON plugin")
63 except Exception as e
:
64 log
.error("Access credentials not provided correctly: %s", str(e
))