cryptoform 0.2.0 → 0.4.0

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: f0f9f5718fd04bc8d3b41709ab275e3c3149c687a05620d08befcfe6ab142465
4
- data.tar.gz: e1007775f8a6ac33000f526f99f9704339e715c133b663a0c29ba00d625acfa3
3
+ metadata.gz: 2c6cc60c333e671e55fbfd296176c2ced70ac3b4fcb02123e1978935ee6de35e
4
+ data.tar.gz: 21c722a203ce621da18fea553a8c1723aa9c4b3357a562aa17a3c1b3d71442dc
5
5
  SHA512:
6
- metadata.gz: 24159b9944f41adae6d9a040531d6470dd5bac1a3de7d08e7d736ece145c7e4f827f3cb205bcc99179005b4cbf04ff21ab6556ee89ad043b5b99946ab5924853
7
- data.tar.gz: 5bb71e41df20928ec480e2eb0c497646e7b43b7087a083900e0f2ddef3926237cc6f95aea6d4f9d04bd0b436309e7b6fe712423c8f1cb67817edbd10c513f8d1
6
+ metadata.gz: ad46477f8340822cb0ece4cedb09f901e9bc12d35c463bb24cc55905d771b65c4fd19fc6c3cec8c8fd555581cd7b61de8b2d208f6615241d00280118960f47fb
7
+ data.tar.gz: 78ae779546f83c481e1c8566c33576c6996a93be972b5d33831616bc3141e7fef6bf16b11fcfe102020ec5140918d74ec9b71c22944d2777327c4eb69894f6bd
data/Cryptofile CHANGED
@@ -2,12 +2,7 @@
2
2
 
3
3
  port 3000
4
4
 
5
- state :state1 do
6
- storage_backend :file, name: "state1.tfstate.enc"
7
- encryption_backend :lockbox, key: -> { ENV.fetch("CRYPTOFORM_KEY") }
8
- end
9
-
10
- state :state2 do
11
- storage_backend :file, name: "state2.tfstate.enc"
5
+ state :state do
6
+ storage_backend :file
12
7
  encryption_backend :lockbox, key: -> { ENV.fetch("CRYPTOFORM_KEY") }
13
8
  end
data/Gemfile.lock CHANGED
@@ -1,50 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cryptoform (0.2.0)
5
- async-http (~> 0.69)
4
+ cryptoform (0.4.0)
6
5
  base64 (~> 0.2)
7
6
  lockbox (~> 1.3)
7
+ rackup (~> 2.1)
8
+ sinatra (~> 4.0)
9
+ sinatra-contrib (~> 4.0)
10
+ webrick (~> 1.8)
8
11
  zeitwerk (~> 2.6)
9
12
 
10
13
  GEM
11
14
  remote: https://rubygems.org/
12
15
  specs:
13
16
  ast (2.4.2)
14
- async (2.12.1)
15
- console (~> 1.25, >= 1.25.2)
16
- fiber-annotation
17
- io-event (~> 1.6, >= 1.6.5)
18
- async-http (0.69.0)
19
- async (>= 2.10.2)
20
- async-pool (~> 0.7)
21
- io-endpoint (~> 0.11)
22
- io-stream (~> 0.4)
23
- protocol-http (~> 0.26)
24
- protocol-http1 (~> 0.19)
25
- protocol-http2 (~> 0.18)
26
- traces (>= 0.10)
27
- async-pool (0.7.0)
28
- async (>= 1.25)
29
17
  backport (1.2.0)
30
18
  base64 (0.2.0)
31
19
  benchmark (0.3.0)
32
20
  childprocess (5.0.0)
33
- console (1.25.2)
34
- fiber-annotation
35
- fiber-local (~> 1.1)
36
- json
37
21
  diff-lcs (1.5.1)
38
22
  docile (1.4.0)
39
23
  e2mmap (0.1.0)
40
- fiber-annotation (0.2.0)
41
- fiber-local (1.1.0)
42
- fiber-storage
43
- fiber-storage (0.1.2)
44
24
  iniparse (1.5.0)
45
- io-endpoint (0.11.0)
46
- io-event (1.6.5)
47
- io-stream (0.4.0)
48
25
  jaro_winkler (1.6.0)
49
26
  json (2.7.2)
50
27
  kramdown (2.4.0)
@@ -54,6 +31,9 @@ GEM
54
31
  language_server-protocol (3.17.0.3)
55
32
  lockbox (1.3.3)
56
33
  mini_portile2 (2.8.7)
34
+ multi_json (1.15.0)
35
+ mustermann (3.0.0)
36
+ ruby2_keywords (~> 0.0.1)
57
37
  nokogiri (1.16.6)
58
38
  mini_portile2 (~> 2.8.2)
