chronicle-shell 0.1.0

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: bb256c224fc5da05d9a0cdcdb9d4efd15156f9194783088e110fd5213549dc55
4
+ data.tar.gz: 1f1f7415835c37376b46ac436f431cb48081bf669440afb58617e41a5a5f27fa
5
+ SHA512:
6
+ metadata.gz: 94112b98f9536c38fdc9bd8de1900b119b92a400e82f93d38de594d12f8baed537081bb1dc07350afbf51fc6a187fa1097f8d82f39adc5ad64067487a994aca7
7
+ data.tar.gz: c813a082d7d2e36f0c4091cd875d3b9be5d262b39ddf249e011f6ac68fcc3aea05e7d73d1855d0d71565cf5e1b7d20c53e6c03d213f01637a684b9a1d1254121
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at andrew@hyfen.net. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in chronicle-shell.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ chronicle-shell (0.1.0)
5
+ chronicle-etl (~> 0.3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (7.0.2)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ chronic_duration (0.10.6)
16
+ numerizer (~> 0.1.1)
17
+ chronicle-etl (0.3.0)
18
+ activesupport
19
+ chronic_duration (~> 0.10.6)
20
+ colorize (~> 0.8.1)
21
+ marcel (~> 1.0.2)
22
+ mini_exiftool (~> 2.10)
23
+ nokogiri (~> 1.13)
24
+ runcom (~> 6.2)
25
+ sequel (~> 5.35)
26
+ sqlite3 (~> 1.4)
27
+ thor (~> 0.20)
28
+ tty-progressbar (~> 0.17)
29
+ tty-table (~> 0.11)
30
+ colorize (0.8.1)
31
+ concurrent-ruby (1.1.9)
32
+ i18n (1.9.1)
33
+ concurrent-ruby (~> 1.0)
34
+ marcel (1.0.2)
35
+ mini_exiftool (2.10.2)
36
+ mini_portile2 (2.7.1)
37
+ minitest (5.15.0)
38
+ nokogiri (1.13.1)
39
+ mini_portile2 (~> 2.7.0)
40
+ racc (~> 1.4)
41
+ numerizer (0.1.1)
42
+ pastel (0.8.0)
43
+ tty-color (~> 0.5)
44
+ racc (1.6.0)
45
+ rake (13.0.6)
46
+ refinements (7.18.0)
47
+ runcom (6.6.0)
48
+ refinements (~> 7.16)
49
+ xdg (~> 4.4)
50
+ sequel (5.53.0)
51
+ sqlite3 (1.4.2)
52
+ strings (0.2.1)
53
+ strings-ansi (~> 0.2)
54
+ unicode-display_width (>= 1.5, < 3.0)
55
+ unicode_utils (~> 1.4)
56
+ strings-ansi (0.2.0)
57
+ thor (0.20.3)
58
+ tty-color (0.6.0)
59
+ tty-cursor (0.7.1)
60
+ tty-progressbar (0.18.2)
61
+ strings-ansi (~> 0.2)
62
+ tty-cursor (~> 0.7)
63
+ tty-screen (~> 0.8)
64
+ unicode-display_width (>= 1.6, < 3.0)
65
+ tty-screen (0.8.1)
66
+ tty-table (0.12.0)
67
+ pastel (~> 0.8)
68
+ strings (~> 0.2.0)
69
+ tty-screen (~> 0.8)
70
+ tzinfo (2.0.4)
71
+ concurrent-ruby (~> 1.0)
72
+ unicode-display_width (2.1.0)
73
+ unicode_utils (1.4.0)
74
+ xdg (4.5.0)
75
+
76
+ PLATFORMS
77
+ -darwin-20
78
+
79
+ DEPENDENCIES
80
+ chronicle-shell!
81
+ rake (~> 13.0)
82
+
83
+ BUNDLED WITH
84
+ 2.3.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Andrew Louis
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Chronicle::Shell
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/chronicle/shell`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'chronicle-shell'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install chronicle-shell
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/chronicle-shell. 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/[USERNAME]/chronicle-shell/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the Chronicle::Shell project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/chronicle-shell/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/chronicle/shell/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "chronicle-shell"
7
+ spec.version = Chronicle::Shell::VERSION
8
+ spec.authors = ["Andrew Louis"]
9
+ spec.email = ["andrew@hyfen.net"]
10
+
11
+ spec.summary = "Shell connectors for Chronicle-ETL"
12
+ spec.description = "Extract shell command history from Bash or Zsh"
13
+ spec.homepage = "https://github.com/chronicle-app/chronicle-shell"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
+ spec.license = "MIT"
16
+
17
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/chronicle-app/chronicle-shell"
21
+ spec.metadata["changelog_uri"] = "https://github.com/chronicle-app/chronicle-shell/releases"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_dependency "chronicle-etl", "~> 0.3.0"
35
+ end
@@ -0,0 +1,90 @@
1
+ require 'chronicle/etl'
2
+ require 'tty-command'
3
+
4
+ module Chronicle
5
+ module Shell
6
+ class ShellHistoryExtractor < Chronicle::ETL::Extractor
7
+ register_connector do |r|
8
+ r.provider = 'shell'
9
+ r.description = 'shell command history'
10
+ r.identifier = 'shell-history'
11
+ end
12
+
13
+ BASH_TIMESTAMP_REGEX = /^\#(?<timestamp>[0-9]{10})/
14
+
15
+ def prepare
16
+ # TODO: determine if we're working with bash or zsh
17
+ @shell_name = 'bash'
18
+
19
+ @filename = history_filename
20
+ @commands = load_commands
21
+ end
22
+
23
+ def results_count
24
+ @commands.count
25
+ end
26
+
27
+ def extract
28
+ @commands.each do |command|
29
+ meta = {
30
+ username: username,
31
+ hostname: hostname,
32
+ shell_name: @shell_name
33
+ }
34
+ yield Chronicle::ETL::Extraction.new(data: command, meta: meta)
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def history_filename
41
+ File.join(Dir.home, ".bash_history")
42
+ end
43
+
44
+ def username
45
+ @username ||= Etc.getlogin
46
+ end
47
+
48
+ def hostname
49
+ @hostname ||= begin
50
+ require 'socket'
51
+ Socket.gethostname
52
+ end
53
+ end
54
+
55
+ def load_commands
56
+ commands = []
57
+
58
+ loader = "load_commands_from_#{@shell_name}"
59
+ send(loader) do |command|
60
+ next if @options[:load_since] && command[:timestamp] < @options[:load_since]
61
+ next if @options[:load_until] && command[:timestamp] > @options[:load_until]
62
+
63
+ if block_given?
64
+ yield command
65
+ else
66
+ commands << command
67
+ end
68
+ end
69
+
70
+ commands
71
+ end
72
+
73
+ def load_commands_from_bash
74
+ timestamp = nil
75
+ File.foreach(@filename) do |line|
76
+ if match = line.scrub.match(BASH_TIMESTAMP_REGEX)
77
+ timestamp = Time.at(match[:timestamp].to_i)
78
+ elsif timestamp
79
+ command = { timestamp: timestamp, command: line.scrub.strip }
80
+ yield command
81
+ end
82
+ end
83
+ end
84
+
85
+ def load_commands_from_zsh
86
+ # TODO: implement this
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,60 @@
1
+ require 'chronicle/etl'
2
+
3
+ module Chronicle
4
+ module Shell
5
+ class ShellHistoryTransformer < Chronicle::ETL::Transformer
6
+ register_connector do |r|
7
+ r.provider = 'shell'
8
+ r.description = 'a shell command'
9
+ r.identifier = 'shell-history'
10
+ end
11
+
12
+ def transform
13
+ @command = @extraction.data
14
+ build_commanded
15
+ end
16
+
17
+ def id
18
+ end
19
+
20
+ def timestamp
21
+ @command[:timestamp]
22
+ end
23
+
24
+ private
25
+
26
+ def build_commanded
27
+ record = ::Chronicle::ETL::Models::Activity.new
28
+ record.verb = 'commanded'
29
+ record.end_at = timestamp
30
+ record.provider = @extraction.meta[:shell_name]
31
+ record.dedupe_on << [:verb, :end_at, :provider]
32
+ record.involved = build_command
33
+ record.actor = build_actor
34
+ record
35
+ end
36
+
37
+ def build_command
38
+ record = ::Chronicle::ETL::Models::Entity.new
39
+ record.represents = 'command'
40
+ record.provider = @extraction.meta[:shell_name]
41
+ record.body = @command[:command]
42
+ record.dedupe_on << [:body, :provider, :represents]
43
+ record
44
+ end
45
+
46
+ def build_actor
47
+ record = ::Chronicle::ETL::Models::Entity.new
48
+ record.represents = 'identity'
49
+ record.provider = 'system'
50
+ record.slug = build_user_slug
51
+ record.dedupe_on << [:represents, :provider, :slug]
52
+ record
53
+ end
54
+
55
+ def build_user_slug
56
+ "#{@extraction.meta[:username]}@#{@extraction.meta[:hostname]}"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Chronicle
4
+ module Shell
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "shell/version"
4
+ require_relative "shell/shell_history_extractor"
5
+ require_relative "shell/shell_history_transformer"
6
+
7
+ module Chronicle
8
+ module Shell
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chronicle-shell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Louis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chronicle-etl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.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.3.0
27
+ description: Extract shell command history from Bash or Zsh
28
+ email:
29
+ - andrew@hyfen.net
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CODE_OF_CONDUCT.md
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - chronicle-shell.gemspec
41
+ - lib/chronicle/shell.rb
42
+ - lib/chronicle/shell/shell_history_extractor.rb
43
+ - lib/chronicle/shell/shell_history_transformer.rb
44
+ - lib/chronicle/shell/version.rb
45
+ homepage: https://github.com/chronicle-app/chronicle-shell
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ allowed_push_host: https://rubygems.org
50
+ homepage_uri: https://github.com/chronicle-app/chronicle-shell
51
+ source_code_uri: https://github.com/chronicle-app/chronicle-shell
52
+ changelog_uri: https://github.com/chronicle-app/chronicle-shell/releases
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.7.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.1.2
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Shell connectors for Chronicle-ETL
72
+ test_files: []