示例#1
0
def create_security_group_with_external_ip():
    ec2 = Client()
    sg_client = SG_Client()
    temporary_security_group = "temporary-security-group"
    result = sg_client.set_client(ec2).set_group_name(
        temporary_security_group).create_sg()
    just_created_group_id = result["GroupId"]
    sg_client.set_rule(just_created_group_id, 'tcp',
                       Wimi().get_ip('ipv4'), '3306')
    return just_created_group_id
示例#2
0
def print_securities_groups_from_rds_instance(rds_name):

    fetcher = Fetcher().set_client(Client())
    rds_data = fetcher.get_rds_data(rds_name)
    rds_parser = RDS_Parser().set_data(rds_data)

    if not rds_parser.is_element_exists(rds_name):
        print('There\'s no instance with name ' + rds_name)
    else:
        rds = rds_parser.get_rds_by_name(rds_name)
        print("Securities groups for " + rds_name)
        for sg_name in rds.get_securities_groups_names():
            print("\t" + sg_name)
示例#3
0
def main():
    arguments_list = [['--profile', '-p'], ['--region',
                                            '-r'], ['--rds', '-rds'],
                      ['--create', '-c'], ['--delete', '-d'],
                      ['--delete-name', '-dn'], ['--protocol', '-pr'],
                      ['--ip', '-i'], ['--port', '-po'],
                      ['--rules-from', '-rf'], ['--fields', '-f']]

    parser = argparse.ArgumentParser()
    parser = fast_add_arguments(arguments_list, parser)
    args = parser.parse_args()

    client_config = Client_Config()

    if args.profile:
        client_config.set_profile(args.profile)
    if args.region:
        client_config.set_region(args.region)
    if args.create:
        create_sg(args)
    elif args.delete:
        ec2 = Client()
        sgclient = SG_Client()
        sgs_to_delete = args.delete.split(",")
        for sg_to_delete in sgs_to_delete:
            sgclient.set_client(ec2).set_group_id(sg_to_delete).delete_sg()
    elif args.delete_name:
        ec2 = Client()
        sgclient = SG_Client()
        sgsnames_to_delete = args.delete_name.split(",")
        for sgname_to_delete in sgsnames_to_delete:
            sgclient.set_client(ec2).set_group_name(
                sgname_to_delete).delete_sg()
    elif args.rules_from:
        get_rules_from(client_config, args)
    else:
        list_sg(args, client_config)
示例#4
0
def create_sg(args):
    group_name = args.create + get_hash_date_from_date(datetime.datetime.now())
    ec2 = Client()
    sg_client = SG_Client()
    result = sg_client.set_client(ec2).set_group_name(group_name).create_sg()
    print("Security group named " + group_name + " has just been created.")
    if args.protocol and args.ip and args.port:

        if args.ip == "mine":
            ip_to_set = Wimi().get_ip('ipv4')
        else:
            ip_to_set = args.ip

        sg_client.set_rule(result["GroupId"], args.protocol, ip_to_set,
                           args.port)
示例#5
0
def get_regions(client: Client) -> list:
    regions_parser = Regions_Parser()
    regions_parser.set_data(client.describe_regions())
    return regions_parser.get_list()
示例#6
0
 def get_client(self):
     return Client()
示例#7
0
    "This action will create a real security group in your infraestructure, just to show the output results."
)
response = input(
    "Are you sure to do so? Type yes. Otherwise, the action will be canceled: "
)

if not response == "yes":
    print("Cancelling...")
    exit()

client_config = Client_Config()

if args.region:
    client_config.set_region(args.region)

ec2 = Client()
sg_client = SG_Client()
sg_client.set_client(ec2).set_group_name(args.name)
if sg_client.is_multiples_vpcs():
    ask = Ask(sg_client.fetch_vpcs_list_names())
    vpc_choosed = None
    try:
        vpc_choosed = ask.ask(
            "Which vpc do you would like to setup the security group?:")
    except AskException:
        print("You choosed an invalid option. Quiting, nothing done.")
        exit()
    sg_client.set_vpc(vpc_choosed)

results_creation = sg_client.create_default_sg()
print(results_creation)
示例#8
0
import argparse
import os

sys.path.insert(1, '..')
from awssg.Client_Config import Client_Config
from awssg.Helpers import fast_add_arguments
from awssg.Client import Client
from danilocgsilvame_python_helpers.DcgsPythonHelpers import DcgsPythonHelpers

args = DcgsPythonHelpers().command_line_argument_names('region', 'r',
                                                       'profile', 'p')

if not args.profile:
    print(
        "You must specify a profile name with --profile or -p argument in commando line."
    )
    exit()

os.environ["AWS_PROFILE"] = args.profile

client_config = Client_Config()

if args.profile is not None:
    client_config.set_profile(args.profile)

if args.region is not None:
    client_config.set_region(args.region)

vpcs_data = Client().describe_vpcs()

print(vpcs_data)