rails-credentials-git 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: 62b2479563d72cb114d6ea43f74958299bb0d5023038029262cea512a744b817
4
+ data.tar.gz: fc6143fa7728060d423a354ab5361801a247870b25b1f676ffa8afa8060b9ef1
5
+ SHA512:
6
+ metadata.gz: d006ed3409435eee157e339f0c4aa508a77a790f71198e30a85675c46908ab83d5f6940e0719e126988a1212053c09bd629fe71ccaa5efff0462b7dea9a52c64
7
+ data.tar.gz: 7ba38be97d6a1b84dcc1dc29c7627f185617264f289c5cfef972c422bd4092d2918ab9e98f2532fd1518df8176fdfed094aab1175167cea0d9aa876c5bc79d18
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ cache: bundler
3
+ env:
4
+ - "RAILS_VERSION=5.2.0"
5
+ - "RAILS_VERSION=6.0.0"
6
+ - "RAILS_VERSION=6.1.0"
7
+ rvm:
8
+ - 2.7.2
9
+ - 3.0.2
10
+ before_install:
11
+ - gem update bundler
12
+ matrix:
13
+ fast_finish: true
@@ -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 cocchi.c@gmail.com. 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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rails-credentials-git.gemspec
6
+ gemspec
7
+
8
+ rails_version = ENV['RAILS_VERSION'] || '5.2.0'
9
+ gem "activesupport", "~> #{rails_version}"
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails-credentials-git (0.1.0)
5
+ thor (> 0.19, < 2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.2.6)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ concurrent-ruby (1.1.9)
16
+ i18n (1.8.10)
17
+ concurrent-ruby (~> 1.0)
18
+ minitest (5.14.4)
19
+ rake (13.0.6)
20
+ thor (1.0.1)
21
+ thread_safe (0.3.6)
22
+ tzinfo (1.2.9)
23
+ thread_safe (~> 0.1)
24
+
25
+ PLATFORMS
26
+ universal-darwin-19
27
+
28
+ DEPENDENCIES
29
+ activesupport (~> 5.2.0)
30
+ bundler (~> 2.2.5)
31
+ minitest (~> 5.0)
32
+ rails-credentials-git!
33
+ rake (~> 13.0)
34
+
35
+ BUNDLED WITH
36
+ 2.2.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 ccocchi
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,74 @@
1
+ # RailsCredentialsGit
2
+
3
+ Have you ever been in the situation where you'd like to see the changes you made in your encrypted credentials when using `git diff` ? Or worse, having conflicts on the same credentials and only seeing two different encrypted strings ?
4
+
5
+ A good stackoverflow solutions is to use `bin/rails encrypted:show`, but this will have to load your entire app not once but twice, resulting in having to wait a long (depending on your app size) time each time you diff credentials.
6
+
7
+ This gem brings you the same functionnality, at the fraction of the time, in less than 100 lines of code.
8
+
9
+ It has been tested successfully with Rails 5.2, 6.0 and 6.1.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'rails-credentials-git', group: :development, require: false
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```sh
22
+ $ bundle install
23
+ ```
24
+
25
+ Finally, run the following to have the ruby binary copied into your project's `bin/` folder:
26
+
27
+ ```sh
28
+ $ bundle exec rails_credentials_git install
29
+ ```
30
+
31
+ ## Configuration
32
+
33
+ Now we're going to configure `git` to use the binary you just installed. Add these lines to your `.git/config` file at the root of your project:
34
+
35
+ ```
36
+ [diff "enc"]
37
+ textconv = ruby --disable-gems bin/enc
38
+ cachetextconv = false
39
+ ```
40
+
41
+ It defines a new diff mode named "enc", using our Rails binary to do the text conversion. Since it does not use any gem, we can use the `--disable-gems` option to speed up the execution.
42
+ The `cachetextconv = false` option, specify that git should not cache the text conversion which in our case would be the decrypted credentials.
43
+
44
+ Finally, create a `.gitattributes` file at the root of your project or edit your existing one with the following lines:
45
+
46
+ ```
47
+ *.yml.enc diff=enc -merge
48
+ ```
49
+
50
+ It instructs git to use you newly define mode "enc" when diff-ing files matching the `*.yml.enc` regexp.
51
+
52
+ If you're using a default Rails installation, everything is set up and you can now modify your credentials file and use `git diff` to see the results. If you're using a custom location for your `master.key`, you can use the env variable `RAILS_MASTER_KEY` (which is also used by Rails) to pass your key directly.
53
+
54
+ ## Usage
55
+
56
+ In addition, you can use this gem's binary during git conflicts (merge or rebase). Using
57
+
58
+ ```sh
59
+ bin/enc --conflict # with RAILS_MASTER_KEY set if you need to
60
+ ```
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ 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).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ccocchi/rails-credentials-git. 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/ccocchi/rails-credentials-git/blob/master/CODE_OF_CONDUCT.md).
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/rails-credentials-git"
5
+ require_relative "../lib/rails-credentials-git/cli"
6
+
7
+ RailsCredentialsGit::CLI.start
@@ -0,0 +1,19 @@
1
+ require "thor"
2
+
3
+ module RailsCredentialsGit
4
+ class CLI < Thor
5
+ include Thor::Actions
6
+
7
+ package_name "git:credentials"
8
+
9
+ source_root(File.expand_path('../../', __dir__))
10
+
11
+ desc "install", "Copy binary into project's folder"
12
+ def install
13
+ copy_file "bin/enc", "bin/enc", mode: :preserve
14
+
15
+ method = RailsCredentialsGit.decrypt_method.sub("self.", "")
16
+ insert_into_file "bin/enc", "\n#{method}" , after: %{require "openssl"\n}
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsCredentialsGit
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,29 @@
1
+ require "base64"
2
+ require "openssl"
3
+
4
+ module RailsCredentialsGit
5
+ @@method = <<~RUBY
6
+ def self.decrypt(content, key)
7
+ encrypted_data, iv, auth_tag = content.split("--").map { |v| ::Base64.strict_decode64(v) }
8
+ secret = [key].pack("H*")
9
+
10
+ cipher = OpenSSL::Cipher.new("aes-128-gcm")
11
+ cipher.decrypt
12
+ cipher.key = secret
13
+ cipher.iv = iv
14
+ cipher.auth_tag = auth_tag
15
+ cipher.auth_data = ""
16
+
17
+ decrypted_data = cipher.update(encrypted_data)
18
+ decrypted_data << cipher.final
19
+
20
+ Marshal.load(decrypted_data)
21
+ end
22
+ RUBY
23
+
24
+ def self.decrypt_method
25
+ @@method
26
+ end
27
+
28
+ class_eval(@@method, __FILE__, __LINE__ + 1)
29
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rails-credentials-git/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rails-credentials-git"
7
+ spec.version = RailsCredentialsGit::VERSION
8
+ spec.authors = ["ccocchi"]
9
+ spec.email = ["cocchi.c@gmail.com"]
10
+
11
+ spec.summary = "Fastest way to diff your Rails credentials files in git"
12
+ spec.description = "Fastest way to diff your Rails credentials files in git"
13
+ spec.homepage = "https://github.com/ccocchi/rails-credentials-git"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|bin)/}) }
25
+ end
26
+ spec.bindir = "bin"
27
+ spec.executables = ["rails_credentials_git"]
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "thor", "> 0.19", "< 2"
31
+
32
+ spec.add_development_dependency "bundler", "~> 2.2.5"
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
+ spec.add_development_dependency "minitest", "~> 5.0"
35
+ spec.add_development_dependency "activesupport", ">= 5.2", "< 7"
36
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-credentials-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ccocchi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.19'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 2.2.5
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 2.2.5
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '13.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '5.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '5.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: activesupport
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '5.2'
82
+ - - "<"
83
+ - !ruby/object:Gem::Version
84
+ version: '7'
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '5.2'
92
+ - - "<"
93
+ - !ruby/object:Gem::Version
94
+ version: '7'
95
+ description: Fastest way to diff your Rails credentials files in git
96
+ email:
97
+ - cocchi.c@gmail.com
98
+ executables:
99
+ - rails_credentials_git
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".travis.yml"
105
+ - CODE_OF_CONDUCT.md
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/rails_credentials_git
112
+ - lib/rails-credentials-git.rb
113
+ - lib/rails-credentials-git/cli.rb
114
+ - lib/rails-credentials-git/version.rb
115
+ - rails-credentials-git.gemspec
116
+ homepage: https://github.com/ccocchi/rails-credentials-git
117
+ licenses:
118
+ - MIT
119
+ metadata:
120
+ homepage_uri: https://github.com/ccocchi/rails-credentials-git
121
+ source_code_uri: https://github.com/ccocchi/rails-credentials-git
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 2.4.0
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.1.4
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Fastest way to diff your Rails credentials files in git
141
+ test_files: []