Skip to content

Commit

Permalink
added resource-specific querying
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Koval committed Feb 1, 2017
1 parent 5ff9e87 commit 547fb6e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
10 changes: 10 additions & 0 deletions aws_workflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def _get_cached_data(wf, profile, region, name, cmdline=None, max_age=60):

class Finder:
item_identifier = None
pretty_name = None
aws_list_function_name = None

def create_title(self, obj):
Expand Down Expand Up @@ -89,6 +90,7 @@ def find(self, wf, profile, region_name, terms, facets, quicklook_baseurl):

class Ec2Finder(Finder):
item_identifier = 'ec2'
pretty_name = 'EC2 Instance'
aws_list_function_name = 'get_ec2_instances'

def create_title(self, instance):
Expand Down Expand Up @@ -152,6 +154,7 @@ def populate_menu_item(self, wf, instance, title, uid, region_name, quicklookurl

class BucketFinder(Finder):
item_identifier = 's3'
pretty_name = 'S3 Bucket'
aws_list_function_name = 'get_s3_buckets'

def create_title(self, bucket):
Expand All @@ -176,6 +179,7 @@ def populate_menu_item(self, wf, bucket, title, uid, region_name, quicklookurl,

class DatabaseFinder(Finder):
item_identifier = 'rds'
pretty_name = 'RDS Database'
aws_list_function_name = 'get_rds_instances'

def create_title(self, db):
Expand Down Expand Up @@ -218,6 +222,7 @@ def populate_menu_item(self, wf, db, title, uid, region_name, quicklookurl, prof

class StackFinder(Finder):
item_identifier = 'cfn'
pretty_name = 'CloudFormation Stack'
aws_list_function_name = 'get_cfn_stacks'

stack_status_icons = create_stack_status_icons()
Expand Down Expand Up @@ -248,6 +253,7 @@ def populate_menu_item(self, wf, stack, title, uid, region_name, quicklookurl, p

class QueueFinder(Finder):
item_identifier = 'sqs'
pretty_name = 'SQS Queue'
aws_list_function_name = 'get_sqs_queues'

def create_title(self, queue):
Expand Down Expand Up @@ -286,6 +292,7 @@ def populate_menu_item(self, wf, queue, title, uid, region_name, quicklookurl, p

class RedshiftClusterFinder(Finder):
item_identifier = 'redshift'
pretty_name = 'Redshift Cluster'
aws_list_function_name = 'get_redshift_clusters'

def create_title(self, item):
Expand Down Expand Up @@ -336,6 +343,7 @@ def populate_menu_item(self, wf, cluster, title, uid, region_name, quicklookurl,

class FunctionFinder(Finder):
item_identifier = 'lambda'
pretty_name = 'Lambda Function'
aws_list_function_name = 'get_lambda_functions'

def create_title(self, item):
Expand Down Expand Up @@ -370,6 +378,7 @@ def populate_menu_item(self, wf, function, title, uid, region_name, quicklookurl

class EnvironmentFinder(Finder):
item_identifier = 'eb'
pretty_name = 'ElasticBeanstalk Environment'
aws_list_function_name = 'get_beanstalk_environments'

def create_title(self, item):
Expand Down Expand Up @@ -413,6 +422,7 @@ def populate_menu_item(self, wf, env, title, uid, region_name, quicklookurl, pro

class LogGroupFinder(Finder):
item_identifier = 'logs'
pretty_name = 'CloudWatch Log Group'
aws_list_function_name = 'get_cloudwatch_log_groups'

def create_title(self, item):
Expand Down
48 changes: 29 additions & 19 deletions aws_workflow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ def setup_logger(wf):
ensure_profile = make_pass_decorator('profile', ensure=True, factory=get_profile)
ensure_region = make_pass_decorator('region', ensure=True, factory=get_region)

finders = [
DatabaseFinder(),
QueueFinder(),
StackFinder(),
BucketFinder(),
Ec2Finder(),
RedshiftClusterFinder(),
FunctionFinder(),
EnvironmentFinder(),
LogGroupFinder(),
]


@click.group()
def cli():
Expand Down Expand Up @@ -168,13 +180,22 @@ def wf_commands():
def resource_commands():
'''search within a particular resource'''

@resource_commands.command('ec2')
@click.argument('query', required=False)
@pass_wf
@pass_complete
def hooray(query, wf, complete):
'''set the active profile (currently active: )'''
wf.send_feedback()
def create_resource_finder(finder):
@resource_commands.command(finder.item_identifier)
@click.argument('query')
@pass_wf
@ensure_profile
@ensure_region
def resource_finder(query, wf, profile, region):
terms, facets = parse_query(query)
finder.find(wf, profile, region, terms, facets, quicklook_baseurl)
wf.send_feedback()

resource_finder.__doc__ = '''search for %ss''' % finder.pretty_name

for finder in finders:
create_resource_finder(finder)


@wf_commands.command('profile')
@click.argument('query', required=False)
Expand Down Expand Up @@ -345,6 +366,7 @@ def aws_console(query, wf, complete, region):
wf.send_feedback()


quicklook_baseurl = None

@click.command()
@click.option('--quicklook_port', envvar='WF_QUICKLOOK_PORT')
Expand All @@ -353,7 +375,6 @@ def aws_console(query, wf, complete, region):
@ensure_profile
@ensure_region
def search(quicklook_port, query, wf, profile, region):
quicklook_baseurl = None
if quicklook_port is not None:
if not is_running('quicklook'):
log.info('\n'.join('%s = %s' % (k, v) for k, v in os.environ.items()))
Expand All @@ -367,17 +388,6 @@ def search(quicklook_port, query, wf, profile, region):
quicklook_baseurl = 'http://localhost:%s/quicklook' % quicklook_port

terms, facets = parse_query(query)
finders = [
DatabaseFinder(),
QueueFinder(),
StackFinder(),
BucketFinder(),
Ec2Finder(),
RedshiftClusterFinder(),
FunctionFinder(),
EnvironmentFinder(),
LogGroupFinder(),
]
for finder in finders:
finder.find(wf, profile, region, terms, facets, quicklook_baseurl)

Expand Down
4 changes: 2 additions & 2 deletions aws_workflow/sflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
('squoted', 'exclusive'),
)
tokens = 'STRING'.split()
literals = ['"', "'", '>', '+']
literals = ['"', "'", '>', '+', '@']

def t_empty_quotes(t):
r"''|\"\""
Expand Down Expand Up @@ -35,7 +35,7 @@ def t_dquoted_end(t):
t.lexer.pop_state()

def t_STRING(t):
r"[a-zA-Z_-]+"
r"[a-zA-Z0-9_-]+"
return t

t_ignore = ' \t'
Expand Down

0 comments on commit 547fb6e

Please sign in to comment.