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"
34 log
= logging
.getLogger(__name__
)
36 class AccessCredentials():
39 log
.info("Access credentials sourced for CloudWatch MON plugin")
42 def access_credential_calls(self
,message
):
44 message
= json
.loads(message
.value
)['access_config']
46 AWS_KEY
= message
['user']
47 AWS_SECRET
= message
['password']
48 AWS_REGION
= message
['vim_tenant_name']
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
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
)
62 cloudwatch_credentials
.close()
63 log
.info("Access credentials sourced for CloudWatch MON plugin")
65 except Exception as e
:
66 log
.error("Access credentials not provided correctly: %s", str(e
))