Class: EY::Enzyme::API
- Inherits:
-
Object
- Object
- EY::Enzyme::API
- Defined in:
- lib/ey_enzyme/api.rb
Instance Method Summary collapse
- #custom_recipe_url ⇒ Object
- #dna ⇒ Object
-
#initialize(api_url, instance_id, token, log_file = "/var/log/enzyme.log") ⇒ API
constructor
A new instance of API.
- #notify_error(type, error) ⇒ Object
- #notify_success ⇒ Object
- #report(message) ⇒ Object
-
#upload(type, content) ⇒ Object
upload, as in, upload the log file output of the chef run.
Constructor Details
#initialize(api_url, instance_id, token, log_file = "/var/log/enzyme.log") ⇒ API
Returns a new instance of API.
5 6 7 8 9 10 11 |
# File 'lib/ey_enzyme/api.rb', line 5 def initialize(api_url, instance_id, token, log_file = "/var/log/enzyme.log") @api_url = api_url @instance_id = instance_id @token = token @logger = MultiLogger.new(log_file) @rest = RestClient::Resource.new(api_url, :timeout => api_rest_timeout_seconds) end |
Instance Method Details
#custom_recipe_url ⇒ Object
33 34 35 36 37 |
# File 'lib/ey_enzyme/api.rb', line 33 def custom_recipe_url if response = retry_api("custom-recipe") response["url"] end end |
#dna ⇒ Object
29 30 31 |
# File 'lib/ey_enzyme/api.rb', line 29 def dna retry_api("dna") end |
#notify_error(type, error) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/ey_enzyme/api.rb', line 21 def notify_error(type, error) @logger.exception "Notifying #{type} error", error call_api("error", params_for(type, error)) rescue RestClient::Exception @logger.exception "Failed to notify of #{type} error", $! raise end |
#notify_success ⇒ Object
17 18 19 |
# File 'lib/ey_enzyme/api.rb', line 17 def notify_success retry_api("completed", :status => 'true') end |
#report(message) ⇒ Object
13 14 15 |
# File 'lib/ey_enzyme/api.rb', line 13 def report() safe_api("report", :message => ) end |
#upload(type, content) ⇒ Object
upload, as in, upload the log file output of the chef run
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ey_enzyme/api.rb', line 40 def upload(type, content) content = content.force_encoding('UTF-8') if content.respond_to?(:force_encoding) retry_api("store", :type => type, :content => content) rescue => e #blanket rescue feels dangerous, but we're at least logging it #we don't have all the information we'd like to include in the exception message here anyway #caller (CookbookSet#upload) should check return value and notify failure api_error("store", e) false end |