Class: Sysdig::Mock
- Inherits:
-
Object
- Object
- Sysdig::Mock
- Defined in:
- lib/sysdig/mock.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #response(options = {}) ⇒ Object
- #serial_id ⇒ Object
- #url_for(*pieces) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
34 35 36 37 38 39 40 41 |
# File 'lib/sysdig/mock.rb', line 34 def initialize(={}) @url = [:url] || "https://langley.engineyard.com" @logger = [:logger] || Logger.new(nil) username, password, token = *.values_at(:username, :password, :token) @account_id = (username && password) ? Digest::SHA256.hexdigest("#{username}:#{password}") : token end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
32 33 34 |
# File 'lib/sysdig/mock.rb', line 32 def account_id @account_id end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
32 33 34 |
# File 'lib/sysdig/mock.rb', line 32 def logger @logger end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
32 33 34 |
# File 'lib/sysdig/mock.rb', line 32 def url @url end |
Class Method Details
.data ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sysdig/mock.rb', line 8 def self.data @@data ||= Hash.new { |h,url| h[url] = { :alerts => {}, :user_notifications => { "email" => { "enabled" => false, "recipients" => [] }, "sns" => { "enabled" => false, "topics" => [] }, "pagerDuty" => { "enabled" => false, "integrated" => false, "resolveOnOk" => false, "connectUrl" => "https://connect.pagerduty.com/connect?vendor=x&callback=https://app.sysdigcloud.com/api/pagerDuty/callback/y/z" } } } } end |
.reset! ⇒ Object
2 3 4 5 6 |
# File 'lib/sysdig/mock.rb', line 2 def self.reset! super @id = 0 end |
Instance Method Details
#data ⇒ Object
70 71 72 |
# File 'lib/sysdig/mock.rb', line 70 def data self.class.data[self.account_id] end |
#response(options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sysdig/mock.rb', line 47 def response(={}) status = [:status] || 200 body = [:body] headers = { "Content-Type" => "application/json; charset=utf-8", }.merge([:headers] || {}) logger.debug "MOCKED RESPONSE: #{status}" logger.debug('response') { headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n") } logger.debug caller[0] logger.debug('response.body') { body } Sysdig::Response.new( :status => status, :headers => headers, :body => body, :request => { :method => :mocked, :url => caller[1], } ).raise! end |
#serial_id ⇒ Object
74 75 76 77 |
# File 'lib/sysdig/mock.rb', line 74 def serial_id @id ||= 0 @id += 1 end |
#url_for(*pieces) ⇒ Object
43 44 45 |
# File 'lib/sysdig/mock.rb', line 43 def url_for(*pieces) File.join(self.url, *pieces) end |