Skip to content

Commit

Permalink
Merge branch 'develop' into r_2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
meshuga committed Jul 11, 2020
2 parents 3a55eca + 53040d1 commit d000bd1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
21 changes: 18 additions & 3 deletions cloudiscovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,24 @@ def main():
filters = parse_filters(args.filters)

# aws profile check
session = generate_session(args.profile_name)
if "region_name" not in args:
session = generate_session(profile_name=args.profile_name, region_name=None)
else:
session = generate_session(
profile_name=args.profile_name, region_name=args.region_name
)

session.get_credentials()
region_name = session.region_name

if "region_name" not in args:
region_names = [DEFAULT_REGION]
else:
if args.region_name is None and region_name is None:
exit_critical(_("Neither region parameter nor region config were passed"))

# checking region configuration
check_region_profile(
arg_region_name=args.region_name, profile_region_name=region_name
)

# assuming region parameter precedes region configuration
if args.region_name is not None:
Expand Down Expand Up @@ -272,6 +281,12 @@ def check_diagram_version(diagram):
)


def check_region_profile(arg_region_name, profile_region_name):

if arg_region_name is None and profile_region_name is None:
exit_critical("Neither region parameter nor region config were passed")


def check_region(region_parameter, region_name, session):
"""
Region us-east-1 as a default region here
Expand Down
10 changes: 9 additions & 1 deletion cloudiscovery/provider/limit/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
)
from shared.common_aws import BaseAwsOptions, BaseAwsCommand, AwsCommandRunner
from shared.diagram import NoDiagram
from provider.limit.data.allowed_resources import ALLOWED_SERVICES_CODES
from provider.limit.data.allowed_resources import (
ALLOWED_SERVICES_CODES,
SPECIAL_RESOURCES,
)


class LimitOptions(BaseAwsOptions, BaseOptions):
Expand Down Expand Up @@ -39,9 +42,12 @@ def __init__(self, session, region: str, services, options: LimitOptions):
self.session = session
self.options = options
self.services = []

if services is None:
for service in ALLOWED_SERVICES_CODES:
self.services.append(service)
for service in SPECIAL_RESOURCES:
self.services.append(service)
else:
self.services = services

Expand Down Expand Up @@ -151,6 +157,8 @@ def run(
services = []
for service in ALLOWED_SERVICES_CODES:
services.append(service)
for service in SPECIAL_RESOURCES:
services.append(service)

for region in self.region_names:
limit_options = LimitOptions(
Expand Down
3 changes: 3 additions & 0 deletions cloudiscovery/provider/limit/data/allowed_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,9 @@
},
}

# These resources are not covered by services-quota, than we must use "manual" checks
SPECIAL_RESOURCES = ["ses"]

FILTER_EC2_BIGFAMILY = {
"filter": {
"Filters": [
Expand Down
7 changes: 6 additions & 1 deletion cloudiscovery/provider/limit/resource/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from provider.limit.data.allowed_resources import (
ALLOWED_SERVICES_CODES,
FILTER_EC2_BIGFAMILY,
SPECIAL_RESOURCES,
)
from shared.common import (
ResourceProvider,
Expand Down Expand Up @@ -49,7 +50,7 @@ def get_resources(self) -> List[Resource]:
0 if self.options.threshold is None else self.options.threshold
)

client_quota = self.options.session.client("service-quotas")
client_quota = self.options.client("service-quotas")

resources_found = []

Expand All @@ -73,6 +74,10 @@ def get_resources(self) -> List[Resource]:

@exception
def analyze_service(self, service_name, client_quota, threshold_requested):

if service_name in SPECIAL_RESOURCES:
return []

cache_key = "aws_limits_" + service_name + "_" + self.options.region_name
cache = self.cache.get_key(cache_key)
resources_found = []
Expand Down
6 changes: 6 additions & 0 deletions cloudiscovery/provider/limit/resource/ses.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def __init__(self, options: LimitOptions):

@exception
def get_resources(self) -> List[Resource]:

services = self.options.services

if "ses" not in services:
return []

client = self.options.client("ses")

response = client.get_send_quota()
Expand Down
4 changes: 2 additions & 2 deletions cloudiscovery/shared/common_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ def get_tag(d, tag_name) -> Optional[str]:
return None


def generate_session(profile_name):
def generate_session(profile_name, region_name):
try:
return boto3.Session(profile_name=profile_name)
return boto3.Session(profile_name=profile_name, region_name=region_name)
# pylint: disable=broad-except
except Exception as e:
message = "You must configure awscli before use this script.\nError: {0}".format(
Expand Down
6 changes: 3 additions & 3 deletions cloudiscovery/shared/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import traceback
import sys

from shared.common import log_critical, exit_critical
from shared.common import log_critical


# Decorator to catch exceptions and avoid stop script.
Expand Down Expand Up @@ -48,7 +48,7 @@ def wrapper(*args, **kwargs):
traceback.format_exc(),
)
)
exit_critical(issue_info)
log_critical(issue_info)

except Exception: # pylint: disable=broad-except
log_critical("You've found a bug! Please, open an issue in GitHub project")
Expand All @@ -63,6 +63,6 @@ def wrapper(*args, **kwargs):
traceback.format_exc(),
)
)
exit_critical(issue_info)
log_critical(issue_info)

return wrapper

0 comments on commit d000bd1

Please sign in to comment.