{"action":"created","comment":{"url":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/comments/82098690","pull_request_review_id":3028030,"id":82098690,"diff_hunk":"@@ -0,0 +1,119 @@\n+function(account_label, env_tag_value, ellipsis) {\n+  \"use strict\"; \n+const Q = require('q');\n+var AWS = require('aws-sdk');\n+var _ = require('underscore');\n+\n+// -----------------------------------------------------------------------------------------------\n+// INPUTS\n+// -----------------------------------------------------------------------------------------------\n+\n+// Add here the region codes of the regions you want Ellipisis to search for Instances\n+var regions = [\n+  'us-east-1',\n+  'us-west-1'\n+]\n+\n+// What tags do you want to use to select the instances?\n+// Add the Tag Key and the Tag Value. Tag Value can be an input param.\n+const searchedTags = [\n+  {Key: \"Environment\", Value: env_tag_value}\n+];\n+\n+// What aws accounts do you want to use?\n+// Add here the accounts you want Ellipisis to use. The label is used to \n+// allow the user to choose what account to use.\n+var accounts = [\n+  {\n+    label: \"mb\",\n+    key: ellipsis.env.MB_AWS_KEY,\n+    secret: ellipsis.env.MB_AWS_SECRET\n+  },\n+  {\n+    label: \"ep\",\n+    key: ellipsis.env.EP_AWS_KEY,\n+    secret: ellipsis.env.EP_AWS_SECRET\n+  }\n+];\n+\n+// -----------------------------------------------------------------------------------------------\n+// Given AWS account and a list of regions it finds all the \n+// instances in the regions that match a given list of tags.\n+// tags are object with a Key and Value properties. For Example:\n+//  {Key: \"Environment\", Value: \"staging4\"}\n+// -----------------------------------------------------------------------------------------------\n+const findInstances = (account, regions) => {\n+  return Q.all(regions.map((r)=>findInstancesInRegion(account, r))); \n+}\n+\n+// -----------------------------------------------------------------------------------------------\n+// Given an AWS account and a region this Promise retrieves\n+// all the instances that have tags matching the tags in the \n+// array withTags\n+// -----------------------------------------------------------------------------------------------\n+const findInstancesInRegion = (account, region) => {\n+  const deferred = Q.defer();\n+  AWS.config.update({\n+    accessKeyId: account.key, \n+    secretAccessKey: account.secret, \n+    region: region\n+  });\n+  const ec2 = new AWS.EC2();\n+  ec2.describeInstances({}, (err, data) => {\n+    if (err) {\n+      deferred.reject(err);\n+    } else {\n+      const instances = data.Reservations.map((ea) => ea.Instances);\n+      var flattened = [].concat.apply([], instances);\n+      _.each(flattened, function(element, index) {\n+\t       _.extend(element, {accountLabel: account.label, accountRegion: region})\n+      });\n+      deferred.resolve(flattened);\n+    }\n+  });\n+  return deferred.promise;\n+}\n+\n+// -----------------------------------------------------------------------------------------------\n+// Given an instance it returns true is the instance has all the tags\n+// specified in searchedTags, both a Key and Value must match\n+// -----------------------------------------------------------------------------------------------\n+const hasTags = (instance, searchedTags) => {\n+  for (var i=0; i < searchedTags.length; i++) {\n+    // if any of the searchedTag is not contained in the instance Tags array\n+    // then return false to indicate that the instance does not have all the \n+    // searchedTags\n+    if (!instance.Tags.find((instanceTag) => instanceTag.Key == searchedTags[i].Key && instanceTag.Value == searchedTags[i].Value)){ ","path":"published/AWS/servers_by_account_and_tags/function.js","position":86,"original_position":86,"commit_id":"a7210d3c208ac6c377ab08b068ce830f4f9daac4","original_commit_id":"a7210d3c208ac6c377ab08b068ce830f4f9daac4","user":{"login":"attaboy","id":71433,"avatar_url":"https://avatars.githubusercontent.com/u/71433?v=3","gravatar_id":"","url":"https://api.github.com/users/attaboy","html_url":"https://github.com/attaboy","followers_url":"https://api.github.com/users/attaboy/followers","following_url":"https://api.github.com/users/attaboy/following{/other_user}","gists_url":"https://api.github.com/users/attaboy/gists{/gist_id}","starred_url":"https://api.github.com/users/attaboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/attaboy/subscriptions","organizations_url":"https://api.github.com/users/attaboy/orgs","repos_url":"https://api.github.com/users/attaboy/repos","events_url":"https://api.github.com/users/attaboy/events{/privacy}","received_events_url":"https://api.github.com/users/attaboy/received_events","type":"User","site_admin":false},"body":"Might not matter here, but it's usually better to use `===` instead of `==` when comparing unknown values, because of all the weird type coercion `==` does (e.g. `[0] == \"0\" == 0 == false`)","created_at":"2016-10-06T00:30:06Z","updated_at":"2016-10-06T00:34:03Z","html_url":"https://github.com/ellipsis-ai/behaviors/pull/4#discussion_r82098690","pull_request_url":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/comments/82098690"},"html":{"href":"https://github.com/ellipsis-ai/behaviors/pull/4#discussion_r82098690"},"pull_request":{"href":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/4","id":88161929,"html_url":"https://github.com/ellipsis-ai/behaviors/pull/4","diff_url":"https://github.com/ellipsis-ai/behaviors/pull/4.diff","patch_url":"https://github.com/ellipsis-ai/behaviors/pull/4.patch","issue_url":"https://api.github.com/repos/ellipsis-ai/behaviors/issues/4","number":4,"state":"open","locked":false,"title":"aws public skills to query servers across zones and accounts","user":{"login":"matteomelani","id":427583,"avatar_url":"https://avatars.githubusercontent.com/u/427583?v=3","gravatar_id":"","url":"https://api.github.com/users/matteomelani","html_url":"https://github.com/matteomelani","followers_url":"https://api.github.com/users/matteomelani/followers","following_url":"https://api.github.com/users/matteomelani/following{/other_user}","gists_url":"https://api.github.com/users/matteomelani/gists{/gist_id}","starred_url":"https://api.github.com/users/matteomelani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matteomelani/subscriptions","organizations_url":"https://api.github.com/users/matteomelani/orgs","repos_url":"https://api.github.com/users/matteomelani/repos","events_url":"https://api.github.com/users/matteomelani/events{/privacy}","received_events_url":"https://api.github.com/users/matteomelani/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-05T21:35:56Z","updated_at":"2016-10-06T00:34:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f544bcea7c6181ebc5337307158feb94199b11ec","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/4/commits","review_comments_url":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/4/comments","review_comment_url":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ellipsis-ai/behaviors/issues/4/comments","statuses_url":"https://api.github.com/repos/ellipsis-ai/behaviors/statuses/a7210d3c208ac6c377ab08b068ce830f4f9daac4","head":{"label":"ellipsis-ai:aws-skill-for-ken","ref":"aws-skill-for-ken","sha":"a7210d3c208ac6c377ab08b068ce830f4f9daac4","user":{"login":"ellipsis-ai","id":19512214,"avatar_url":"https://avatars.githubusercontent.com/u/19512214?v=3","gravatar_id":"","url":"https://api.github.com/users/ellipsis-ai","html_url":"https://github.com/ellipsis-ai","followers_url":"https://api.github.com/users/ellipsis-ai/followers","following_url":"https://api.github.com/users/ellipsis-ai/following{/other_user}","gists_url":"https://api.github.com/users/ellipsis-ai/gists{/gist_id}","starred_url":"https://api.github.com/users/ellipsis-ai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ellipsis-ai/subscriptions","organizations_url":"https://api.github.com/users/ellipsis-ai/orgs","repos_url":"https://api.github.com/users/ellipsis-ai/repos","events_url":"https://api.github.com/users/ellipsis-ai/events{/privacy}","received_events_url":"https://api.github.com/users/ellipsis-ai/received_events","type":"Organization","site_admin":false},"repo":{"id":61961394,"name":"behaviors","full_name":"ellipsis-ai/behaviors","owner":{"login":"ellipsis-ai","id":19512214,"avatar_url":"https://avatars.githubusercontent.com/u/19512214?v=3","gravatar_id":"","url":"https://api.github.com/users/ellipsis-ai","html_url":"https://github.com/ellipsis-ai","followers_url":"https://api.github.com/users/ellipsis-ai/followers","following_url":"https://api.github.com/users/ellipsis-ai/following{/other_user}","gists_url":"https://api.github.com/users/ellipsis-ai/gists{/gist_id}","starred_url":"https://api.github.com/users/ellipsis-ai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ellipsis-ai/subscriptions","organizations_url":"https://api.github.com/users/ellipsis-ai/orgs","repos_url":"https://api.github.com/users/ellipsis-ai/repos","events_url":"https://api.github.com/users/ellipsis-ai/events{/privacy}","received_events_url":"https://api.github.com/users/ellipsis-ai/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ellipsis-ai/behaviors","description":null,"fork":false,"url":"https://api.github.com/repos/ellipsis-ai/behaviors","forks_url":"https://api.github.com/repos/ellipsis-ai/behaviors/forks","keys_url":"https://api.github.com/repos/ellipsis-ai/behaviors/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ellipsis-ai/behaviors/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ellipsis-ai/behaviors/teams","hooks_url":"https://api.github.com/repos/ellipsis-ai/behaviors/hooks","issue_events_url":"https://api.github.com/repos/ellipsis-ai/behaviors/issues/events{/number}","events_url":"https://api.github.com/repos/ellipsis-ai/behaviors/events","assignees_url":"https://api.github.com/repos/ellipsis-ai/behaviors/assignees{/user}","branches_url":"https://api.github.com/repos/ellipsis-ai/behaviors/branches{/branch}","tags_url":"https://api.github.com/repos/ellipsis-ai/behaviors/tags","blobs_url":"https://api.github.com/repos/ellipsis-ai/behaviors/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ellipsis-ai/behaviors/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ellipsis-ai/behaviors/git/refs{/sha}","trees_url":"https://api.github.com/repos/ellipsis-ai/behaviors/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ellipsis-ai/behaviors/statuses/{sha}","languages_url":"https://api.github.com/repos/ellipsis-ai/behaviors/languages","stargazers_url":"https://api.github.com/repos/ellipsis-ai/behaviors/stargazers","contributors_url":"https://api.github.com/repos/ellipsis-ai/behaviors/contributors","subscribers_url":"https://api.github.com/repos/ellipsis-ai/behaviors/subscribers","subscription_url":"https://api.github.com/repos/ellipsis-ai/behaviors/subscription","commits_url":"https://api.github.com/repos/ellipsis-ai/behaviors/commits{/sha}","git_commits_url":"https://api.github.com/repos/ellipsis-ai/behaviors/git/commits{/sha}","comments_url":"https://api.github.com/repos/ellipsis-ai/behaviors/comments{/number}","issue_comment_url":"https://api.github.com/repos/ellipsis-ai/behaviors/issues/comments{/number}","contents_url":"https://api.github.com/repos/ellipsis-ai/behaviors/contents/{+path}","compare_url":"https://api.github.com/repos/ellipsis-ai/behaviors/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ellipsis-ai/behaviors/merges","archive_url":"https://api.github.com/repos/ellipsis-ai/behaviors/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ellipsis-ai/behaviors/downloads","issues_url":"https://api.github.com/repos/ellipsis-ai/behaviors/issues{/number}","pulls_url":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls{/number}","milestones_url":"https://api.github.com/repos/ellipsis-ai/behaviors/milestones{/number}","notifications_url":"https://api.github.com/repos/ellipsis-ai/behaviors/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ellipsis-ai/behaviors/labels{/name}","releases_url":"https://api.github.com/repos/ellipsis-ai/behaviors/releases{/id}","deployments_url":"https://api.github.com/repos/ellipsis-ai/behaviors/deployments","created_at":"2016-06-25T20:59:51Z","updated_at":"2016-06-25T21:05:33Z","pushed_at":"2016-10-05T21:35:56Z","git_url":"git://github.com/ellipsis-ai/behaviors.git","ssh_url":"git@github.com:ellipsis-ai/behaviors.git","clone_url":"https://github.com/ellipsis-ai/behaviors.git","svn_url":"https://github.com/ellipsis-ai/behaviors","homepage":null,"size":46,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ellipsis-ai:master","ref":"master","sha":"54eb816281513d2e1a8c683ea4fa8c737dd89b00","user":{"login":"ellipsis-ai","id":19512214,"avatar_url":"https://avatars.githubusercontent.com/u/19512214?v=3","gravatar_id":"","url":"https://api.github.com/users/ellipsis-ai","html_url":"https://github.com/ellipsis-ai","followers_url":"https://api.github.com/users/ellipsis-ai/followers","following_url":"https://api.github.com/users/ellipsis-ai/following{/other_user}","gists_url":"https://api.github.com/users/ellipsis-ai/gists{/gist_id}","starred_url":"https://api.github.com/users/ellipsis-ai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ellipsis-ai/subscriptions","organizations_url":"https://api.github.com/users/ellipsis-ai/orgs","repos_url":"https://api.github.com/users/ellipsis-ai/repos","events_url":"https://api.github.com/users/ellipsis-ai/events{/privacy}","received_events_url":"https://api.github.com/users/ellipsis-ai/received_events","type":"Organization","site_admin":false},"repo":{"id":61961394,"name":"behaviors","full_name":"ellipsis-ai/behaviors","owner":{"login":"ellipsis-ai","id":19512214,"avatar_url":"https://avatars.githubusercontent.com/u/19512214?v=3","gravatar_id":"","url":"https://api.github.com/users/ellipsis-ai","html_url":"https://github.com/ellipsis-ai","followers_url":"https://api.github.com/users/ellipsis-ai/followers","following_url":"https://api.github.com/users/ellipsis-ai/following{/other_user}","gists_url":"https://api.github.com/users/ellipsis-ai/gists{/gist_id}","starred_url":"https://api.github.com/users/ellipsis-ai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ellipsis-ai/subscriptions","organizations_url":"https://api.github.com/users/ellipsis-ai/orgs","repos_url":"https://api.github.com/users/ellipsis-ai/repos","events_url":"https://api.github.com/users/ellipsis-ai/events{/privacy}","received_events_url":"https://api.github.com/users/ellipsis-ai/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ellipsis-ai/behaviors","description":null,"fork":false,"url":"https://api.github.com/repos/ellipsis-ai/behaviors","forks_url":"https://api.github.com/repos/ellipsis-ai/behaviors/forks","keys_url":"https://api.github.com/repos/ellipsis-ai/behaviors/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ellipsis-ai/behaviors/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ellipsis-ai/behaviors/teams","hooks_url":"https://api.github.com/repos/ellipsis-ai/behaviors/hooks","issue_events_url":"https://api.github.com/repos/ellipsis-ai/behaviors/issues/events{/number}","events_url":"https://api.github.com/repos/ellipsis-ai/behaviors/events","assignees_url":"https://api.github.com/repos/ellipsis-ai/behaviors/assignees{/user}","branches_url":"https://api.github.com/repos/ellipsis-ai/behaviors/branches{/branch}","tags_url":"https://api.github.com/repos/ellipsis-ai/behaviors/tags","blobs_url":"https://api.github.com/repos/ellipsis-ai/behaviors/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ellipsis-ai/behaviors/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ellipsis-ai/behaviors/git/refs{/sha}","trees_url":"https://api.github.com/repos/ellipsis-ai/behaviors/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ellipsis-ai/behaviors/statuses/{sha}","languages_url":"https://api.github.com/repos/ellipsis-ai/behaviors/languages","stargazers_url":"https://api.github.com/repos/ellipsis-ai/behaviors/stargazers","contributors_url":"https://api.github.com/repos/ellipsis-ai/behaviors/contributors","subscribers_url":"https://api.github.com/repos/ellipsis-ai/behaviors/subscribers","subscription_url":"https://api.github.com/repos/ellipsis-ai/behaviors/subscription","commits_url":"https://api.github.com/repos/ellipsis-ai/behaviors/commits{/sha}","git_commits_url":"https://api.github.com/repos/ellipsis-ai/behaviors/git/commits{/sha}","comments_url":"https://api.github.com/repos/ellipsis-ai/behaviors/comments{/number}","issue_comment_url":"https://api.github.com/repos/ellipsis-ai/behaviors/issues/comments{/number}","contents_url":"https://api.github.com/repos/ellipsis-ai/behaviors/contents/{+path}","compare_url":"https://api.github.com/repos/ellipsis-ai/behaviors/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ellipsis-ai/behaviors/merges","archive_url":"https://api.github.com/repos/ellipsis-ai/behaviors/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ellipsis-ai/behaviors/downloads","issues_url":"https://api.github.com/repos/ellipsis-ai/behaviors/issues{/number}","pulls_url":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls{/number}","milestones_url":"https://api.github.com/repos/ellipsis-ai/behaviors/milestones{/number}","notifications_url":"https://api.github.com/repos/ellipsis-ai/behaviors/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ellipsis-ai/behaviors/labels{/name}","releases_url":"https://api.github.com/repos/ellipsis-ai/behaviors/releases{/id}","deployments_url":"https://api.github.com/repos/ellipsis-ai/behaviors/deployments","created_at":"2016-06-25T20:59:51Z","updated_at":"2016-06-25T21:05:33Z","pushed_at":"2016-10-05T21:35:56Z","git_url":"git://github.com/ellipsis-ai/behaviors.git","ssh_url":"git@github.com:ellipsis-ai/behaviors.git","clone_url":"https://github.com/ellipsis-ai/behaviors.git","svn_url":"https://github.com/ellipsis-ai/behaviors","homepage":null,"size":46,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/4"},"html":{"href":"https://github.com/ellipsis-ai/behaviors/pull/4"},"issue":{"href":"https://api.github.com/repos/ellipsis-ai/behaviors/issues/4"},"comments":{"href":"https://api.github.com/repos/ellipsis-ai/behaviors/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ellipsis-ai/behaviors/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/ellipsis-ai/behaviors/statuses/a7210d3c208ac6c377ab08b068ce830f4f9daac4"}}}}
{"actor":{"display_login":"attaboy"}}