Last active
August 29, 2015 14:07
-
-
Save johndagostino/29093e355393338095f6 to your computer and use it in GitHub Desktop.
Buildbox Agent Auto Discovery
This file contains hidden or 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' | |
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