pry-auditlog 0.1.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/lib/ext/pry/history.rb +30 -0
- data/lib/ext/pry/pry_instance.rb +11 -0
- data/lib/pry-auditlog.rb +38 -0
- data/lib/pry-auditlog/logger.rb +26 -0
- data/lib/pry-auditlog/output.rb +13 -0
- data/lib/pry-auditlog/version.rb +3 -0
- data/pry-auditlog.gemspec +19 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Cozy Services Ltd.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# PryAuditlog
|
2
|
+
|
3
|
+
PryAuditlog is a plugin for the [Pry](http://pry.github.com) REPL that enables logging of any combination of Pry input and output to a configured audit log file.
|
4
|
+
|
5
|
+
It scrapes the Pry history sender to read input statements to Pry, and it inserts itself into the `output` mechanism to scrape a copy of all emitted data. It also redirects `$stdout` and `$stderr` during the Pry session in order to capture all output emitted from any `puts` or similar statements.
|
6
|
+
|
7
|
+
All output data is forwarded to the original configured `Pry.config.output` mechanism after logging, and this plugin should (hopefully) respect any configured outputter.
|
8
|
+
|
9
|
+
The log file location is configurable, and the choice of logging input statements, output statements or both (the default) is configurable.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
$ gem install pry-auditlog
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Set appropriate config values and then require the plugin in your `.pryrc` or any other location where you configure Pry.
|
18
|
+
|
19
|
+
```
|
20
|
+
# The auditlog must be explicitly enabled
|
21
|
+
Pry.config.auditlog_enabled = true # default: false
|
22
|
+
|
23
|
+
# Optional path to audit log destination
|
24
|
+
Pry.config.auditlog_file = '/path/to/file' # default: "~/.pry_auditlog"
|
25
|
+
|
26
|
+
# We log both input and output by default
|
27
|
+
Pry.config.auditlog_log_input = false # default: true
|
28
|
+
Pry.config.auditlog_log_output = false # default: true
|
29
|
+
|
30
|
+
# Set all config values *before* requiring the plugin
|
31
|
+
require 'pry-auditlog'
|
32
|
+
```
|
33
|
+
|
34
|
+
### Author
|
35
|
+
|
36
|
+
Matt Greensmith for [Cozy](http://www.cozy.co)
|
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,11 @@
|
|
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
|
data/lib/pry-auditlog.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'pry-auditlog/version'
|
3
|
+
require 'pry-auditlog/logger'
|
4
|
+
require 'pry-auditlog/output'
|
5
|
+
|
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
|
11
|
+
|
12
|
+
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
|
17
|
+
|
18
|
+
if Pry.config.auditlog_log_output
|
19
|
+
Pry.config._orig_stdout = $stdout
|
20
|
+
Pry.config._orig_stderr = $stderr
|
21
|
+
|
22
|
+
original_output = Pry.config.output
|
23
|
+
Pry.config.output = PryAuditlog::Output.new
|
24
|
+
Pry.config.output._set_original_output(original_output)
|
25
|
+
end
|
26
|
+
|
27
|
+
Pry.config.hooks.add_hook(:before_session, :prepare_auditlog) do
|
28
|
+
$stdout = $stderr = Pry.config.output if Pry.config.auditlog_log_output
|
29
|
+
PryAuditlog::Logger.set_session_token(Time.now.to_i)
|
30
|
+
PryAuditlog::Logger.log("AUDIT LOG", "Pry session started")
|
31
|
+
end
|
32
|
+
|
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")
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PryAuditlog
|
2
|
+
class Logger
|
3
|
+
begin
|
4
|
+
@@audit_file = File.open(Pry.config.auditlog_file, 'a', 0600).tap { |f| f.sync = true }
|
5
|
+
rescue Errno::EACCES
|
6
|
+
@@audit_file = false
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.set_session_token(token)
|
10
|
+
@@session_token = token
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.set_prompt(current_prompt)
|
14
|
+
@@current_prompt = current_prompt
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.log(type, line)
|
18
|
+
if type == 'I'
|
19
|
+
line = "#{@@current_prompt}#{line}"
|
20
|
+
end
|
21
|
+
log_line = "[#{Time.now.to_s}][#{@@session_token}][#{type}] #{line}"
|
22
|
+
@@audit_file.puts log_line if @@audit_file
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pry-auditlog/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pry-auditlog"
|
8
|
+
spec.version = PryAuditlog::VERSION
|
9
|
+
spec.authors = ["Cozy Services Ltd.", "Matt Greensmith"]
|
10
|
+
spec.email = ["opensource@cozy.co"]
|
11
|
+
spec.summary = %q{Adds audit log capability to Pry}
|
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"
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency 'pry', '~> 0.9'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pry-auditlog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cozy Services Ltd.
|
9
|
+
- Matt Greensmith
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-03-28 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: pry
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.9'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0.9'
|
31
|
+
description: PryAuditlog is a plugin for the Pry REPL that enables logging of any
|
32
|
+
combination of Pry input and output to a configured audit log file.
|
33
|
+
email:
|
34
|
+
- opensource@cozy.co
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- .gitignore
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- lib/ext/pry/history.rb
|
44
|
+
- lib/ext/pry/pry_instance.rb
|
45
|
+
- lib/pry-auditlog.rb
|
46
|
+
- lib/pry-auditlog/logger.rb
|
47
|
+
- lib/pry-auditlog/output.rb
|
48
|
+
- lib/pry-auditlog/version.rb
|
49
|
+
- pry-auditlog.gemspec
|
50
|
+
homepage: http://github.com/cozyco/pry-auditlog
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.23
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Adds audit log capability to Pry
|
75
|
+
test_files: []
|