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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af937c9a5fbea99d7a4aaca80b06798d815c10756179009fcc11ac30b7806958
4
- data.tar.gz: b76e39b7f89e8c6ca0a8144ddb7cdcd415809edd7c1f53d0b8d6110cc3260ccd
3
+ metadata.gz: c940578d417b5a01690bd7556fe71200d528d94faa0cbf233d255661ee59bd01
4
+ data.tar.gz: 791cb4520aeafaba912447e0640d649577d0c44fb376fc2ea8e81d500a276560
5
5
  SHA512:
6
- metadata.gz: 316029e4aee29d648f671009258c0de6e922c1f12288b848a974552e4ca46aabe7c5e62956c76d257d86352181af376eb49771d1855908fa2aa3d9618479fa7d
7
- data.tar.gz: 6e380a6ee636e0d4ae291feed8df07236e6da769eff0effe7dcf3bf86714084c6794d6e9e44bd541af92fc23838f907951c8eee767f8cd2d2a875fbfe2bbcfe5
6
+ metadata.gz: cb00673e88937702be516a5be5ba28cbd9249eb15952b1f3a9cc72a0de07f800d7599fdff5a844e261ae158bc5efdb26ae7a8b1a603e15c80d7631852cd5d391
7
+ data.tar.gz: '09ef78c7cb5b84ba01e75a8077acd74f4ce8d59c620f4cd3b06cfa2824095bb5e6c72120927d0b45993e6668f46ae60fe373df0648265879da4c2d29ed396b68'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake_secrets (0.1.0.pre.1)
4
+ rake_secrets (0.1.0.pre.2)
5
5
  colored2 (~> 3.1)
6
6
  rake_factory (= 0.32.0.pre.2)
7
7
 
@@ -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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'storage/in_memory'
4
+
5
+ module RakeSecrets
6
+ module Storage
7
+ class << self
8
+ def in_memory(initial = {})
9
+ InMemory.new(initial)
10
+ end
11
+ end
12
+ end
13
+ 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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'tasks/placeholder'
3
+ require_relative 'tasks/generate'
4
4
 
5
5
  module RakeSecrets
6
6
  module Tasks
@@ -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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RakeSecrets
4
+ module Transformers
5
+ class Identity
6
+ def transform(value)
7
+ value
8
+ end
9
+ end
10
+ end
11
+ 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,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RakeSecrets
4
+ module Types
5
+ class Constant
6
+ def initialize(value)
7
+ @value = value
8
+ end
9
+
10
+ def generate
11
+ @value
12
+ end
13
+ end
14
+ end
15
+ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RakeSecrets
4
- VERSION = '0.1.0.pre.1'
4
+ VERSION = '0.1.0.pre.2'
5
5
  end
data/lib/rake_secrets.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rake_secrets/tasks'
4
+ require 'rake_secrets/storage'
5
+ require 'rake_secrets/types'
6
+ require 'rake_secrets/transformers'
4
7
  require 'rake_secrets/version'
5
8
 
6
9
  module RakeSecrets
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.1
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-06 00:00:00.000000000 Z
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/placeholder.rb
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