pry-auditlog 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 67d9ed197727c56d85aa7aefa09f11cde697742d
4
+ data.tar.gz: d737eade85330cc3479a9b0fec714ae1ae3ff28d
5
+ SHA512:
6
+ metadata.gz: 612ea3ed9905a1a035a456ed0307464cd884f43b50f546dcf8c8e77531f6f6187aba9d20622faa5a4896b1abd1f80f2f1aa6860191389769abd4df0d7564330f
7
+ data.tar.gz: 62b61633fd4d5b2cbb1cd3bbd130ab91d057adcbfeaba3f8f82a38f7e01d97e75dea4891de6bcdc382aed59527839e1703221d64149d1029f17d46b21950866c
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in pry-auditlog.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'rubocop'
8
+ end
@@ -0,0 +1,54 @@
1
+ class Pry
2
+ class REPL
3
+ # Read a line of input from the user.
4
+ # @return [String] The line entered by the user.
5
+ # @return [nil] On `<Ctrl-D>`.
6
+ # @return [:control_c] On `<Ctrl+C>`.
7
+ # @return [:no_more_input] On EOF.
8
+ def read
9
+ @indent.reset if pry.eval_string.empty?
10
+ current_prompt = pry.select_prompt
11
+ indentation = pry.config.auto_indent ? @indent.current_prefix : ''
12
+
13
+ val = read_line("#{current_prompt}#{indentation}")
14
+
15
+ # Return nil for EOF, :no_more_input for error, or :control_c for <Ctrl-C>
16
+ return val unless String === val
17
+
18
+ if pry.config.auto_indent
19
+ original_val = "#{indentation}#{val}"
20
+ indented_val = @indent.indent(val)
21
+
22
+ if pry.config.correct_indent && Pry::Helpers::BaseHelpers.use_ansi_codes?
23
+
24
+ # if we're logging output, send the input line through the original
25
+ # pry output, so that we see it prettified on the TTY.
26
+ if Pry.config.auditlog_log_output
27
+ pry.config.original_output.print @indent.correct_indentation(
28
+ current_prompt, indented_val,
29
+ original_val.length - indented_val.length
30
+ )
31
+ pry.config.original_output.flush
32
+ # Fall back on default behavior, our stuff isn't loaded
33
+ elsif output.tty?
34
+ output.print @indent.correct_indentation(
35
+ current_prompt, indented_val,
36
+ original_val.length - indented_val.length
37
+ )
38
+ output.flush
39
+ end
40
+ end
41
+ else
42
+ indented_val = val
43
+ end
44
+
45
+ # send the prompt and log line to our logger.
46
+ if Pry.config.auditlog_log_input
47
+ PryAuditlog::Logger.set_prompt(current_prompt)
48
+ PryAuditlog::Logger.log('I', indented_val)
49
+ end
50
+
51
+ indented_val
52
+ end
53
+ end
54
+ end
data/lib/pry-auditlog.rb CHANGED
@@ -1,38 +1,40 @@
1
1
  require 'pry'
2
2
  require 'pry-auditlog/version'
3
- require 'pry-auditlog/logger'
4
- require 'pry-auditlog/output'
5
3
 
6
-
7
- Pry.config.auditlog_enabled ||= false
8
- Pry.config.auditlog_file ||= "~/.pry_auditlog"
9
- Pry.config.auditlog_log_input ||= true
10
- Pry.config.auditlog_log_output ||= true
4
+ Pry.config.auditlog_enabled = false unless defined?(Pry.config.auditlog_enabled)
5
+ Pry.config.auditlog_file = '/dev/null' unless defined?(Pry.config.auditlog_file)
6
+ Pry.config.auditlog_log_input = true unless defined?(Pry.config.auditlog_log_input)
7
+ Pry.config.auditlog_log_output = true unless defined?(Pry.config.auditlog_log_output)
11
8
 
12
9
  if Pry.config.auditlog_enabled
13
- if Pry.config.auditlog_log_input
14
- require 'ext/pry/history'
15
- require 'ext/pry/pry_instance'
16
- end
10
+ require 'pry-auditlog/logger'
11
+ require 'pry-auditlog/output'
12
+ require 'ext/pry/repl'
17
13
 
18
14
  if Pry.config.auditlog_log_output
