credman 0.0.2.pre.alpha → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/bin/rspec +29 -0
- data/lib/credman/commands.rb +16 -0
- data/lib/credman/delete.rb +56 -0
- data/lib/credman/version.rb +1 -1
- data/lib/credman.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f3f7223fef1b2a86ff1cb2d922ceb13ab7be255564904e3d9c323ea8b01f8f2
|
4
|
+
data.tar.gz: fb0930eea7b736c7205b9d395ea4798bd66bdc6fd16c8a16ffb88e8fbf101112
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cab55b97eac2c2bde4b6a28e2d60866261aedf7359189b2c70c5feb5e8c58d4358ccb096271657532cb1108db5c7887d42044e5bed52aede92faa318363bbab
|
7
|
+
data.tar.gz: 3e1b42772d70645693f918d87da78b9590a54a100b30b195ad284d067112d326bb36944a3a1635ed0d79b44bd1a9c61f6d0718e1512723612ce22d738a7a4b0a
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/lib/credman/commands.rb
CHANGED
@@ -48,6 +48,22 @@ module Credman
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
class Delete < Dry::CLI::Command
|
52
|
+
desc "Delete a key for given environments"
|
53
|
+
|
54
|
+
argument :keys, type: :array, required: true, desc: "keys to delete"
|
55
|
+
|
56
|
+
option :environments,
|
57
|
+
aliases: ["e"],
|
58
|
+
type: :array,
|
59
|
+
default: [],
|
60
|
+
desc: "filter for environments"
|
61
|
+
|
62
|
+
def call(keys:, environments:, **)
|
63
|
+
Credman::Delete.new(environments).perform(keys)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
51
67
|
class Diff < Dry::CLI::Command
|
52
68
|
desc "Show credentials diff between given branch (heroku by default) and current changes"
|
53
69
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Credman
|
2
|
+
class Delete < Credman::Base
|
3
|
+
def perform(keys)
|
4
|
+
abort pastel.red("At least one key required") if keys.empty?
|
5
|
+
|
6
|
+
configs.each do |env, config|
|
7
|
+
puts pastel.green("#{env}:")
|
8
|
+
|
9
|
+
updated_config = config.dup
|
10
|
+
is_updated = false
|
11
|
+
|
12
|
+
keys_with_path = keys.index_with { |key| key.split(".").map(&:to_sym) }
|
13
|
+
keys_with_path.each do |full_key, key_path|
|
14
|
+
if config_has_keys?(config, key_path)
|
15
|
+
is_updated ||= true
|
16
|
+
deep_delete!(updated_config, key_path)
|
17
|
+
print pastel.blue("\t#{full_key}:\t"), pastel.green("✅ deleted\n")
|
18
|
+
else
|
19
|
+
print pastel.blue("\t#{full_key}:\t"), pastel.red("❌ key not found, can't delete\n")
|
20
|
+
end
|
21
|
+
end
|
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
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
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
|
+
def deep_delete!(obj, keys)
|
41
|
+
key = keys.first
|
42
|
+
if keys.length == 1
|
43
|
+
obj.delete(key)
|
44
|
+
else
|
45
|
+
obj[key] = {} unless obj[key]
|
46
|
+
deep_delete!(obj[key], keys.slice(1..-1))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def normalize_new_value(new_value)
|
51
|
+
return if new_value.in?(%w[nil null])
|
52
|
+
|
53
|
+
new_value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/credman/version.rb
CHANGED
data/lib/credman.rb
CHANGED
@@ -10,6 +10,7 @@ require_relative "credman/commands"
|
|
10
10
|
require_relative "credman/get"
|
11
11
|
require_relative "credman/list"
|
12
12
|
require_relative "credman/set"
|
13
|
+
require_relative "credman/delete"
|
13
14
|
require_relative "credman/diff"
|
14
15
|
require_relative "credman/conflicts"
|
15
16
|
require_relative "credman/version"
|
@@ -22,6 +23,7 @@ module Credman
|
|
22
23
|
register "get", Get
|
23
24
|
register "list", List
|
24
25
|
register "set", Set
|
26
|
+
register "delete", Delete
|
25
27
|
register "diff", Diff
|
26
28
|
register "conflicts", Conflicts
|
27
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: credman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Andronov
|
@@ -126,12 +126,14 @@ files:
|
|
126
126
|
- Rakefile
|
127
127
|
- bin/console
|
128
128
|
- bin/credman
|
129
|
+
- bin/rspec
|
129
130
|
- bin/setup
|
130
131
|
- credman.gemspec
|
131
132
|
- lib/credman.rb
|
132
133
|
- lib/credman/base.rb
|
133
134
|
- lib/credman/commands.rb
|
134
135
|
- lib/credman/conflicts.rb
|
136
|
+
- lib/credman/delete.rb
|
135
137
|
- lib/credman/diff.rb
|
136
138
|
- lib/credman/get.rb
|
137
139
|
- lib/credman/list.rb
|
@@ -155,9 +157,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
157
|
version: 2.7.0
|
156
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
159
|
requirements:
|
158
|
-
- - "
|
160
|
+
- - ">="
|
159
161
|
- !ruby/object:Gem::Version
|
160
|
-
version:
|
162
|
+
version: '0'
|
161
163
|
requirements: []
|
162
164
|
rubygems_version: 3.1.6
|
163
165
|
signing_key:
|