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 +4 -4
- data/Cryptofile +2 -7
- data/Gemfile.lock +31 -36
- data/README.md +3 -3
- data/exe/cryptoform +1 -7
- data/lib/cryptoform/application.rb +38 -0
- data/lib/cryptoform/server.rb +12 -47
- data/lib/cryptoform/version.rb +1 -1
- data/lib/cryptoform.rb +4 -1
- data/terraform/backend.tf +1 -1
- metadata +54 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c6cc60c333e671e55fbfd296176c2ced70ac3b4fcb02123e1978935ee6de35e
|
4
|
+
data.tar.gz: 21c722a203ce621da18fea553a8c1723aa9c4b3357a562aa17a3c1b3d71442dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 :
|
6
|
-
storage_backend :file
|
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.
|
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/
|
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/
|
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
@@ -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
|
data/lib/cryptoform/server.rb
CHANGED
@@ -2,55 +2,20 @@
|
|
2
2
|
|
3
3
|
class Cryptoform::Server
|
4
4
|
def initialize(config)
|
5
|
-
@
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
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
|
38
|
-
|
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
|
data/lib/cryptoform/version.rb
CHANGED
data/lib/cryptoform.rb
CHANGED
data/terraform/backend.tf
CHANGED
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.
|
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-
|
11
|
+
date: 2024-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: base64
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
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.
|
26
|
+
version: '0.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: lockbox
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
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: '
|
40
|
+
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rackup
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1
|
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
|
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
|