Skip to content

Commit

Permalink
added beanstalk environment lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Koval committed Dec 27, 2016
1 parent 175c99d commit 8bd0607
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 9 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ To perform a query against your selected profile. Alfred will then auto-populate
#### Modifier Key Cheat Sheet
Below is a table describing the currently supported AWS resource lookups and what Alfred will do upon hitting **Enter** when combined with modifier keys:

| | (none) | Cmd | Alt / Option | Ctrl | Shift <sub>(_press_, not hold)</sub> |
| :---: | --- | --- | --- | --- | --- |
| ![](icons/cfn_stack.png)CloudFormation | Open stack in AWS console | | | | Quicklook |
| ![](icons/ec2_instance.png)<br/>EC2 | Copies _private_ IP | Open instance in AWS console | Copies _public_ IP (if available) | | Quicklook |
| ![](icons/services/lambda.png)<br/>Lambda | Open function in AWS console | | | | Quicklook |
| ![](icons/db_instance.png)![](icons/db_cluster.png)<br/>RDS | Copy endpoint URL | Open cluster or node in AWS Console | | | Quicklook |
| ![](icons/services/redshift.png)<br/>Redshift | Open cluster in AWS console | Copies first node's _private_ IP (if available) | Copies first node's _public_ IP (if available) | | Quicklook |
| ![](icons/s3_bucket.png)<br/>S3 | Open bucket in AWS Console | | | | Quicklook |
| ![](icons/sqs_queue.png)<br/>SQS | Open queue in AWS console | Copy queue URL | | | Quicklook |
| | (none) | Cmd | Alt / Option | Ctrl | Shift <sub>(_press_, not hold)</sub> |
| :---: | --- | --- | --- | --- | --- |
| ![](icons/cfn_stack.png)CloudFormation | Open stack in AWS console | | | | Quicklook |
| ![](icons/ec2_instance.png)<br/>EC2 | Copies _private_ IP | Open instance in AWS console | Copies _public_ IP (if available) | | Quicklook |
| ![](icons/eb_environment.png)<br/>Elastic Beanstalk | Open environment in AWS Console | Copies load balancer URL (if available) | | | Quicklook |
| ![](icons/services/lambda.png)<br/>Lambda | Open function in AWS console | | | | Quicklook |
| ![](icons/db_instance.png)![](icons/db_cluster.png)<br/>RDS | Copy endpoint URL | Open cluster or node in AWS Console | | | Quicklook |
| ![](icons/services/redshift.png)<br/>Redshift | Open cluster in AWS console | Copies first node's _private_ IP (if available) | Copies first node's _public_ IP (if available) | | Quicklook |
| ![](icons/s3_bucket.png)<br/>S3 | Open bucket in AWS Console | | | | Quicklook |
| ![](icons/sqs_queue.png)<br/>SQS | Open queue in AWS console | Copy queue URL | | | Quicklook |

