ruby-ant-server 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ant/client.rb +2 -2
- data/lib/ant/client/format/xml_format.rb +0 -0
- data/lib/ant/client/session/base.rb +17 -0
- data/lib/ant/client/validator/jsend.rb +0 -1
- data/lib/ant/dry/daemon.rb +31 -0
- data/lib/ant/exceptions.rb +2 -0
- data/lib/ant/server/grape.rb +6 -0
- data/lib/ant/server/nanoservice/datasource/exceptions.rb +9 -2
- data/lib/ant/server/nanoservice/datasource/model.rb +3 -2
- data/lib/ant/server/nanoservice/datasource/mongo.rb +0 -0
- data/lib/ant/server/nanoservice/datasource/repository.rb +3 -3
- data/lib/ant/server/nanoservice/factory.rb +6 -3
- data/lib/ant/server/nanoservice/schema.rb +15 -0
- data/lib/ant/server/nanoservice/validator.rb +0 -0
- data/lib/ant/server/nanoservice/validators/date.rb +0 -0
- data/lib/ant/server/nanoservice/validators/numeric.rb +0 -0
- data/lib/ant/server/nanoservice/validators/relation.rb +0 -0
- data/lib/ant/server/nanoservice/validators/text.rb +0 -0
- data/lib/ant/ssl.rb +1 -0
- data/lib/ant/ssl/certificate.rb +51 -0
- data/lib/ant/ssl/configuration.rb +54 -0
- data/lib/ant/ssl/inventory.rb +61 -0
- data/lib/ant/ssl/revocation_list.rb +7 -0
- data/lib/ant/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6befcf2bfdc8e67ce383fb20467d1b1fd2fd608b0e7beac423aed30d7483a6e0
|
4
|
+
data.tar.gz: 5420a89f2112d28f28c6e43cba260b2fbf6a525202e36c56544b5ca8a2453ada
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b4644ce8168d792b9acd7275eb8ea1847d3114643f8362ad608582e94cb3630dae3aa8ae8523ffb8026aeabeaa4e92c27f8b620f4259afd9c2d38ee2a9b4d57
|
7
|
+
data.tar.gz: 883d571e5fe1209590c36cb7c188ce8a4bafd055a0a4552609665d0b98ad4b1c3a9a3410e7b20ba3f94f3628457a5d40a249aea606ef6ef7954e2154f4b9221b
|
data/lib/ant/client.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative '../ant'
|
2
|
+
require_relative 'client/rest_client'
|
File without changes
|
@@ -11,12 +11,29 @@ module Ant
|
|
11
11
|
class Base
|
12
12
|
include HTTParty
|
13
13
|
include BasicAuth
|
14
|
+
|
14
15
|
def initialize(config)
|
15
16
|
@config = config
|
17
|
+
register_certificate
|
18
|
+
register_ca
|
19
|
+
end
|
20
|
+
|
21
|
+
def register_certificate
|
22
|
+
return unless @config[:client_certificate]
|
23
|
+
cert = File.read(@config[:client_certificate])
|
24
|
+
self.class.pkcs12(cert, @config[:client_certificate_pass])
|
25
|
+
end
|
26
|
+
|
27
|
+
def register_ca
|
28
|
+
return unless @config[:ca_validate]
|
29
|
+
puts @config[:ca_validate]
|
30
|
+
self.class.ssl_ca_file(@config[:ca_validate])
|
16
31
|
end
|
17
32
|
|
18
33
|
def configure_request(request)
|
19
34
|
basic_auth(request, @config[:basic_auth]) if @config[:basic_auth]
|
35
|
+
request[:verify] = @config[:verify] if @config.key?(:verify)
|
36
|
+
|
20
37
|
end
|
21
38
|
|
22
39
|
def perform_request(method, endpoint, data)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Ant
|
2
|
+
module DRY
|
3
|
+
class Daemon
|
4
|
+
def initialize(wait_time, attach, proc)
|
5
|
+
@proc = proc
|
6
|
+
@wait_time = wait_time
|
7
|
+
@attach = attach
|
8
|
+
@finish = false
|
9
|
+
end
|
10
|
+
|
11
|
+
def task
|
12
|
+
loop do
|
13
|
+
begin
|
14
|
+
@proc.exec
|
15
|
+
rescue StandarError => ex
|
16
|
+
log_error('Unexpected error', error: ex)
|
17
|
+
end
|
18
|
+
sleep(@wait_time)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
if @attach
|
24
|
+
task
|
25
|
+
else
|
26
|
+
Thread.new(&:task)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/ant/exceptions.rb
CHANGED
@@ -35,6 +35,7 @@ module Ant
|
|
35
35
|
class AntFail < AntBaseException
|
36
36
|
def initialize(message, code = nil, data = {})
|
37
37
|
code ||= self.class.name.split('::').last
|
38
|
+
code = 'BadRequest' if code == 'AntFail'
|
38
39
|
super(message, code, data)
|
39
40
|
end
|
40
41
|
end
|
@@ -46,6 +47,7 @@ module Ant
|
|
46
47
|
class AntError < AntBaseException
|
47
48
|
def initialize(message, code = nil, data = {})
|
48
49
|
code ||= self.class.name.split('::').last
|
50
|
+
code = 'ServerError' if code == 'AntError'
|
49
51
|
super(message, code, data)
|
50
52
|
end
|
51
53
|
end
|
data/lib/ant/server/grape.rb
CHANGED
@@ -29,6 +29,12 @@ module Ant
|
|
29
29
|
error!(response, http_code)
|
30
30
|
end
|
31
31
|
end
|
32
|
+
base.rescue_from(Grape::Exceptions::Base) do |ex|
|
33
|
+
ant_ex = Ant::Exceptions::AntFail.new(ex.message)
|
34
|
+
response = Ant::Server::GrapeDecorator
|
35
|
+
.handler.call(env, :fail, ant_ex)
|
36
|
+
error!(response, 400)
|
37
|
+
end
|
32
38
|
base.rescue_from(:all) do |ex|
|
33
39
|
level = :fatal
|
34
40
|
response = Ant::Server::GrapeDecorator.handler.call(env, level, ex)
|
@@ -5,9 +5,16 @@ module Ant
|
|
5
5
|
module Exceptions
|
6
6
|
class ObjectAlreadyExists < Ant::Exceptions::AntFail
|
7
7
|
attr_reader :id
|
8
|
-
def initialize(id)
|
8
|
+
def initialize(id, object)
|
9
|
+
@id = id
|
10
|
+
super("Object #{id} already exists", nil, object)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ValidationErrors < Ant::Exceptions::AntFail
|
15
|
+
def initialize(data)
|
9
16
|
@id = id
|
10
|
-
super(
|
17
|
+
super('Error while validating object', 'ValidationErrors', data)
|
11
18
|
end
|
12
19
|
end
|
13
20
|
|
@@ -21,11 +21,12 @@ module Ant
|
|
21
21
|
@repository.create(@data)
|
22
22
|
end
|
23
23
|
|
24
|
-
def initialize(data
|
24
|
+
def initialize(data)
|
25
25
|
@data = data
|
26
|
-
@repository = repository || default_repository
|
27
26
|
end
|
28
27
|
|
28
|
+
attr_writer :repository
|
29
|
+
|
29
30
|
def to_json(options)
|
30
31
|
@data.to_json(options)
|
31
32
|
end
|
File without changes
|
@@ -19,15 +19,15 @@ module Ant
|
|
19
19
|
|
20
20
|
def create(id = nil)
|
21
21
|
data = create_initial_object(id)
|
22
|
-
|
22
|
+
existent = exist?(data[@id])
|
23
|
+
raise(ObjectAlreadyExists.new(data[@id], existent)) if existent
|
23
24
|
create_(data)
|
24
25
|
end
|
25
26
|
|
26
27
|
def exist?(id)
|
27
28
|
get(id)
|
28
|
-
true
|
29
29
|
rescue ObjectNotFound
|
30
|
-
|
30
|
+
nil
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -10,15 +10,18 @@ module Ant
|
|
10
10
|
|
11
11
|
def create(data, source = resource(:default))
|
12
12
|
repository = resource(source)
|
13
|
-
model = @model.new(data
|
13
|
+
model = @model.new(data)
|
14
|
+
model.repository = repository
|
14
15
|
model.create
|
15
16
|
model
|
16
17
|
end
|
17
18
|
|
18
19
|
def get(id, source = resource(:default))
|
19
20
|
repository = resource(source)
|
20
|
-
|
21
|
-
@model.new(
|
21
|
+
data = repository.get(id)
|
22
|
+
model = @model.new(data)
|
23
|
+
model.repository = repository
|
24
|
+
model
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/ant/ssl.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'ssl/inventory'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
module Ant
|
4
|
+
module SSL
|
5
|
+
class Certificate
|
6
|
+
attr_reader :cert, :key
|
7
|
+
|
8
|
+
def initialize(config, inventory)
|
9
|
+
@config = config
|
10
|
+
@inventory = inventory
|
11
|
+
@key = OpenSSL::PKey::RSA.new(@config['key_size'])
|
12
|
+
@cert = OpenSSL::X509::Certificate.new
|
13
|
+
@cert.public_key = @key.public_key
|
14
|
+
@extensions = OpenSSL::X509::ExtensionFactory.new
|
15
|
+
@extensions.subject_certificate = @cert
|
16
|
+
end
|
17
|
+
|
18
|
+
def create!
|
19
|
+
# return if File.file?(@config.key_path)
|
20
|
+
@ca = @inventory.ca(@config['parent'])
|
21
|
+
configure_details!
|
22
|
+
configure_extensions!
|
23
|
+
sign!
|
24
|
+
save!
|
25
|
+
end
|
26
|
+
|
27
|
+
def configure_details!
|
28
|
+
@config.configure_cert_details!(@cert)
|
29
|
+
end
|
30
|
+
|
31
|
+
def configure_extensions!
|
32
|
+
@extensions.issuer_certificate = @ca.cert
|
33
|
+
@config.configure_extensions!(@cert, @extensions)
|
34
|
+
end
|
35
|
+
|
36
|
+
def sign!
|
37
|
+
@cert.issuer = @ca.cert.subject
|
38
|
+
@cert.sign(@ca.key, OpenSSL::Digest::SHA256.new)
|
39
|
+
end
|
40
|
+
|
41
|
+
def save!
|
42
|
+
File.write(@config.key_path, @key.to_s)
|
43
|
+
File.write(@config.crt_path, @cert.to_s)
|
44
|
+
end
|
45
|
+
|
46
|
+
def ca_name
|
47
|
+
@config['ca']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Ant
|
2
|
+
module SSL
|
3
|
+
class Configuration
|
4
|
+
ONE_YEAR = 60 * 60 * 24 * 365
|
5
|
+
|
6
|
+
def initialize(root, group, cert)
|
7
|
+
@config = root.merge(group).merge(cert)
|
8
|
+
end
|
9
|
+
|
10
|
+
def saving_directory(type)
|
11
|
+
path = @config['saving_directory']
|
12
|
+
serial = @config['serial']
|
13
|
+
"#{path}/#{serial}.#{type}.pem"
|
14
|
+
end
|
15
|
+
|
16
|
+
def crt_path
|
17
|
+
saving_directory('crt')
|
18
|
+
end
|
19
|
+
|
20
|
+
def key_path
|
21
|
+
saving_directory('key')
|
22
|
+
end
|
23
|
+
|
24
|
+
def subject_string
|
25
|
+
"/C=#{@config['country']}/ST=#{@config['state']}" \
|
26
|
+
"/L=#{@config['city']}/O=#{@config['organization']}" \
|
27
|
+
"/OU=#{@config['team']}/CN=#{@config['name']}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def configure_cert_details!(cert)
|
31
|
+
cert.version = 2
|
32
|
+
cert.serial = @config['serial']
|
33
|
+
cert.subject = OpenSSL::X509::Name.parse(subject_string)
|
34
|
+
cert.not_before = Time.now
|
35
|
+
cert.not_after = cert.not_before + ONE_YEAR * @config['expiration']
|
36
|
+
end
|
37
|
+
|
38
|
+
def configure_extensions!(cert, extension_factory)
|
39
|
+
@config['extensions'].each do |name, details|
|
40
|
+
extension = extension_factory.create_extension(
|
41
|
+
name,
|
42
|
+
details['details'],
|
43
|
+
details['critical']
|
44
|
+
)
|
45
|
+
cert.add_extension(extension)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def [](key)
|
50
|
+
@config[key]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative 'configuration'
|
2
|
+
require_relative 'certificate'
|
3
|
+
require_relative 'revocation_list'
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
module Ant
|
8
|
+
module SSL
|
9
|
+
class Inventory
|
10
|
+
attr_reader :defaults
|
11
|
+
|
12
|
+
def initialize(defaults, auth, clients, servers)
|
13
|
+
@defaults = defaults
|
14
|
+
@authorities = SubInventory.new(auth, self)
|
15
|
+
@clients = SubInventory.new(clients, self)
|
16
|
+
@servers = SubInventory.new(servers, self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_certificates!
|
20
|
+
validate_inventories!
|
21
|
+
create_directory!
|
22
|
+
[@authorities, @clients, @servers].each(&:create_certificates!)
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate_inventories!
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_directory!
|
30
|
+
FileUtils.mkdir_p(@defaults['saving_directory'])
|
31
|
+
end
|
32
|
+
|
33
|
+
def ca(name)
|
34
|
+
@authorities.ca(name)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class SubInventory
|
39
|
+
def initialize(configs, inventory)
|
40
|
+
defaults = configs['defaults']
|
41
|
+
@parent = inventory
|
42
|
+
@certificates = configs['certificates'].map do |cert|
|
43
|
+
configuration = Configuration.new(
|
44
|
+
inventory.defaults,
|
45
|
+
defaults,
|
46
|
+
cert
|
47
|
+
)
|
48
|
+
Certificate.new(configuration, inventory)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_certificates!
|
53
|
+
@certificates.each(&:create!)
|
54
|
+
end
|
55
|
+
|
56
|
+
def ca(name)
|
57
|
+
@certificates.find { |cert| cert.ca_name == name }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/ant/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-ant-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilberto Vargas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cute_logger
|
@@ -232,12 +232,14 @@ files:
|
|
232
232
|
- lib/ant/client/format/format.rb
|
233
233
|
- lib/ant/client/format/json_format.rb
|
234
234
|
- lib/ant/client/format/url_encoded.rb
|
235
|
+
- lib/ant/client/format/xml_format.rb
|
235
236
|
- lib/ant/client/rest_client.rb
|
236
237
|
- lib/ant/client/session/base.rb
|
237
238
|
- lib/ant/client/session/basic_auth.rb
|
238
239
|
- lib/ant/client/validator.rb
|
239
240
|
- lib/ant/client/validator/jsend.rb
|
240
241
|
- lib/ant/client/validator/no_validator.rb
|
242
|
+
- lib/ant/dry/daemon.rb
|
241
243
|
- lib/ant/dry/resource_injector.rb
|
242
244
|
- lib/ant/exceptions.rb
|
243
245
|
- lib/ant/nanoservice.rb
|
@@ -248,11 +250,23 @@ files:
|
|
248
250
|
- lib/ant/server/nanoservice/datasource/id_generators.rb
|
249
251
|
- lib/ant/server/nanoservice/datasource/json_repository.rb
|
250
252
|
- lib/ant/server/nanoservice/datasource/model.rb
|
253
|
+
- lib/ant/server/nanoservice/datasource/mongo.rb
|
251
254
|
- lib/ant/server/nanoservice/datasource/repository.rb
|
252
255
|
- lib/ant/server/nanoservice/datasource/sequel.rb
|
253
256
|
- lib/ant/server/nanoservice/factory.rb
|
257
|
+
- lib/ant/server/nanoservice/schema.rb
|
258
|
+
- lib/ant/server/nanoservice/validator.rb
|
259
|
+
- lib/ant/server/nanoservice/validators/date.rb
|
260
|
+
- lib/ant/server/nanoservice/validators/numeric.rb
|
261
|
+
- lib/ant/server/nanoservice/validators/relation.rb
|
262
|
+
- lib/ant/server/nanoservice/validators/text.rb
|
254
263
|
- lib/ant/server/request_response.rb
|
255
264
|
- lib/ant/server/response.rb
|
265
|
+
- lib/ant/ssl.rb
|
266
|
+
- lib/ant/ssl/certificate.rb
|
267
|
+
- lib/ant/ssl/configuration.rb
|
268
|
+
- lib/ant/ssl/inventory.rb
|
269
|
+
- lib/ant/ssl/revocation_list.rb
|
256
270
|
- lib/ant/version.rb
|
257
271
|
homepage: https://github.com/KueskiEngineering/ruby-ant-server
|
258
272
|
licenses:
|