Exemple #1
0
def test_get_all_elbs(app):
    from lemur.plugins.lemur_aws.elb import get_all_elbs
    conn = boto.ec2.elb.connect_to_region('us-east-1')
    elbs = get_all_elbs(account_number='123456789012', region='us-east-1')
    assert not elbs
    conn.create_load_balancer('example-lb', ['us-east-1a', 'us-east-1b'], [(443, 5443, 'tcp')])
    elbs = get_all_elbs(account_number='123456789012', region='us-east-1')
    assert elbs
Exemple #2
0
def test_get_all_elbs(app):
    from lemur.plugins.lemur_aws.elb import get_all_elbs
    conn = boto.ec2.elb.connect_to_region('us-east-1')
    elbs = get_all_elbs(account_number='123456789012', region='us-east-1')
    assert not elbs
    conn.create_load_balancer('example-lb', ['us-east-1a', 'us-east-1b'],
                              [(443, 5443, 'tcp')])
    elbs = get_all_elbs(account_number='123456789012', region='us-east-1')
    assert elbs
Exemple #3
0
    def get_endpoints(self, options, **kwargs):
        endpoints = []
        account_number = self.get_option("accountNumber", options)
        regions = self.get_option("regions", options)

        if not regions:
            regions = ec2.get_regions(account_number=account_number)
        else:
            regions = regions.split(",")

        for region in regions:
            elbs = elb.get_all_elbs(account_number=account_number,
                                    region=region)
            current_app.logger.info(
                "Describing classic load balancers in {0}-{1}".format(
                    account_number, region))

            for e in elbs:
                endpoints.extend(get_elb_endpoints(account_number, region, e))

            # fetch advanced ELBs
            elbs_v2 = elb.get_all_elbs_v2(account_number=account_number,
                                          region=region)
            current_app.logger.info(
                "Describing advanced load balancers in {0}-{1}".format(
                    account_number, region))

            for e in elbs_v2:
                endpoints.extend(
                    get_elb_endpoints_v2(account_number, region, e))

        return endpoints
Exemple #4
0
    def get_endpoints(self, options, **kwargs):
        endpoints = []
        account_number = self.get_option('accountNumber', options)
        regions = self.get_option('regions', options)

        if not regions:
            regions = ec2.get_regions(account_number=account_number)
        else:
            regions = regions.split(',')

        for region in regions:
            elbs = elb.get_all_elbs(account_number=account_number, region=region)
            current_app.logger.info("Describing classic load balancers in {0}-{1}".format(account_number, region))

            for e in elbs:
                endpoints.extend(get_elb_endpoints(account_number, region, e))

            # fetch advanced ELBs
            elbs_v2 = elb.get_all_elbs_v2(account_number=account_number, region=region)
            current_app.logger.info("Describing advanced load balancers in {0}-{1}".format(account_number, region))

            for e in elbs_v2:
                endpoints.extend(get_elb_endpoints_v2(account_number, region, e))

        return endpoints
Exemple #5
0
    def get_endpoints(self, options, **kwargs):
        endpoints = []
        account_number = self.get_option("accountNumber", options)
        regions = self.get_option("regions", options)

        if not regions:
            regions = ec2.get_regions(account_number=account_number)
        else:
            regions = "".join(regions.split()).split(",")

        for region in regions:
            elbs = elb.get_all_elbs(account_number=account_number, region=region)
            current_app.logger.info({
                "message": "Describing classic load balancers",
                "account_number": account_number,
                "region": region,
                "number_of_load_balancers": len(elbs)
            })

            for e in elbs:
                endpoints.extend(get_elb_endpoints(account_number, region, e))

            # fetch advanced ELBs
            elbs_v2 = elb.get_all_elbs_v2(account_number=account_number, region=region)
            current_app.logger.info({
                "message": "Describing advanced load balancers",
                "account_number": account_number,
                "region": region,
                "number_of_load_balancers": len(elbs_v2)
            })

            for e in elbs_v2:
                endpoints.extend(get_elb_endpoints_v2(account_number, region, e))

        return endpoints
Exemple #6
0
def test_get_all_elbs(app):
    from lemur.plugins.lemur_aws.elb import get_all_elbs
    client = boto3.client('elb', region_name='us-east-1')

    elbs = get_all_elbs(account_number='123456789012', region='us-east-1')
    assert not elbs

    client.create_load_balancer(LoadBalancerName='example-lb',
                                Listeners=[{
                                    'Protocol': 'string',
                                    'LoadBalancerPort': 443,
                                    'InstanceProtocol': 'tcp',
                                    'InstancePort': 5443,
                                    'SSLCertificateId': 'tcp'
                                }])

    elbs = get_all_elbs(account_number='123456789012', region='us-east-1')
    assert elbs