... more resources and modifiers to be implemented. Feel free to [fork this repo](#fork-destination-box) to implement your own!

Expand Down
12 changes: 12 additions & 0 deletions aws_workflow/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,15 @@ def get_lambda_functions():
else:
break
return items


def get_beanstalk_environments():
client = boto3.client('elasticbeanstalk')
items = []
log.debug('calling describe_environments')
response = client.describe_environments()
for item in response['Environments']:
item['facets'] = {}
item['facets']['name'] = item['EnvironmentName']
items.append(item)
return items
7 changes: 7 additions & 0 deletions aws_workflow/aws_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ def test_get_redshift_clusters():
def test_get_lambda_functions():
items = get_lambda_functions()
assert items


def test_get_beanstalk_environments():
items = get_beanstalk_environments()
printer = pprint.PrettyPrinter()
printer.pprint(items)
assert not items
43 changes: 43 additions & 0 deletions aws_workflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,46 @@ def populate_menu_item(self, wf, function, title, uid, region_name, quicklookurl
quicklookurl=quicklookurl
)
item.setvar('action', 'open-url')


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

def create_title(self, item):
return item['EnvironmentName']

def filter_items(self, wf, items, terms):
return wf.filter(' '.join(terms), items, key=lambda item: unicode(item['EnvironmentName']))

health_icons = {
'Green': u'🍏',
'Yellow': u'🌕',
'Red': u'🔴',
'Grey': u'⚫',
}

def populate_menu_item(self, wf, env, title, uid, region_name, quicklookurl):
url = 'https://%s.console.aws.amazon.com/elasticbeanstalk/home?region=%s#/environment/dashboard?applicationName=%s&environmentId=%s' % (region_name, region_name, env['ApplicationName'], env['EnvironmentId'])
item = wf.add_item(
title,
subtitle='open in AWS console (status: %s; health: %s %s)' % (env['Status'], env['HealthStatus'], self.health_icons[env['Health']]),
arg=url,
valid=True,
uid=uid,
icon='icons/eb_environment.png',
type='default',
quicklookurl=quicklookurl
)
item.setvar('action', 'open-url')

load_balancer_url = env.get('EndpointURL', 'N/A')
cmdmod = item.add_modifier(
'cmd',
subtitle='copy load balancer url - %s' % load_balancer_url,
arg=load_balancer_url,
valid='EndpointURL' in env,
)
cmdmod.setvar('action', 'copy-to-clipboard,post-notification')
cmdmod.setvar('notification_title', 'Copied Load Balancer URL')
cmdmod.setvar('notification_text', load_balancer_url)
1 change: 1 addition & 0 deletions aws_workflow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def search(quicklook_port, query, wf, profile, region):
Ec2Finder(),
RedshiftClusterFinder(),
FunctionFinder(),
EnvironmentFinder(),
]
for finder in finders:
finder.find(wf, profile, region, terms, facets, quicklook_baseurl)
Expand Down
Binary file added icons/eb_environment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions quicklook_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class LambdaQuicklookHandler(BaseHandler):
template = 'lambda.html.j2'


class EbQuicklookHandler(BaseHandler):
template = 'eb.html.j2'


def make_app():
return tornado.web.Application([
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': os.path.join(os.getcwd(), 'static')}),
Expand All @@ -57,6 +61,7 @@ def make_app():
(r'/quicklook/sqs', SqsQuicklookHandler),
(r'/quicklook/redshift', RedshiftClusterQuicklookHandler),
(r'/quicklook/lambda', LambdaQuicklookHandler),
(r'/quicklook/eb', EbQuicklookHandler),
])


Expand Down
79 changes: 79 additions & 0 deletions templates/eb.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<html>
<head>
<title>{{ title }}</title>
<link rel="stylesheet" type="text/css" href="/static/css/main.css">
</head>
<body>
<h1>{{ title }}</h1>
<table>
<tr>
<td>ID:</td>
<td>{{ eb.EnvironmentId }}</td>
</tr>
<tr>
<td>Application Name:</td>
<td>{{ eb.ApplicationName }}</td>
</tr>
<tr>
<td>Description:</td>
<td>{{ eb.Description }}</td>
</tr>
<tr>
<td>Status:</td>
<td>{{ eb.Status }}</td>
</tr>
<tr>
<td>Health:</td>
<td>{{ eb.Health }}</td>
</tr>
<tr>
<td>Health Status:</td>
<td>{{ eb.HealthStatus }}</td>
</tr>
<tr>
<td>Date Created:</td>
<td>{{ eb.DateCreated }}</td>
</tr>
<tr>
<td>Date Updated:</td>
<td>{{ eb.DateUpdated }}</td>
</tr>
<tr>
<td>Endpoint URL:</td>
<td>{{ eb.EndpountURL | default('N/A') }}</td>
</tr>
<tr>
<td>Version Label:</td>
<td>{{ eb.VersionLabel }}</td>
</tr>
<tr>
<td>Solution Stack Name:</td>
<td>{{ eb.SolutionStackName }}</td>
</tr>
<tr>
<td>Template Name:</td>
<td>{{ eb.TemplateName | default('N/A') }}</td>
</tr>
<tr>
<td>CNAME:</td>
<td>{{ eb.CNAME }}</td>
</tr>
<tr>
<td>Tier Name:</td>
<td>{{ eb.Tier.Name }}</td>
</tr>
<tr>
<td>Tier Type:</td>
<td>{{ eb.Tier.Type }}</td>
</tr>
<tr>
<td>Tier Version:</td>
<td>{{ eb.Tier.Version }}</td>
</tr>
<tr>
<td>Abortable Operation in Progress:</td>
<td>{{ eb.AbortableOperationInProgress }}</td>
</tr>
</table>
</body>
</html>

0 comments on commit 8bd0607

Please sign in to comment.