credman 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6388da4cf0f1f8567e5a14e214e1ed7db9143307d836286050a91fbeeaf03f16
4
- data.tar.gz: 3a8b0e4e839371279e819463c659898556f81d171ba980da006b459f4e7812f4
3
+ metadata.gz: 7091148f095fc916aa4cf688580c55738c3e5729a151b0cd13641f56f6555800
4
+ data.tar.gz: f491e43c418467b63854fe11a796e0bd53a23d32e2bfee1451584a27045b63d7
5
5
  SHA512:
6
- metadata.gz: 605cb0d66f1a5c7889325e80ae3de4f604ab6958a0c08ceef401f35db8b6378d949030d4f58502ce91fe699563a206ffb7dac418315732d544b0d2eecf3cb262
7
- data.tar.gz: 9cd6975ad0f9a1ebdfa69fac1807a27217a0a0fce7c6ebf66ee07c804e4a38e18631c6a0def1732fc4d5d61a817fb65edd62f48a225f875400795ca6b2d2d209
6
+ metadata.gz: 5847672f5ff43eccece5a745b247348384feaf4df52d15e84d6a4b37bd50eac8793272abe2231ffe93542be4fde2c6c4db8e23d6851459c4cea63a59230d95ea
7
+ data.tar.gz: 835d72fe2686d7aa562c28bbe956d1d867833d0bfb1d1df52b7fa6127a22b3186e48dd756d8bc606a91a99da28994607d7e39a8e418e4868653e0549c3f85f34
data/Appraisals ADDED
@@ -0,0 +1,15 @@
1
+ appraise "activesupport-6" do
2
+ gem "activesupport", "~> 6.0.0"
3
+ end
4
+
5
+ appraise "activesupport-6-1" do
6
+ gem "activesupport", "~> 6.1.0"
7
+ end
8
+
9
+ appraise "activesupport-7" do
10
+ gem "activesupport", "~> 7.0.0"
11
+ end
12
+
13
+ appraise "activesupport-master" do
14
+ gem "activesupport", github: "rails/rails", branch: "main"
15
+ end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [0.0.6] - 2022-09-19
2
+
3
+ - Cover all commands by specs (PR #11)
4
+ - Small refactoring with extracting common methods into Credman::Base class (PR #11)
5
+ - default `default_diff_branch` changed to `origin/main` (PR #11)
6
+ - `version` command added (PR #13)
7
+
8
+ ## [0.0.5] - 2022-09-06
9
+
10
+ - Introduce config with `default_diff_branch` and `available_environments` options (PR #9)
11
+ - Setup Github actions (PR #6)
12
+ - small fixes related to linters and specs (PR #6)
13
+
1
14
  ## [0.0.4] - 2022-09-06
2
15
 
3
16
  - fix: list command failure when root key exists (PR #2)
data/Gemfile CHANGED
@@ -4,7 +4,3 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in credman.gemspec
6
6
  gemspec
7
-
8
- gem "rake", "~> 13.0"
9
- gem "rspec", "~> 3.0"
10
- gem "standard", "~> 1.13"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- credman (0.0.4)
4
+ credman (0.0.6)
5
5
  activesupport (>= 6.0)
6
6
  dry-cli (~> 0.7)
7
7
  hash_diff (~> 1.0)
@@ -11,16 +11,20 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (7.0.3.1)
14
+ activesupport (7.0.4)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
16
  i18n (>= 1.6, < 2)
17
17
  minitest (>= 5.1)
18
18
  tzinfo (~> 2.0)
19
+ appraisal (2.4.1)
20
+ bundler
21
+ rake
22
+ thor (>= 0.14.0)
19
23
  ast (2.4.2)
20
24
  concurrent-ruby (1.1.10)
21
25
  diff-lcs (1.5.0)
22
26
  dry-cli (0.7.0)
23
- hash_diff (1.1.0)
27
+ hash_diff (1.1.1)
24
28
  i18n (1.12.0)
25
29
  concurrent-ruby (~> 1.0)
26
30
  json (2.6.2)
@@ -66,6 +70,7 @@ GEM
66
70
  standard (1.13.0)
67
71
  rubocop (= 1.31.2)
68
72
  rubocop-performance (= 1.14.3)
73
+ thor (1.2.1)
69
74
  tty-color (0.6.0)
70
75
  tty-command (0.10.1)
71
76
  pastel (~> 0.8)
@@ -74,9 +79,12 @@ GEM
74
79
  unicode-display_width (2.2.0)
75
80
 
76
81
  PLATFORMS
82
+ ruby
77
83
  x86_64-darwin-21
84
+ x86_64-linux
78
85
 
79
86
  DEPENDENCIES
87
+ appraisal
80
88
  credman!
81
89
  rake (~> 13.0)
82
90
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,6 +1,20 @@
1
+ [![Gem Version](https://badge.fury.io/rb/credman.svg)](https://badge.fury.io/rb/credman)
2
+
1
3
  # Credman
2
4
 
3
- Handy console command for developers to manage Rails credentials.
5
+ Handy console tool for developers to manage Rails credentials.
6
+
7
+ ## Motivation
8
+
9
+ Rails credentials is a nice tool to store encrypted credentials directly in your repo. Starting with Rails 6.0 it brings multi environment credentials feature that allows us to split credentials into separate files.
10
+
11
+ But it also brought a lot of pain for developers:
12
+ - Each enviroment credentials file must have a complete list of all keys. It's easy to forget to add a key into one of the environments (see [set](#credman-set) and [delete](#credman-delete) command)
13
+ - You have to manually open each environment file. It's ok for one file but not for 3 or more. It also brings mistakes you might miss until deploy to production. (see [set](#credman-set) and [delete](#credman-delete) command)
14
+ - Merge conflicts become a hell since files are encrypted (see [conflicts](#credman-conflicts) command)
15
+ - You can't easily see what keys were added/changed/deleted in the current branch (see [diff](#credman-diff) command)
16
+
17
+ This gem is designed to solve all these problems and make life easier for developers who use multi environment credentials.
4
18
 
5
19
  ## Installation
6
20
 
@@ -25,12 +39,51 @@ or
25
39
  bundle exec credman usage
26
40
  ```
27
41
 
42
+ <details>
43
+ <summary>Output</summary>
44
+
45
+ ```
46
+ Commands:
47
+ credman conflicts # Help to resolve merge conflicts for credentials
48
+ credman delete KEYS # Delete keys for given environments
49
+ credman diff [BRANCH] # Show credentials diff between given branch (heroku by default) and current changes
50
+ credman get KEYS # Find keys in credentials files for each environment
51
+ credman list # List of all keys for each environment
52
+ credman set KEY VALUE # Set a value to the key provided for given environments
53
+ ```
54
+
55
+ </details>
56
+
28
57
  Details of any command:
29
58
 
30
59
  ```
31
60
  bundle exec credman set -h
32
61
  ```
33
62
 
63
+ <details>
64
+ <summary>Output</summary>
65
+
66
+ ```
67
+ Command:
68
+ credman set
69
+
70
+ Usage:
71
+ credman set KEY VALUE
72
+
73
+ Description:
74
+ Set a value to the key provided for given environments
75
+
76
+ Arguments:
77
+ KEY # REQUIRED
78
+ VALUE # REQUIRED
79
+
80
+ Options:
81
+ --environments=VALUE1,VALUE2,.., -e VALUE # filter for environments, default: []
82
+ --help, -h
83
+ ```
84
+
85
+ </details>
86
+
34
87
  ### credman list
35
88
  List all your keys for all environments.
36
89
 
@@ -38,48 +91,138 @@ List all your keys for all environments.
38
91
  bundle exec credman list
39
92
  ```
40
93
 
94
+ <details>
95
+ <summary>Output</summary>
96
+
97
+ ```
98
+ development:
99
+ aws.api_key: 123
100
+ ...
101
+ test:
102
+ aws.api_key: nil
103
+ ...
104
+ production:
105
+ aws.api_key: nil
106
+ ...
107
+ ```
108
+ </details>
109
+
41
110
  ### credman get
42
111
  Getting a particular key's values.
43
112
 
44
113
  ```
45
- bundle exec credman get google.maps.api_key github.private_key
114
+ bundle exec credman get google.recaptcha.secret circle_ci.token
46
115
  ```
47
116
 
117
+ <details>
118
+ <summary>Output</summary>
119
+
120
+ ```
121
+ development:
122
+ google.recaptcha.secret: nil
123
+ circle_ci.token: <secret>
124
+ test:
125
+ google.recaptcha.secret: nil
126
+ circle_ci.token: nil
127
+ production:
128
+ google.recaptcha.secret: <secret>
129
+ circle_ci.token: <secret>
130
+ ```
131
+ </details>
132
+
48
133
  ### credman set
49
134
 
50
135
  Add/change a value for a particular key. `-e` attribute is mandatory for this command.
51
136
 
52
137
 
53
138
  ```
54
- bundle exec credman set new_service.super_key new_secret_value -e development,test,staging,production
139
+ bundle exec credman set new_service.super_key new_secret_value -e development,test,production
55
140
  ```
56
141
 
142
+ <details>
143
+ <summary>Output</summary>
144
+
145
+ ```
146
+ development:
147
+ new_service.super_key: ADDED: new_secret_value
148
+ test:
149
+ new_service.super_key: ADDED: new_secret_value
150
+ production:
151
+ new_service.super_key: ADDED: new_secret_value
152
+ ```
153
+ </details>
154
+
57
155
  ### credman delete
58
156
 
59
157
  Delete for keys. `-e` attribute is mandatory for this command.
60
158
 
61
159
  ```
62
- bundle exec credman delete new_service.super_key new_service.another_key -e development,test,staging,production
160
+ bundle exec credman delete new_service.super_key new_service.another_key -e development,test,production
161
+ ```
162
+
163
+ <details>
164
+ <summary>Output</summary>
165
+
166
+ ```
167
+ development:
168
+ new_service.super_key: ✅ deleted
169
+ new_service.another_key: ❌ key not found, can't delete
170
+ test:
171
+ new_service.super_key: ✅ deleted
172
+ new_service.another_key: ❌ key not found, can't delete
173
+ production:
174
+ new_service.super_key: ✅ deleted
175
+ new_service.another_key: ❌ key not found, can't delete
63
176
  ```
177
+ </details>
64
178
 
65
179
  ### credman diff
66
180
 
67
- Shows all keys changed compared with `heroku` branch by default. You can specify any branch from origin you want to. For example `bin/earl diff my_branch`
181
+ Shows all keys changed compared with `main` branch by default.
182
+ You can set the default branch by adding `config/credman.yml` file with `default_diff_branch: your_branch`
183
+ You can specify any branch from origin you want to. For example `credman diff my_branch`
184
+
185
+ ```
186
+ bundle exec credman diff
187
+ ```
188
+
189
+ <details>
190
+ <summary>Output</summary>
68
191
 
69
192
  ```
70
- > bundle exec credman diff
71
193
  development:
72
194
  new_service.super_key: ADDED: "new_secret_value"
73
195
  test:
74
196
  new_service.super_key: ADDED: "new_secret_value"
75
- staging:
76
- new_service.super_key: ADDED: "new_secret_value"
77
197
  production:
78
198
  new_service.super_key: ADDED: "new_secret_value"
79
199
  ```
200
+ </details>
80
201
 
81
202
  ### credman conflicts
82
- Run it if you have merge conflicts in `configs/credentials/*.yml.enc`. That interactive tool will help you resolve the conflict.
203
+
204
+ Run it if you have merge conflicts in `configs/credentials/*.yml.enc`.
205
+ That interactive tool will help you resolve the conflict.
206
+ In most of cases it will just automagically resolve the conflicts.
207
+ In case of a key was changed in both branches it will ask you to choose the correct value.
208
+
209
+ ```
210
+ bundle exec credman conflicts
211
+ ```
212
+
213
+ <details>
214
+ <summary>Output</summary>
215
+
216
+ ```
217
+ development:
218
+ ❗️ The key another_key changed in both branches, their: "another_value", our: "conflicting_value"
219
+ Which one should we use? Please type `their` or `our` to apply particular change or enter to abort.
220
+ > their
221
+ ✅ another_key set as "another_value"
222
+ ✅ Merged config for rspec has been saved
223
+ resolves conflict with user input
224
+ ```
225
+ </details>
83
226
 
84
227
  ## Development
85
228
 
File without changes
@@ -0,0 +1,5 @@
1
+ default_diff_branch: origin/main
2
+ available_environments:
3
+ - development
4
+ - test
5
+ - production
data/credman.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
24
  end
25
25
  end
26
- spec.executables = 'credman'
26
+ spec.executables = "credman"
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_dependency "activesupport", ">= 6.0"
@@ -32,6 +32,8 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "pastel", "~> 0.8"
33
33
  spec.add_dependency "hash_diff", "~> 1.0"
34
34
 
35
+ spec.add_development_dependency "rake", "~> 13.0"
35
36
  spec.add_development_dependency "rspec", "~> 3.0"
36
37
  spec.add_development_dependency "standard", "~> 1.13"
38
+ spec.add_development_dependency "appraisal"
37
39
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 6.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ credman (0.0.5)
5
+ activesupport (>= 6.0)
6
+ dry-cli (~> 0.7)
7
+ hash_diff (~> 1.0)
8
+ pastel (~> 0.8)
9
+ tty-command (~> 0.10)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (6.0.5.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ zeitwerk (~> 2.2, >= 2.2.2)
20
+ appraisal (2.4.1)
21
+ bundler
22
+ rake
23
+ thor (>= 0.14.0)
24
+ ast (2.4.2)
25
+ concurrent-ruby (1.1.10)
26
+ diff-lcs (1.5.0)
27
+ dry-cli (0.7.0)
28
+ hash_diff (1.1.1)
29
+ i18n (1.12.0)
30
+ concurrent-ruby (~> 1.0)
31
+ json (2.6.2)
32
+ minitest (5.16.3)
33
+ parallel (1.22.1)
34
+ parser (3.1.2.1)
35
+ ast (~> 2.4.1)
36
+ pastel (0.8.0)
37
+ tty-color (~> 0.5)
38
+ rainbow (3.1.1)
39
+ rake (13.0.6)
40
+ regexp_parser (2.5.0)
41
+ rexml (3.2.5)
42
+ rspec (3.11.0)
43
+ rspec-core (~> 3.11.0)
44
+ rspec-expectations (~> 3.11.0)
45
+ rspec-mocks (~> 3.11.0)
46
+ rspec-core (3.11.0)
47
+ rspec-support (~> 3.11.0)
48
+ rspec-expectations (3.11.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.11.0)
51
+ rspec-mocks (3.11.1)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.11.0)
54
+ rspec-support (3.11.0)
55
+ rubocop (1.35.1)
56
+ json (~> 2.3)
57
+ parallel (~> 1.10)
58
+ parser (>= 3.1.2.1)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ regexp_parser (>= 1.8, < 3.0)
61
+ rexml (>= 3.2.5, < 4.0)
62
+ rubocop-ast (>= 1.20.1, < 2.0)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (>= 1.4.0, < 3.0)
65
+ rubocop-ast (1.21.0)
66
+ parser (>= 3.1.1.0)
67
+ rubocop-performance (1.14.3)
68
+ rubocop (>= 1.7.0, < 2.0)
69
+ rubocop-ast (>= 0.4.0)
70
+ ruby-progressbar (1.11.0)
71
+ standard (1.16.1)
72
+ rubocop (= 1.35.1)
73
+ rubocop-performance (= 1.14.3)
74
+ thor (1.2.1)
75
+ thread_safe (0.3.6)
76
+ tty-color (0.6.0)
77
+ tty-command (0.10.1)
78
+ pastel (~> 0.8)
79
+ tzinfo (1.2.10)
80
+ thread_safe (~> 0.1)
81
+ unicode-display_width (2.2.0)
82
+ zeitwerk (2.6.0)
83
+
84
+ PLATFORMS
85
+ ruby
86
+ x86_64-darwin-21
87
+ x86_64-linux
88
+
89
+ DEPENDENCIES
90
+ activesupport (~> 6.0.0)
91
+ appraisal
92
+ credman!
93
+ rake (~> 13.0)
94
+ rspec (~> 3.0)
95
+ standard (~> 1.13)
96
+
97
+ BUNDLED WITH
98
+ 2.2.29
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 6.1.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ credman (0.0.5)
5
+ activesupport (>= 6.0)
6
+ dry-cli (~> 0.7)
7
+ hash_diff (~> 1.0)
8
+ pastel (~> 0.8)
9
+ tty-command (~> 0.10)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (6.1.5.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ zeitwerk (~> 2.3)
20
+ appraisal (2.4.1)
21
+ bundler
22
+ rake
23
+ thor (>= 0.14.0)
24
+ ast (2.4.2)
25
+ concurrent-ruby (1.1.10)
26
+ diff-lcs (1.5.0)
27
+ dry-cli (0.7.0)
28
+ hash_diff (1.1.1)
29
+ i18n (1.12.0)
30
+ concurrent-ruby (~> 1.0)
31
+ json (2.6.2)
32
+ minitest (5.16.3)
33
+ parallel (1.22.1)
34
+ parser (3.1.2.1)
35
+ ast (~> 2.4.1)
36
+ pastel (0.8.0)
37
+ tty-color (~> 0.5)
38
+ rainbow (3.1.1)
39
+ rake (13.0.6)
40
+ regexp_parser (2.5.0)
41
+ rexml (3.2.5)
42
+ rspec (3.11.0)
43
+ rspec-core (~> 3.11.0)
44
+ rspec-expectations (~> 3.11.0)
45
+ rspec-mocks (~> 3.11.0)
46
+ rspec-core (3.11.0)
47
+ rspec-support (~> 3.11.0)
48
+ rspec-expectations (3.11.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.11.0)
51
+ rspec-mocks (3.11.1)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.11.0)
54
+ rspec-support (3.11.0)
55
+ rubocop (1.35.1)
56
+ json (~> 2.3)
57
+ parallel (~> 1.10)
58
+ parser (>= 3.1.2.1)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ regexp_parser (>= 1.8, < 3.0)
61
+ rexml (>= 3.2.5, < 4.0)
62
+ rubocop-ast (>= 1.20.1, < 2.0)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (>= 1.4.0, < 3.0)
65
+ rubocop-ast (1.21.0)
66
+ parser (>= 3.1.1.0)
67
+ rubocop-performance (1.14.3)
68
+ rubocop (>= 1.7.0, < 2.0)
69
+ rubocop-ast (>= 0.4.0)
70
+ ruby-progressbar (1.11.0)
71
+ standard (1.16.1)
72
+ rubocop (= 1.35.1)
73
+ rubocop-performance (= 1.14.3)
74
+ thor (1.2.1)
75
+ tty-color (0.6.0)
76
+ tty-command (0.10.1)
77
+ pastel (~> 0.8)
78
+ tzinfo (2.0.5)
79
+ concurrent-ruby (~> 1.0)
80
+ unicode-display_width (2.2.0)
81
+ zeitwerk (2.6.0)
82
+
83
+ PLATFORMS
84
+ ruby
85
+ x86_64-darwin-21
86
+ x86_64-linux
87
+
88
+ DEPENDENCIES
89
+ activesupport (~> 6.1.0)
90
+ appraisal
91
+ credman!
92
+ rake (~> 13.0)
93
+ rspec (~> 3.0)
94
+ standard (~> 1.13)
95
+
96
+ BUNDLED WITH
97
+ 2.2.29
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 7.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ credman (0.0.5)
5
+ activesupport (>= 6.0)
6
+ dry-cli (~> 0.7)
7
+ hash_diff (~> 1.0)
8
+ pastel (~> 0.8)
9
+ tty-command (~> 0.10)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (7.0.3.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ appraisal (2.4.1)
20
+ bundler
21
+ rake
22
+ thor (>= 0.14.0)
23
+ ast (2.4.2)
24
+ concurrent-ruby (1.1.10)
25
+ diff-lcs (1.5.0)
26
+ dry-cli (0.7.0)
27
+ hash_diff (1.1.1)
28
+ i18n (1.12.0)
29
+ concurrent-ruby (~> 1.0)
30
+ json (2.6.2)
31
+ minitest (5.16.3)
32
+ parallel (1.22.1)
33
+ parser (3.1.2.1)
34
+ ast (~> 2.4.1)
35
+ pastel (0.8.0)
36
+ tty-color (~> 0.5)
37
+ rainbow (3.1.1)
38
+ rake (13.0.6)
39
+ regexp_parser (2.5.0)
40
+ rexml (3.2.5)
41
+ rspec (3.11.0)
42
+ rspec-core (~> 3.11.0)
43
+ rspec-expectations (~> 3.11.0)
44
+ rspec-mocks (~> 3.11.0)
45
+ rspec-core (3.11.0)
46
+ rspec-support (~> 3.11.0)
47
+ rspec-expectations (3.11.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.11.0)
50
+ rspec-mocks (3.11.1)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.11.0)
53
+ rspec-support (3.11.0)
54
+ rubocop (1.35.1)
55
+ json (~> 2.3)
56
+ parallel (~> 1.10)
57
+ parser (>= 3.1.2.1)
58
+ rainbow (>= 2.2.2, < 4.0)
59
+ regexp_parser (>= 1.8, < 3.0)
60
+ rexml (>= 3.2.5, < 4.0)
61
+ rubocop-ast (>= 1.20.1, < 2.0)
62
+ ruby-progressbar (~> 1.7)
63
+ unicode-display_width (>= 1.4.0, < 3.0)
64
+ rubocop-ast (1.21.0)
65
+ parser (>= 3.1.1.0)
66
+ rubocop-performance (1.14.3)
67
+ rubocop (>= 1.7.0, < 2.0)
68
+ rubocop-ast (>= 0.4.0)
69
+ ruby-progressbar (1.11.0)
70
+ standard (1.16.1)
71
+ rubocop (= 1.35.1)
72
+ rubocop-performance (= 1.14.3)
73
+ thor (1.2.1)
74
+ tty-color (0.6.0)
75
+ tty-command (0.10.1)
76
+ pastel (~> 0.8)
77
+ tzinfo (2.0.5)
78
+ concurrent-ruby (~> 1.0)
79
+ unicode-display_width (2.2.0)
80
+
81
+ PLATFORMS
82
+ ruby
83
+ x86_64-darwin-21
84
+ x86_64-linux
85
+
86
+ DEPENDENCIES
87
+ activesupport (~> 7.0.0)
88
+ appraisal
89
+ credman!
90
+ rake (~> 13.0)
91
+ rspec (~> 3.0)
92
+ standard (~> 1.13)
93
+
94
+ BUNDLED WITH
95
+ 2.2.29
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", github: "rails/rails", branch: "main"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,103 @@
1
+ GIT
2
+ remote: https://github.com/rails/rails.git
3
+ revision: 9a439f633205af0800f34af32f2122150faa2767
4
+ branch: main
5
+ specs:
6
+ activesupport (7.1.0.alpha)
7
+ concurrent-ruby (~> 1.0, >= 1.0.2)
8
+ connection_pool (>= 2.2.5)
9
+ i18n (>= 1.6, < 2)
10
+ minitest (>= 5.1)
11
+ tzinfo (~> 2.0)
12
+
13
+ PATH
14
+ remote: ..
15
+ specs:
16
+ credman (0.0.5)
17
+ activesupport (>= 6.0)
18
+ dry-cli (~> 0.7)
19
+ hash_diff (~> 1.0)
20
+ pastel (~> 0.8)
21
+ tty-command (~> 0.10)
22
+
23
+ GEM
24
+ remote: https://rubygems.org/
25
+ specs:
26
+ appraisal (2.4.1)
27
+ bundler
28
+ rake
29
+ thor (>= 0.14.0)
30
+ ast (2.4.2)
31
+ concurrent-ruby (1.1.10)
32
+ connection_pool (2.2.5)
33
+ diff-lcs (1.5.0)
34
+ dry-cli (0.7.0)
35
+ hash_diff (1.1.1)
36
+ i18n (1.12.0)
37
+ concurrent-ruby (~> 1.0)
38
+ json (2.6.2)
39
+ minitest (5.16.3)
40
+ parallel (1.22.1)
41
+ parser (3.1.2.1)
42
+ ast (~> 2.4.1)
43
+ pastel (0.8.0)
44
+ tty-color (~> 0.5)
45
+ rainbow (3.1.1)
46
+ rake (13.0.6)
47
+ regexp_parser (2.5.0)
48
+ rexml (3.2.5)
49
+ rspec (3.11.0)
50
+ rspec-core (~> 3.11.0)
51
+ rspec-expectations (~> 3.11.0)
52
+ rspec-mocks (~> 3.11.0)
53
+ rspec-core (3.11.0)
54
+ rspec-support (~> 3.11.0)
55
+ rspec-expectations (3.11.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.11.0)
58
+ rspec-mocks (3.11.1)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.11.0)
61
+ rspec-support (3.11.0)
62
+ rubocop (1.35.1)
63
+ json (~> 2.3)
64
+ parallel (~> 1.10)
65
+ parser (>= 3.1.2.1)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ regexp_parser (>= 1.8, < 3.0)
68
+ rexml (>= 3.2.5, < 4.0)
69
+ rubocop-ast (>= 1.20.1, < 2.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (>= 1.4.0, < 3.0)
72
+ rubocop-ast (1.21.0)
73
+ parser (>= 3.1.1.0)
74
+ rubocop-performance (1.14.3)
75
+ rubocop (>= 1.7.0, < 2.0)
76
+ rubocop-ast (>= 0.4.0)
77
+ ruby-progressbar (1.11.0)
78
+ standard (1.16.1)
79
+ rubocop (= 1.35.1)
80
+ rubocop-performance (= 1.14.3)
81
+ thor (1.2.1)
82
+ tty-color (0.6.0)
83
+ tty-command (0.10.1)
84
+ pastel (~> 0.8)
85
+ tzinfo (2.0.5)
86
+ concurrent-ruby (~> 1.0)
87
+ unicode-display_width (2.2.0)
88
+
89
+ PLATFORMS
90
+ ruby
91
+ x86_64-darwin-21
92
+ x86_64-linux
93
+
94
+ DEPENDENCIES
95
+ activesupport!
96
+ appraisal
97
+ credman!
98
+ rake (~> 13.0)
99
+ rspec (~> 3.0)
100
+ standard (~> 1.13)
101
+
102
+ BUNDLED WITH
103
+ 2.2.29
data/lib/credman/base.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  module Credman
2
2
  class Base
3
- AVAILABLE_ENVIRONMENTS = %i[development test staging production].freeze
4
-
5
3
  def initialize(environment_list)
6
- @environment_list = environment_list.map(&:to_sym).keep_if { |env| env.to_sym.in?(AVAILABLE_ENVIRONMENTS) }
4
+ @environment_list = environment_list.keep_if { |env| env.in?(Credman.config.available_environments) }
7
5
  abort pastel.red("No valid environments specified. Valid example: `-e development,test`") if @environment_list.empty?
8
6
  end
9
7
 
@@ -37,15 +35,35 @@ module Credman
37
35
  config.dig(*dig_keys)&.key?(keys_path.last)
38
36
  end
39
37
 
38
+ def rewrite_config_for(environment, new_config)
39
+ # removes "---\n" in the very beginning
40
+ config_as_string = new_config.deep_stringify_keys.to_yaml[4..]
41
+
42
+ encrypted_configuration(environment).write(config_as_string)
43
+ end
44
+
45
+ def key_for(environment)
46
+ ENV["RAILS_MASTER_KEY"] || Pathname.new("config/credentials/#{environment}.key").binread.strip
47
+ end
48
+
49
+ def decript(key, content)
50
+ ActiveSupport::MessageEncryptor.new([key].pack("H*"), cipher: "aes-128-gcm")
51
+ .decrypt_and_verify(content)
52
+ end
53
+
40
54
  private
41
55
 
42
56
  def config_for(environment)
57
+ encrypted_configuration(environment).config
58
+ end
59
+
60
+ def encrypted_configuration(environment)
43
61
  ActiveSupport::EncryptedConfiguration.new(
44
62
  config_path: "config/credentials/#{environment}.yml.enc",
45
63
  key_path: "config/credentials/#{environment}.key",
46
64
  env_key: "RAILS_MASTER_KEY",
47
65
  raise_if_missing_key: true
48
- ).config
66
+ )
49
67
  end
50
68
  end
51
69
  end
@@ -9,7 +9,7 @@ module Credman
9
9
  option :environments,
10
10
  aliases: ["e"],
11
11
  type: :array,
12
- default: Credman::Base::AVAILABLE_ENVIRONMENTS,
12
+ default: Credman.config.available_environments,
13
13
  desc: "filter for environments"
14
14
 
15
15
  def call(keys:, environments:, **)
@@ -23,7 +23,7 @@ module Credman
23
23
  option :environments,
24
24
  aliases: ["e"],
25
25
  type: :array,
26
- default: Credman::Base::AVAILABLE_ENVIRONMENTS,
26
+ default: Credman.config.available_environments,
27
27
  desc: "filter for environments"
28
28
 
29
29
  def call(environments:, **)
@@ -67,12 +67,12 @@ module Credman
67
67
  class Diff < Dry::CLI::Command
68
68
  desc "Show credentials diff between given branch (heroku by default) and current changes"
69
69
 
70
- argument :branch, type: :string, default: "heroku", required: false
70
+ argument :branch, type: :string, default: Credman.config.default_diff_branch, required: false
71
71
 
72
72
  option :environments,
73
73
  aliases: ["e"],
74
74
  type: :array,
75
- default: Credman::Base::AVAILABLE_ENVIRONMENTS,
75
+ default: Credman.config.available_environments,
76
76
  desc: "filter for environments"
77
77
 
78
78
  def call(branch:, environments:, **)
@@ -86,13 +86,21 @@ module Credman
86
86
  option :environments,
87
87
  aliases: ["e"],
88
88
  type: :array,
89
- default: Credman::Base::AVAILABLE_ENVIRONMENTS,
89
+ default: Credman.config.available_environments,
90
90
  desc: "filter for environments"
91
91
 
92
92
  def call(environments:, **)
93
93
  Credman::Conflicts.new(environments).perform
94
94
  end
95
95
  end
96
+
97
+ class Version < Dry::CLI::Command
98
+ desc "Print current version"
99
+
100
+ def call(*)
101
+ puts Credman::VERSION
102
+ end
103
+ end
96
104
  end
97
105
  end
98
106
  end
@@ -0,0 +1,42 @@
1
+ require "yaml"
2
+
3
+ module Credman
4
+ class Configuration
5
+ include Singleton
6
+
7
+ attr_writer :settings_list
8
+
9
+ def self.add_setting(name, default_value = nil)
10
+ attr_accessor name
11
+ instance.send("#{name}=", default_value)
12
+ instance.settings_list = instance.settings_list.push(name.to_sym)
13
+ end
14
+
15
+ def self.reset
16
+ load __FILE__
17
+ self
18
+ end
19
+
20
+ def settings_list
21
+ @settings_list ||= []
22
+ end
23
+
24
+ def setting_exists?(setting_name)
25
+ settings_list.include?(setting_name)
26
+ end
27
+
28
+ def load_from_yml(config_path = "config/credman.yml")
29
+ return unless File.exist?(config_path)
30
+
31
+ settings = YAML.load_file(config_path)
32
+ return unless settings
33
+
34
+ settings.each do |setting_name, setting_value|
35
+ send("#{setting_name}=", setting_value) if setting_exists?(setting_name.to_sym)
36
+ end
37
+ end
38
+
39
+ add_setting :default_diff_branch, "origin/main"
40
+ add_setting :available_environments, %w[development test production]
41
+ end
42
+ end
@@ -20,9 +20,7 @@ module Credman
20
20
  @merged_config = our_config.deep_merge(their_config)
21
21
  deep_print_diff(HashDiff.diff(their_config, our_config))
22
22
 
23
- # removes "---\n" in the very beginning
24
- merged_config_as_string = @merged_config.deep_stringify_keys.to_yaml[4..]
25
- rewrite_config_for(env, merged_config_as_string)
23
+ rewrite_config_for(env, @merged_config)
26
24
  puts "✅ Merged config for #{env} has been saved"
27
25
  end
28
26
  end
@@ -33,19 +31,8 @@ module Credman
33
31
  deserialize(decript(key_for(environment), encripted_file_content)).deep_symbolize_keys
34
32
  end
35
33
 
36
- def key_for(environment)
37
- Pathname.new("config/credentials/#{environment}.key").binread.strip
38
- end
39
-
40
- def decript(key, content)
41
- ActiveSupport::MessageEncryptor.new([key].pack("H*"), cipher: "aes-128-gcm")
42
- .decrypt_and_verify(content)
43
- end
44
-
45
34
  def deserialize(raw_config)
46
- # rubocop:disable Security/YAMLLoad
47
- YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(raw_config) : YAML.load(raw_config)
48
- # rubocop:enable Security/YAMLLoad
35
+ YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(raw_config) : YAML.safe_load(raw_config)
49
36
  end
50
37
 
51
38
  def deep_print_diff(diff, key_path = [])
@@ -107,14 +94,5 @@ module Credman
107
94
  deep_set!(obj[key], keys.slice(1..-1), value)
108
95
  end
109
96
  end
110
-
111
- def rewrite_config_for(environment, new_config)
112
- ActiveSupport::EncryptedFile.new(
113
- content_path: "config/credentials/#{environment}.yml.enc",
114
- key_path: "config/credentials/#{environment}.key",
115
- env_key: "RAILS_MASTER_KEY",
116
- raise_if_missing_key: true
117
- ).write(new_config)
118
- end
119
97
  end
120
98
  end
@@ -20,23 +20,10 @@ module Credman
20
20
  end
21
21
  end
22
22
 
23
- if is_updated
24
- # removes "---\n" in the very beginning
25
- config_as_string = updated_config.deep_stringify_keys.to_yaml[4..]
26
- rewrite_config_for(env, config_as_string)
27
- end
23
+ rewrite_config_for(env, updated_config) if is_updated
28
24
  end
29
25
  end
30
26
 
31
- def rewrite_config_for(environment, new_config)
32
- ActiveSupport::EncryptedConfiguration.new(
33
- config_path: "config/credentials/#{environment}.yml.enc",
34
- key_path: "config/credentials/#{environment}.key",
35
- env_key: "RAILS_MASTER_KEY",
36
- raise_if_missing_key: true
37
- ).write(new_config)
38
- end
39
-
40
27
  def deep_delete!(obj, keys)
41
28
  key = keys.first
42
29
  if keys.length == 1
data/lib/credman/diff.rb CHANGED
@@ -8,11 +8,11 @@ module Credman
8
8
  configs.each do |env, config|
9
9
  puts pastel.green("#{env}:")
10
10
 
11
- result = cmd.run!("echo `git show origin/#{branch_to_compare}:config/credentials/#{env}.yml.enc`")
11
+ result = cmd.run!("echo `git show #{branch_to_compare}:config/credentials/#{env}.yml.enc`")
12
12
  encripted_file_content = result.out.strip
13
13
 
14
14
  if encripted_file_content.blank?
15
- puts "❗️ Can not find #{env} credentials file in origin/#{branch_to_compare} branch"
15
+ puts "❗️ Can not find #{env} credentials file in #{branch_to_compare} branch"
16
16
  next
17
17
  end
18
18
  branch_config = config_to_compare_for(env, encripted_file_content)
@@ -27,19 +27,8 @@ module Credman
27
27
  deserialize(decript(key_for(environment), encripted_file_content)).deep_symbolize_keys
28
28
  end
29
29
 
30
- def key_for(environment)
31
- Pathname.new("config/credentials/#{environment}.key").binread.strip
32
- end
33
-
34
- def decript(key, content)
35
- ActiveSupport::MessageEncryptor.new([key].pack("H*"), cipher: "aes-128-gcm")
36
- .decrypt_and_verify(content)
37
- end
38
-
39
30
  def deserialize(raw_config)
40
- # rubocop:disable Security/YAMLLoad
41
- YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(raw_config) : YAML.load(raw_config)
42
- # rubocop:enable Security/YAMLLoad
31
+ YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(raw_config) : YAML.safe_load(raw_config)
43
32
  end
44
33
 
45
34
  def deep_print_diff(diff, key_path = [])
data/lib/credman/set.rb CHANGED
@@ -3,6 +3,7 @@ module Credman
3
3
  def perform(key, new_value)
4
4
  key_with_path = key.split(".").map(&:to_sym)
5
5
  new_value = normalize_new_value(new_value)
6
+ abort pastel.red("Invalid key") if key.blank?
6
7
 
7
8
  configs.each do |env, config|
8
9
  puts pastel.green("#{env}:")
@@ -25,22 +26,11 @@ module Credman
25
26
  if update_config
26
27
  updated_config = config.dup
27
28
  deep_set!(updated_config, key_with_path, new_value)
28
- # removes "---\n" in the very beginning
29
- config_as_string = updated_config.deep_stringify_keys.to_yaml[4..]
30
- rewrite_config_for(env, config_as_string)
29
+ rewrite_config_for(env, updated_config)
31
30
  end
32
31
  end
33
32
  end
34
33
 
35
- def rewrite_config_for(environment, new_config)
36
- ActiveSupport::EncryptedConfiguration.new(
37
- config_path: "config/credentials/#{environment}.yml.enc",
38
- key_path: "config/credentials/#{environment}.key",
39
- env_key: "RAILS_MASTER_KEY",
40
- raise_if_missing_key: true
41
- ).write(new_config)
42
- end
43
-
44
34
  def deep_set!(obj, keys, value)
45
35
  key = keys.first
46
36
  if keys.length == 1
@@ -1,3 +1,3 @@
1
1
  module Credman
2
- VERSION = "0.0.4".freeze
2
+ VERSION = "0.0.6".freeze
3
3
  end
data/lib/credman.rb CHANGED
@@ -5,6 +5,15 @@ require "dry/cli"
5
5
  require "pastel"
6
6
  require "hash_diff"
7
7
 
8
+ require_relative "credman/configuration"
9
+ module Credman
10
+ def self.configuration
11
+ Credman::Configuration.instance
12
+ end
13
+ singleton_class.send(:alias_method, :config, :configuration)
14
+ end
15
+ Credman.configuration.load_from_yml
16
+
8
17
  require_relative "credman/base"
9
18
  require_relative "credman/commands"
10
19
  require_relative "credman/get"
@@ -26,6 +35,7 @@ module Credman
26
35
  register "delete", Delete
27
36
  register "diff", Diff
28
37
  register "conflicts", Conflicts
38
+ register "version", Version, aliases: ["v", "-v", "--version"]
29
39
  end
30
40
  end
31
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: credman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Andronov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-06 00:00:00.000000000 Z
11
+ date: 2022-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rspec
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,20 @@ dependencies:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: '1.13'
125
+ - !ruby/object:Gem::Dependency
126
+ name: appraisal
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  description: The tool what you miss for managing Rails credentials
112
140
  email:
113
141
  - dev@uscreen.tv
@@ -118,6 +146,7 @@ extra_rdoc_files: []
118
146
  files:
119
147
  - ".rspec"
120
148
  - ".vscode/settings.json"
149
+ - Appraisals
121
150
  - CHANGELOG.md
122
151
  - Gemfile
123
152
  - Gemfile.lock
@@ -128,10 +157,22 @@ files:
128
157
  - bin/credman
129
158
  - bin/rspec
130
159
  - bin/setup
160
+ - config/credentials/.gitkeep
161
+ - config/credman.yml
131
162
  - credman.gemspec
163
+ - gemfiles/.bundle/config
164
+ - gemfiles/activesupport_6.gemfile
165
+ - gemfiles/activesupport_6.gemfile.lock
166
+ - gemfiles/activesupport_6_1.gemfile
167
+ - gemfiles/activesupport_6_1.gemfile.lock
168
+ - gemfiles/activesupport_7.gemfile
169
+ - gemfiles/activesupport_7.gemfile.lock
170
+ - gemfiles/activesupport_master.gemfile
171
+ - gemfiles/activesupport_master.gemfile.lock
132
172
  - lib/credman.rb
133
173
  - lib/credman/base.rb
134
174
  - lib/credman/commands.rb
175
+ - lib/credman/configuration.rb
135
176
  - lib/credman/conflicts.rb
136
177
  - lib/credman/delete.rb
137
178
  - lib/credman/diff.rb