Last active
August 29, 2015 14:05
-
-
Save phoet/93637bb3732ceb9b8b63 to your computer and use it in GitHub Desktop.
heroku plugin search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require_relative 'util' | |
include Util | |
auth_key = key_hash(ARGV.last) | |
puts "restarting all processes" | |
apps = curl('https://api.heroku.com/apps', auth_key) | |
apps.each do |app| | |
name = app['name'] | |
cmd = "heroku ps:restart --app #{name}" | |
puts cmd | |
puts `#{cmd}` | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require_relative 'util' | |
include Util | |
addon_name = ARGV.first | |
abort "usage: #{__FILE__} ADDON-NAME [API-KEY]" if addon_name.nil? | |
auth_key = key_hash(ARGV.last) | |
puts "searching for addon #{addon_name}" | |
apps = curl('https://api.heroku.com/apps', auth_key) | |
apps.each do |app| | |
name = app['name'] | |
addons = curl("https://api.heroku.com/apps/#{name}/addons", auth_key) | |
addon_names = addons.map { |addon| addon["addon_service"]["name"] } | |
if addon_names.grep(/#{addon_name}/i).size > 0 | |
puts "found #{name} -> #{addon_names}" | |
collaborators = curl("https://api.heroku.com/apps/#{name}/collaborators", auth_key) | |
emails = collaborators.map { |collaborator| collaborator['user']['email'] } | |
emails -= ["admins+deploy@shopify.com", "admins@shopify.com"] | |
puts "contact #{emails}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require_relative 'util' | |
include Util | |
env_value = ARGV.first | |
abort "usage: #{__FILE__} VAR-VALUE [API-KEY]" if env_value.nil? | |
auth_key = key_hash(ARGV.last) | |
puts "searching for env-var-value #{env_value}" | |
apps = curl('https://api.heroku.com/apps', auth_key) | |
apps.each do |app| | |
name = app['name'] | |
vars = curl("https://api.heroku.com/apps/#{name}/config-vars", auth_key) | |
if vars.any? { |key, value| key.match(env_value) || value.match(env_value) } | |
puts "#{name} contains value: #{vars}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require_relative 'util' | |
include Util | |
auth_key = key_hash(ARGV.last) | |
puts "searching for idle dynos" | |
apps = curl('https://api.heroku.com/apps', auth_key) | |
apps.each do |app| | |
name = app['name'] | |
dynos = curl("https://api.heroku.com/apps/#{name}/dynos", auth_key) | |
states = dynos.map { |dyno| dyno['state'] } | |
if states.include?('idle') | |
puts "#{name} has idle dynos" | |
collaborators = curl("https://api.heroku.com/apps/#{name}/collaborators", auth_key) | |
emails = collaborators.map { |collaborator| collaborator['user']['email'] } | |
emails -= ["admins+deploy@shopify.com", "admins@shopify.com"] | |
puts "contact #{emails}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
module Util | |
def key_hash(auth_token) | |
if auth_token.nil? | |
puts "fetching key from heroku config" | |
`(echo -n ":" ; heroku auth:token) | base64`.chomp | |
else | |
puts "using provided key" | |
`(echo -n ":" ; echo "#{auth_token}") | base64`.chomp | |
end | |
end | |
def curl(url, auth_key, method: 'GET') | |
response = `curl -sS -X #{method} #{url} -H "Accept: application/vnd.heroku+json; version=3" -H "Authorization: #{auth_key}"`.chomp | |
JSON.parse(response) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment