rake_secrets 0.1.0.pre.2 → 0.1.0.pre.4

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: c940578d417b5a01690bd7556fe71200d528d94faa0cbf233d255661ee59bd01
4
- data.tar.gz: 791cb4520aeafaba912447e0640d649577d0c44fb376fc2ea8e81d500a276560
3
+ metadata.gz: 100abe0dc35580a1e91253c092dcea4d8beb79899f90aa8addf82b6854a6dcb3
4
+ data.tar.gz: 8659c46791c6434d9d187b1f3233e6a25f0f61cc99f9d9182ba616ef950454ed
5
5
  SHA512:
6
- metadata.gz: cb00673e88937702be516a5be5ba28cbd9249eb15952b1f3a9cc72a0de07f800d7599fdff5a844e261ae158bc5efdb26ae7a8b1a603e15c80d7631852cd5d391
7
- data.tar.gz: '09ef78c7cb5b84ba01e75a8077acd74f4ce8d59c620f4cd3b06cfa2824095bb5e6c72120927d0b45993e6668f46ae60fe373df0648265879da4c2d29ed396b68'
6
+ metadata.gz: d43fdad6d0f931f43e5f480db007705f8bc4c62c37824652b8e78dc08b6f4f02dfeddfd9c7f61f97addc6fc0d0cabb86f03949afd1103f027ff5103f9cfcd215
7
+ data.tar.gz: b6116f103ac51326ff0244119710b56d13d706bfd14d624b011624698fa2aa513361dd8c4233bdd3c14e9922173c1e751bcc9c1dac3b681bb7000a63ea7a28f5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake_secrets (0.1.0.pre.2)
4
+ rake_secrets (0.1.0.pre.4)
5
5
  colored2 (~> 3.1)
6
6
  rake_factory (= 0.32.0.pre.2)
7
7
 
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RakeSecrets
4
+ module Errors
5
+ class NoSuchPathError < StandardError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RakeSecrets
4
+ module Errors
5
+ class RemoveError < StandardError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RakeSecrets
4
+ module Errors
5
+ class RetrieveError < StandardError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RakeSecrets
4
+ module Errors
5
+ class StoreError < StandardError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RakeSecrets
4
+ module Errors
5
+ class UnsupportedOperationError < StandardError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'errors/unsupported_operation_error'
4
+ require_relative 'errors/no_such_path_error'
5
+ require_relative 'errors/store_error'
6
+ require_relative 'errors/remove_error'
7
+ require_relative 'errors/retrieve_error'
8
+
9
+ module RakeSecrets
10
+ module Errors
11
+ end
12
+ end
@@ -1,23 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rake_factory'
3
+ require_relative '../errors'
4
4
 
5
5
  module RakeSecrets
6
6
  module Storage
7
- class UnsupportedOperationError < StandardError
8
- end
9
-
10
7
  class Base
11
8
  def store(_path, _content)
12
- raise(UnsupportedOperationError, '#store not supported.')
9
+ raise(Errors::UnsupportedOperationError, '#store not supported.')
13
10
  end
14
11
 
15
12
  def remove(_path)
16
- raise(UnsupportedOperationError, '#remove not supported.')
13
+ raise(Errors::UnsupportedOperationError, '#remove not supported.')
17
14
  end
18
15
 
19
- def get(_path)
20
- raise(UnsupportedOperationError, '#get not supported.')
16
+ def retrieve(_path)
17
+ raise(Errors::UnsupportedOperationError, '#retrieve not supported.')
21
18
  end
22
19
  end
23
20
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ require_relative './base'
6
+ require_relative '../errors'
7
+
8
+ module RakeSecrets
9
+ module Storage
10
+ class FileSystem < Base
11
+ def store(path, content)
12
+ FileUtils.mkdir_p(File.dirname(path))
13
+ File.write(path, content)
14
+ rescue SystemCallError, IOError
15
+ raise(
16
+ RakeSecrets::Errors::StoreError,
17
+ "Failed to store at path: '#{path}'."
18
+ )
19
+ end
20
+
21
+ def remove(path)
22
+ ensure_path_exists(path)
23
+
24
+ File.delete(path)
25
+ rescue SystemCallError
26
+ raise(
27
+ RakeSecrets::Errors::RemoveError,
28
+ "Failed to remove from path: '#{path}'."
29
+ )
30
+ end
31
+
32
+ def retrieve(path)
33
+ ensure_path_exists(path)
34
+
35
+ File.read(path)
36
+ rescue SystemCallError
37
+ raise(
38
+ RakeSecrets::Errors::RetrieveError,
39
+ "Failed to retrieve from path: '#{path}'."
40
+ )
41
+ end
42
+
43
+ private
44
+
45
+ def ensure_path_exists(path)
46
+ return if File.exist?(path)
47
+
48
+ raise(Errors::NoSuchPathError, "Path '#{path}' not in storage.")
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,13 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative './base'
4
+ require_relative '../errors'
4
5
 
