rake_secrets 0.1.0.pre.1 → 0.1.0.pre.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rake_secrets/storage/base.rb +24 -0
- data/lib/rake_secrets/storage/in_memory.rb +26 -0
- data/lib/rake_secrets/storage.rb +13 -0
- data/lib/rake_secrets/tasks/generate.rb +29 -0
- data/lib/rake_secrets/tasks.rb +1 -1
- data/lib/rake_secrets/template.rb +24 -0
- data/lib/rake_secrets/transformers/erb_template.rb +18 -0
- data/lib/rake_secrets/transformers/identity.rb +11 -0
- data/lib/rake_secrets/transformers.rb +18 -0
- data/lib/rake_secrets/types/alphabetic.rb +32 -0
- data/lib/rake_secrets/types/alphanumeric.rb +33 -0
- data/lib/rake_secrets/types/character_set.rb +27 -0
- data/lib/rake_secrets/types/constant.rb +15 -0
- data/lib/rake_secrets/types/numeric.rb +22 -0
- data/lib/rake_secrets/types.rb +33 -0
- data/lib/rake_secrets/version.rb +1 -1
- data/lib/rake_secrets.rb +3 -0
- metadata +16 -3
- data/lib/rake_secrets/tasks/placeholder.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74d4dd4e8fc036cfe4489f8998c46d8841b298cdd0b50583c7233e8fdd5d8aed
|
4
|
+
data.tar.gz: b1e2cba8af58326856a87aaaa0cc60d494b4892e52b8be21850b17ba1030156e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da7bd3843a0d2bf0515e6c92f00427d97d3d589f7971c406e8b6ee94e5cd73ca8036a73c856525724a6cc8b416e225eb2cd368af540ba42a99f4123887d5463b
|
7
|
+
data.tar.gz: '080cfd5e18baeee7134bcd6285483b4bfdf0790656842fc28f391e3ec11a34a9ff1f8daf5042bde61077122798008c9cfc0535e5cc65ac0182ab3e04ec73fa12'
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake_factory'
|
4
|
+
|
5
|
+
module RakeSecrets
|
6
|
+
module Storage
|
7
|
+
class UnsupportedOperationError < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
class Base
|
11
|
+
def store(_path, _content)
|
12
|
+
raise(UnsupportedOperationError, '#store not supported.')
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove(_path)
|
16
|
+
raise(UnsupportedOperationError, '#remove not supported.')
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(_path)
|
20
|
+
raise(UnsupportedOperationError, '#get not supported.')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './base'
|
4
|
+
|
5
|
+
module RakeSecrets
|
6
|
+
module Storage
|
7
|
+
class InMemory < Base
|
8
|
+
def initialize(persistence = {})
|
9
|
+
super()
|
10
|
+
@persistence = persistence
|
11
|
+
end
|
12
|
+
|
13
|
+
def store(path, content)
|
14
|
+
@persistence[path] = content
|
15
|
+
end
|
16
|
+
|
17
|
+
def remove(path)
|
18
|
+
@persistence.delete(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(path)
|
22
|
+
@persistence[path]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake_factory'
|
4
|
+
|
5
|
+
require_relative '../transformers'
|
6
|
+
|
7
|
+
module RakeSecrets
|
8
|
+
module Tasks
|
9
|
+
class Generate < RakeFactory::Task
|
10
|
+
default_name :generate
|
11
|
+
default_description(RakeFactory::DynamicValue.new do |t|
|
12
|
+
"Generates and stores the '#{t.id}' secret."
|
13
|
+
end)
|
14
|
+
|
15
|
+
parameter :id, required: true
|
16
|
+
parameter :specification, required: true
|
17
|
+
parameter :backend, required: true
|
18
|
+
parameter :path, required: true
|
19
|
+
parameter :transformer, default: Transformers.identity
|
20
|
+
|
21
|
+
action do
|
22
|
+
puts("Generating '#{id}' secret...")
|
23
|
+
secret = specification.generate
|
24
|
+
transformed = transformer.transform(secret)
|
25
|
+
backend.store(path, transformed)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/rake_secrets/tasks.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module RakeSecrets
|
6
|
+
class Template
|
7
|
+
def self.from_file(path)
|
8
|
+
new(File.read(path))
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(contents)
|
12
|
+
@contents = contents
|
13
|
+
end
|
14
|
+
|
15
|
+
def render(parameters = {})
|
16
|
+
context = Object.new
|
17
|
+
parameters.each do |key, value|
|
18
|
+
context.instance_variable_set("@#{key}", value)
|
19
|
+
end
|
20
|
+
context_binding = context.instance_eval { binding }
|
21
|
+
ERB.new(@contents).result(context_binding)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../template'
|
4
|
+
|
5
|
+
module RakeSecrets
|
6
|
+
module Transformers
|
7
|
+
class ERBTemplate
|
8
|
+
def initialize(opts)
|
9
|
+
super()
|
10
|
+
@template = Template.new(opts[:content])
|
11
|
+
end
|
12
|
+
|
13
|
+
def transform(value)
|
14
|
+
@template.render(value: value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'transformers/erb_template'
|
4
|
+
require_relative 'transformers/identity'
|
5
|
+
|
6
|
+
module RakeSecrets
|
7
|
+
module Transformers
|
8
|
+
class << self
|
9
|
+
def erb_template(opts)
|
10
|
+
ERBTemplate.new(opts)
|
11
|
+
end
|
12
|
+
|
13
|
+
def identity
|
14
|
+
Identity.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './character_set'
|
4
|
+
|
5
|
+
module RakeSecrets
|
6
|
+
module Types
|
7
|
+
class Alphabetic
|
8
|
+
LOWERCASE_CHARACTERS = ('a'..'z').to_a
|
9
|
+
UPPERCASE_CHARACTERS = ('A'..'Z').to_a
|
10
|
+
|
11
|
+
def initialize(opts = {})
|
12
|
+
@delegate = CharacterSet.new(
|
13
|
+
character_set(opts[:case]),
|
14
|
+
length: opts[:length] || 32
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate
|
19
|
+
@delegate.generate
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def character_set(case_type)
|
25
|
+
characters = []
|
26
|
+
characters += UPPERCASE_CHARACTERS if %i[upper both].include?(case_type)
|
27
|
+
characters += LOWERCASE_CHARACTERS unless case_type == :upper
|
28
|
+
characters
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './character_set'
|
4
|
+
|
5
|
+
module RakeSecrets
|
6
|
+
module Types
|
7
|
+
class Alphanumeric
|
8
|
+
LOWERCASE_CHARACTERS = ('a'..'z').to_a
|
9
|
+
UPPERCASE_CHARACTERS = ('A'..'Z').to_a
|
10
|
+
NUMBER_CHARACTERS = ('0'..'9').to_a
|
11
|
+
|
12
|
+
def initialize(opts = {})
|
13
|
+
@delegate = CharacterSet.new(
|
14
|
+
character_set(opts[:case]),
|
15
|
+
length: opts[:length] || 32
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate
|
20
|
+
@delegate.generate
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def character_set(case_type)
|
26
|
+
characters = NUMBER_CHARACTERS
|
27
|
+
characters += UPPERCASE_CHARACTERS if %i[upper both].include?(case_type)
|
28
|
+
characters += LOWERCASE_CHARACTERS unless case_type == :upper
|
29
|
+
characters
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
module RakeSecrets
|
6
|
+
module Types
|
7
|
+
class CharacterSet
|
8
|
+
def initialize(character_set, opts = {})
|
9
|
+
@character_set = character_set
|
10
|
+
@character_count = character_set.length
|
11
|
+
@length = opts[:length] || 32
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate
|
15
|
+
(1..@length)
|
16
|
+
.collect { @character_set[random_index] }
|
17
|
+
.join
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def random_index
|
23
|
+
SecureRandom.random_number(@character_count)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './character_set'
|
4
|
+
|
5
|
+
module RakeSecrets
|
6
|
+
module Types
|
7
|
+
class Numeric
|
8
|
+
NUMBER_CHARACTERS = ('0'..'9').to_a
|
9
|
+
|
10
|
+
def initialize(opts = {})
|
11
|
+
@delegate = CharacterSet.new(
|
12
|
+
NUMBER_CHARACTERS,
|
13
|
+
length: opts[:length] || 32
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate
|
18
|
+
@delegate.generate
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'types/constant'
|
4
|
+
require_relative 'types/character_set'
|
5
|
+
require_relative 'types/alphabetic'
|
6
|
+
require_relative 'types/alphanumeric'
|
7
|
+
require_relative 'types/numeric'
|
8
|
+
|
9
|
+
module RakeSecrets
|
10
|
+
module Types
|
11
|
+
class << self
|
12
|
+
def constant(value)
|
13
|
+
Constant.new(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
def character_set(set, opts = {})
|
17
|
+
CharacterSet.new(set, opts)
|
18
|
+
end
|
19
|
+
|
20
|
+
def alphabetic(opts = {})
|
21
|
+
Alphabetic.new(opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def alphanumeric(opts = {})
|
25
|
+
Alphanumeric.new(opts)
|
26
|
+
end
|
27
|
+
|
28
|
+
def numeric(opts = {})
|
29
|
+
Numeric.new(opts)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/rake_secrets/version.rb
CHANGED
data/lib/rake_secrets.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake_secrets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.
|
4
|
+
version: 0.1.0.pre.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- InfraBlocks Maintainers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored2
|
@@ -55,8 +55,21 @@ files:
|
|
55
55
|
- bin/setup
|
56
56
|
- lib/rake_secrets.rb
|
57
57
|
- lib/rake_secrets/mixins/support.rb
|
58
|
+
- lib/rake_secrets/storage.rb
|
59
|
+
- lib/rake_secrets/storage/base.rb
|
60
|
+
- lib/rake_secrets/storage/in_memory.rb
|
58
61
|
- lib/rake_secrets/tasks.rb
|
59
|
-
- lib/rake_secrets/tasks/
|
62
|
+
- lib/rake_secrets/tasks/generate.rb
|
63
|
+
- lib/rake_secrets/template.rb
|
64
|
+
- lib/rake_secrets/transformers.rb
|
65
|
+
- lib/rake_secrets/transformers/erb_template.rb
|
66
|
+
- lib/rake_secrets/transformers/identity.rb
|
67
|
+
- lib/rake_secrets/types.rb
|
68
|
+
- lib/rake_secrets/types/alphabetic.rb
|
69
|
+
- lib/rake_secrets/types/alphanumeric.rb
|
70
|
+
- lib/rake_secrets/types/character_set.rb
|
71
|
+
- lib/rake_secrets/types/constant.rb
|
72
|
+
- lib/rake_secrets/types/numeric.rb
|
60
73
|
- lib/rake_secrets/version.rb
|
61
74
|
- rake_secrets.gemspec
|
62
75
|
homepage: https://github.com/infrablocks/rake_secrets
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rake_factory'
|
4
|
-
|
5
|
-
module RakeSecrets
|
6
|
-
module Tasks
|
7
|
-
class Placeholder < RakeFactory::Task
|
8
|
-
default_name :placeholder
|
9
|
-
default_description 'Create a placeholder secrets for testing access etc.'
|
10
|
-
|
11
|
-
action do
|
12
|
-
puts('Creating placeholder secret...')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|