Skip to content

Commit

Permalink
Merge pull request #71 from garnaat/develop
Browse files Browse the repository at this point in the history
Merge release code to master
  • Loading branch information
garnaat committed Nov 4, 2015
2 parents e2db7bb + 201175e commit fcff0bf
Show file tree
Hide file tree
Showing 13 changed files with 608 additions and 43 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
six>=1.8.0,<2.0.0
botocore>=1.2.6
botocore>=1.3.4
PyYAML==3.11
python-dateutil>=2.1,<3.0.0
mock==1.0.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

requires = [
'six>=1.8.0,<2.0.0',
'botocore>=1.2.4',
'botocore>=1.3.4',
'python-dateutil>=2.1,<3.0.0',
'PyYAML==3.11']

Expand Down
2 changes: 1 addition & 1 deletion skew/_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.0
0.13.0
40 changes: 4 additions & 36 deletions skew/arn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import jmespath

import skew.resources
import skew.awsclient
from skew.config import get_config

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -112,47 +111,16 @@ def choices(self, context=None):
def enumerate(self, context):
LOG.debug('Resource.enumerate %s', context)
_, provider, service_name, region, account = context
client = skew.awsclient.get_awsclient(
service_name, region, account)
resource_type, resource_id = self._split_resource(self.pattern)
LOG.debug('resource_type=%s, resource_id=%s',
resource_type, resource_id)
resources = []
for resource_type in self.matches(context):
kwargs = {}
resource_path = '.'.join([provider, service_name, resource_type])
resource_cls = skew.resources.find_resource_class(resource_path)
do_client_side_filtering = False
if resource_id and resource_id != '*':
# If we are looking for a specific resource and the
# API provides a way to filter on a specific resource
# id then let's insert the right parameter to do the filtering.
# If the API does not support that, we will have to filter
# after we get all of the results.
filter_name = resource_cls.Meta.filter_name
if filter_name:
if resource_cls.Meta.filter_type == 'list':
kwargs[filter_name] = [resource_id]
else:
kwargs[filter_name] = resource_id
else:
do_client_side_filtering = True
enum_op, path, extra_args = resource_cls.Meta.enum_spec
if extra_args:
kwargs.update(extra_args)
LOG.debug('enum_op=%s' % enum_op)
data = client.call(enum_op, query=path, **kwargs)
LOG.debug(data)
if data:
for d in data:
if do_client_side_filtering:
# If the API does not support filtering, the resource
# class should provide a filter method that will
# return True if the returned data matches the
# resource ID we are looking for.
if not resource_cls.filter(resource_id, d):
continue
resource = resource_cls(client, d, self._arn.query)
yield resource
resources.extend(resource_cls.enumerate(
self._arn, region, account, resource_id))
return resources


