irb_tracker 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 24a2d3e713f454ea93b72a89319a7a6ee6537a2546e45af0181a407aaaafc3c6
4
+ data.tar.gz: 9382ae60ac08b325c92a821cd2066a9e1db03a4bd5f72ecf905aeeb49051e025
5
+ SHA512:
6
+ metadata.gz: 7caaa57d35f1c8260f4557af458652e463c22cabcc460c271166b983b8ae318ebc6034f19d871e0e46a464f2968f33d41f5c9a735ae416b0f2a0e0d45888c362
7
+ data.tar.gz: 2f0418dd1a4d7870f32b1988325d54a9c7444337e31601ab12429b872793f8db704211f32cfc79b578f4db0343deb5e61d2b8696d9e929d4913221ef0fd79b61
@@ -0,0 +1,33 @@
1
+ name: CI-PRS-MASTER
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+ push:
8
+ branches:
9
+ - master
10
+
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - uses: actions/checkout@v1
19
+ with:
20
+ fetch-depth: 1
21
+ - uses: actions/setup-ruby@v1
22
+ with:
23
+ ruby-version: '2.6'
24
+ - name: Install Dependencies
25
+ run: |
26
+ gem install bundler
27
+ bundle install
28
+ - name: Eexecute Unit Tests
29
+ run: |
30
+ bundle exec rspec
31
+ - name: Validate Code Style
32
+ run: |
33
+ bundle exec rubocop
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /log/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .byebug_history
14
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ Style/ModuleFunction:
2
+ Enabled: false
3
+
4
+ Metrics/MethodLength:
5
+ Max: 20
6
+
7
+ Metrics/AbcSize:
8
+ Max: 17
9
+
10
+ Metrics/CyclomaticComplexity:
11
+ Max: 8
12
+
13
+ Metrics/ModuleLength:
14
+ Exclude:
15
+ - spec/*
16
+ - spec/**/*spec.rb
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - spec/*
20
+ - spec/**/*spec.rb
21
+ - rabbitmq_client.gemspec
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ irb_tracker
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ # Specify your gem's dependencies in irb_tracker.gemspec
5
+ gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # IRBTracker
2
+
3
+ IRBTracker is a tool that helps in tracking and correlating all commands exected in the IRB console. the gem supports the following features. 
4
+
5
+ - Authenticate IRB console users using LDAP.
6
+ - Collect IRB command logs into a local file.
7
+ - Forward Logs to a centralized server using fluent-logger.
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'irb_tracker'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ ## Usage
23
+
24
+ ### Console
25
+
26
+ In your `bin/rails` file you should add following
27
+
28
+ ```ruby
29
+ #!/usr/bin/env ruby
30
+ APP_PATH = File.expand_path('../config/application', __dir__)
31
+ require_relative '../config/boot'
32
+ require 'irb_tracker'
33
+ require 'irb'
34
+ require 'io/console'
35
+
36
+ RAILS_USER = STDIN.getpass("Email:")
37
+ if (IRBTracker::LDAPLogin.authenticate(RAILS_USER, STDIN.getpass("Password:")))
38
+ IRB::Context.prepend(IRBTracker::IRBLoggable.new("MyRailsApp"))
39
+ require 'rails/commands'
40
+ else
41
+ puts "Invalid email and user"
42
+ end
43
+
44
+ ```
45
+
46
+ ## LDAP Environment Variables
47
+ ```
48
+ LDAP_HOST
49
+ LDAP_PORT
50
+ LDAP_BASELDAP_ADMIN_USER
51
+ LDAP_ADMIN_PASSWORD
52
+ ```
53
+
54
+ ## FluentD Environment Variables
55
+ ```
56
+ FLUENTD_LOGGING_ENABLED
57
+ FLUENTD_LOG_HOST
58
+ FLUENTD_LOG_HOST_PORT
59
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'irb_tracker'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ # require "irb"
15
+ # IRB.start(__FILE__)
16
+
17
+ require 'pry-byebug'
18
+ Pry.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'irb_tracker/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'irb_tracker'
9
+ spec.version = IRBTracker::VERSION
10
+ spec.authors = ['Al-waleed Shihadeh']
11
+ spec.email = ['wshihadeh dot dev at gmail dot com']
12
+
13
+ spec.summary = 'Track and corrolate IRB activities to users.'
14
+ spec.description = 'Track all commands exected in an IRB console and '\
15
+ 'correlate the actions to the users executed them.'
16
+ spec.homepage = 'https://github.com/wshihadeh/irb_tracker'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+
23
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
+ spec.metadata['homepage_uri'] = spec.homepage
25
+
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'net-ldap', '~> 0.16.0'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 2.1.4'
33
+ spec.add_development_dependency 'fluent-logger', '~> 0.8.1'
34
+ spec.add_development_dependency 'net-ldap', '~> 0.16.0'
35
+ spec.add_development_dependency 'rake', '~> 12.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'rubocop', '~> 0.75.1'
38
+ end
data/lib/fluentd.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fluent-logger'
4
+
5
+ #:nodoc:
6
+ class Fluentd
7
+ def self.get_logger(**options)
8
+ service_name = options.delete(:service_name)
9
+ logger = Fluent::Logger::LevelFluentLogger.new(
10
+ service_name,
11
+ host: options.delete(:host),
12
+ port: options.delete(:port)
13
+ )
14
+
15
+ logger.formatter = build_formatter(service_name)
16
+ logger
17
+ end
18
+
19
+ def self.build_formatter(service_name)
20
+ proc do |severity, datetime, progname, message|
21
+ map = { level: severity }
22
+ map[:message] = message[:error] || message[:event] || message[:command]
23
+ %i[error error_trace command result event name args source].each do |item|
24
+ map[item] = message[item] if message[item] && !message[item].empty?
25
+ end
26
+ map[:progname] = progname if progname
27
+ if datetime
28
+ map['@timestamp'] = datetime.strftime('%Y-%m-%dT%H:%M:%S.%3NZ')
29
+ end
30
+ map[:environment] = ENV.fetch('FLUENTD_LOGGING_ENVIRONMENT', 'undefined')
31
+ map[:service_name] = service_name
32
+ map[:app_version] = ENV.fetch('APP_VERSION', 'undefined')
33
+ map
34
+ end
35
+ end
36
+ private_class_method :build_formatter
37
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'irb_tracker/version'
4
+
5
+ #:nodoc:
6
+ module IRBTracker
7
+ end
8
+
9
+ require 'irb_tracker/irb_loggable'
10
+ require 'irb_tracker/ldap_login'
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'irb_tracker/logger_factory'
4
+
5
+ module IRBTracker
6
+ #:nodoc:
7
+ class IRBLoggable < Module
8
+ def initialize(service_name = 'undefined')
9
+ logger = LoggerFactory.create service_name
10
+ # rubocop:disable Style/RedundantBegin
11
+ define_method :evaluate do |*args, &block|
12
+ begin
13
+ result = super(*args, &block)
14
+ logger.info(source: 'irb_console',
15
+ user: LDAPLogin.current_user,
16
+ command: args.first.chomp,
17
+ result: inspect_last_value.chomp)
18
+ result
19
+ rescue StandardError => e
20
+ logger.error(source: 'irb_console',
21
+ user: LDAPLogin.current_user,
22
+ command: args.first.chomp,
23
+ error: e.message,
24
+ error_trace: e.backtrace.inspect)
25
+ raise e
26
+ end
27
+ end
28
+ # rubocop:enable Style/RedundantBegin
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/ldap'
4
+
5
+ module IRBTracker
6
+ #:nodoc:
7
+ class LDAPLogin
8
+ class << self
9
+ attr_reader :current_user
10
+
11
+ def authenticate(username, password)
12
+ @current_user = username
13
+ conn = ldap_connection
14
+ filter = Net::LDAP::Filter.eq('mail', username)
15
+ conn.bind_as(filter: filter, password: password)
16
+ rescue StandardError
17
+ false
18
+ end
19
+
20
+ private
21
+
22
+ def ldap_connection
23
+ conn = Net::LDAP.new(
24
+ host: ENV['LDAP_HOST'],
25
+ port: ENV['LDAP_PORT'],
26
+ base: ENV['LDAP_BASE'],
27
+ encryption: nil
28
+ )
29
+ conn.auth ENV['LDAP_ADMIN_USER'], ENV['LDAP_ADMIN_PASSWORD']
30
+ return false unless conn.bind
31
+
32
+ conn
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ #:nodoc:
4
+ module LoggerFactory
5
+ def self.create(service_name)
6
+ if ENV['FLUENTD_LOGGING_ENABLED'] == 'true'
7
+ require_relative '../fluentd'
8
+ Fluentd.get_logger(
9
+ service_name: service_name,
10
+ host: ENV['FLUENTD_LOG_HOST'],
11
+ port: ENV.fetch('FLUENTD_LOG_HOST_PORT', '24224')
12
+ )
13
+ else
14
+ require 'logger'
15
+ log_folder = 'log'
16
+ Dir.mkdir(log_folder) unless Dir.exist?(log_folder)
17
+ Logger.new("./#{log_folder}/console.log")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRBTracker
4
+ VERSION = '0.0.2'
5
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irb_tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Al-waleed Shihadeh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ldap
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.16.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.16.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: fluent-logger
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-ldap
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.16.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.75.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.75.1
111
+ description: Track all commands exected in an IRB console and correlate the actions
112
+ to the users executed them.
113
+ email:
114
+ - wshihadeh dot dev at gmail dot com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".github/workflows/prs-master.yml"
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".ruby-gemset"
124
+ - ".ruby-version"
125
+ - Gemfile
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/setup
130
+ - irb_tracker.gemspec
131
+ - lib/fluentd.rb
132
+ - lib/irb_tracker.rb
133
+ - lib/irb_tracker/irb_loggable.rb
134
+ - lib/irb_tracker/ldap_login.rb
135
+ - lib/irb_tracker/logger_factory.rb
136
+ - lib/irb_tracker/version.rb
137
+ homepage: https://github.com/wshihadeh/irb_tracker
138
+ licenses:
139
+ - MIT
140
+ metadata:
141
+ allowed_push_host: https://rubygems.org
142
+ homepage_uri: https://github.com/wshihadeh/irb_tracker
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubygems_version: 3.0.3
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Track and corrolate IRB activities to users.
162
+ test_files: []