file_sv 0.1.8 → 0.1.10
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/exe/file_sv +0 -0
- data/lib/file_sv/service_loader.rb +1 -1
- data/lib/file_sv/sv_plan.rb +6 -1
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv/virtual_server.rb +9 -0
- data/lib/file_sv/yaml_processor.rb +16 -16
- data/lib/file_sv.rb +64 -64
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f3dee5f4fc52defa4ee2156a4b55a99d451096a9f306649447d4284cc7762c0
|
4
|
+
data.tar.gz: d7e6529719bd1cb331608774478b512027184dff994a5ae2037cb704c102cfb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5342a57f1dc12b968065b1d2558a25a17a8178bc36e7d0c3d1c48a67520dea9ea5ffeae8c09240e2ea29a7ae75cee8af2d0c463298713976dcefdb54c30a4b00
|
7
|
+
data.tar.gz: 44dfc851b979dd6c9cad3a05a531efaf87a8bf31da6d329c01bb40201bca0a6d2e97f8bd8ba3eb1c0aed6e33a5a000a081a7990f1159b334e760a647f3dbc8c3
|
data/exe/file_sv
CHANGED
File without changes
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# Responsible for loading all files in service directory and creating service
|
4
4
|
module ServiceLoader
|
5
5
|
# @return [String] Folder where service served from
|
6
|
-
@serving_folder = ""
|
6
|
+
@serving_folder = "."
|
7
7
|
|
8
8
|
class << self
|
9
9
|
# Create virtual service plan based on folder
|
data/lib/file_sv/sv_plan.rb
CHANGED
@@ -5,19 +5,24 @@ require_relative "file_processor"
|
|
5
5
|
# Holds plan of what virtual service will look like
|
6
6
|
class SvPlan
|
7
7
|
@endpoints = {}
|
8
|
+
@file_list = []
|
8
9
|
class << self
|
9
10
|
# @return [Hash] Endpoints included in plan. Key - endpoint, value - methods served under it
|
10
11
|
attr_reader :endpoints
|
11
12
|
# @return [String] Folder plan is served from
|
12
13
|
attr_accessor :serving_folder
|
13
14
|
|
15
|
+
# @return [String] List of files plan is built from
|
16
|
+
attr_accessor :file_list
|
17
|
+
|
14
18
|
# Create a plan new plan for a virtual service
|
15
19
|
def create(folder)
|
16
20
|
self.serving_folder = folder
|
17
21
|
puts "Creating service based on files in #{folder}"
|
18
|
-
file_list = Dir.glob("#{folder}/**/*.*", File::FNM_DOTMATCH) - Dir.glob("#{folder}/#{GlobalSettings.ignore_files}, File::FNM_DOTMATCH
|
22
|
+
file_list = Dir.glob("#{folder}/**/*.*", File::FNM_DOTMATCH) - Dir.glob("#{folder}/#{GlobalSettings.ignore_files}", File::FNM_DOTMATCH)
|
19
23
|
file_list.each do |file|
|
20
24
|
next if File.directory? file
|
25
|
+
SvPlan.file_list << file
|
21
26
|
process_file file
|
22
27
|
end
|
23
28
|
end
|
data/lib/file_sv/version.rb
CHANGED
@@ -32,10 +32,19 @@ for more details'
|
|
32
32
|
endpoint.file? ? send_file(endpoint.serving_file_name) : endpoint.content(binding)
|
33
33
|
end
|
34
34
|
|
35
|
+
def append_content_type(endpoint)
|
36
|
+
if (endpoint.file_path.end_with? '.json')
|
37
|
+
content_type :json
|
38
|
+
elsif endpoint.file_path.end_with? '.xml'
|
39
|
+
content_type :xml
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
35
43
|
# Log endpoint. Return content and status code defined by endpoint
|
36
44
|
# @param [PlannedEndpoint] endpoint Planned endpoint to serve
|
37
45
|
def serve(endpoint, id = nil)
|
38
46
|
@id = id
|
47
|
+
append_content_type(endpoint)
|
39
48
|
if ENV['debug'] == "true"
|
40
49
|
message = "Using endpoint based on file #{endpoint.serving_file_name}."
|
41
50
|
message += " Using param '#{@id}'" if id
|
@@ -1,16 +1,16 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Process YAML files
|
4
|
-
class YamlProcessor
|
5
|
-
class << self
|
6
|
-
# Process YAML file
|
7
|
-
def process(filename)
|
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..]
|
11
|
-
else
|
12
|
-
puts "Skipping #{filename}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Process YAML files
|
4
|
+
class YamlProcessor
|
5
|
+
class << self
|
6
|
+
# Process YAML file
|
7
|
+
def process(filename)
|
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..]
|
11
|
+
else
|
12
|
+
puts "Skipping #{filename}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/file_sv.rb
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "yaml"
|
4
|
-
require_relative "file_sv/version"
|
5
|
-
require_relative "file_sv/global_settings"
|
6
|
-
require_relative "file_sv/sv_plan"
|
7
|
-
require_relative "file_sv/service_loader"
|
8
|
-
require_relative "file_sv/planned_endpoint"
|
9
|
-
|
10
|
-
# Create Service Virtualization from a simple file system
|
11
|
-
module FileSv
|
12
|
-
# General error for FileSv
|
13
|
-
class Error < StandardError; end
|
14
|
-
|
15
|
-
# Error related to incorrect format of filename
|
16
|
-
class FileNameError < Error; end
|
17
|
-
|
18
|
-
class << self
|
19
|
-
# @return [Hash] Mapping of REST method names to setting classes
|
20
|
-
def rest_methods
|
21
|
-
{
|
22
|
-
get: GetSettings, post: PostSettings, patch: PatchSettings, options: OptionsSettings,
|
23
|
-
delete: DeleteSettings, put: PutSettings
|
24
|
-
}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
CONFIG_FILE = "file_sv.yaml"
|
30
|
-
|
31
|
-
# Set values in global settings based on config
|
32
|
-
def load_default_config(file_path)
|
33
|
-
return unless File.exist? file_path
|
34
|
-
|
35
|
-
config = YAML.load_file file_path
|
36
|
-
return unless config # Handle empty YAML file
|
37
|
-
|
38
|
-
config["global"]&.each do |key, value|
|
39
|
-
GlobalSettings.send("#{key}=", value)
|
40
|
-
end
|
41
|
-
|
42
|
-
load_rest_method_config config
|
43
|
-
end
|
44
|
-
|
45
|
-
# Load details of each REST method
|
46
|
-
def load_rest_method_config(config)
|
47
|
-
FileSv.rest_methods.each do |method, setting_class|
|
48
|
-
config[method.to_s]&.each { |key, value| setting_class.send("#{key}=", value) }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Set global params based on ENV vars
|
53
|
-
def set_based_on_env_vars
|
54
|
-
GlobalSettings.instance_variables.each do |setting|
|
55
|
-
setting_name = setting.to_s[1..]
|
56
|
-
if ENV[setting_name]
|
57
|
-
puts "Setting #{setting_name} to #{ENV[setting_name]}"
|
58
|
-
GlobalSettings.send("#{setting_name}=", ENV[setting_name])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
load_default_config CONFIG_FILE
|
64
|
-
set_based_on_env_vars
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
require_relative "file_sv/version"
|
5
|
+
require_relative "file_sv/global_settings"
|
6
|
+
require_relative "file_sv/sv_plan"
|
7
|
+
require_relative "file_sv/service_loader"
|
8
|
+
require_relative "file_sv/planned_endpoint"
|
9
|
+
|
10
|
+
# Create Service Virtualization from a simple file system
|
11
|
+
module FileSv
|
12
|
+
# General error for FileSv
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
# Error related to incorrect format of filename
|
16
|
+
class FileNameError < Error; end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
# @return [Hash] Mapping of REST method names to setting classes
|
20
|
+
def rest_methods
|
21
|
+
{
|
22
|
+
get: GetSettings, post: PostSettings, patch: PatchSettings, options: OptionsSettings,
|
23
|
+
delete: DeleteSettings, put: PutSettings
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
CONFIG_FILE = "file_sv.yaml"
|
30
|
+
|
31
|
+
# Set values in global settings based on config
|
32
|
+
def load_default_config(file_path)
|
33
|
+
return unless File.exist? file_path
|
34
|
+
|
35
|
+
config = YAML.load_file file_path
|
36
|
+
return unless config # Handle empty YAML file
|
37
|
+
|
38
|
+
config["global"]&.each do |key, value|
|
39
|
+
GlobalSettings.send("#{key}=", value)
|
40
|
+
end
|
41
|
+
|
42
|
+
load_rest_method_config config
|
43
|
+
end
|
44
|
+
|
45
|
+
# Load details of each REST method
|
46
|
+
def load_rest_method_config(config)
|
47
|
+
FileSv.rest_methods.each do |method, setting_class|
|
48
|
+
config[method.to_s]&.each { |key, value| setting_class.send("#{key}=", value) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Set global params based on ENV vars
|
53
|
+
def set_based_on_env_vars
|
54
|
+
GlobalSettings.instance_variables.each do |setting|
|
55
|
+
setting_name = setting.to_s[1..]
|
56
|
+
if ENV[setting_name]
|
57
|
+
puts "Setting #{setting_name} to #{ENV[setting_name]}"
|
58
|
+
GlobalSettings.send("#{setting_name}=", ENV[setting_name])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
load_default_config CONFIG_FILE
|
64
|
+
set_based_on_env_vars
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rackup
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: sinatra
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
138
|
- !ruby/object:Gem::Version
|
125
139
|
version: '0'
|
126
140
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
141
|
+
rubygems_version: 3.1.4
|
128
142
|
signing_key:
|
129
143
|
specification_version: 4
|
130
144
|
summary: REST service virtualisation through file structure.
|