file_sv 0.1.13 → 0.2.1
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/version.rb +1 -1
- data/lib/file_sv/virtual_server.rb +23 -11
- data/lib/file_sv.rb +6 -4
- 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: baf2b31a16ce8df2b4d5090be3fb176064c86930518b0c0879eee59fcd95216c
|
4
|
+
data.tar.gz: 78b452772bc26da778f339ab205962ccfb9c8d993d3aab7aff3a31a18cf70103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 930fd5e3ebf4ea16112f353805188367b476aa788bf147d576f6a2dbf8c616849ed951710b471004b006d162ebaf6897ca625fa4ad422c41cfdb7c822cc45698
|
7
|
+
data.tar.gz: aac656a5c5a10c5fc3e56e86978da3b9b60e44a420ae84df7c4dfdc7a17b0005be772d84f5711fc1bb587da5c2dc2e6b77ce7a9b51bbf400f569bc4bf6266b00
|
data/lib/file_sv/version.rb
CHANGED
@@ -8,7 +8,7 @@ require "openssl"
|
|
8
8
|
# Virtual server hosting virtual service defined through files
|
9
9
|
class VirtualServer < Sinatra::Base
|
10
10
|
set :server, :puma
|
11
|
-
enable :logging if ENV[
|
11
|
+
enable :logging if ENV["debug"] == "true"
|
12
12
|
set :bind, "0.0.0.0"
|
13
13
|
|
14
14
|
register Sinatra::DocDsl
|
@@ -33,23 +33,23 @@ for more details'
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def append_content_type(endpoint)
|
36
|
-
if
|
36
|
+
if endpoint.file_path.end_with? ".json"
|
37
37
|
content_type :json
|
38
|
-
elsif endpoint.file_path.end_with?
|
38
|
+
elsif endpoint.file_path.end_with? ".xml"
|
39
39
|
content_type :xml
|
40
|
-
elsif endpoint.file_path.end_with?
|
40
|
+
elsif endpoint.file_path.end_with? ".css"
|
41
41
|
content_type :css
|
42
|
-
elsif endpoint.file_path.end_with?
|
43
|
-
content_type :js
|
42
|
+
elsif endpoint.file_path.end_with? ".js"
|
43
|
+
content_type :js
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
# Log endpoint. Return content and status code defined by endpoint
|
48
48
|
# @param [PlannedEndpoint] endpoint Planned endpoint to serve
|
49
|
-
def serve(endpoint, id = nil)
|
49
|
+
def serve(endpoint, id = nil)
|
50
50
|
@id = id
|
51
51
|
append_content_type(endpoint)
|
52
|
-
if ENV[
|
52
|
+
if ENV["debug"] == "true"
|
53
53
|
message = "Using endpoint based on file #{endpoint.serving_file_name}."
|
54
54
|
message += " Using param '#{@id}'" if id
|
55
55
|
puts message
|
@@ -58,7 +58,7 @@ for more details'
|
|
58
58
|
[endpoint.status_code, output_for(endpoint, binding)]
|
59
59
|
end
|
60
60
|
|
61
|
-
SvPlan.endpoints.each do |
|
61
|
+
SvPlan.endpoints.each do |endpoint_path, endpoint_value|
|
62
62
|
endpoint_value.each do |_method_name, endpoints|
|
63
63
|
endpoint_base = endpoints[0]
|
64
64
|
documentation "Endpoint #{endpoint_base.path}" do
|
@@ -66,19 +66,31 @@ for more details'
|
|
66
66
|
end
|
67
67
|
if endpoint_base.path.include? "#{File::Separator}:"
|
68
68
|
send(endpoint_base.method, endpoint_base.path) do |id|
|
69
|
+
response["Access-Control-Allow-Origin"] = "*"
|
69
70
|
endpoint = endpoints.sample
|
70
71
|
@params = params
|
71
|
-
puts "#{
|
72
|
+
puts "#{request.request_method} #{request.fullpath}"
|
72
73
|
serve endpoint, id
|
73
74
|
end
|
74
75
|
else
|
75
76
|
send(endpoint_base.method, endpoint_base.path) do
|
77
|
+
response["Access-Control-Allow-Origin"] = "*"
|
76
78
|
endpoint = endpoints.sample
|
77
79
|
@params = params
|
78
|
-
|
80
|
+
unless ENV["ignore_path"] && ("/#{ENV["ignore_path"]}" == endpoint_base.path)
|
81
|
+
puts "#{request.request_method} #{request.fullpath}"
|
82
|
+
end
|
79
83
|
serve endpoint
|
80
84
|
end
|
81
85
|
end
|
82
86
|
end
|
87
|
+
# options endpoint for CORS
|
88
|
+
options endpoint_path do
|
89
|
+
puts "options: #{endpoint_path}"
|
90
|
+
response["Allow"] = "*"
|
91
|
+
response["Access-Control-Allow-Origin"] = "*"
|
92
|
+
response["Access-Control-Allow-Methods"] = "*"
|
93
|
+
response["Access-Control-Allow-Headers"] = "*"
|
94
|
+
end
|
83
95
|
end
|
84
96
|
end
|
data/lib/file_sv.rb
CHANGED
@@ -7,6 +7,8 @@ require_relative "file_sv/sv_plan"
|
|
7
7
|
require_relative "file_sv/service_loader"
|
8
8
|
require_relative "file_sv/planned_endpoint"
|
9
9
|
|
10
|
+
ENV["APP_ENV"] ||= "production"
|
11
|
+
|
10
12
|
# Create Service Virtualization from a simple file system
|
11
13
|
module FileSv
|
12
14
|
# General error for FileSv
|
@@ -31,17 +33,17 @@ CONFIG_FILE = "file_sv.yaml"
|
|
31
33
|
# Set values in global settings based on config
|
32
34
|
def load_default_config(file_path)
|
33
35
|
unless File.exist? file_path
|
34
|
-
puts "No config found at #{file_path}" if ENV[
|
36
|
+
puts "No config found at #{file_path}" if ENV["debug"] == "true"
|
35
37
|
return
|
36
38
|
end
|
37
|
-
puts "Loading config from #{file_path}" if ENV[
|
39
|
+
puts "Loading config from #{file_path}" if ENV["debug"] == "true"
|
38
40
|
|
39
41
|
config = YAML.load_file file_path
|
40
42
|
return unless config # Handle empty YAML file
|
41
43
|
|
42
|
-
puts "Config #{config}" if ENV[
|
44
|
+
puts "Config #{config}" if ENV["debug"] == "true"
|
43
45
|
config["global"]&.each do |key, value|
|
44
|
-
puts "Setting #{key} to #{value}" if ENV[
|
46
|
+
puts "Setting #{key} to #{value}" if ENV["debug"] == "true"
|
45
47
|
GlobalSettings.send("#{key}=", value)
|
46
48
|
end
|
47
49
|
|
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.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|