59
39
  racc (~> 1.4)
@@ -67,14 +47,16 @@ GEM
67
47
  parser (3.3.4.0)
68
48
  ast (~> 2.4.1)
69
49
  racc
70
- protocol-hpack (1.4.3)
71
- protocol-http (0.26.8)
72
- protocol-http1 (0.19.1)
73
- protocol-http (~> 0.22)
74
- protocol-http2 (0.18.0)
75
- protocol-hpack (~> 1.4)
76
- protocol-http (~> 0.18)
77
50
  racc (1.8.0)
51
+ rack (3.1.7)
52
+ rack-protection (4.0.0)
53
+ base64 (>= 0.1.0)
54
+ rack (>= 3.0.0, < 4)
55
+ rack-session (2.0.0)
56
+ rack (>= 3.0.0)
57
+ rackup (2.1.0)
58
+ rack (>= 3)
59
+ webrick (~> 1.8)
78
60
  rainbow (3.1.1)
79
61
  rake (13.2.1)
80
62
  rbs (2.8.4)
@@ -119,12 +101,25 @@ GEM
119
101
  rubocop-rspec (3.0.3)
120
102
  rubocop (~> 1.61)
121
103
  ruby-progressbar (1.13.0)
104
+ ruby2_keywords (0.0.5)
122
105
  simplecov (0.22.0)
123
106
  docile (~> 1.1)
124
107
  simplecov-html (~> 0.11)
125
108
  simplecov_json_formatter (~> 0.1)
126
109
  simplecov-html (0.12.3)
127
110
  simplecov_json_formatter (0.1.4)
111
+ sinatra (4.0.0)
112
+ mustermann (~> 3.0)
113
+ rack (>= 3.0.0, < 4)
114
+ rack-protection (= 4.0.0)
115
+ rack-session (>= 2.0.0, < 3)
116
+ tilt (~> 2.0)
117
+ sinatra-contrib (4.0.0)
118
+ multi_json (>= 0.0.2)
119
+ mustermann (~> 3.0)
120
+ rack-protection (= 4.0.0)
121
+ sinatra (= 4.0.0)
122
+ tilt (~> 2.0)
128
123
  solargraph (0.50.0)
129
124
  backport (~> 1.2)
130
125
  benchmark
@@ -144,8 +139,8 @@ GEM
144
139
  strscan (3.1.0)
145
140
  thor (1.3.1)
146
141
  tilt (2.4.0)
147
- traces (0.11.1)
148
142
  unicode-display_width (2.5.0)
143
+ webrick (1.8.1)
149
144
  yard (0.9.36)
150
145
  zeitwerk (2.6.16)
151
146
 
data/README.md CHANGED
@@ -33,7 +33,7 @@ bother configuring an external state store.
33
33
  ```hcl
34
34
  terraform {
35
35
  backend "http" {
36
- address = "http://127.0.0.1:3000/state"
36
+ address = "http://127.0.0.1:3000/states/state"
37
37
  }
38
38
  }
39
39
  ```
@@ -52,7 +52,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
52
52
 
53
53
  ## Contributing
54
54
 
55
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cryptoform. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/cryptoform/blob/main/CODE_OF_CONDUCT.md).
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zhulik/cryptoform. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/zhulik/cryptoform/blob/main/CODE_OF_CONDUCT.md).
56
56
 
57
57
  ## License
58
58
 
@@ -60,4 +60,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
60
60
 
61
61
  ## Code of Conduct
62
62
 
63
- Everyone interacting in the Cryptoform project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cryptoform/blob/main/CODE_OF_CONDUCT.md).
63
+ Everyone interacting in the Cryptoform project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zhulik/cryptoform/blob/main/CODE_OF_CONDUCT.md).
data/exe/cryptoform CHANGED
@@ -3,10 +3,4 @@
3
3
 
4
4
  require "cryptoform"
5
5
 
6
- begin
7
- Sync do
8
- Cryptoform.run("Cryptofile")
9
- end
10
- rescue Interrupt
11
- puts("Interrupted")
12
- end
6
+ Cryptoform.run("Cryptofile")
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Cryptoform::Application < Sinatra::Application
4
+ set :show_exceptions, false
5
+
6
+ def initialize(config)
7
+ super
8
+ @states = config.states
9
+ end
10
+
11
+ get "/states/:name" do
12
+ state = state_config.encryption_backend.decrypt(state_config.storage_backend.read)
13
+ json(state)
14
+ end
15
+
16
+ post "/states/:name" do
17
+ state = JSON.parse(request.body.read)
18
+ state_config.storage_backend.write(state_config.encryption_backend.encrypt(state))
19
+ json(state)
20
+ end
21
+
22
+ error Cryptoform::StateMissingError do |e|
23
+ status 404
24
+ json(error: e.message)
25
+ end
26
+
27
+ error Sinatra::NotFound do |e|
28
+ status 404
29
+ json(error: e.message)
30
+ end
31
+
32
+ private
33
+
34
+ def state_config
35
+ name = params[:name].to_sym
36
+ @states[name] || raise(Sinatra::NotFound, "state #{name} is not configured in Cryptofile")
37
+ end
38
+ end
@@ -2,55 +2,20 @@
2
2
 