5
6
  module RakeSecrets
6
7
  module Storage
7
8
  class InMemory < Base
8
- def initialize(persistence = {})
9
+ def initialize(opts = {})
9
10
  super()
10
- @persistence = persistence
11
+ @persistence = opts[:contents] || {}
11
12
  end
12
13
 
13
14
  def store(path, content)
@@ -18,7 +19,11 @@ module RakeSecrets
18
19
  @persistence.delete(path)
19
20
  end
20
21
 
21
- def get(path)
22
+ def retrieve(path)
23
+ unless @persistence.include?(path)
24
+ raise(Errors::NoSuchPathError, "Path '#{path}' not in storage.")
25
+ end
26
+
22
27
  @persistence[path]
23
28
  end
24
29
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'storage/in_memory'
4
+ require_relative 'storage/file_system'
4
5
 
5
6
  module RakeSecrets
6
7
  module Storage
@@ -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,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
@@ -2,7 +2,9 @@
2
2
 
3
3
  require_relative 'types/constant'
4
4
  require_relative 'types/character_set'
5
+ require_relative 'types/alphabetic'
5
6
  require_relative 'types/alphanumeric'
7
+ require_relative 'types/numeric'
6
8
 
7
9
  module RakeSecrets
8
10
  module Types
@@ -15,9 +17,17 @@ module RakeSecrets
15
17
  CharacterSet.new(set, opts)
16
18
  end
17
19
 
20
+ def alphabetic(opts = {})
21
+ Alphabetic.new(opts)
22
+ end
23
+
18
24
  def alphanumeric(opts = {})
19
25
  Alphanumeric.new(opts)
20
26
  end
27
+
28
+ def numeric(opts = {})
29
+ Numeric.new(opts)
30
+ end
21
31
  end
22
32
  end
23
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RakeSecrets
4
- VERSION = '0.1.0.pre.2'
4
+ VERSION = '0.1.0.pre.4'
5
5
  end
data/lib/rake_secrets.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rake_secrets/errors'
3
4
  require 'rake_secrets/tasks'
4
5
  require 'rake_secrets/storage'
5
6
  require 'rake_secrets/types'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake_secrets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.2
4
+ version: 0.1.0.pre.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfraBlocks Maintainers
@@ -54,9 +54,16 @@ files:
54
54
  - bin/console
55
55
  - bin/setup
56
56
  - lib/rake_secrets.rb
57
+ - lib/rake_secrets/errors.rb
58
+ - lib/rake_secrets/errors/no_such_path_error.rb
59
+ - lib/rake_secrets/errors/remove_error.rb
60
+ - lib/rake_secrets/errors/retrieve_error.rb
61
+ - lib/rake_secrets/errors/store_error.rb
62
+ - lib/rake_secrets/errors/unsupported_operation_error.rb
57
63
  - lib/rake_secrets/mixins/support.rb
58
64
  - lib/rake_secrets/storage.rb
59
65
  - lib/rake_secrets/storage/base.rb
66
+ - lib/rake_secrets/storage/file_system.rb
60
67
  - lib/rake_secrets/storage/in_memory.rb
61
68
  - lib/rake_secrets/tasks.rb
62
69
  - lib/rake_secrets/tasks/generate.rb
@@ -65,9 +72,11 @@ files:
65
72
  - lib/rake_secrets/transformers/erb_template.rb
66
73
  - lib/rake_secrets/transformers/identity.rb
67
74
  - lib/rake_secrets/types.rb
75
+ - lib/rake_secrets/types/alphabetic.rb
68
76
  - lib/rake_secrets/types/alphanumeric.rb
69
77
  - lib/rake_secrets/types/character_set.rb
70
78
  - lib/rake_secrets/types/constant.rb
79
+ - lib/rake_secrets/types/numeric.rb
71
80
  - lib/rake_secrets/version.rb
72
81
  - rake_secrets.gemspec
73
82
  homepage: https://github.com/infrablocks/rake_secrets