ridley 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1502e3edb782cbe22be2729744d1272bb81c9863
4
- data.tar.gz: 26860b2a9731e88a3077d58ae1b46257c6055157
3
+ metadata.gz: 3440ef439aff4fca73a0bb7943c5883b73d4ee6a
4
+ data.tar.gz: d1f414b2cb9a4f5210f59068bcde449f369013b9
5
5
  SHA512:
6
- metadata.gz: 13bae8f8d79d3baeea469c9cb082f143a6a6bbaf976cd61b8c936e51fc5603ae59dcc09fa17dbe696f894c3ca384fe3a064cdb57997ca4061f3ec6a043864b79
7
- data.tar.gz: f536df4f30fd045955a06108adc8df2284fb4b6425d4fabc054bf262e2e8f8d06f5b9025cc8e1b25278bfe0daa199dc41fe2b3459d05503b5a8cb340d62d9f57
6
+ metadata.gz: fe0cdd7ea95cd9a6d6357c9242d1d73300de0777291499f9f61ce254fe1fa914c506a1be30065e8738a52bc8209bc6e5859975fdcf3c59ea0411642263f4dc0f
7
+ data.tar.gz: a67ccd75c7ff3006a70acd1d93154aab3de632c9a01464749a19d973ade48f2292704f481c08de7e93d603b23aa2c7e912afa083e99762f767bfa9399fa383b7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.1.0
2
+
3
+ * [#228](https://github.com/RiotGames/ridley/pull/228) Add a new API for filtering log output. Useful for output you might not want to display because it is sensitive.
4
+
1
5
  # 2.0.0
2
6
 
3
7
  * [#227](https://github.com/RiotGames/ridley/pull/227) HostCommander and HostConnector code has been moved into its own gem - [found here](https://github.com/RiotGames/ridley-connectors)
data/lib/ridley.rb CHANGED
@@ -64,6 +64,7 @@ module Ridley
64
64
 
65
65
  require_relative 'ridley/mixin'
66
66
  require_relative 'ridley/logging'
67
+ require_relative 'ridley/logger'
67
68
  require_relative 'ridley/bootstrap_context'
68
69
  require_relative 'ridley/command_context'
69
70
  require_relative 'ridley/chef_object'
@@ -0,0 +1,66 @@
1
+ module Ridley
2
+ module Logging
3
+ class Logger < Logger
4
+ def initialize(device = STDOUT)
5
+ super
6
+ self.level = Logger::WARN
7
+ @filter_params = Array.new
8
+ end
9
+
10
+ # Reimplements Logger#add adding message filtering. The info,
11
+ # warn, debug, error, and fatal methods all call add.
12
+ #
13
+ # @param [Fixnum] severity
14
+ # an integer measuing the severity - Logger::INFO, etc.
15
+ # @param [String] message = nil
16
+ # the message to log
17
+ # @param [String] progname = nil
18
+ # the program name performing the logging
19
+ # @param &block
20
+ # a block that will be evaluated (for complicated logging)
21
+ #
22
+ # @example
23
+ # log.filter_param("hello")
24
+ # log.info("hello world!") => "FILTERED world!"
25
+ #
26
+ # @return [Boolean]
27
+ def add(severity, message = nil, progname = nil, &block)
28
+ severity ||= Logger::UNKNOWN
29
+ if @logdev.nil? or severity < @level
30
+ return true
31
+ end
32
+ progname ||= @progname
33
+ if message.nil?
34
+ if block_given?
35
+ message = yield
36
+ else
37
+ message = progname
38
+ progname = @progname
39
+ end
40
+ end
41
+ @logdev.write(
42
+ format_message(format_severity(severity), Time.now, progname, filter(message)))
43
+ true
44
+ end
45
+
46
+ def filter_params
47
+ @filter_params.dup
48
+ end
49
+
50
+ def filter_param(param)
51
+ @filter_params << param unless filter_params.include?(param)
52
+ end
53
+
54
+ def clear_filter_params
55
+ @filter_params.clear
56
+ end
57
+
58
+ def filter(message)
59
+ filter_params.each do |param|
60
+ message.gsub!(param.to_s, 'FILTERED')
61
+ end
62
+ message
63
+ end
64
+ end
65
+ end
66
+ end
@@ -3,12 +3,11 @@ require 'logger'
3
3
  module Ridley
4
4
  module Logging
5
5
  class << self
6
+
6
7
  # @return [Logger]
7
8
  def logger
8
9
  @logger ||= begin
9
- log = Logger.new(STDOUT)
10
- log.level = Logger::WARN
11
- log
10
+ Ridley::Logging::Logger.new
12
11
  end
13
12
  end
14
13
 
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ridley::Logging::Logger do
4
+ subject { described_class.new("/dev/null") }
5
+ let(:message) { "my message" }
6
+ let(:filtered_param) { "message" }
7
+
8
+ describe "::initialize" do
9
+ it "defaults to info" do
10
+ expect(subject.level).to eq(Logger::WARN)
11
+ end
12
+ end
13
+
14
+ describe "#info" do
15
+
16
+ before do
17
+ subject.level = Logger::INFO
18
+ subject.filter_param filtered_param
19
+ end
20
+
21
+ it "supports filtering" do
22
+ expect(subject).to receive(:filter).with("my message").and_return("my FILTERED")
23
+ subject.info message
24
+ end
25
+ end
26
+
27
+ describe "#filter_params" do
28
+ it "returns an array" do
29
+ expect(subject.filter_params).to be_a(Array)
30
+ end
31
+ end
32
+
33
+ describe "#filter_param" do
34
+ let(:param) { "hello" }
35
+
36
+ before do
37
+ subject.clear_filter_params
38
+ end
39
+
40
+ it "adds an element to the array" do
41
+ subject.filter_param(param)
42
+ expect(subject.filter_params).to include(param)
43
+ expect(subject.filter_params.size).to eq(1)
44
+ end
45
+
46
+ context "when the element is already in the array" do
47
+
48
+ before do
49
+ subject.filter_param(param)
50
+ end
51
+ it "does not duplicate the element" do
52
+ subject.filter_param(param)
53
+ expect(subject.filter_params.size).to eq(1)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#filter" do
59
+
60
+ before do
61
+ subject.filter_param(filtered_param)
62
+ end
63
+
64
+ it "replaces entries in filter_params" do
65
+ expect(subject.filter(message)).to eq("my FILTERED")
66
+ end
67
+
68
+ context "when there are multiple filter_params" do
69
+ before do
70
+ subject.filter_param("fake param")
71
+ subject.filter_param(filtered_param)
72
+ end
73
+
74
+ it "replaces only matching filter_params" do
75
+ expect(subject.filter(message)).to eq("my FILTERED")
76
+ end
77
+ end
78
+ end
79
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridley
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-21 00:00:00.000000000 Z
12
+ date: 2013-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -295,6 +295,7 @@ files:
295
295
  - lib/ridley/command_context/windows_uninstall.rb
296
296
  - lib/ridley/connection.rb
297
297
  - lib/ridley/errors.rb
298
+ - lib/ridley/logger.rb
298
299
  - lib/ridley/logging.rb
299
300
  - lib/ridley/middleware.rb
300
301
  - lib/ridley/middleware/chef_auth.rb
@@ -378,6 +379,7 @@ files:
378
379
  - spec/unit/ridley/client_spec.rb
379
380
  - spec/unit/ridley/connection_spec.rb
380
381
  - spec/unit/ridley/errors_spec.rb
382
+ - spec/unit/ridley/logger_spec.rb
381
383
  - spec/unit/ridley/middleware/chef_auth_spec.rb
382
384
  - spec/unit/ridley/middleware/chef_response_spec.rb
383
385
  - spec/unit/ridley/middleware/gzip_spec.rb
@@ -474,6 +476,7 @@ test_files:
474
476
  - spec/unit/ridley/client_spec.rb
475
477
  - spec/unit/ridley/connection_spec.rb
476
478
  - spec/unit/ridley/errors_spec.rb
479
+ - spec/unit/ridley/logger_spec.rb
477
480
  - spec/unit/ridley/middleware/chef_auth_spec.rb
478
481
  - spec/unit/ridley/middleware/chef_response_spec.rb
479
482
  - spec/unit/ridley/middleware/gzip_spec.rb