file_sv 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/file_sv/global_settings.rb +1 -1
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv/virtual_server.rb +13 -42
- data/lib/file_sv/yaml_processor.rb +2 -2
- data/lib/file_sv.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43425956ba3f1325aa81876eea311cabd364f35ae2735adf79f4cb2daed69dd4
|
4
|
+
data.tar.gz: 629f16289572cb0407ae010a5322f96b07ab6261e591b55dd080f3c9d5e5b58c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec1ca5bffdfcbcc83f94cde7838bc1cdccf844c6c58f45a768203f8d72f2c77e0ce49f706ba7878cb9ba414a58863fb7438e056d76c341a16b258e6de31d3125
|
7
|
+
data.tar.gz: c8e605801443bbd947769ce32bfd376daad28c98bf05dcbca4e1cbbf81a09d1b6a50b9a5f6d0dc1aab29d494f6796bf400bbda023e95ddb8e57c3e241bf16692
|
@@ -18,7 +18,7 @@ class GlobalSettings
|
|
18
18
|
attr_accessor :empty_body_status
|
19
19
|
# @return [Array] Expression representing files to ignore
|
20
20
|
attr_accessor :ignore_files
|
21
|
-
# @return [Boolean] Whether to serve https using self signed certificate
|
21
|
+
# @return [Boolean] Whether to serve https using self signed certificate. Deprecated now
|
22
22
|
attr_accessor :https
|
23
23
|
# @return [String] Path to HTTPS cert
|
24
24
|
attr_accessor :cert
|
data/lib/file_sv/version.rb
CHANGED
@@ -1,53 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "puma"
|
4
4
|
require "sinatra"
|
5
5
|
require "docdsl"
|
6
|
-
require "webrick/https"
|
7
6
|
require "openssl"
|
8
7
|
|
9
8
|
# Virtual server hosting virtual service defined through files
|
10
9
|
class VirtualServer < Sinatra::Base
|
11
|
-
set :server,
|
10
|
+
set :server, :puma
|
11
|
+
enable :logging if ENV['debug'] == "true"
|
12
12
|
set :bind, "0.0.0.0"
|
13
13
|
|
14
14
|
register Sinatra::DocDsl
|
15
15
|
|
16
|
-
if GlobalSettings.https
|
17
|
-
def self.own_certs(webrick_options)
|
18
|
-
puts "Using cert from #{GlobalSettings.cert}"
|
19
|
-
cert = OpenSSL::X509::Certificate.new File.read GlobalSettings.cert
|
20
|
-
pkey = OpenSSL::PKey::RSA.new File.read GlobalSettings.key
|
21
|
-
webrick_options[:SSLCertificate] = cert
|
22
|
-
webrick_options[:SSLPrivateKey] = pkey
|
23
|
-
webrick_options
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.determine_certs(webrick_options)
|
27
|
-
if GlobalSettings.key && GlobalSettings.cert
|
28
|
-
webrick_options = own_certs webrick_options
|
29
|
-
else
|
30
|
-
puts "Using self signed cert"
|
31
|
-
webrick_options[:ServerName] = "localhost"
|
32
|
-
webrick_options[:SSLCertName] = "/CN=localhost"
|
33
|
-
end
|
34
|
-
webrick_options
|
35
|
-
end
|
36
|
-
|
37
|
-
# Run as https with self signed cert
|
38
|
-
def self.run!
|
39
|
-
logger = WEBrick::Log.new(nil, WEBrick::BasicLog::WARN)
|
40
|
-
webrick_options = { Port: port, SSLEnable: true, Logger: logger }
|
41
|
-
webrick_options = determine_certs webrick_options
|
42
|
-
# TODO: Following run does not work on Ruby 3
|
43
|
-
Rack::Handler::WEBrick.run(self, webrick_options) do |server|
|
44
|
-
%i[INT TERM].each { |sig| trap(sig) { server.stop } }
|
45
|
-
server.threaded = settings.threaded if server.respond_to? :threaded=
|
46
|
-
set :running, true
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
16
|
page do
|
52
17
|
title "File SV"
|
53
18
|
header "Service virtualization created from #{Dir.pwd}"
|
@@ -69,11 +34,13 @@ for more details'
|
|
69
34
|
|
70
35
|
# Log endpoint. Return content and status code defined by endpoint
|
71
36
|
# @param [PlannedEndpoint] endpoint Planned endpoint to serve
|
72
|
-
def serve(endpoint, id = nil)
|
73
|
-
message = "Using endpoint based on file #{endpoint.serving_file_name}."
|
37
|
+
def serve(endpoint, id = nil)
|
74
38
|
@id = id
|
75
|
-
|
76
|
-
|
39
|
+
if ENV['debug'] == "true"
|
40
|
+
message = "Using endpoint based on file #{endpoint.serving_file_name}."
|
41
|
+
message += " Using param '#{@id}'" if id
|
42
|
+
puts message
|
43
|
+
end
|
77
44
|
[endpoint.status_code, output_for(endpoint, binding)]
|
78
45
|
end
|
79
46
|
|
@@ -86,11 +53,15 @@ for more details'
|
|
86
53
|
if endpoint_base.path.include? "#{File::Separator}:"
|
87
54
|
send(endpoint_base.method, endpoint_base.path) do |id|
|
88
55
|
endpoint = endpoints.sample
|
56
|
+
@params = params
|
57
|
+
puts "#{endpoint_base.method} #{endpoint_base.path} ?#{@params}"
|
89
58
|
serve endpoint, id
|
90
59
|
end
|
91
60
|
else
|
92
61
|
send(endpoint_base.method, endpoint_base.path) do
|
93
62
|
endpoint = endpoints.sample
|
63
|
+
@params = params
|
64
|
+
puts "#{endpoint_base.method} #{endpoint_base.path} ?#{@params}" unless ENV['ignore_path'] && ("/#{ENV['ignore_path']}" == endpoint_base.path)
|
94
65
|
serve endpoint
|
95
66
|
end
|
96
67
|
end
|
@@ -6,8 +6,8 @@ class YamlProcessor
|
|
6
6
|
# Process YAML file
|
7
7
|
def process(filename)
|
8
8
|
if filename == "/file_sv.yaml"
|
9
|
-
puts "Overriding default config based on #{File.join(Dir.pwd, filename[1
|
10
|
-
load_default_config filename[1
|
9
|
+
puts "Overriding default config based on #{File.join(Dir.pwd, filename[1..])}"
|
10
|
+
load_default_config filename[1..]
|
11
11
|
else
|
12
12
|
puts "Skipping #{filename}"
|
13
13
|
end
|
data/lib/file_sv.rb
CHANGED
@@ -52,7 +52,7 @@ end
|
|
52
52
|
# Set global params based on ENV vars
|
53
53
|
def set_based_on_env_vars
|
54
54
|
GlobalSettings.instance_variables.each do |setting|
|
55
|
-
setting_name = setting.to_s[1
|
55
|
+
setting_name = setting.to_s[1..]
|
56
56
|
if ENV[setting_name]
|
57
57
|
puts "Setting #{setting_name} to #{ENV[setting_name]}"
|
58
58
|
GlobalSettings.send("#{setting_name}=", ENV[setting_name])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_sv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: puma
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '0'
|
83
83
|
description: |-
|
84
84
|
Create a virtual REST service through file structure. Customize it more
|
85
85
|
through ERB and special file names
|