console_tracker 0.0.0.pre.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1a590b25b800fda6109f9d718fa77791a19453e5e88d314c3a6d5315d4d08876
4
+ data.tar.gz: a1336e6a559c8b3ad4342d2cff7f671c0eae32056e32d1be8cbe901b795ac2ff
5
+ SHA512:
6
+ metadata.gz: 69f1972d2b72db299cc1c9a520f91ef55b0a4f7eca2c7c143329da18eddd3b1915d35f4b7603c615f034ed185438881d2297f6ea6ca5ce753257d418f976fc9f
7
+ data.tar.gz: 848924c64a83b33f48abc7dcdeba97203e8cd78f047b85897f0e7c731b8569bf8b7399d68c9a892d0853faefb2c764dcbacba8d66e1e324226606ba34fe2628e
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,46 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6.2
3
+ EnabledByDefault: true
4
+
5
+ Metrics/LineLength:
6
+ Max: 120
7
+
8
+ Style/SignalException:
9
+ Enabled: false
10
+ Lint/UnreachableCode:
11
+ Description: 'Unreachable code.'
12
+ Enabled: false
13
+
14
+ Metrics/ModuleLength:
15
+ Exclude:
16
+ - spec/*
17
+ - spec/**/*spec.rb
18
+
19
+ Metrics/BlockLength:
20
+ Exclude:
21
+ - spec/*
22
+ - spec/**/*spec.rb
23
+
24
+ Lint/ConstantResolution:
25
+ Enabled: false
26
+
27
+ Style/Copyright:
28
+ Enabled: false
29
+
30
+ Style/Documentation:
31
+ Enabled: false
32
+
33
+ Style/DocumentationMethod:
34
+ Enabled: false
35
+
36
+ Style/ConstantVisibility:
37
+ Enabled: false
38
+
39
+ Style/FrozenStringLiteralComment:
40
+ Enabled: true
41
+ Exclude:
42
+ - 'Gemfile'
43
+ - 'console_tracker.gemspec'
44
+ - 'Rakefile'
45
+ - 'bin/*'
46
+ - 'spec/*'
@@ -0,0 +1 @@
1
+ console_tracker
@@ -0,0 +1 @@
1
+ 2.6.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at s_s_s@ua.fm. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source('https://rubygems.org')
2
+
3
+ # Specify your gem's dependencies in console_tracker.gemspec
4
+ gemspec
@@ -0,0 +1,129 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ console_tracker (0.0.0.pre.beta2)
5
+ aws-sdk-cognitoidentityprovider (~> 1.26)
6
+ slack-ruby-client (~> 0.14)
7
+ trailblazer-macro (>= 2.1.0.rc1, < 2.2)
8
+ trailblazer-operation (~> 0.4)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (6.0.3.4)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ i18n (>= 0.7, < 2)
16
+ minitest (~> 5.1)
17
+ tzinfo (~> 1.1)
18
+ zeitwerk (~> 2.2, >= 2.2.2)
19
+ ast (2.4.1)
20
+ aws-eventstream (1.1.0)
21
+ aws-partitions (1.385.0)
22
+ aws-sdk-cognitoidentityprovider (1.42.0)
23
+ aws-sdk-core (~> 3, >= 3.99.0)
24
+ aws-sigv4 (~> 1.1)
25
+ aws-sdk-core (3.109.1)
26
+ aws-eventstream (~> 1, >= 1.0.2)
27
+ aws-partitions (~> 1, >= 1.239.0)
28
+ aws-sigv4 (~> 1.1)
29
+ jmespath (~> 1.0)
30
+ aws-sigv4 (1.2.2)
31
+ aws-eventstream (~> 1, >= 1.0.2)
32
+ concurrent-ruby (1.1.7)
33
+ declarative (0.0.20)
34
+ declarative-option (0.1.0)
35
+ diff-lcs (1.4.4)
36
+ faraday (0.17.3)
37
+ multipart-post (>= 1.2, < 3)
38
+ faraday_middleware (0.14.0)
39
+ faraday (>= 0.7.4, < 1.0)
40
+ gli (2.19.2)
41
+ hashie (3.6.0)
42
+ hirb (0.7.3)
43
+ i18n (1.8.5)
44
+ concurrent-ruby (~> 1.0)
45
+ jmespath (1.4.0)
46
+ minitest (5.14.2)
47
+ multipart-post (2.1.1)
48
+ parallel (1.19.2)
49
+ parser (2.7.1.4)
50
+ ast (~> 2.4.1)
51
+ rainbow (3.0.0)
52
+ rake (13.0.1)
53
+ regexp_parser (1.7.1)
54
+ representable (3.0.4)
55
+ declarative (< 0.1.0)
56
+ declarative-option (< 0.2.0)
57
+ uber (< 0.2.0)
58
+ rexml (3.2.4)
59
+ rspec (3.9.0)
60
+ rspec-core (~> 3.9.0)
61
+ rspec-expectations (~> 3.9.0)
62
+ rspec-mocks (~> 3.9.0)
63
+ rspec-core (3.9.2)
64
+ rspec-support (~> 3.9.3)
65
+ rspec-expectations (3.9.2)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.9.0)
68
+ rspec-mocks (3.9.1)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.9.0)
71
+ rspec-support (3.9.3)
72
+ rubocop (0.88.0)
73
+ parallel (~> 1.10)
74
+ parser (>= 2.7.1.1)
75
+ rainbow (>= 2.2.2, < 4.0)
76
+ regexp_parser (>= 1.7)
77
+ rexml
78
+ rubocop-ast (>= 0.1.0, < 1.0)
79
+ ruby-progressbar (~> 1.7)
80
+ unicode-display_width (>= 1.4.0, < 2.0)
81
+ rubocop-ast (0.2.0)
82
+ parser (>= 2.7.0.1)
83
+ ruby-progressbar (1.10.1)
84
+ slack-ruby-client (0.14.6)
85
+ activesupport
86
+ faraday (>= 0.9)
87
+ faraday_middleware
88
+ gli
89
+ hashie
90
+ websocket-driver
91
+ thread_safe (0.3.6)
92
+ trailblazer-activity (0.11.0)
93
+ trailblazer-context (>= 0.3.0, < 0.4.0)
94
+ trailblazer-activity-dsl-linear (0.3.1)
95
+ trailblazer-activity (>= 0.9.1, < 1.0.0)
96
+ trailblazer-context (0.3.0)
97
+ trailblazer-developer (0.0.16)
98
+ hirb
99
+ representable
100
+ trailblazer-activity (>= 0.11.0, < 1.0.0)
101
+ trailblazer-activity-dsl-linear
102
+ trailblazer-macro (2.1.3)
103
+ trailblazer-activity (>= 0.10.0, < 1.0.0)
104
+ trailblazer-activity-dsl-linear (>= 0.2.7, < 1.0.0)
105
+ trailblazer-operation (>= 0.6.2)
106
+ trailblazer-operation (0.6.4)
107
+ trailblazer-activity (>= 0.10.0, < 1.0.0)
108
+ trailblazer-activity-dsl-linear (>= 0.3.1, < 1.0.0)
109
+ trailblazer-developer (>= 0.0.8)
110
+ tzinfo (1.2.7)
111
+ thread_safe (~> 0.1)
112
+ uber (0.1.0)
113
+ unicode-display_width (1.7.0)
114
+ websocket-driver (0.7.3)
115
+ websocket-extensions (>= 0.1.0)
116
+ websocket-extensions (0.1.5)
117
+ zeitwerk (2.4.0)
118
+
119
+ PLATFORMS
120
+ ruby
121
+
122
+ DEPENDENCIES
123
+ console_tracker!
124
+ rake (~> 13.0)
125
+ rspec (~> 3.9)
126
+ rubocop (~> 0.88)
127
+
128
+ BUNDLED WITH
129
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Svatok
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ # ConsoleTracker
2
+
3
+ `console_tracker` is tool for authentication users in console and tracking the commands they enter.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'console_tracker'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install console_tracker
20
+
21
+ ## Usage
22
+
23
+ ### Spring
24
+
25
+ `console_tracker` will not work with `Spring`. You must not install Spring on environment where you will use
26
+ `console_tracker`. To prevent it from being installed, provide the `--without development test` argument to the `bundle install` command which is used to install gems:
27
+
28
+ ```bash
29
+ $ bundle install --without development test
30
+ ```
31
+
32
+ ### Example of configuration with AWS Cognito authenticator and Slack logger
33
+
34
+ #### Step 1
35
+
36
+ Create file `config/initializers/console_tracker.rb`
37
+
38
+ ```ruby
39
+ ConsoleTracker.configure do |config|
40
+ config.client = :cognito
41
+ config.client_settings = {
42
+ region: ENV['region'],
43
+ client_id: ENV['client_id'],
44
+ access_key_id: ENV['AWS_KEY_ID'],
45
+ secret_access_key: ENV['AWS_ACCESS_KEY']
46
+ }
47
+ end
48
+
49
+ ConsoleTracker.start
50
+ ```
51
+
52
+ #### Step 2
53
+
54
+ Create user in https://aws.amazon.com/cognito/
55
+
56
+ ![Screenshot from 2020-10-30 09-12-37](https://user-images.githubusercontent.com/18479771/97674468-416cd480-1a96-11eb-95c7-fd51912dbc4a.png)
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Svatok/console_tracker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Svatok/console_tracker/blob/master/CODE_OF_CONDUCT.md).
61
+
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT)
66
+
67
+ ## Code of Conduct
68
+
69
+ Everyone interacting in the ConsoleTracker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Svatok/console_tracker/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require('bundler/gem_tasks')
2
+ require('rspec/core/rake_task')
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task(default: :spec)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require('bundler/setup')
4
+ require('console_tracker')
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require('irb')
14
+ IRB.start(__FILE__)
@@ -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,36 @@
1
+ require_relative('lib/console_tracker/version')
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'console_tracker'
5
+ spec.version = ConsoleTracker::VERSION
6
+ spec.authors = ['Svatok']
7
+ spec.email = ['svatok1991 at gmail dot com']
8
+
9
+ spec.summary = 'Users authentication in console and their activity tracking'
10
+ spec.description = 'Users authentication in console and their activity tracking'
11
+ spec.homepage = 'https://github.com/Svatok/console_tracker'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files =
21
+ Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency('aws-sdk-cognitoidentityprovider', '~> 1.26')
29
+ spec.add_dependency('slack-ruby-client', '~> 0.14')
30
+ spec.add_dependency('trailblazer-macro', ['>= 2.1.0.rc1', '< 2.2'])
31
+ spec.add_dependency('trailblazer-operation', '~> 0.4')
32
+
33
+ spec.add_development_dependency('rake', '~> 13.0')
34
+ spec.add_development_dependency('rspec', '~> 3.9')
35
+ spec.add_development_dependency('rubocop', '~> 0.88')
36
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('console_tracker/version')
4
+ require('console_tracker/configure')
5
+ require('console_tracker/user')
6
+ require('console_tracker/authenticate')
7
+ require('console_tracker/connect')
8
+ require('io/console')
9
+
10
+ module ConsoleTracker
11
+ class << self
12
+ def start
13
+ return unless defined?(Rails::Console)
14
+
15
+ ConsoleTracker::Authenticate.call
16
+ ConsoleTracker.connect
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('trailblazer/operation')
4
+ require('trailblazer/macro')
5
+ require('console_tracker/authenticators')
6
+
7
+ module ConsoleTracker
8
+ class Authenticate < Trailblazer::Operation
9
+ step :user
10
+ step Nested(:authenticate_operation)
11
+ fail :close_console
12
+
13
+ pass :success_message
14
+
15
+ def user(_ctx, **)
16
+ username = STDIN.getpass('Username:')
17
+ ConsoleTracker.user.name = username
18
+ end
19
+
20
+ def authenticate_operation(_ctx, **)
21
+ ConsoleTracker::AUTHENTICATORS[ConsoleTracker.config.authenticator]
22
+ end
23
+
24
+ def close_console(_ctx, error:, **)
25
+ abort(error)
26
+ end
27
+
28
+ def success_message(_ctx, **)
29
+ puts('You have successfully logged in.')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('console_tracker/authenticators/cognito/authenticate')
4
+
5
+ module ConsoleTracker
6
+ AUTHENTICATORS = {
7
+ cognito: Authenticators::Cognito::Authenticate
8
+ }.freeze
9
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('aws-sdk-cognitoidentityprovider')
4
+
5
+ module ConsoleTracker
6
+ module Authenticators
7
+ class CognitoAuthenticator
8
+ attr_reader :username, :authenticator_settings
9
+
10
+ def initialize
11
+ @username = ConsoleTracker.user.name
12
+ @authenticator_settings = ConsoleTracker.config.authenticator_settings
13
+ end
14
+
15
+ def authenticate(password)
16
+ client.initiate_auth(
17
+ auth_flow: 'USER_PASSWORD_AUTH',
18
+ auth_parameters: {
19
+ USERNAME: username,
20
+ PASSWORD: password
21
+ },
22
+ client_id: client_id
23
+ )
24
+ end
25
+
26
+ def change_temporary_password(session, new_password)
27
+ client.respond_to_auth_challenge(
28
+ challenge_name: 'NEW_PASSWORD_REQUIRED',
29
+ challenge_responses: {
30
+ USERNAME: username,
31
+ NEW_PASSWORD: new_password
32
+ },
33
+ client_id: client_id,
34
+ session: session
35
+ )
36
+ end
37
+
38
+ private
39
+
40
+ def client
41
+ @client ||= Aws::CognitoIdentityProvider::Client.new(
42
+ region: authenticator_settings[:region],
43
+ access_key_id: authenticator_settings[:access_key_id],
44
+ secret_access_key: authenticator_settings[:secret_access_key]
45
+ )
46
+ end
47
+
48
+ def client_id
49
+ @client_id ||= authenticator_settings[:client_id]
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('trailblazer/operation')
4
+ require('trailblazer/macro')
5
+ require('console_tracker/authenticators/cognito')
6
+
7
+ module ConsoleTracker
8
+ module Authenticators
9
+ module Cognito
10
+ class Authenticate < Trailblazer::Operation
11
+ step :client
12
+
13
+ step Rescue(StandardError, handler: :handle_exception!) {
14
+ step :authenticate
15
+ step :change_temporary_password?, Output(:failure) => 'End.success'
16
+ step :change_temporary_password
17
+ }
18
+
19
+ def client(ctx, **)
20
+ ctx[:client] = CognitoAuthenticator.new
21
+ end
22
+
23
+ def authenticate(ctx, client:, **)
24
+ password = STDIN.getpass('Password:')
25
+ ctx[:authentication_response] = client.authenticate(password)
26
+ end
27
+
28
+ def change_temporary_password?(_ctx, authentication_response:, **)
29
+ authentication_response.challenge_name == 'NEW_PASSWORD_REQUIRED'
30
+ end
31
+
32
+ def change_temporary_password(_ctx, client:, authentication_response:, **)
33
+ puts('Please change temporary password')
34
+ new_password = STDIN.getpass('New password:')
35
+ client.change_temporary_password(authentication_response.session, new_password)
36
+ end
37
+
38
+ def handle_exception!(exception, (ctx), *)
39
+ ctx[:error] = exception.message
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConsoleTracker
4
+ class << self
5
+ def configure
6
+ yield(config)
7
+ end
8
+
9
+ def config
10
+ @config ||= Config.new
11
+ end
12
+ end
13
+
14
+ class Config
15
+ attr_accessor :authenticator, :authenticator_settings, :logger, :logger_settings
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('console_tracker/log')
4
+
5
+ module ConsoleTracker
6
+ class << self
7
+ def connect
8
+ with_irb if defined?(IRB)
9
+ with_pry if defined?(Pry)
10
+ end
11
+
12
+ def with_irb
13
+ IRB::Context.class_eval do
14
+ alias_method :usual_evaluate, :evaluate
15
+
16
+ def evaluate(*params)
17
+ usual_evaluate(*params)
18
+ ConsoleTracker::Log.call(command: params.first)
19
+ end
20
+ end
21
+ end
22
+
23
+ def with_pry
24
+ Pry.hooks.add_hook(:after_read, 'console_tracker') do |string, _pry|
25
+ ConsoleTracker::Log.call(command: string)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('trailblazer/operation')
4
+ require('trailblazer/macro')
5
+ require('console_tracker/loggers')
6
+
7
+ module ConsoleTracker
8
+ class Log < Trailblazer::Operation
9
+ step :username
10
+ step :logger
11
+ step Nested(:message_operation)
12
+ step :send_message
13
+
14
+ def username(ctx, **)
15
+ ctx[:username] = ConsoleTracker.user.name
16
+ end
17
+
18
+ def logger(ctx, **)
19
+ ctx[:logger] = ConsoleTracker::LOGGERS[ConsoleTracker.config.logger].new
20
+ end
21
+
22
+ def message_operation(_ctx, logger:, **)
23
+ logger.message_composer
24
+ end
25
+
26
+ def send_message(_ctx, logger:, message_params:, **)
27
+ logger.log_command(message_params)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('console_tracker/loggers/slack')
4
+
5
+ module ConsoleTracker
6
+ LOGGERS = {
7
+ slack: Loggers::SlackLogger
8
+ }.freeze
9
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('slack-ruby-client')
4
+ require('console_tracker/loggers/slack/compose_message')
5
+
6
+ module ConsoleTracker
7
+ module Loggers
8
+ class SlackLogger
9
+ attr_reader :logger_settings
10
+
11
+ def initialize
12
+ @logger_settings = ConsoleTracker.config.logger_settings
13
+ end
14
+
15
+ def message_composer
16
+ ConsoleTracker::Slack::ComposeMessage
17
+ end
18
+
19
+ def log_command(message_params)
20
+ message_params[:channel] = logger_settings[:channel]
21
+ client.chat_postMessage(message_params)
22
+ end
23
+
24
+ private
25
+
26
+ def client
27
+ @client ||= ::Slack::Web::Client.new(token: logger_settings[:token])
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('trailblazer/operation')
4
+ require('trailblazer/macro')
5
+
6
+ module ConsoleTracker
7
+ module Slack
8
+ class ComposeMessage < Trailblazer::Operation
9
+ step :text
10
+ step :attachment
11
+ step :command_field
12
+
13
+ step :message_params
14
+
15
+ def text(ctx, username:, **)
16
+ ctx[:text] = "*DEVELOPER: _#{username}_*"
17
+ end
18
+
19
+ def attachment(ctx, **)
20
+ ctx[:attachment] = {
21
+ fields: [],
22
+ color: '#e74c3c',
23
+ footer: 'Console spy',
24
+ footer_icon: 'https://drivy-prod-static.s3.amazonaws.com/slack/spy-small.png',
25
+ ts: Time.zone.now.to_i,
26
+ mrkdwn_in: ['fields']
27
+ }
28
+ end
29
+
30
+ def command_field(_ctx, attachment:, command:, **)
31
+ attachment[:fields] << {
32
+ title: 'Command',
33
+ value: "```#{command}```",
34
+ short: false
35
+ }
36
+ end
37
+
38
+ def message_params(ctx, attachment:, text:, **)
39
+ ctx[:message_params] = { text: text, attachments: [attachment] }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConsoleTracker
4
+ class << self
5
+ def user
6
+ @user ||= User.new
7
+ end
8
+ end
9
+
10
+ class User
11
+ attr_accessor :name
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConsoleTracker
4
+ VERSION = '0.0.0-beta2'
5
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: console_tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.pre.beta2
5
+ platform: ruby
6
+ authors:
7
+ - Svatok
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-cognitoidentityprovider
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.26'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.26'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slack-ruby-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.14'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: trailblazer-macro
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.0.rc1
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '2.2'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.1.0.rc1
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.2'
61
+ - !ruby/object:Gem::Dependency
62
+ name: trailblazer-operation
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.4'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.4'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '13.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '13.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.9'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.9'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.88'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.88'
117
+ description: Users authentication in console and their activity tracking
118
+ email:
119
+ - svatok1991 at gmail dot com
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".gitignore"
125
+ - ".rspec"
126
+ - ".rubocop.yml"
127
+ - ".ruby-gemset"
128
+ - ".ruby-version"
129
+ - CODE_OF_CONDUCT.md
130
+ - Gemfile
131
+ - Gemfile.lock
132
+ - LICENSE.txt
133
+ - README.md
134
+ - Rakefile
135
+ - bin/console
136
+ - bin/setup
137
+ - console_tracker.gemspec
138
+ - lib/console_tracker.rb
139
+ - lib/console_tracker/authenticate.rb
140
+ - lib/console_tracker/authenticators.rb
141
+ - lib/console_tracker/authenticators/cognito.rb
142
+ - lib/console_tracker/authenticators/cognito/authenticate.rb
143
+ - lib/console_tracker/configure.rb
144
+ - lib/console_tracker/connect.rb
145
+ - lib/console_tracker/log.rb
146
+ - lib/console_tracker/loggers.rb
147
+ - lib/console_tracker/loggers/slack.rb
148
+ - lib/console_tracker/loggers/slack/compose_message.rb
149
+ - lib/console_tracker/user.rb
150
+ - lib/console_tracker/version.rb
151
+ homepage: https://github.com/Svatok/console_tracker
152
+ licenses:
153
+ - MIT
154
+ metadata:
155
+ homepage_uri: https://github.com/Svatok/console_tracker
156
+ source_code_uri: https://github.com/Svatok/console_tracker
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: 2.3.0
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">"
169
+ - !ruby/object:Gem::Version
170
+ version: 1.3.1
171
+ requirements: []
172
+ rubygems_version: 3.0.3
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Users authentication in console and their activity tracking
176
+ test_files: []