invisible_ink 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07c86e1e6ef511722eedcaa46277efa7967337e9261fc69c5bbf3038029fef88
4
- data.tar.gz: 857ee8d11d96e89b1e27bd605c790d7a425934a0d3bed5b655890b5f81d3f7b3
3
+ metadata.gz: 57dbbf05dc3059727a486c602cee310c18fe3e2a6d7be2ab2d3d8bf29940ba4b
4
+ data.tar.gz: 87dc8fe7f9cd5e1e5eaa3d3a16e221e351dae81b42face71d74493ce8d323cd8
5
5
  SHA512:
6
- metadata.gz: a6ffcca4b895c8976506e457bf08d2616006a96656cb3fdfd01ad027f1e6a9d5866bda71af84675bd821234b5fe2466b402dbdebe6f9943d28547750147e8db6
7
- data.tar.gz: 99edfecf2b9b5abde8c16c75552a5147786029ae41076cf66e2b704ee9d2098a088bf3d14a4f11735b3ad05b7fa50ca39c168d252fbfcc106b86c672aa18a839
6
+ metadata.gz: 07d7732c7b04fe0114b59bdf662227e2d1a848f787ecc2e8a6305dc00acad37d9616c24ec431ec04cc6a8b55dbc6cfba6c158d83437ad2bd2ea74354f728d028
7
+ data.tar.gz: 976184bfc8d79af3b99f915367bd4fbce8a4282ae816324a97845911f631b769ab14c9fd73ad47c0a71f52e7bfc7d6b9705da9fff16a38b0c56e6df0b13822f4
data/.docs/demo.gif ADDED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
- ## [Unreleased]
1
+ ## [0.2.1 - 2023-10-16]
2
+
3
+ - Require base Active Support library before specific extensions (#5)
4
+ - Bump activesupport from 7.0.4.3 to 7.0.7.1 (#3)
5
+
6
+ ## [0.2.0 - 2023-03-19]
7
+
8
+ - Proof of concept
2
9
 
3
10
  ## [0.1.0] - 2023-03-14
4
11
 
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
+ gem "activesupport", "~> 7.0"
7
8
  gem "rake", "~> 13.0"
8
9
  gem "rspec", "~> 3.0"
9
10
  gem "standard", "~> 1.3"
data/Gemfile.lock CHANGED
@@ -1,15 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invisible_ink (0.1.0)
4
+ invisible_ink (0.2.0)
5
+ activesupport (~> 7.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ activesupport (7.0.7.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
9
15
  ast (2.4.2)
16
+ concurrent-ruby (1.2.2)
10
17
  diff-lcs (1.5.0)
18
+ i18n (1.14.1)
19
+ concurrent-ruby (~> 1.0)
11
20
  json (2.6.3)
12
21
  language_server-protocol (3.17.0.3)
22
+ minitest (5.19.0)
13
23
  parallel (1.22.1)
14
24
  parser (3.2.1.1)
15
25
  ast (~> 2.4.1)
@@ -50,6 +60,8 @@ GEM
50
60
  language_server-protocol (~> 3.17.0.2)
51
61
  rubocop (= 1.44.1)
52
62
  rubocop-performance (= 1.15.2)
63
+ tzinfo (2.0.6)
64
+ concurrent-ruby (~> 1.0)
53
65
  unicode-display_width (2.4.2)
54
66
 
55
67
  PLATFORMS
@@ -57,6 +69,7 @@ PLATFORMS
57
69
  x86_64-linux
58
70
 
59
71
  DEPENDENCIES
72
+ activesupport (~> 7.0)
60
73
  invisible_ink!
61
74
  rake (~> 13.0)
62
75
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
- # đŸĒ„ Invisible Ink
1
+ # 🔏 Invisible Ink
2
2
 
3
3
  Encrypt text files in your open source projects so that they can be committed to
4
4
  your repository without exposing sensitive information.
5
5
 
6
- ## Installation
6
+ ## 📸 Demo
7
+
8
+ ![A demo showing how to use the Gem](.docs/demo.gif)
9
+
10
+ ## ✅ Installation
7
11
 
8
12
  Install the gem and add to the application's Gemfile by executing:
9
13
 
@@ -13,11 +17,29 @@ If bundler is not being used to manage dependencies, install the gem by executin
13
17
 
14
18
  $ gem install invisible_ink
15
19
 
16
- ## Usage
17
20
 
18
- TODO: Write usage instructions here
21
+ ## ℹī¸ Usage
22
+
23
+ Once installed in your project's `Gemfile`, run `bundle exec invisible_ink
24
+ --setup` to create an encryption key saved to `invisible_ink.key`. This will
25
+ also update your `.gitignore` file to ensure the key is not saved to version
26
+ control.
27
+
28
+ Alternatively, you can set `ENV["INVISIBLE_INK_KEY"]` to the value of a 32
29
+ character hash.
30
+
31
+ ### ⌨ī¸ Commands
32
+
33
+ ```text
34
+ Usage: invisible_ink COMMAND [options]
35
+ -w, --write FILE Encrypt a file using an encryption key and open it in the specified $EDITOR
36
+ -r, --read FILE Decrypt and display the content of an encrypted file
37
+ -s, --setup Generate an encryption key, save it to a file, and add it to .gitignore
38
+ -h, --help Display help message
39
+ -v, --version Display Gem version
40
+ ```
19
41
 
20
- ## Development
42
+ ## 🔨 Development
21
43
 
22
44
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
23
45
  `rake spec` to run the tests. You can also run `bin/console` for an interactive
@@ -29,7 +51,7 @@ release a new version, update the version number in `version.rb`, and then run
29
51
  git commits and the created tag, and push the `.gem` file to
30
52
  [rubygems.org](https://rubygems.org).
31
53
 
32
- ## Contributing
54
+ ## 🙏 Contributing
33
55
 
34
56
  Bug reports and pull requests are welcome on GitHub at
35
57
  https://github.com/stevepolitodesign/invisible_ink. This project is intended to be a
@@ -37,12 +59,12 @@ safe, welcoming space for collaboration, and contributors are expected to adhere
37
59
  to the [code of
38
60
  conduct](https://github.com/stevepolitodesign/invisible_ink/blob/main/CODE_OF_CONDUCT.md).
39
61
 
40
- ## License
62
+ ## 📜 License
41
63
 
42
64
  The gem is available as open source under the terms of the [MIT
43
65
  License](https://opensource.org/licenses/MIT).
44
66
 
45
- ## Code of Conduct
67
+ ## ❤ī¸ Code of Conduct
46
68
 
47
69
  Everyone interacting in the InvisibleInk project's codebases, issue trackers,
48
70
  chat rooms and mailing lists is expected to follow the [code of
data/exe/invisible_ink ADDED
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/invisible_ink"
3
+ require "optparse"
4
+
5
+ options = {}
6
+
7
+ begin
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: invisible_ink COMMAND [options]"
10
+
11
+ opts.on("-w", "--write FILE", String, "Encrypt a file using an encryption key and open it in the specified $EDITOR") do |file|
12
+ options[:command] = "write"
13
+ options[:file] = file
14
+ end
15
+
16
+ opts.on("-r", "--read FILE", String, "Decrypt and display the content of an encrypted file") do |file|
17
+ options[:command] = "read"
18
+ options[:file] = file
19
+ end
20
+
21
+ opts.on("-s", "--setup", "Generate an encryption key, save it to a file, and add it to .gitignore") do
22
+ options[:command] = "setup"
23
+ end
24
+
25
+ opts.on("-h", "--help", "Display help message") do
26
+ puts opts
27
+ exit
28
+ end
29
+
30
+ opts.on("-v", "--version", "Display Gem version") do
31
+ puts InvisibleInk::VERSION
32
+ exit
33
+ end
34
+ end.parse!
35
+ rescue OptionParser::MissingArgument => e
36
+ puts "ERROR: #{e.message}. The #{e.args.first} command requires a file argument."
37
+ puts ""
38
+ puts "EXAMPLE: invisible_ink #{e.args.first} path/to/file.txt"
39
+ exit 1
40
+ end
41
+
42
+ if options[:command].nil?
43
+ puts "Invalid command. Run 'invisible_ink --help' for a list of available commands."
44
+ exit 1
45
+ end
46
+
47
+ def build_encrypted_file(file_path)
48
+ ActiveSupport::EncryptedFile.new(
49
+ content_path: file_path,
50
+ key_path: "invisible_ink.key",
51
+ env_key: "INVISIBLE_INK_KEY",
52
+ raise_if_missing_key: true
53
+ )
54
+ end
55
+
56
+ def handle_missing_key_error(error)
57
+ puts "ERROR: #{error}"
58
+ puts ""
59
+ puts "Did you run 'invisible_ink setup'?"
60
+ end
61
+
62
+ case options[:command]
63
+ when "write"
64
+ file_path = options[:file]
65
+ if ENV["EDITOR"].to_s.empty?
66
+ puts "No $EDITOR to open file in. Assign one like this:"
67
+ puts ""
68
+ puts %(EDITOR="mate --wait" exe/invisible_ink write #{file_path})
69
+ puts ""
70
+ puts "For editors that fork and exit immediately, it's important to pass a wait flag;"
71
+ puts "otherwise, the file will be saved immediately with no chance to edit."
72
+ exit 1
73
+ end
74
+ begin
75
+ dir_path = File.dirname(file_path)
76
+ FileUtils.mkdir_p(dir_path)
77
+
78
+ encrypted_file = build_encrypted_file(file_path)
79
+ encrypted_file.write(nil) unless File.exist?(file_path)
80
+
81
+ encrypted_file.change do |tmp_path|
82
+ system(*Shellwords.split(ENV["EDITOR"]), tmp_path.to_s)
83
+ rescue Interrupt
84
+ puts "File not saved"
85
+ end
86
+ rescue ActiveSupport::EncryptedFile::MissingKeyError => error
87
+ handle_missing_key_error(error)
88
+ exit 1
89
+ end
90
+ when "read"
91
+ begin
92
+ encrypted_file = build_encrypted_file(options[:file])
93
+ puts encrypted_file.read
94
+ rescue ActiveSupport::EncryptedFile::MissingKeyError => error
95
+ handle_missing_key_error(error)
96
+ exit 1
97
+ end
98
+ when "setup"
99
+ if File.exist?("invisible_ink.key")
100
+ puts "ERROR: invisible_ink.key already exists"
101
+ exit 1
102
+ else
103
+ ignore_key = if File.exist?(".gitignore") && !File.read(".gitignore").empty?
104
+ "\ninvisible_ink.key"
105
+ else
106
+ "invisible_ink.key"
107
+ end
108
+ File.open(".gitignore", "a") { |file| file.puts(ignore_key) }
109
+ key = ActiveSupport::EncryptedFile.generate_key
110
+ File.write("invisible_ink.key", key)
111
+ puts "invisible_ink.key generated"
112
+ end
113
+ end
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  # Uncomment to register a new dependency of your gem
33
- # spec.add_dependency "example-gem", "~> 1.0"
33
+ spec.add_dependency "activesupport", "~> 7.0"
34
34
 
35
35
  # For more information and examples about making a new gem, check out our
36
36
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InvisibleInk
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/invisible_ink.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "invisible_ink/version"
4
+ require "active_support"
5
+ require "active_support/encrypted_file"
6
+ require "securerandom"
7
+ require "shellwords"
4
8
 
5
9
  module InvisibleInk
6
10
  class Error < StandardError; end
metadata CHANGED
@@ -1,23 +1,39 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invisible_ink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Polito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-14 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
13
27
  description: Encrypt text files in your open source projects so that they can be committed
14
28
  to your repository without exposing sensitive information.
15
29
  email:
16
30
  - stevepolito@hey.com
17
- executables: []
31
+ executables:
32
+ - invisible_ink
18
33
  extensions: []
19
34
  extra_rdoc_files: []
20
35
  files:
36
+ - ".docs/demo.gif"
21
37
  - ".rspec"
22
38
  - ".standard.yml"
23
39
  - CHANGELOG.md
@@ -27,6 +43,7 @@ files:
27
43
  - LICENSE.txt
28
44
  - README.md
29
45
  - Rakefile
46
+ - exe/invisible_ink
30
47
  - invisible_ink.gemspec
31
48
  - lib/invisible_ink.rb
32
49
  - lib/invisible_ink/version.rb
@@ -53,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
70
  - !ruby/object:Gem::Version
54
71
  version: '0'
55
72
  requirements: []
56
- rubygems_version: 3.3.26
73
+ rubygems_version: 3.4.12
57
74
  signing_key:
58
75
  specification_version: 4
59
76
  summary: Keep your private notes in plain sight.