19
15
  Pry.config._orig_stdout = $stdout
20
16
  Pry.config._orig_stderr = $stderr
21
17
 
22
- original_output = Pry.config.output
18
+ Pry.config.original_output = Pry.config.output
23
19
  Pry.config.output = PryAuditlog::Output.new
24
- Pry.config.output._set_original_output(original_output)
20
+ Pry.config.output._set_original_output(Pry.config.original_output)
25
21
  end
26
22
 
27
- Pry.config.hooks.add_hook(:before_session, :prepare_auditlog) do
23
+ local_hooks = Pry::Hooks.new
24
+
25
+ local_hooks.add_hook(:before_session, :prepare_auditlog) do
28
26
  $stdout = $stderr = Pry.config.output if Pry.config.auditlog_log_output
29
27
  PryAuditlog::Logger.set_session_token(Time.now.to_i)
30
- PryAuditlog::Logger.log("AUDIT LOG", "Pry session started")
28
+ PryAuditlog::Logger.log('AUDIT LOG', 'Pry session started')
31
29
  end
32
30
 
33
- Pry.config.hooks.add_hook(:after_session, :unhijack_stdout) do
34
- $stdout = Pry.config._orig_stdout
35
- $stderr = Pry.config._orig_stderr
36
- PryAuditlog::Logger.log("AUDIT LOG", "Pry session ended")
31
+ local_hooks.add_hook(:after_session, :clean_up_auditlog) do
32
+ if Pry.config.auditlog_log_output
33
+ $stdout = Pry.config._orig_stdout
34
+ $stderr = Pry.config._orig_stderr
35
+ end
36
+ PryAuditlog::Logger.log('AUDIT LOG', 'Pry session ended')
37
37
  end
38
+
39
+ Pry.config.hooks = local_hooks
38
40
  end
@@ -1,8 +1,14 @@
1
1
  module PryAuditlog
2
2
  class Logger
3
+ @@current_prompt = ''
4
+ @@session_token = ''
3
5
  begin
4
- @@audit_file = File.open(Pry.config.auditlog_file, 'a', 0600).tap { |f| f.sync = true }
5
- rescue Errno::EACCES
6
+ if Pry.config.auditlog_file
7
+ @@audit_file = File.open(Pry.config.auditlog_file, 'a', 0600).tap { |f| f.sync = true }
8
+ else
9
+ @@audit_file = false
10
+ end
11
+ rescue Errno::EACCES, Errno::ENOENT
6
12
  @@audit_file = false
7
13
  end
8
14
 
@@ -15,12 +21,9 @@ module PryAuditlog
15
21
  end
16
22
 
17
23
  def self.log(type, line)
18
- if type == 'I'
19
- line = "#{@@current_prompt}#{line}"
20
- end
24
+ line = "#{@@current_prompt}#{line}" if type == 'I'
21
25
  log_line = "[#{Time.now.to_s}][#{@@session_token}][#{type}] #{line}"
22
- @@audit_file.puts log_line if @@audit_file
26
+ @@audit_file.puts log_line if @@audit_file && !line.strip.empty?
23
27
  end
24
-
25
28
  end
26
- end
29
+ end
@@ -1,13 +1,14 @@
1
1
  module PryAuditlog
2
2
  class Output < StringIO
3
-
4
3
  def _set_original_output(orig)
5
4
  @original_output = orig
6
5
  end
7
6
 
8
- def puts(line)
9
- PryAuditlog::Logger.log("O", line)
10
- @original_output.puts(line)
7
+ def print(line)
8
+ PryAuditlog::Logger.log('O', line)
9
+ @original_output.print(line)
11
10
  end
11
+ alias << print
12
+ alias write print
12
13
  end
13
14
  end
@@ -1,3 +1,3 @@
1
1
  module PryAuditlog
2
- VERSION = "0.1.0"
3
- end
2
+ VERSION = '0.2.0'
3
+ end
data/pry-auditlog.gemspec CHANGED
@@ -4,16 +4,16 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'pry-auditlog/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "pry-auditlog"
7
+ spec.name = 'pry-auditlog'
8
8
  spec.version = PryAuditlog::VERSION
