Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cloudiscovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

# pylint: disable=wrong-import-position
from provider.aws.command import aws_main
from provider.ibm.command import ibm_main
from shared.parameters import generate_parser


Expand Down Expand Up @@ -54,14 +55,11 @@ def main():
if len(sys.argv) <= 1:
parser.print_help()
return

args = parser.parse_args()

if args.language is None or args.language not in AVAILABLE_LANGUAGES:
language = "en_US"
else:
language = args.language

# Diagram check
if "diagram" not in args:
diagram = False
Expand All @@ -77,7 +75,6 @@ def main():

# diagram version check
check_diagram_version(diagram)

# filters check
filters: List[Filterable] = []
if "filters" in args:
Expand All @@ -86,6 +83,10 @@ def main():

if args.command.startswith("aws"):
command = aws_main(args)
import_module = "provider.aws."
elif args.command.startswith("ibm"):
command = ibm_main(args)
import_module = "provider.ibm."
else:
raise NotImplementedError("Unknown command")

Expand All @@ -94,7 +95,7 @@ def main():
else:
services = []

command.run(diagram, args.verbose, services, filters)
command.run(diagram, args.verbose, services, filters, import_module)


def check_diagram_version(diagram):
Expand Down
4 changes: 3 additions & 1 deletion cloudiscovery/provider/aws/all/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ def __init__(self, verbose, filters, session, region_name, services: List[str]):


class All(BaseAwsCommand):
#pylint: disable=too-many-arguments
def run(
self,
diagram: bool,
verbose: bool,
services: List[str],
filters: List[Filterable],
import_module: str,
):
for region in self.region_names:
self.init_region_cache(region)
Expand All @@ -32,7 +34,6 @@ def run(
region_name=region,
services=services,
)

