forked from bkdinoop/awstagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkConfig.py
53 lines (45 loc) · 1.5 KB
/
checkConfig.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
#!/usr/bin/python
#Class to check the validation of user's input
#Seperate method for File check, region check and aws credentials.
from connectAws import ConnectAws
class CheckValidation():
def fileExists(self,fName):
status =""
try:
with open(fName) as f:
status='File Exists'
return True,status
except IOError as e:
return False,e
def regValidate(self, regValue):
available = False
regionList = ['us-west-1','us-east-1','us-west-2','sa-east-1','eu-west-1','ap-southeast-1','ap-northeast-1','ap-southeast-2']
for rL in regionList:
if rL == regValue:
available = True
return available
def checkAWSkey(self, akey, skey, region):
ec2 = ConnectAws()
ec2Obj = ec2.ec2Instance(akey, skey, region)
del ec2Obj
return True
def chkOperation(self,operation):
available = False
operations = {'add','remove'}
for op in operations:
if op == operation:
available = True
return available
def customCheck(self,region,ak,sk,fileinfo,operation):
ckObj = CheckValidation()
if ckObj.regValidate(region) and ckObj.chkOperation(operation):
if ckObj.checkAWSkey(ak, sk, region):
fCheck,fStatus = ckObj.fileExists(fileinfo)
if fCheck:
print fStatus;return True
else:
print fStatus;exit()
else:
print "Error in Acess and Secret Key"
else:
print "Error in the Region-Name or operation should be 'add' or 'remove' "