file_sv 0.1.1 → 0.1.2
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 +9 -3
- data/lib/file_sv.rb +9 -6
- data/lib/file_sv/file_sv.ico +0 -0
- data/lib/file_sv/service_loader.rb +6 -0
- data/lib/file_sv/sv_plan.rb +20 -6
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv/virtual_server.rb +22 -0
- data/lib/file_sv/yaml_processor.rb +7 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa3ba8f0ed5971a7bda5814fb1c3905e6705cf2d164f8a13efab46983b31a4fe
|
4
|
+
data.tar.gz: d8e303e7b3170f5435828e0cf4e36507e980e75669526e7ebced88db3d0f394d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 717ee4f0ad3368c5ad27fbe4c751b778cc29359ec79345c143aa0272dbb079deb2e7d5fbdad4d16807b01a0fd39d5dc3764b6592fc5ec88594dbeaa98c1db433
|
7
|
+
data.tar.gz: 0e84459ad829475c060a8947a9526fe8618fcb1bc5e46653da7c7ab65b41d540e050801dc55dc502f550091189d3dd285898a0382896ea14fa5a916e86650959
|
data/exe/file_sv
CHANGED
@@ -18,10 +18,16 @@ class Exe < Thor
|
|
18
18
|
ServiceLoader.serve_plan
|
19
19
|
end
|
20
20
|
|
21
|
-
desc "
|
22
|
-
def
|
21
|
+
desc "inspect folder", "Inspect details of what's served at folder"
|
22
|
+
def inspect(folder)
|
23
23
|
require "file_sv"
|
24
|
-
|
24
|
+
ServiceLoader.inspect folder
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "version", "Version of FileSv"
|
28
|
+
def version
|
29
|
+
require "file_sv/version"
|
30
|
+
puts "FileSv version #{FileSv::VERSION}"
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
data/lib/file_sv.rb
CHANGED
@@ -24,14 +24,15 @@ module FileSv
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
require "yaml"
|
28
27
|
CONFIG_FILE = "file_sv.yaml"
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
|
29
|
+
# Set values in global settings based on config
|
30
|
+
def load_default_config(file_path)
|
31
|
+
require "yaml"
|
32
|
+
if File.exist? file_path
|
33
|
+
config = YAML.load_file file_path
|
33
34
|
config["global"]&.each do |key, value|
|
34
|
-
send("#{key}=", value)
|
35
|
+
GlobalSettings.send("#{key}=", value)
|
35
36
|
end
|
36
37
|
|
37
38
|
FileSv.rest_methods.each do |method, setting_class|
|
@@ -41,3 +42,5 @@ if File.exist? CONFIG_FILE
|
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
45
|
+
|
46
|
+
load_default_config CONFIG_FILE
|
Binary file
|
data/lib/file_sv/sv_plan.rb
CHANGED
@@ -6,7 +6,7 @@ require_relative "file_processor"
|
|
6
6
|
class SvPlan
|
7
7
|
@endpoints = {}
|
8
8
|
class << self
|
9
|
-
# @return [
|
9
|
+
# @return [Hash] Endpoints included in plan. Key - endpoint, value - methods served under it
|
10
10
|
attr_reader :endpoints
|
11
11
|
# @return [String] Folder plan is served from
|
12
12
|
attr_accessor :serving_folder
|
@@ -21,21 +21,35 @@ class SvPlan
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
# Process file, for the most part creating endpoint.method from it
|
24
25
|
def process_file(file)
|
25
26
|
file.slice! serving_folder
|
26
27
|
extension = File.extname(file)
|
27
28
|
case extension
|
28
|
-
when "yaml" then YamlProcessor.process(file)
|
29
|
+
when ".yaml" then YamlProcessor.process(file)
|
29
30
|
else
|
30
31
|
FileProcessor.process(file)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
+
# Show plan
|
36
|
+
def show
|
37
|
+
endpoint_desc = ""
|
38
|
+
endpoints.sort { |a,b| a[0].length - b[0].length }.each do |endpoint, methods|
|
39
|
+
endpoint_desc += "#{endpoint} \n"
|
40
|
+
methods.each do |method_name, endpoints|
|
41
|
+
endpoint_desc += " #{method_name.upcase} (#{endpoints.size} responses)\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
35
45
|
"** VIRTUAL SERVICE PLAN **
|
36
|
-
Serving based on folder: #{serving_folder}
|
37
|
-
|
38
|
-
|
46
|
+
Serving based on folder: #{Dir.pwd}. Related to folder executed: #{serving_folder}
|
47
|
+
#{endpoint_desc}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# Inspect details
|
51
|
+
def inspect
|
52
|
+
"Endpoints: #{endpoints.inspect}"
|
39
53
|
end
|
40
54
|
|
41
55
|
def +(other)
|
data/lib/file_sv/version.rb
CHANGED
@@ -2,21 +2,43 @@
|
|
2
2
|
|
3
3
|
require "webrick"
|
4
4
|
require "sinatra"
|
5
|
+
require "docdsl"
|
5
6
|
|
6
7
|
# Virtual server hosting virtual service defined through files
|
7
8
|
class VirtualServer < Sinatra::Base
|
8
9
|
set :server, "webrick"
|
9
10
|
set :bind, "0.0.0.0"
|
10
11
|
|
12
|
+
register Sinatra::DocDsl
|
13
|
+
|
14
|
+
page do
|
15
|
+
title 'File SV'
|
16
|
+
header "Service virtualization created from #{Dir.pwd}"
|
17
|
+
introduction 'Created using file_sv. See <a href="https://gitlab.com/samuel-garratt/file_sv">File SV</a> for more details'
|
18
|
+
end
|
19
|
+
|
20
|
+
get '/favicon.ico' do
|
21
|
+
send_file File.join(__dir__, 'file_sv.ico')
|
22
|
+
end
|
23
|
+
|
24
|
+
doc_endpoint '/docs'
|
25
|
+
|
11
26
|
SvPlan.endpoints.each do |_endpoint_path, endpoint_value|
|
12
27
|
endpoint_value.each do |_method_name, endpoints|
|
13
28
|
if endpoints.size < 2
|
14
29
|
endpoint = endpoints[0]
|
30
|
+
documentation "Endpoint #{endpoint.path}" do
|
31
|
+
response "1 kind of response"
|
32
|
+
status endpoint.status_code
|
33
|
+
end
|
15
34
|
send(endpoint.method, endpoint.path) do
|
16
35
|
[endpoint.status_code, endpoint.file? ? send_file(endpoint.serving_file_name) : endpoint.content]
|
17
36
|
end
|
18
37
|
else
|
19
38
|
endpoint_base = endpoints[0]
|
39
|
+
documentation "Endpoint #{endpoint_base.path}" do
|
40
|
+
response "#{endpoints.size} kinds of response"
|
41
|
+
end
|
20
42
|
send(endpoint_base.method, endpoint_base.path) do
|
21
43
|
my_points = endpoints
|
22
44
|
endpoint = my_points.sample
|
@@ -3,8 +3,14 @@
|
|
3
3
|
# Process YAML files
|
4
4
|
class YamlProcessor
|
5
5
|
class << self
|
6
|
+
# Process YAML file
|
6
7
|
def process(filename)
|
7
|
-
|
8
|
+
if filename == "/file_sv.yaml"
|
9
|
+
puts "Overriding default config based on #{Dir.pwd}#{filename[1..-1]}"
|
10
|
+
load_default_config filename[1..-1]
|
11
|
+
else
|
12
|
+
puts "Skipping #{filename}"
|
13
|
+
end
|
8
14
|
end
|
9
15
|
end
|
10
16
|
end
|
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.2
|
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-03-
|
11
|
+
date: 2021-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sinatra-docdsl
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: thor
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,6 +93,7 @@ files:
|
|
79
93
|
- exe/file_sv
|
80
94
|
- lib/file_sv.rb
|
81
95
|
- lib/file_sv/file_processor.rb
|
96
|
+
- lib/file_sv/file_sv.ico
|
82
97
|
- lib/file_sv/global_settings.rb
|
83
98
|
- lib/file_sv/planned_endpoint.rb
|
84
99
|
- lib/file_sv/render_file.rb
|