credman 0.0.6 → 0.0.7

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: 7091148f095fc916aa4cf688580c55738c3e5729a151b0cd13641f56f6555800
4
- data.tar.gz: f491e43c418467b63854fe11a796e0bd53a23d32e2bfee1451584a27045b63d7
3
+ metadata.gz: c74165bc022e5e8e8d0db40be010d9baf8933bb62156aa6ac35ea6ac3f1256a5
4
+ data.tar.gz: 3dafb6835263b103cce2382446107276c88286b66518055b17867b95db71cb2d
5
5
  SHA512:
6
- metadata.gz: 5847672f5ff43eccece5a745b247348384feaf4df52d15e84d6a4b37bd50eac8793272abe2231ffe93542be4fde2c6c4db8e23d6851459c4cea63a59230d95ea
7
- data.tar.gz: 835d72fe2686d7aa562c28bbe956d1d867833d0bfb1d1df52b7fa6127a22b3186e48dd756d8bc606a91a99da28994607d7e39a8e418e4868653e0549c3f85f34
6
+ metadata.gz: 8d78cf276672cf343575c884177181dffac89e06ccde37d27955f21186c500e70037cfbad3968e7b889cc5b4cc0cf533fd65100baa666dd114af9e0ff0a1e0fe
7
+ data.tar.gz: 620b1c2d8dd5695b02e4713c3ff66cfa33d0832d00766340e3fa31b39bb3a540202a479e456d10461fba7fbd23965e71ac440eea85a3e4847c7c5f0b2ac079a5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.7] - 2022-11-28
2
+
3
+ - Introduce `init` command (PR #12)
4
+
1
5
  ## [0.0.6] - 2022-09-19
2
6
 
3
7
  - Cover all commands by specs (PR #11)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- credman (0.0.6)
4
+ credman (0.0.7)
5
5
  activesupport (>= 6.0)
6
6
  dry-cli (~> 0.7)
7
7
  hash_diff (~> 1.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- credman (0.0.5)
4
+ credman (0.0.7)
5
5
  activesupport (>= 6.0)
6
6
  dry-cli (~> 0.7)
7
7
  hash_diff (~> 1.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- credman (0.0.5)
4
+ credman (0.0.7)
5
5
  activesupport (>= 6.0)
6
6
  dry-cli (~> 0.7)
7
7
  hash_diff (~> 1.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- credman (0.0.5)
4
+ credman (0.0.7)
5
5
  activesupport (>= 6.0)
6
6
  dry-cli (~> 0.7)
7
7
  hash_diff (~> 1.0)
@@ -13,7 +13,7 @@ GIT
13
13
  PATH
14
14
  remote: ..
15
15
  specs:
16
- credman (0.0.5)
16
+ credman (0.0.7)
17
17
  activesupport (>= 6.0)
18
18
  dry-cli (~> 0.7)
19
19
  hash_diff (~> 1.0)
@@ -1,6 +1,20 @@
1
1
  module Credman
2
2
  module CLI
3
3
  module Commands
4
+ class Init < Dry::CLI::Command
5
+ desc "Create initial config for credman"
6
+
7
+ option :force_rewrite,
8
+ aliases: ["f"],
9
+ type: :boolean,
10
+ default: false,
11
+ desc: "rewrite existing config"
12
+
13
+ def call(force_rewrite:, **)
14
+ Credman::Init.new.perform(force_rewrite)
15
+ end
16
+ end
17
+
4
18
  class Get < Dry::CLI::Command
5
19
  desc "Find keys in credentials files for each environment"
6
20
 
@@ -0,0 +1,49 @@
1
+ require "tty-command"
2
+
3
+ module Credman
4
+ class Init
5
+ attr_reader :config_path
6
+
7
+ def initialize
8
+ @config_path = "config/credman.yml"
9
+ end
10
+
11
+ def perform(force_rewrite)
12
+ if config_exists? && !force_rewrite
13
+ abort "[SKIPPED] config/credman.yml already exist. You can run with `--force-rewrite` option to rewrite it"
14
+ end
15
+
16
+ save_config(available_environments: available_environments, default_diff_branch: default_diff_branch)
17
+ puts "[CREATED] config/credman.yml"
18
+ end
19
+
20
+ private
21
+
22
+ def config_exists?
23
+ File.exist?(config_path)
24
+ end
25
+
26
+ def save_config(**options)
27
+ File.write(config_path, config_file_content(**options))
28
+ end
29
+
30
+ def config_file_content(available_environments:, default_diff_branch:)
31
+ <<~YML
32
+ default_diff_branch: #{default_diff_branch}
33
+ available_environments:
34
+ #{available_environments.map { |env| " - " + env }.join("\n")}
35
+ YML
36
+ end
37
+
38
+ def default_diff_branch
39
+ cmd = TTY::Command.new(pty: true, printer: :null)
40
+ base_branch = cmd.run!("git remote show origin | sed -n '/HEAD branch/s/.*: //p'").out.strip
41
+ base_branch = "main" if base_branch.blank?
42
+ "origin/#{base_branch}"
43
+ end
44
+
45
+ def available_environments
46
+ Dir.glob("./config/credentials/*.yml.enc").map { |filepath| File.basename(filepath, ".yml.enc") }
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module Credman
2
- VERSION = "0.0.6".freeze
2
+ VERSION = "0.0.7".freeze
3
3
  end
data/lib/credman.rb CHANGED
@@ -5,6 +5,7 @@ require "dry/cli"
5
5
  require "pastel"
6
6
  require "hash_diff"
7
7
 
8
+ require_relative "credman/init"
8
9
  require_relative "credman/configuration"
9
10
  module Credman
10
11
  def self.configuration
@@ -29,6 +30,7 @@ module Credman
29
30
  module Commands
30
31
  extend Dry::CLI::Registry
31
32
 
33
+ register "init", Init
32
34
  register "get", Get
33
35
  register "list", List
34
36
  register "set", Set
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Andronov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-19 00:00:00.000000000 Z
11
+ date: 2022-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -177,6 +177,7 @@ files:
177
177
  - lib/credman/delete.rb
178
178
  - lib/credman/diff.rb
179
179
  - lib/credman/get.rb
180
+ - lib/credman/init.rb
180
181
  - lib/credman/list.rb
181
182
  - lib/credman/set.rb
182
183
  - lib/credman/version.rb
@@ -187,7 +188,7 @@ metadata:
187
188
  homepage_uri: https://github.com/Uscreen-video/credman
188
189
  source_code_uri: https://github.com/Uscreen-video/credman
189
190
  changelog_uri: https://github.com/Uscreen-video/credman/blob/main/CHANGELOG.md
190
- post_install_message:
191
+ post_install_message:
191
192
  rdoc_options: []
192
193
  require_paths:
193
194
  - lib
@@ -203,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
204
  version: '0'
204
205
  requirements: []
205
206
  rubygems_version: 3.1.6
206
- signing_key:
207
+ signing_key:
207
208
  specification_version: 4
208
209
  summary: The tool what you miss for managing Rails credentials
209
210
  test_files: []