Skip to content

Instantly share code, notes, and snippets.

@johndagostino
Last active August 29, 2015 14:07
Show Gist options
  • Save johndagostino/29093e355393338095f6 to your computer and use it in GitHub Desktop.
Save johndagostino/29093e355393338095f6 to your computer and use it in GitHub Desktop.
Buildbox Agent Auto Discovery
require 'json'
require 'socket'
require 'net/http'
hostname = Socket.gethostname
api_key = ENV['API_KEY']
account_name = ENV['ACCOUNT_NAME']
uri = URI("https://api.buildbox.io/v1/accounts/#{account_name}/agents?api_key=#{api_key}")
req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' =>'application/json'})
req.body = {name: hostname}.to_json
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(req)
end
agent = JSON.parse(res.body)
puts agent["access_token"]
# run with BUILDBOX_AGENT_ACCESS_TOKEN=`API_KEY=123455 ACCOUNT_NAME=jobready ruby buildbox-discover.rb` buildbox-agent start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment