From 265e7f55d7bf481757b12218e893231a7d6e092e Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Fri, 6 Apr 2018 21:19:07 +0200 Subject: refactor githubrepo credential handling --- lib/oxidized/hook/githubrepo.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index f74b22a..715438b 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -45,16 +45,23 @@ class GithubRepo < Oxidized::Hook private def credentials - @credentials ||= if cfg.has_key?('username') && cfg.has_key?('password') - log "Using https auth", :debug - Rugged::Credentials::UserPassword.new(username: cfg.username, password: cfg.password) - else - if cfg.has_key?('publickey') && cfg.has_key?('privatekey') - log "Using ssh auth with key", :debug - Rugged::Credentials::SshKey.new(username: 'git', publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"]) + Proc.new do |url, username_from_url, allowed_types| + + if cfg.has_key?('username') + git_user = cfg.username + else + git_user = username_from_url ? username_from_url : 'git' + end + + if cfg.has_key?('password') + log "Authenticating using username and password", :debug + Rugged::Credentials::UserPassword.new(username: git_user, password: cfg.password) + elsif cfg.has_key?('publickey') && cfg.has_key?('privatekey') + log "Authenticating using ssh keys", :debug + Rugged::Credentials::SshKey.new(username: git_user, publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"]) else - log "Using ssh auth with agentforwarding", :debug - Rugged::Credentials::SshKeyFromAgent.new(username: 'git') + log "Authenticating using ssh agent", :debug + Rugged::Credentials::SshKeyFromAgent.new(username: git_user) end end end -- cgit v1.2.1 From 331838fd9203dcf72e94ea218defc9a2115fabf6 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Fri, 6 Apr 2018 22:12:18 +0200 Subject: expose username in debug log --- lib/oxidized/hook/githubrepo.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index 715438b..4cae4e6 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -54,13 +54,13 @@ class GithubRepo < Oxidized::Hook end if cfg.has_key?('password') - log "Authenticating using username and password", :debug + log "Authenticating using username and password as '#{git_user}'", :debug Rugged::Credentials::UserPassword.new(username: git_user, password: cfg.password) elsif cfg.has_key?('publickey') && cfg.has_key?('privatekey') - log "Authenticating using ssh keys", :debug + log "Authenticating using ssh keys as '#{git_user}'", :debug Rugged::Credentials::SshKey.new(username: git_user, publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"]) else - log "Authenticating using ssh agent", :debug + log "Authenticating using ssh agent as '#{git_user}'", :debug Rugged::Credentials::SshKeyFromAgent.new(username: git_user) end end -- cgit v1.2.1 From 09bcf46e276662ef518aac5fb11bc2eb4e127d36 Mon Sep 17 00:00:00 2001 From: rgnv Date: Thu, 12 Apr 2018 15:22:50 -0700 Subject: Added Cisco Spark hook --- lib/oxidized/hook/ciscosparkdiff.rb | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lib/oxidized/hook/ciscosparkdiff.rb (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/ciscosparkdiff.rb b/lib/oxidized/hook/ciscosparkdiff.rb new file mode 100644 index 0000000..a1c9130 --- /dev/null +++ b/lib/oxidized/hook/ciscosparkdiff.rb @@ -0,0 +1,54 @@ +require 'cisco_spark' + +# defaults to posting a diff, if messageformat is supplied them a message will be posted too +# diffenable defaults to true +# Modified from slackdiff + +class CiscoSparkDiff < Oxidized::Hook + def validate_cfg! + raise KeyError, 'hook.accesskey is required' unless cfg.has_key?('accesskey') + raise KeyError, 'hook.space is required' unless cfg.has_key?('space') + end + + def run_hook(ctx) + if ctx.node + if ctx.event.to_s == "post_store" + log "Connecting to Cisco Spark" + CiscoSpark.configure do |config| + config.api_key = cfg.accesskey + config.proxy = cfg.proxy if cfg.has_key?('proxy') + end + space = cfg.space + client = CiscoSpark::Room.new(id: space) + client.fetch + log "Connected" + # diff snippet - default + diffenable = true + if cfg.has_key?('diff') == true + if cfg.diff == false + diffenable = false + end + end + if diffenable == true + gitoutput = ctx.node.output.new + diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil + title = "#{ctx.node.name.to_s}" + log "Posting diff as snippet to #{cfg.space}" + message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join + ) + room = CiscoSpark::Room.new(id: space) + room.send_message(message) + end + # message custom formatted - optional + if cfg.has_key?('message') == true + log cfg.message + msg = cfg.message % {:node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase} + log msg + log "Posting message to #{cfg.space}" + client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) + end + log "Finished" + end + end + end +end -- cgit v1.2.1 From ec90b081f0fed05497ce6ae21e4b4ba4d44ecc01 Mon Sep 17 00:00:00 2001 From: rgnv Date: Thu, 12 Apr 2018 15:41:31 -0700 Subject: fix formatting to comply with Rubocop --- lib/oxidized/hook/ciscosparkdiff.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/ciscosparkdiff.rb b/lib/oxidized/hook/ciscosparkdiff.rb index a1c9130..12094e6 100644 --- a/lib/oxidized/hook/ciscosparkdiff.rb +++ b/lib/oxidized/hook/ciscosparkdiff.rb @@ -22,7 +22,6 @@ class CiscoSparkDiff < Oxidized::Hook client = CiscoSpark::Room.new(id: space) client.fetch log "Connected" - # diff snippet - default diffenable = true if cfg.has_key?('diff') == true if cfg.diff == false @@ -34,12 +33,10 @@ class CiscoSparkDiff < Oxidized::Hook diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil title = "#{ctx.node.name.to_s}" log "Posting diff as snippet to #{cfg.space}" - message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join - ) + message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join) room = CiscoSpark::Room.new(id: space) room.send_message(message) end - # message custom formatted - optional if cfg.has_key?('message') == true log cfg.message msg = cfg.message % {:node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase} -- cgit v1.2.1 From a26a1f78a71a03f5de7bbeee11a87d57be6a5343 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sun, 15 Apr 2018 08:58:25 +0200 Subject: massage into rubocop compliance --- lib/oxidized/hook/ciscosparkdiff.rb | 66 ++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 34 deletions(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/ciscosparkdiff.rb b/lib/oxidized/hook/ciscosparkdiff.rb index 12094e6..d43ff81 100644 --- a/lib/oxidized/hook/ciscosparkdiff.rb +++ b/lib/oxidized/hook/ciscosparkdiff.rb @@ -11,41 +11,39 @@ class CiscoSparkDiff < Oxidized::Hook end def run_hook(ctx) - if ctx.node - if ctx.event.to_s == "post_store" - log "Connecting to Cisco Spark" - CiscoSpark.configure do |config| - config.api_key = cfg.accesskey - config.proxy = cfg.proxy if cfg.has_key?('proxy') - end - space = cfg.space - client = CiscoSpark::Room.new(id: space) - client.fetch - log "Connected" - diffenable = true - if cfg.has_key?('diff') == true - if cfg.diff == false - diffenable = false - end - end - if diffenable == true - gitoutput = ctx.node.output.new - diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil - title = "#{ctx.node.name.to_s}" - log "Posting diff as snippet to #{cfg.space}" - message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join) - room = CiscoSpark::Room.new(id: space) - room.send_message(message) - end - if cfg.has_key?('message') == true - log cfg.message - msg = cfg.message % {:node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase} - log msg - log "Posting message to #{cfg.space}" - client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) - end - log "Finished" + return unless ctx.node + return unless ctx.event.to_s == "post_store" + log "Connecting to Cisco Spark" + CiscoSpark.configure do |config| + config.api_key = cfg.accesskey + config.proxy = cfg.proxy if cfg.has_key?('proxy') + end + space = cfg.space + client = CiscoSpark::Room.new(id: space) + client.fetch + log "Connected" + diffenable = true + if cfg.has_key?('diff') == true + if cfg.diff == false + diffenable = false end end + if diffenable == true + gitoutput = ctx.node.output.new + diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil + title = ctx.node.name.to_s + log "Posting diff as snippet to #{cfg.space}" + message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join) + room = CiscoSpark::Room.new(id: space) + room.send_message(message) + end + if cfg.has_key?('message') == true + log cfg.message + msg = format(cfg.message, :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase) + log msg + log "Posting message to #{cfg.space}" + client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) + end + log "Finished" end end -- cgit v1.2.1 From cc5c846b3b88cafd8c01c645e6ada3bab714ae91 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sun, 15 Apr 2018 13:08:53 +0200 Subject: restructure xmppdiff.rb to comply with rubocop --- lib/oxidized/hook/xmppdiff.rb | 86 +++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 44 deletions(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/xmppdiff.rb b/lib/oxidized/hook/xmppdiff.rb index 396d1b3..52cc0e0 100644 --- a/lib/oxidized/hook/xmppdiff.rb +++ b/lib/oxidized/hook/xmppdiff.rb @@ -7,54 +7,52 @@ class XMPPDiff < Oxidized::Hook raise KeyError, 'hook.password is required' unless cfg.has_key?('password') raise KeyError, 'hook.channel is required' unless cfg.has_key?('channel') raise KeyError, 'hook.nick is required' unless cfg.has_key?('nick') - end + end def run_hook(ctx) - if ctx.node - if ctx.event.to_s == "post_store" - begin - Timeout::timeout(15) do - gitoutput = ctx.node.output.new - diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil - - interesting = diff[:patch].lines.to_a[4..-1].any? { |line| - ["+", "-"].include?(line[0]) and not ["#", "!"].include?(line[1]) - } - interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '-' } - interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '+' } - - if interesting - log "Connecting to XMPP" - client = Jabber::Client.new(Jabber::JID.new(cfg.jid)) - client.connect - sleep 1 - client.auth(cfg.password) - sleep 1 - - log "Connected" - - m = Jabber::MUC::SimpleMUCClient.new(client) - m.join(cfg.channel + "/" + cfg.nick) - - log "Joined" - - title = "#{ctx.node.name.to_s} #{ctx.node.group.to_s} #{ctx.node.model.class.name.to_s.downcase}" - log "Posting diff as snippet to #{cfg.channel}" - - m.say(title + "\n\n" + diff[:patch].lines.to_a[4..-1].join) - - sleep 1 - - client.close - - log "Finished" - - end - end - rescue Timeout::Error - log "timed out" + return unless ctx.node + return unless ctx.event.to_s == "post_store" + begin + Timeout.timeout(15) do + gitoutput = ctx.node.output.new + diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil + + interesting = diff[:patch].lines.to_a[4..-1].any? do |line| + ["+", "-"].include?(line[0]) and not ["#", "!"].include?(line[1]) + end + interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '-' } + interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '+' } + + if interesting + log "Connecting to XMPP" + client = Jabber::Client.new(Jabber::JID.new(cfg.jid)) + client.connect + sleep 1 + client.auth(cfg.password) + sleep 1 + + log "Connected" + + m = Jabber::MUC::SimpleMUCClient.new(client) + m.join(cfg.channel + "/" + cfg.nick) + + log "Joined" + + title = "#{ctx.node.name} #{ctx.node.group} #{ctx.node.model.class.name.to_s.downcase}" + log "Posting diff as snippet to #{cfg.channel}" + + m.say(title + "\n\n" + diff[:patch].lines.to_a[4..-1].join) + + sleep 1 + + client.close + + log "Finished" + end end + rescue Timeout::Error + log "timed out" end end end -- cgit v1.2.1 From 140954f78e50bed1aaf3f8fd42f849e3892e55c0 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sun, 15 Apr 2018 13:24:05 +0200 Subject: restructure slackdiff.rb to comply with rubocop --- lib/oxidized/hook/slackdiff.rb | 77 ++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 40 deletions(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/slackdiff.rb b/lib/oxidized/hook/slackdiff.rb index 7cd4465..e271d5f 100644 --- a/lib/oxidized/hook/slackdiff.rb +++ b/lib/oxidized/hook/slackdiff.rb @@ -10,47 +10,44 @@ class SlackDiff < Oxidized::Hook end def run_hook(ctx) - if ctx.node - if ctx.event.to_s == "post_store" - log "Connecting to slack" - Slack.configure do |config| - config.token = cfg.token - config.proxy = cfg.proxy if cfg.has_key?('proxy') - end - client = Slack::Client.new - client.auth_test - log "Connected" - # diff snippet - default - diffenable = true - if cfg.has_key?('diff') == true - if cfg.diff == false - diffenable = false - end - end - if diffenable == true - gitoutput = ctx.node.output.new - diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil - unless diff == "no diffs" - title = "#{ctx.node.name.to_s} #{ctx.node.group.to_s} #{ctx.node.model.class.name.to_s.downcase}" - log "Posting diff as snippet to #{cfg.channel}" - client.files_upload(channels: cfg.channel, as_user: true, - content: diff[:patch].lines.to_a[4..-1].join, - filetype: "diff", - title: title, - filename: "change" - ) - end - end - # message custom formatted - optional - if cfg.has_key?('message') == true - log cfg.message - msg = cfg.message % {:node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase} - log msg - log "Posting message to #{cfg.channel}" - client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) - end - log "Finished" + return unless ctx.node + return unless ctx.event.to_s == "post_store" + log "Connecting to slack" + Slack.configure do |config| + config.token = cfg.token + config.proxy = cfg.proxy if cfg.has_key?('proxy') + end + client = Slack::Client.new + client.auth_test + log "Connected" + # diff snippet - default + diffenable = true + if cfg.has_key?('diff') == true + if cfg.diff == false + diffenable = false + end + end + if diffenable == true + gitoutput = ctx.node.output.new + diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil + unless diff == "no diffs" + title = "#{ctx.node.name} #{ctx.node.group} #{ctx.node.model.class.name.to_s.downcase}" + log "Posting diff as snippet to #{cfg.channel}" + client.files_upload(channels: cfg.channel, as_user: true, + content: diff[:patch].lines.to_a[4..-1].join, + filetype: "diff", + title: title, + filename: "change") end end + # message custom formatted - optional + if cfg.has_key?('message') == true + log cfg.message + msg = format(cfg.message, :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase) + log msg + log "Posting message to #{cfg.channel}" + client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) + end + log "Finished" end end -- cgit v1.2.1 From 1b66348be97d4603566a262756d6ad5a2d21bd58 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Mon, 16 Apr 2018 21:03:35 +0200 Subject: restructure awssns.rb to comply with rubocop --- lib/oxidized/hook/awssns.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/awssns.rb b/lib/oxidized/hook/awssns.rb index dbc2d47..82c118e 100644 --- a/lib/oxidized/hook/awssns.rb +++ b/lib/oxidized/hook/awssns.rb @@ -19,9 +19,9 @@ class AwsSns < Oxidized::Hook :node => ctx.node.name.to_s ) end - topic.publish({ + topic.publish( message: message.to_json - }) + ) end end -- cgit v1.2.1 From 21e3d6490496573f25ef77fe8172766ac7d1a736 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sat, 21 Apr 2018 13:27:05 +0200 Subject: the great makeover - standardize layout, alignment, indentation --- lib/oxidized/hook/awssns.rb | 1 - lib/oxidized/hook/exec.rb | 5 ++--- lib/oxidized/hook/githubrepo.rb | 13 ++++++------- lib/oxidized/hook/slackdiff.rb | 6 +++--- lib/oxidized/hook/xmppdiff.rb | 18 +++++++++--------- 5 files changed, 20 insertions(+), 23 deletions(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/awssns.rb b/lib/oxidized/hook/awssns.rb index 82c118e..183cd2c 100644 --- a/lib/oxidized/hook/awssns.rb +++ b/lib/oxidized/hook/awssns.rb @@ -23,5 +23,4 @@ class AwsSns < Oxidized::Hook message: message.to_json ) end - end diff --git a/lib/oxidized/hook/exec.rb b/lib/oxidized/hook/exec.rb index 3f984c2..8a32412 100644 --- a/lib/oxidized/hook/exec.rb +++ b/lib/oxidized/hook/exec.rb @@ -23,10 +23,9 @@ class Exec < Oxidized::Hook @cmd = cfg.cmd raise "invalid cmd value" unless @cmd.is_a?(String) || @cmd.is_a?(Array) end - rescue RuntimeError => e raise ArgumentError, - "#{self.class.name}: configuration invalid: #{e.message}" + "#{self.class.name}: configuration invalid: #{e.message}" end def run_hook ctx @@ -45,7 +44,7 @@ class Exec < Oxidized::Hook def run_cmd! env pid, status = nil, nil Timeout.timeout(@timeout) do - pid = spawn env, @cmd , :unsetenv_others => true + pid = spawn env, @cmd, :unsetenv_others => true pid, status = wait2 pid unless status.exitstatus.zero? msg = "#{@cmd.inspect} failed with exit value #{status.exitstatus}" diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index 4cae4e6..e077d5d 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -35,21 +35,20 @@ class GithubRepo < Oxidized::Hook end Rugged::Commit.create(repo, { - parents: [repo.head.target, their_branch.target], - tree: merge_index.write_tree(repo), - message: "Merge remote-tracking branch '#{their_branch.name}'", - update_ref: "HEAD" - }) + parents: [repo.head.target, their_branch.target], + tree: merge_index.write_tree(repo), + message: "Merge remote-tracking branch '#{their_branch.name}'", + update_ref: "HEAD" + }) end private def credentials Proc.new do |url, username_from_url, allowed_types| - if cfg.has_key?('username') git_user = cfg.username - else + else git_user = username_from_url ? username_from_url : 'git' end diff --git a/lib/oxidized/hook/slackdiff.rb b/lib/oxidized/hook/slackdiff.rb index e271d5f..2c5ec14 100644 --- a/lib/oxidized/hook/slackdiff.rb +++ b/lib/oxidized/hook/slackdiff.rb @@ -14,8 +14,8 @@ class SlackDiff < Oxidized::Hook return unless ctx.event.to_s == "post_store" log "Connecting to slack" Slack.configure do |config| - config.token = cfg.token - config.proxy = cfg.proxy if cfg.has_key?('proxy') + config.token = cfg.token + config.proxy = cfg.proxy if cfg.has_key?('proxy') end client = Slack::Client.new client.auth_test @@ -46,7 +46,7 @@ class SlackDiff < Oxidized::Hook msg = format(cfg.message, :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase) log msg log "Posting message to #{cfg.channel}" - client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) + client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) end log "Finished" end diff --git a/lib/oxidized/hook/xmppdiff.rb b/lib/oxidized/hook/xmppdiff.rb index 52cc0e0..6acb172 100644 --- a/lib/oxidized/hook/xmppdiff.rb +++ b/lib/oxidized/hook/xmppdiff.rb @@ -30,25 +30,25 @@ class XMPPDiff < Oxidized::Hook sleep 1 client.auth(cfg.password) sleep 1 - + log "Connected" - + m = Jabber::MUC::SimpleMUCClient.new(client) m.join(cfg.channel + "/" + cfg.nick) - + log "Joined" - + title = "#{ctx.node.name} #{ctx.node.group} #{ctx.node.model.class.name.to_s.downcase}" log "Posting diff as snippet to #{cfg.channel}" - + m.say(title + "\n\n" + diff[:patch].lines.to_a[4..-1].join) - + sleep 1 - + client.close - + log "Finished" - + end end rescue Timeout::Error -- cgit v1.2.1 From 5e31f4bc028f0e0bd6aade771fe10a3cc6d2a5fa Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Wed, 25 Apr 2018 18:43:23 +0200 Subject: fine tune rubocop to yttis exacting specifications --- lib/oxidized/hook/slackdiff.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/slackdiff.rb b/lib/oxidized/hook/slackdiff.rb index 2c5ec14..baaf291 100644 --- a/lib/oxidized/hook/slackdiff.rb +++ b/lib/oxidized/hook/slackdiff.rb @@ -43,7 +43,7 @@ class SlackDiff < Oxidized::Hook # message custom formatted - optional if cfg.has_key?('message') == true log cfg.message - msg = format(cfg.message, :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase) + msg = cfg.message % { :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase } log msg log "Posting message to #{cfg.channel}" client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) -- cgit v1.2.1 From 83a00943d7333fafdfe352173713a22a5ac89f6f Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Fri, 27 Apr 2018 12:39:07 +0200 Subject: bring ciscosparkdiff.rb back into compliance with rubocop --- lib/oxidized/hook/ciscosparkdiff.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/ciscosparkdiff.rb b/lib/oxidized/hook/ciscosparkdiff.rb index d43ff81..e45d7c6 100644 --- a/lib/oxidized/hook/ciscosparkdiff.rb +++ b/lib/oxidized/hook/ciscosparkdiff.rb @@ -15,8 +15,8 @@ class CiscoSparkDiff < Oxidized::Hook return unless ctx.event.to_s == "post_store" log "Connecting to Cisco Spark" CiscoSpark.configure do |config| - config.api_key = cfg.accesskey - config.proxy = cfg.proxy if cfg.has_key?('proxy') + config.api_key = cfg.accesskey + config.proxy = cfg.proxy if cfg.has_key?('proxy') end space = cfg.space client = CiscoSpark::Room.new(id: space) @@ -39,10 +39,10 @@ class CiscoSparkDiff < Oxidized::Hook end if cfg.has_key?('message') == true log cfg.message - msg = format(cfg.message, :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase) + msg = cfg.message % { :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase } log msg log "Posting message to #{cfg.space}" - client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) + client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) end log "Finished" end -- cgit v1.2.1 From ae9c7c2a65d65bea136669bc9cbc2d645841a017 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Fri, 27 Apr 2018 17:11:42 +0200 Subject: transition from TimeoutError to Timeout::Error --- lib/oxidized/hook/exec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/oxidized/hook') diff --git a/lib/oxidized/hook/exec.rb b/lib/oxidized/hook/exec.rb index 8a32412..069b888 100644 --- a/lib/oxidized/hook/exec.rb +++ b/lib/oxidized/hook/exec.rb @@ -52,11 +52,11 @@ class Exec < Oxidized::Hook raise msg end end - rescue TimeoutError + rescue Timeout::Error kill "TERM", pid msg = "#{@cmd} timed out" log msg, :error - raise TimeoutError, msg + raise Timeout::Error, msg end def make_env ctx -- cgit v1.2.1