class Account(ARNComponent):
Expand Down
1 change: 1 addition & 0 deletions skew/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ResourceTypes = {
'aws.autoscaling.autoScalingGroup': 'aws.autoscaling.AutoScalingGroup',
'aws.autoscaling.launchConfigurationName': 'aws.autoscaling.LaunchConfiguration',
'aws.cloudformation.stack': 'aws.cloudformation.Stack',
'aws.cloudwatch.alarm': 'aws.cloudwatch.Alarm',
'aws.dynamodb.table': 'aws.dynamodb.Table',
'aws.ec2.address': 'aws.ec2.Address',
Expand Down
2 changes: 0 additions & 2 deletions skew/resources/aws/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
from collections import namedtuple

import jmespath
import botocore.session

import skew.awsclient
from skew.resources import find_resource_class
from skew.resources.resource import Resource

LOG = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion skew/resources/aws/autoscaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LaunchConfiguration(AWSResource):

class Meta(object):
service = 'autoscaling'
type = 'launchConfigurationName'
type = 'launchConfiguration'
name = 'LaunchConfigurationName'
date = 'CreatedTime'
dimension = 'AutoScalingGroupName'
Expand Down
48 changes: 48 additions & 0 deletions skew/resources/aws/cloudformation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2014 Scopely, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import jmespath

from skew.resources.aws import AWSResource


class Stack(AWSResource):

class Meta(object):
service = 'cloudformation'
type = 'stack'
enum_spec = ('describe_stacks', 'Stacks[]', None)
detail_spec = ('describe_stack_resources', 'StackName',
'StackResources[]')
id = 'StackName'
filter_name = 'StackName'
name = 'StackName'
date = 'CreationTime'
dimension = None

def __init__(self, client, data, query=None):
super(Stack, self).__init__(client, data, query)
self._data = data
self._resources = []

def __iter__(self):
detail_op, param_name, detail_path = self.Meta.detail_spec
params = {param_name: self.id}
if not self._resources:
data = self._client.call(detail_op, **params)
self._resources = jmespath.search(detail_path, data)
for resource in self._resources:
yield resource

@property
def arn(self):
return self._data['StackId']
41 changes: 41 additions & 0 deletions skew/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,52 @@
import logging
import jmespath

import skew.awsclient

LOG = logging.getLogger(__name__)


class Resource(object):

@classmethod
def enumerate(cls, arn, region, account, resource_id=None):
client = skew.awsclient.get_awsclient(
cls.Meta.service, region, account)
kwargs = {}
do_client_side_filtering = False
if resource_id and resource_id != '*':
# If we are looking for a specific resource and the
# API provides a way to filter on a specific resource
# id then let's insert the right parameter to do the filtering.
# If the API does not support that, we will have to filter
# after we get all of the results.
filter_name = cls.Meta.filter_name
if filter_name:
if cls.Meta.filter_type == 'list':
kwargs[filter_name] = [resource_id]
else:
kwargs[filter_name] = resource_id
else:
do_client_side_filtering = True
enum_op, path, extra_args = cls.Meta.enum_spec
if extra_args:
kwargs.update(extra_args)
LOG.debug('enum_op=%s' % enum_op)
data = client.call(enum_op, query=path, **kwargs)
LOG.debug(data)
resources = []
if data:
for d in data:
if do_client_side_filtering:
# If the API does not support filtering, the resource
# class should provide a filter method that will
# return True if the returned data matches the
# resource ID we are looking for.
if not cls.filter(resource_id, d):
continue
resources.append(cls(client, d, arn.query))
return resources

class Meta(object):
type = 'resource'
dimension = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"StackResources": [
{
"StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/Production-Worker-Resources/684bc4e0-4c32-11e5-b67b-500160d4da7c",
"ResourceStatus": "CREATE_COMPLETE",
"ResourceType": "AWS::EC2::SecurityGroupIngress",
"Timestamp": "2015-08-26T20:39:18.642000+00:00",
"StackName": "Production-Worker-Resources",
"PhysicalResourceId": "dbSecurityGroupIngress",
"LogicalResourceId": "dbSecurityGroupIngress"
},
{
"StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/Production-Worker-Resources/684bc4e0-4c32-11e5-b67b-500160d4da7c",
"ResourceStatus": "CREATE_COMPLETE",
"ResourceType": "AWS::EC2::SecurityGroup",
"Timestamp": "2015-08-26T20:39:16.348000+00:00",
"StackName": "Production-Worker-Resources",
"PhysicalResourceId": "sg-a77fc8c3",
"LogicalResourceId": "ec2SecurityGroup"
},
{
"StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/Production-Worker-Resources/684bc4e0-4c32-11e5-b67b-500160d4da7c",
"ResourceStatus": "UPDATE_COMPLETE",
"ResourceType": "AWS::ElasticLoadBalancing::LoadBalancer",
"Timestamp": "2015-08-26T21:15:29.762000+00:00",
"StackName": "Production-Worker-Resources",
"PhysicalResourceId": "worker-production",
"LogicalResourceId": "elb"
},
{
"StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/Production-Worker-Resources/684bc4e0-4c32-11e5-b67b-500160d4da7c",
"ResourceStatus": "CREATE_COMPLETE",
"ResourceType": "AWS::EC2::SecurityGroup",
"Timestamp": "2015-08-26T20:38:57.834000+00:00",
"StackName": "Production-Worker-Resources",
"PhysicalResourceId": "sg-d77fc8b3",
"LogicalResourceId": "elbSecurityGroup"
},
{
"StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/Production-Worker-Resources/684bc4e0-4c32-11e5-b67b-500160d4da7c",
"ResourceStatus": "CREATE_COMPLETE",
"ResourceType": "AWS::IAM::Role",
"Timestamp": "2015-08-26T20:38:52.422000+00:00",
"StackName": "Production-Worker-Resources",
"PhysicalResourceId": "Production-Worker-Resources-workersIamRole-436UOCN5ITI3",
"LogicalResourceId": "workersIamRole"
},
{
"StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/Production-Worker-Resources/684bc4e0-4c32-11e5-b67b-500160d4da7c",
"ResourceStatus": "CREATE_COMPLETE",
"ResourceType": "AWS::IAM::InstanceProfile",
"Timestamp": "2015-08-26T20:40:55.821000+00:00",
"StackName": "Production-Worker-Resources",
"PhysicalResourceId": "Production-Worker-Resources-workersInstanceProfile-1MX8GHOXXDU95",
"LogicalResourceId": "workersInstanceProfile"
}
],
"ResponseMetadata": {
"HTTPStatusCode": 200,
"RequestId": "a236e60a-8266-11e5-ba6f-7fb96a223003"
}
}
Loading

0 comments on commit fcff0bf

Please sign in to comment.