Skip to content

Commit

Permalink
Added EKS check #6
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrodamascena committed May 11, 2020
1 parent 6873d98 commit fa156a9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
32 changes: 25 additions & 7 deletions shared/awscommands.py
Expand Up @@ -2,7 +2,7 @@
from shared.internal.security import IAM, IAMPOLICY
from shared.internal.network import VPC, IGW, NATGATEWAY, ELB, ELBV2, ROUTETABLE, SUBNET, NACL, SG, VPCPEERING
from shared.internal.network import VPCENDPOINT
from shared.internal.compute import LAMBDA, EC2
from shared.internal.compute import LAMBDA, EC2, EKS
from shared.internal.database import RDS, ELASTICACHE, DOCUMENTDB
from shared.internal.storage import EFS, S3POLICY
from shared.internal.analytics import ELASTICSEARCH, MSK
Expand All @@ -15,19 +15,36 @@ def __init__(self, vpc_options: VpcOptions):
self.vpc_options = vpc_options

def run(self):

""" IAM and VPC validations """
IAM(self.vpc_options).run()
VPC(self.vpc_options).run()
LAMBDA(self.vpc_options).run()

""" Compute resources """
EC2(self.vpc_options).run()
LAMBDA(self.vpc_options).run()
EKS(self.vpc_options).run()

""" Database resources """
RDS(self.vpc_options).run()
EFS(self.vpc_options).run()
ELASTICACHE(self.vpc_options).run()
IAMPOLICY(self.vpc_options).run()
S3POLICY(self.vpc_options).run()
ELASTICSEARCH(self.vpc_options).run()
DOCUMENTDB(self.vpc_options).run()

""" Application resources """
SQSPOLICY(self.vpc_options).run()

""" Storage resources """
EFS(self.vpc_options).run()
S3POLICY(self.vpc_options).run()

""" Analytics resources """
ELASTICSEARCH(self.vpc_options).run()
MSK(self.vpc_options).run()

""" Security resources """
IAMPOLICY(self.vpc_options).run()

""" Network resources """
IGW(self.vpc_options).run()
NATGATEWAY(self.vpc_options).run()
ELB(self.vpc_options).run()
Expand All @@ -37,4 +54,5 @@ def run(self):
NACL(self.vpc_options).run()
SG(self.vpc_options).run()
VPCPEERING(self.vpc_options).run()
VPCENDPOINT(self.vpc_options).run()
VPCENDPOINT(self.vpc_options).run()

35 changes: 35 additions & 0 deletions shared/internal/compute.py
Expand Up @@ -67,3 +67,38 @@ def run(self):
except Exception as e:
message = "Can't list EC2 Instances\nError {0}".format(str(e))
exit_critical(message)

class EKS(object):

def __init__(self, vpc_options: VpcOptions):
self.vpc_options = vpc_options

def run(self):
try:
client = self.vpc_options.client('eks')

response = client.list_clusters()

message_handler("\nChecking EKS CLUSTERS...", "HEADER")

if len(response["clusters"]) == 0:
message_handler("Found 0 EKS Clusters in region {0}".format(self.vpc_options.region_name), "OKBLUE")
else:
found = 0
message = ""
for data in response["clusters"]:

cluster = client.describe_cluster(name=data)

if cluster['cluster']['resourcesVpcConfig']['vpcId'] == self.vpc_options.vpc_id:
found += 1
message = message + "\ncluster: {} - VpcId {}".format(
data,
self.vpc_options.vpc_id
)

message_handler("Found {0} EKS Clusters using VPC {1} {2}".format(str(found), self.vpc_options.vpc_id, message),'OKBLUE')

except Exception as e:
message = "Can't list EKS Clusters\nError {0}".format(str(e))
exit_critical(message)

0 comments on commit fa156a9

Please sign in to comment.