command_runner = AwsCommandRunner(filters=filters)
command_runner.run(
provider="all",
Expand All @@ -41,4 +42,5 @@ def run(
title="AWS Resources - Region {}".format(region),
# pylint: disable=no-member
filename=options.resulting_file_name("all"),
import_module=import_module,
)
48 changes: 26 additions & 22 deletions cloudiscovery/provider/aws/common_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ def __init__(self, region_names, session, partition_code):
self.session: Session = session
self.partition_code: str = partition_code

#pylint: disable=too-many-arguments
def run(
self,
diagram: bool,
verbose: bool,
services: List[str],
filters: List[Filterable],
import_module: str,
):
raise NotImplementedError()

Expand Down Expand Up @@ -197,22 +199,22 @@ def resource_tags(resource_data: dict) -> List[Filterable]:

def resource_tags_from_tuples(tuples: List[Dict[str, str]]) -> List[Filterable]:
"""
List of key-value tuples that store tags, syntax:
[
{
'Key': 'string',
'Value': 'string',
...
},
]
OR
[
{
'key': 'string',
'value': 'string',
...
},
]
List of key-value tuples that store tags, syntax:
[
{
'Key': 'string',
'Value': 'string',
...
},
]
OR
[
{
'key': 'string',
'value': 'string',
...
},
]
"""
result = []
for tuple_elem in tuples:
Expand All @@ -225,10 +227,10 @@ def resource_tags_from_tuples(tuples: List[Dict[str, str]]) -> List[Filterable]:

def resource_tags_from_dict(tags: Dict[str, str]) -> List[Filterable]:
"""
List of key-value dict that store tags, syntax:
{
'string': 'string'
}
List of key-value dict that store tags, syntax:
{
'string': 'string'
}
"""
result = []
for key, value in tags.items():
Expand All @@ -255,8 +257,10 @@ def generate_session(profile_name, region_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(
str(e)
message = (
"You must configure awscli before use this script.\nError: {0}".format(
str(e)
)
)
exit_critical(message)

Expand Down
4 changes: 4 additions & 0 deletions cloudiscovery/provider/aws/iot/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ def __init__(self, thing_name, region_names, session, partition_code):
super().__init__(region_names, session, partition_code)
self.thing_name = thing_name

#pylint: disable=too-many-arguments
def run(
self,
diagram: bool,
verbose: bool,
services: List[str],
filters: List[Filterable],
import_module: str,
):
command_runner = AwsCommandRunner(filters)

Expand Down Expand Up @@ -67,6 +69,7 @@ def run(
diagram_builder=diagram_builder,
title="AWS IoT Resources - Region {}".format(region_name),
filename=thing_options.resulting_file_name("iot"),
import_module=import_module,
)
else:
things = dict()
Expand Down Expand Up @@ -94,4 +97,5 @@ def run(
filename=thing_options.resulting_file_name(
self.thing_name + "_iot"
),
import_module=import_module,
)
3 changes: 3 additions & 0 deletions cloudiscovery/provider/aws/limit/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ def init_globalaws_limits_cache(self, region, services, options: LimitOptions):
session=self.session, region=region, services=services, options=options
).init_globalaws_limits_cache()

#pylint: disable=too-many-arguments
def run(
self,
diagram: bool,
verbose: bool,
services: List[str],
filters: List[Filterable],
import_module: str,
):
if not services:
services = []
Expand Down Expand Up @@ -182,4 +184,5 @@ def run(
title="AWS Limits - Region {}".format(region),
# pylint: disable=no-member
filename=limit_options.resulting_file_name("limit"),
import_module=import_module,
)
3 changes: 3 additions & 0 deletions cloudiscovery/provider/aws/policy/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ def __init__(self, verbose, filters, session, region_name):


class Policy(BaseAwsCommand):
#pylint: disable=too-many-arguments
def run(
self,
diagram: bool,
verbose: bool,
services: List[str],
filters: List[Filterable],
import_module: str,
):
for region in self.region_names:
self.init_region_cache(region)
Expand All @@ -40,4 +42,5 @@ def run(
diagram_builder=diagram,
title="AWS IAM Policies - Region {}".format(region),
filename=options.resulting_file_name("policy"),
import_module=import_module,
)
10 changes: 9 additions & 1 deletion cloudiscovery/provider/aws/security/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ class SecurityOptions(BaseAwsOptions, BaseOptions):

# pylint: disable=too-many-arguments
def __init__(
self, verbose: bool, filters: List[Filterable], session, region_name, commands,
self,
verbose: bool,
filters: List[Filterable],
session,
region_name,
commands,
):
BaseAwsOptions.__init__(self, session, region_name)
BaseOptions.__init__(self, verbose, filters)
Expand Down Expand Up @@ -43,12 +48,14 @@ def __init__(self, region_names, session, commands, partition_code):
super().__init__(region_names, session, partition_code)
self.commands = commands

#pylint: disable=too-many-arguments
def run(
self,
diagram: bool,
verbose: bool,
services: List[str],
filters: List[Filterable],
import_module: str,
):

for region in self.region_names:
Expand All @@ -68,4 +75,5 @@ def run(
title="AWS Security - Region {}".format(region),
# pylint: disable=no-member
filename=security_options.resulting_file_name("security"),
import_module=import_module,
)
5 changes: 4 additions & 1 deletion cloudiscovery/provider/aws/vpc/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ def check_vpc(vpc_options: VpcOptions):
)
print(message)

#pylint: disable=too-many-arguments
def run(
self,
diagram: bool,
verbose: bool,
services: List[str],
filters: List[Filterable],
import_module: str,
):
# pylint: disable=too-many-branches
command_runner = AwsCommandRunner(filters)

for region in self.region_names:
Expand Down Expand Up @@ -100,6 +101,7 @@ def run(
diagram_builder=diagram_builder,
title="AWS VPC {} Resources - Region {}".format(vpc_id, region),
filename=vpc_options.resulting_file_name(vpc_id + "_vpc"),
import_module=import_module,
)
else:
vpc_options = VpcOptions(
Expand All @@ -123,6 +125,7 @@ def run(
self.vpc_id, region
),
filename=vpc_options.resulting_file_name(self.vpc_id + "_vpc"),
import_module=import_module,
)


Expand Down
Empty file.
40 changes: 40 additions & 0 deletions cloudiscovery/provider/ibm/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from provider.ibm.vpc.command import Vpc
from shared.common import (
exit_critical,
BaseCommand,
)

DEFAULT_REGION = "us-south"


def ibm_main(args) -> BaseCommand:

# Check if verbose mode is enabled

# ibm profile check
region_name = args.region_name

if "region_name" not in args:
region_name = [DEFAULT_REGION]

if "url" not in args:
url = "https://us-south.iaas.cloud.ibm.com"

if "threshold" in args:
if args.threshold is not None:
if args.threshold.isdigit() is False:
exit_critical("Threshold must be between 0 and 100")
else:
if int(args.threshold) < 0 or int(args.threshold) > 100:
exit_critical("Threshold must be between 0 and 100")

if args.command == "ibm-vpc":
command = Vpc(
vpc_id=args.vpc_id,
apikey=args.api_key,
region=region_name,
url=url,
)
else:
raise NotImplementedError("Unknown command")
return command
Loading