3
3
  class Cryptoform::Server
4
4
  def initialize(config)
5
- @config = config
6
- end
7
-
8
- def run
9
- logger.info { "Cryptoform is listening on #{endpoint.url}..." }
10
- Async::HTTP::Server.for(endpoint) do |request|
11
- log_request(request) { handle_request(request) }
12
- end.run
13
- end
14
-
15
- private
16
-
17
- def handle_request(request) # rubocop:disable Metrics/AbcSize
18
- name = request.path.split("/")&.[](1)&.to_sym
19
- return ::Protocol::HTTP::Response[404, {}, []] unless @config.states.key?(name)
20
-
21
- handler_name = :"#{request.method.downcase}_state"
22
- return ::Protocol::HTTP::Response[405, {}, []] unless respond_to?(handler_name, true)
23
-
24
- send(handler_name, @config.states[name], request:)
25
- rescue Cryptoform::StateMissingError
26
- ::Protocol::HTTP::Response[404, {}, []]
27
- rescue StandardError => e
28
- logger.error(e)
29
- ::Protocol::HTTP::Response[500, {}, []]
30
- end
5
+ @server = WEBrick::HTTPServer.new(
6
+ Port: config.port,
7
+ BindAddress: "0.0.0.0",
8
+ AccessLog: [
9
+ [$stdout, WEBrick::AccessLog::COMMON_LOG_FORMAT],
10
+ [$stdout, WEBrick::AccessLog::REFERER_LOG_FORMAT]
11
+ ]
12
+ )
13
+ trap("INT") { @server.shutdown }
31
14
 
32
- def get_state(state_config, *)
33
- state = state_config.encryption_backend.decrypt(state_config.storage_backend.read)
34
- ::Protocol::HTTP::Response[200, {}, [JSON.pretty_generate(state)]]
15
+ @server.mount("/", Rackup::Handler::WEBrick, Cryptoform::Application.new(config))
35
16
  end
36
17
 
37
- def post_state(state_config, request:)
38
- state_config.storage_backend.write(state_config.encryption_backend.encrypt(request.body.read))
39
-
40
- ::Protocol::HTTP::Response[201, {}, []]
41
- end
42
-
43
- def logger
44
- @logger ||= Logger.new($stdout)
45
- end
46
-
47
- def endpoint
48
- @endpoint ||= Async::HTTP::Endpoint.parse("http://localhost:#{@config.port}")
49
- end
50
-
51
- def log_request(request)
52
- yield.tap do |response|
53
- logger.info { "#{request.method} #{request.path}: #{response.status}" }
54
- end
18
+ def run
19
+ @server.start
55
20
  end
56
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cryptoform
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/cryptoform.rb CHANGED
@@ -4,7 +4,10 @@ require "zeitwerk"
4
4
  require "logger"
5
5
 
6
6
  require "lockbox"
7
- require "async/http"
7
+ require "webrick"
8
+ require "rackup"
9
+ require "sinatra"
10
+ require "sinatra/json"
8
11
 
9
12
  loader = Zeitwerk::Loader.for_gem
10
13
 
data/terraform/backend.tf CHANGED
@@ -1,5 +1,5 @@
1
1
  terraform {
2
2
  backend "http" {
3
- address = "http://127.0.0.1:3000/state1"
3
+ address = "http://127.0.0.1:3000/states/state"
4
4
  }
5
5
  }
metadata CHANGED
@@ -1,57 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptoform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Sinyavskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-13 00:00:00.000000000 Z
11
+ date: 2024-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: async-http
14
+ name: base64
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.69'
19
+ version: '0.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.69'
26
+ version: '0.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: base64
28
+ name: lockbox
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
33
+ version: '1.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.2'
40
+ version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
- name: lockbox
42
+ name: rackup
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.3'
47
+ version: '2.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.3'
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra-contrib
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webrick
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.8'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.8'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: zeitwerk
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +129,7 @@ files:
87
129
  - Rakefile
88
130
  - exe/cryptoform
89
131
  - lib/cryptoform.rb
132
+ - lib/cryptoform/application.rb
90
133
  - lib/cryptoform/config/builder.rb
91
134
  - lib/cryptoform/config/state_config_builder.rb
92
135
  - lib/cryptoform/encryption_backends/backend.rb