Exemple #7
0
def test_get_all_elbs(app, aws_credentials):
    from lemur.plugins.lemur_aws.elb import get_all_elbs

    client = boto3.client("elb", region_name="us-east-1")

    elbs = get_all_elbs(account_number="123456789012", region="us-east-1")
    assert not elbs

    client.create_load_balancer(
        LoadBalancerName="example-lb",
        Listeners=[{
            "Protocol": "string",
            "LoadBalancerPort": 443,
            "InstanceProtocol": "tcp",
            "InstancePort": 5443,
            "SSLCertificateId": "tcp",
        }],
    )

    elbs = get_all_elbs(account_number="123456789012", region="us-east-1")
    assert elbs
Exemple #8
0
def test_get_all_elbs(app):
    from lemur.plugins.lemur_aws.elb import get_all_elbs
    client = boto3.client('elb', region_name='us-east-1')

    elbs = get_all_elbs(account_number='123456789012', region='us-east-1')
    assert not elbs

    client.create_load_balancer(
        LoadBalancerName='example-lb',
        Listeners=[
            {
                'Protocol': 'string',
                'LoadBalancerPort': 443,
                'InstanceProtocol': 'tcp',
                'InstancePort': 5443,
                'SSLCertificateId': 'tcp'
            }
        ]
    )

    elbs = get_all_elbs(account_number='123456789012', region='us-east-1')
    assert elbs
Exemple #9
0
def test_get_all_elbs(app, aws_credentials):
    from lemur.plugins.lemur_aws.elb import get_all_elbs

    client = boto3.client("elb", region_name="us-east-1")

    elbs = get_all_elbs(account_number="123456789012", region="us-east-1")
    assert not elbs

    client.create_load_balancer(
        LoadBalancerName="example-lb",
        Listeners=[{
            "Protocol": "string",
            "LoadBalancerPort": 443,
            "InstanceProtocol": "tcp",
            "InstancePort": 5443,
        }],
    )

    elbs = get_all_elbs(account_number="123456789012", region="us-east-1")
    assert elbs

    client.create_load_balancer(LoadBalancerName="example-lb-ignored",
                                Listeners=[{
                                    "Protocol": "string",
                                    "LoadBalancerPort": 443,
                                    "InstanceProtocol": "tcp",
                                    "InstancePort": 5443,
                                }],
                                Tags=[{
                                    "Key": "lemur-test-ignore",
                                    "Value": "",
                                }])

    elbs = get_all_elbs(account_number="123456789012", region="us-east-1")
    names = [elb["LoadBalancerName"] for elb in elbs]
    assert "example-lb" in names
    assert "example-lb-ignored" not in names
Exemple #10
0
    def get_endpoints(self, options, **kwargs):
        endpoints = []
        account_number = self.get_option('accountNumber', options)
        regions = self.get_option('regions', options)

        if not regions:
            regions = ec2.get_regions(account_number=account_number)
        else:
            regions = regions.split(',')

        for region in regions:
            elbs = elb.get_all_elbs(account_number=account_number,
                                    region=region)
            current_app.logger.info(
                "Describing load balancers in {0}-{1}".format(
                    account_number, region))
            for e in elbs:
                for listener in e['ListenerDescriptions']:
                    if not listener['Listener'].get('SSLCertificateId'):
                        continue

                    if listener['Listener'][
                            'SSLCertificateId'] == 'Invalid-Certificate':
                        continue

                    endpoint = dict(
                        name=e['LoadBalancerName'],
                        dnsname=e['DNSName'],
                        type='e',
                        port=listener['Listener']['LoadBalancerPort'],
                        certificate_name=iam.get_name_from_arn(
                            listener['Listener']['SSLCertificateId']))

                    if listener['PolicyNames']:
                        policy = elb.describe_load_balancer_policies(
                            e['LoadBalancerName'],
                            listener['PolicyNames'],
                            account_number=account_number,
                            region=region)
                        endpoint['policy'] = format_elb_cipher_policy(policy)

                    endpoints.append(endpoint)

        return endpoints
Exemple #11
0
    def get_endpoints(self, options, **kwargs):
        endpoints = []
        account_number = self.get_option('accountNumber', options)
        regions = self.get_option('regions', options)

        if not regions:
            regions = get_regions(account_number=account_number)
        else:
            regions = regions.split(',')

        for region in regions:
            elbs = get_all_elbs(account_number=account_number, region=region)
            current_app.logger.info("Describing load balancers in {0}-{1}".format(account_number, region))
            for elb in elbs:
                for listener in elb['ListenerDescriptions']:
                    if not listener['Listener'].get('SSLCertificateId'):
                        continue

                    if listener['Listener']['SSLCertificateId'] == 'Invalid-Certificate':
                        continue

                    endpoint = dict(
                        name=elb['LoadBalancerName'],
                        dnsname=elb['DNSName'],
                        type='elb',
                        port=listener['Listener']['LoadBalancerPort'],
                        certificate_name=iam.get_name_from_arn(listener['Listener']['SSLCertificateId'])
                    )

                    if listener['PolicyNames']:
                        policy = describe_load_balancer_policies(elb['LoadBalancerName'], listener['PolicyNames'], account_number=account_number, region=region)
                        endpoint['policy'] = format_elb_cipher_policy(policy)

                    endpoints.append(endpoint)

        return endpoints