file_sv 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/file_sv +3 -1
- data/lib/file_sv/global_settings.rb +8 -0
- data/lib/file_sv/planned_endpoint.rb +1 -1
- data/lib/file_sv/service_loader.rb +3 -1
- data/lib/file_sv/sv_plan.rb +1 -1
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv/virtual_server.rb +37 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb4214e64bca77866967b848fb88c40eabe0a999d03e1ba88e47500662314b44
|
4
|
+
data.tar.gz: de2aa37269d3fc2d22904a1535a2d8e6308f011baae82fd352ee853def74f4d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72685470cd73d2f13d6e0d5894980d7603787204bcd5d454f339f81d105f96f0276b9d32026e3485e02abeb9001fcfe25648d64686fa804c0f57fc5a9df3ec0d
|
7
|
+
data.tar.gz: 786f78f51f7c02605b235c4306b972f67c33cd31c537a1af0ec41b363f5b8c340baee5648f40a3ae9006dc3561783d8dab6086d4412e4844da0515ff5d6175d8
|
data/exe/file_sv
CHANGED
@@ -12,10 +12,12 @@ class Exe < Thor
|
|
12
12
|
ServiceLoader.create_plan_for folder
|
13
13
|
end
|
14
14
|
|
15
|
+
option :crt, default: nil, banner: "HTTPS CRT"
|
16
|
+
option :key, default: nil, banner: "HTTPS key"
|
15
17
|
desc "serve folder", "Serve virtual service based on folder"
|
16
18
|
def serve(folder)
|
17
19
|
plan folder
|
18
|
-
ServiceLoader.serve_plan
|
20
|
+
ServiceLoader.serve_plan options
|
19
21
|
end
|
20
22
|
|
21
23
|
desc "inspect folder", "Inspect details of what's served at folder"
|
@@ -7,6 +7,8 @@ class GlobalSettings
|
|
7
7
|
@empty_body_status = 204
|
8
8
|
|
9
9
|
@ignore_files = "{*.md,Dockerfile,.*}"
|
10
|
+
|
11
|
+
@https = false
|
10
12
|
class << self
|
11
13
|
# @return [String] Default REST method when none specified by filename
|
12
14
|
attr_accessor :default_method
|
@@ -14,6 +16,12 @@ class GlobalSettings
|
|
14
16
|
attr_accessor :empty_body_status
|
15
17
|
# @return [Array] Expression representing files to ignore
|
16
18
|
attr_accessor :ignore_files
|
19
|
+
# @return [Boolean] Whether to serve https using self signed certificate
|
20
|
+
attr_accessor :https
|
21
|
+
# @return [String] Path to HTTPS cert
|
22
|
+
attr_accessor :cert
|
23
|
+
# @return [String] Path to HTTPS key
|
24
|
+
attr_accessor :key
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
@@ -19,9 +19,11 @@ module ServiceLoader
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# Serve plan
|
22
|
-
def serve_plan
|
22
|
+
def serve_plan(thor_options)
|
23
23
|
require "sinatra"
|
24
24
|
require_relative "virtual_server"
|
25
|
+
GlobalSettings.key = thor_options[:key] if thor_options[:key]
|
26
|
+
GlobalSettings.cert = thor_options[:crt] if thor_options[:crt]
|
25
27
|
VirtualServer.run!
|
26
28
|
end
|
27
29
|
end
|
data/lib/file_sv/sv_plan.rb
CHANGED
@@ -15,7 +15,7 @@ class SvPlan
|
|
15
15
|
def create(folder)
|
16
16
|
self.serving_folder = folder
|
17
17
|
puts "Creating service based on files in #{folder}"
|
18
|
-
file_list = Dir.glob("#{folder}/**/*.*") - Dir.glob(GlobalSettings.ignore_files)
|
18
|
+
file_list = Dir.glob("#{folder}/**/*.*") - Dir.glob("#{folder}/#{GlobalSettings.ignore_files}")
|
19
19
|
file_list.each { |file| process_file file }
|
20
20
|
end
|
21
21
|
|
data/lib/file_sv/version.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require "webrick"
|
4
4
|
require "sinatra"
|
5
5
|
require "docdsl"
|
6
|
+
require "webrick/https"
|
7
|
+
require "openssl"
|
6
8
|
|
7
9
|
# Virtual server hosting virtual service defined through files
|
8
10
|
class VirtualServer < Sinatra::Base
|
@@ -11,6 +13,41 @@ class VirtualServer < Sinatra::Base
|
|
11
13
|
|
12
14
|
register Sinatra::DocDsl
|
13
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
|
+
|
14
51
|
page do
|
15
52
|
title "File SV"
|
16
53
|
header "Service virtualization created from #{Dir.pwd}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.1.4
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: REST service virtualisation through file structure.
|