rake_secrets 0.1.0.pre.1 → 0.1.0.pre.2
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/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.rb +23 -0
- data/lib/rake_secrets/version.rb +1 -1
- data/lib/rake_secrets.rb +3 -0
- metadata +14 -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: c940578d417b5a01690bd7556fe71200d528d94faa0cbf233d255661ee59bd01
|
4
|
+
data.tar.gz: 791cb4520aeafaba912447e0640d649577d0c44fb376fc2ea8e81d500a276560
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb00673e88937702be516a5be5ba28cbd9249eb15952b1f3a9cc72a0de07f800d7599fdff5a844e261ae158bc5efdb26ae7a8b1a603e15c80d7631852cd5d391
|
7
|
+
data.tar.gz: '09ef78c7cb5b84ba01e75a8077acd74f4ce8d59c620f4cd3b06cfa2824095bb5e6c72120927d0b45993e6668f46ae60fe373df0648265879da4c2d29ed396b68'
|
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,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,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'types/constant'
|
4
|
+
require_relative 'types/character_set'
|
5
|
+
require_relative 'types/alphanumeric'
|
6
|
+
|
7
|
+
module RakeSecrets
|
8
|
+
module Types
|
9
|
+
class << self
|
10
|
+
def constant(value)
|
11
|
+
Constant.new(value)
|
12
|
+
end
|
13
|
+
|
14
|
+
def character_set(set, opts = {})
|
15
|
+
CharacterSet.new(set, opts)
|
16
|
+
end
|
17
|
+
|
18
|
+
def alphanumeric(opts = {})
|
19
|
+
Alphanumeric.new(opts)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
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.2
|
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,19 @@ 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/alphanumeric.rb
|
69
|
+
- lib/rake_secrets/types/character_set.rb
|
70
|
+
- lib/rake_secrets/types/constant.rb
|
60
71
|
- lib/rake_secrets/version.rb
|
61
72
|
- rake_secrets.gemspec
|
62
73
|
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
|