9
- spec.authors = ["Cozy Services Ltd.", "Matt Greensmith"]
10
- spec.email = ["opensource@cozy.co"]
9
+ spec.authors = ['Cozy Services Ltd.', 'Matt Greensmith']
10
+ spec.email = ['opensource@cozy.co']
11
11
  spec.summary = %q{Adds audit log capability to Pry}
12
12
  spec.description = %q{PryAuditlog is a plugin for the Pry REPL that enables logging of any combination of Pry input and output to a configured audit log file.}
13
- spec.homepage = "http://github.com/cozyco/pry-auditlog"
14
- spec.license = "MIT"
13
+ spec.homepage = 'http://github.com/cozyco/pry-auditlog'
14
+ spec.license = 'MIT'
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
- spec.require_paths = ["lib"]
16
+ spec.require_paths = ['lib']
17
17
 
18
- spec.add_dependency 'pry', '~> 0.9'
18
+ spec.add_dependency 'pry', '~> 0.10'
19
19
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-auditlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Cozy Services Ltd.
@@ -10,24 +9,22 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2014-03-28 00:00:00.000000000 Z
12
+ date: 2014-07-07 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: pry
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ~>
21
19
  - !ruby/object:Gem::Version
22
- version: '0.9'
20
+ version: '0.10'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ~>
29
26
  - !ruby/object:Gem::Version
30
- version: '0.9'
27
+ version: '0.10'
31
28
  description: PryAuditlog is a plugin for the Pry REPL that enables logging of any
32
29
  combination of Pry input and output to a configured audit log file.
33
30
  email:
@@ -40,8 +37,7 @@ files:
40
37
  - Gemfile
41
38
  - LICENSE.txt
42
39
  - README.md
43
- - lib/ext/pry/history.rb
44
- - lib/ext/pry/pry_instance.rb
40
+ - lib/ext/pry/repl.rb
45
41
  - lib/pry-auditlog.rb
46
42
  - lib/pry-auditlog/logger.rb
47
43
  - lib/pry-auditlog/output.rb
@@ -50,26 +46,25 @@ files:
50
46
  homepage: http://github.com/cozyco/pry-auditlog
51
47
  licenses:
52
48
  - MIT
49
+ metadata: {}
53
50
  post_install_message:
54
51
  rdoc_options: []
55
52
  require_paths:
56
53
  - lib
57
54
  required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
55
  requirements:
60
- - - ! '>='
56
+ - - '>='
61
57
  - !ruby/object:Gem::Version
62
58
  version: '0'
63
59
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
60
  requirements:
66
- - - ! '>='
61
+ - - '>='
67
62
  - !ruby/object:Gem::Version
68
63
  version: '0'
69
64
  requirements: []
70
65
  rubyforge_project:
71
- rubygems_version: 1.8.23
66
+ rubygems_version: 2.0.14
72
67
  signing_key:
73
- specification_version: 3
68
+ specification_version: 4
74
69
  summary: Adds audit log capability to Pry
75
70
  test_files: []
@@ -1,30 +0,0 @@
1
- class Pry
2
- class History
3
-
4
- #attr_accessor :original_pusher
5
-
6
- # we monkeypatch 'load' to
7
- # 1. Overwrite @pusher with our own audit_and_push method
8
- # 2. ensure that we don't write the entire history into the audit log on load.
9
- def load
10
- @original_pusher ||= @pusher
11
- @pusher = method(:audit_and_push) if Pry.config.auditlog_enabled
12
- @loader.call do |line|
13
- if Pry.config.auditlog_enabled
14
- @original_pusher.call(line.chomp)
15
- else
16
- @pusher.call(line.chomp)
17
- end
18
- @history << line.chomp
19
- end
20
- @saved_lines = @original_lines = @history.length
21
- end
22
-
23
- # new method
24
- def audit_and_push(line)
25
- PryAuditlog::Logger.log("I", line)
26
- @original_pusher.call(line)
27
- end
28
-
29
- end
30
- end
@@ -1,11 +0,0 @@
1
- class Pry
2
- # we monkeypatch retrieve_line to send the current prompt string to the logger
3
-
4
- alias original_retrieve_line retrieve_line
5
-
6
- def retrieve_line(eval_string, target)
7
- current_prompt = select_prompt(eval_string, target)
8
- PryAuditlog::Logger.set_prompt(current_prompt)
9
- original_retrieve_line(eval_string, target)
10
- end
11
- end