file_sv 0.2.0 → 0.2.1
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/file_sv/planned_endpoint.rb +0 -13
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv/virtual_server.rb +12 -10
- 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
|
@@ -130,19 +130,6 @@ class PlannedEndpoint
|
|
130
130
|
ERB.new(File.read(serving_file_name)).result(binding)
|
131
131
|
end
|
132
132
|
|
133
|
-
# Log when API is called
|
134
|
-
def log_call(params)
|
135
|
-
if params.keys.count > 0
|
136
|
-
show_params = []
|
137
|
-
params.each do |key, value|
|
138
|
-
show_params << "#{key}=#{value}"
|
139
|
-
end
|
140
|
-
"#{self.method} #{self.path}?#{show_params.join('&')}"
|
141
|
-
else
|
142
|
-
"#{self.method} #{self.path}"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
133
|
def short_description
|
147
134
|
desc = self.status_code.to_s
|
148
135
|
desc += " (delay #{self.delay} sec)" if self.delay > 0
|
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
|
@@ -69,7 +69,7 @@ for more details'
|
|
69
69
|
response["Access-Control-Allow-Origin"] = "*"
|
70
70
|
endpoint = endpoints.sample
|
71
71
|
@params = params
|
72
|
-
puts
|
72
|
+
puts "#{request.request_method} #{request.fullpath}"
|
73
73
|
serve endpoint, id
|
74
74
|
end
|
75
75
|
else
|
@@ -77,7 +77,9 @@ for more details'
|
|
77
77
|
response["Access-Control-Allow-Origin"] = "*"
|
78
78
|
endpoint = endpoints.sample
|
79
79
|
@params = params
|
80
|
-
|
80
|
+
unless ENV["ignore_path"] && ("/#{ENV["ignore_path"]}" == endpoint_base.path)
|
81
|
+
puts "#{request.request_method} #{request.fullpath}"
|
82
|
+
end
|
81
83
|
serve endpoint
|
82
84
|
end
|
83
85
|
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.2.
|
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
|