Permalink
Browse files

Client now can read token/project_id from env and config.

  • Loading branch information...
1 parent 6b4c71a commit 577481adb11aa5d5b988577f4937219b18a2c3d8 Andrew Kirilenko committed Apr 23, 2012
Showing with 42 additions and 0 deletions.
  1. +27 −0 lib/iron_worker_ng/api_client.rb
  2. +15 −0 lib/iron_worker_ng/code/ruby.rb
@@ -1,6 +1,7 @@
require 'rest-client'
require 'rest'
require 'json'
+require 'yaml'
require 'time'
require_relative 'api_client_error'
@@ -19,7 +20,33 @@ class APIClient
def initialize(options = {})
@token = options[:token] || options['token']
+ @token ||= ENV['IRON_IO_TOKEN']
+ @token ||= ENV['IRON_TOKEN']
+
@project_id = options[:project_id] || options['project_id']
+ @project_id ||= ENV['IRON_IO_PROJECT_ID']
+ @project_id ||= ENV['IRON_PROJECT_ID']
+
+ if @token.nil? || @project_id.nil?
+ [ENV['IRON_IO_CONFIG'], ENV['IRON_IO_CONFIG_FILE'], ENV['IRON_CONFIG'], ENV['IRON_CONFIG_FILE'], '~/.iron', '/etc/iron.conf'].each do |config_file|
+ if (not config_file.nil?) && File.exists?(File.expand_path(config_file))
+ config = YAML.load_file(File.expand_path(config_file))
+
+ unless config['iron_io'].nil?
+ @token ||= config['iron_io']['token']
+ @project_id ||= config['iron_io']['project_id']
+ end
+
+ unless config['iron'].nil?
+ @token ||= config['iron']['token']
+ @project_id ||= config['iron']['project_id']
+ end
+
+ @token ||= config['token']
+ @project_id ||= config['project_id']
+ end
+ end
+ end
if (not @token) || (not @project_id)
IronWorkerNG::Logger.error 'Both iron.io token and project_id must be specified'
@@ -42,6 +42,7 @@ def create_runner(zip)
require 'json'
@iron_worker_task_id = task_id
+@iron_task_id = task_id
@payload = File.read(payload_file)
@@ -52,7 +53,9 @@ def create_runner(zip)
end
@iron_io_token = parsed_payload['token'] || nil
+@iron_token = @iron_io_token
@iron_io_project_id = parsed_payload['project_id'] || nil
+@iron_project_id = @iron_io_project_id
@params = parsed_payload['params'] || {}
keys = @params.keys
@@ -68,14 +71,26 @@ def iron_worker_task_id
@iron_worker_task_id
end
+def iron_task_id
+ @iron_task_id
+end
+
def iron_io_token
@iron_io_token
end
+def iron_token
+ @iron_token
+end
+
def iron_io_project_id
@iron_io_project_id
end
+def iron_project_id
+ @iron_project_id
+end
+
def params
@params
end

0 comments on commit 577481a

Please sign in to comment.