@@ -31,7 +31,7 @@ module Agents |
||
| 31 | 31 |
end |
| 32 | 32 |
|
| 33 | 33 |
def validate_options |
| 34 |
- errors.add(:base, "you need to specify a hipchat auth_token") unless options['auth_token'].present? |
|
| 34 |
+ errors.add(:base, "you need to specify a hipchat auth_token or provide a credential named hipchat_auth_token") unless options['auth_token'].present? || credential('hipchat_auth_token').present?
|
|
| 35 | 35 |
errors.add(:base, "you need to specify a room_name or a room_name_path") if options['room_name'].blank? && options['room_name_path'].blank? |
| 36 | 36 |
end |
| 37 | 37 |
|
@@ -40,7 +40,7 @@ module Agents |
||
| 40 | 40 |
end |
| 41 | 41 |
|
| 42 | 42 |
def receive(incoming_events) |
| 43 |
- client = HipChat::Client.new(interpolated[:auth_token]) |
|
| 43 |
+ client = HipChat::Client.new(interpolated[:auth_token] || credential('hipchat_auth_token'))
|
|
| 44 | 44 |
incoming_events.each do |event| |
| 45 | 45 |
mo = interpolated(event) |
| 46 | 46 |
client[mo[:room_name]].send(mo[:username], mo[:message], :notify => mo[:notify].to_s == 'true' ? 1 : 0, :color => mo[:color]) |
@@ -42,6 +42,12 @@ describe Agents::HipchatAgent do |
||
| 42 | 42 |
@checker.should be_valid |
| 43 | 43 |
end |
| 44 | 44 |
|
| 45 |
+ it "should also allow a credential" do |
|
| 46 |
+ @checker.options['auth_token'] = nil |
|
| 47 |
+ @checker.should_not be_valid |
|
| 48 |
+ @checker.user.user_credentials.create :credential_name => 'hipchat_auth_token', :credential_value => 'something' |
|
| 49 |
+ @checker.reload.should be_valid |
|
| 50 |
+ end |
|
| 45 | 51 |
end |
| 46 | 52 |
|
| 47 | 53 |
describe "#receive" do |