file_sv 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6fe6c5fff5f5d93506024349027d89d5ae0331b22f1dc15c94aaf72b18d1c8a
4
- data.tar.gz: b8c7f47b3602949beb64b5b7e9fa7f859b2fc3020f5c1a3d91fa9a6309a1ad8a
3
+ metadata.gz: 43425956ba3f1325aa81876eea311cabd364f35ae2735adf79f4cb2daed69dd4
4
+ data.tar.gz: 629f16289572cb0407ae010a5322f96b07ab6261e591b55dd080f3c9d5e5b58c
5
5
  SHA512:
6
- metadata.gz: 3b6521770efbd56f4b790650de3801668e80b4c197e995d3cdd1a97326013c58e241d265caf1735eeeae020050aa775ad44d7acb29b0c651aa3401b109bd7be0
7
- data.tar.gz: ac3d6a6d948161f2b96f38090a148e3605927a9a43a690a05933b3a942905903f1c95b9e84ead1a204441b7edd66ef179be8aac3e30d6ddb2946a0330314d195
6
+ metadata.gz: ec1ca5bffdfcbcc83f94cde7838bc1cdccf844c6c58f45a768203f8d72f2c77e0ce49f706ba7878cb9ba414a58863fb7438e056d76c341a16b258e6de31d3125
7
+ data.tar.gz: c8e605801443bbd947769ce32bfd376daad28c98bf05dcbca4e1cbbf81a09d1b6a50b9a5f6d0dc1aab29d494f6796bf400bbda023e95ddb8e57c3e241bf16692
@@ -18,7 +18,7 @@ class GlobalSettings
18
18
  attr_accessor :empty_body_status
19
19
  # @return [Array] Expression representing files to ignore
20
20
  attr_accessor :ignore_files
21
- # @return [Boolean] Whether to serve https using self signed certificate
21
+ # @return [Boolean] Whether to serve https using self signed certificate. Deprecated now
22
22
  attr_accessor :https
23
23
  # @return [String] Path to HTTPS cert
24
24
  attr_accessor :cert
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FileSv
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
@@ -1,53 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "webrick"
3
+ require "puma"
4
4
  require "sinatra"
5
5
  require "docdsl"
6
- require "webrick/https"
7
6
  require "openssl"
8
7
 
9
8
  # Virtual server hosting virtual service defined through files
10
9
  class VirtualServer < Sinatra::Base
11
- set :server, "webrick"
10
+ set :server, :puma
11
+ enable :logging if ENV['debug'] == "true"
12
12
  set :bind, "0.0.0.0"
13
13
 
14
14
  register Sinatra::DocDsl
15
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
-
51
16
  page do
52
17
  title "File SV"
53
18
  header "Service virtualization created from #{Dir.pwd}"
@@ -69,11 +34,13 @@ for more details'
69
34
 
70
35
  # Log endpoint. Return content and status code defined by endpoint
71
36
  # @param [PlannedEndpoint] endpoint Planned endpoint to serve
72
- def serve(endpoint, id = nil)
73
- message = "Using endpoint based on file #{endpoint.serving_file_name}."
37
+ def serve(endpoint, id = nil)
74
38
  @id = id
75
- message += " Using param '#{@id}'" if id
76
- puts message
39
+ if ENV['debug'] == "true"
40
+ message = "Using endpoint based on file #{endpoint.serving_file_name}."
41
+ message += " Using param '#{@id}'" if id
42
+ puts message
43
+ end
77
44
  [endpoint.status_code, output_for(endpoint, binding)]
78
45
  end
79
46
 
@@ -86,11 +53,15 @@ for more details'
86
53
  if endpoint_base.path.include? "#{File::Separator}:"
87
54
  send(endpoint_base.method, endpoint_base.path) do |id|
88
55
  endpoint = endpoints.sample
56
+ @params = params
57
+ puts "#{endpoint_base.method} #{endpoint_base.path} ?#{@params}"
89
58
  serve endpoint, id
90
59
  end
91
60
  else
92
61
  send(endpoint_base.method, endpoint_base.path) do
93
62
  endpoint = endpoints.sample
63
+ @params = params
64
+ puts "#{endpoint_base.method} #{endpoint_base.path} ?#{@params}" unless ENV['ignore_path'] && ("/#{ENV['ignore_path']}" == endpoint_base.path)
94
65
  serve endpoint
95
66
  end
96
67
  end
@@ -6,8 +6,8 @@ class YamlProcessor
6
6
  # Process YAML file
7
7
  def process(filename)
8
8
  if filename == "/file_sv.yaml"
9
- puts "Overriding default config based on #{File.join(Dir.pwd, filename[1..-1])}"
10
- load_default_config filename[1..-1]
9
+ puts "Overriding default config based on #{File.join(Dir.pwd, filename[1..])}"
10
+ load_default_config filename[1..]
11
11
  else
12
12
  puts "Skipping #{filename}"
13
13
  end
data/lib/file_sv.rb CHANGED
@@ -52,7 +52,7 @@ end
52
52
  # Set global params based on ENV vars
53
53
  def set_based_on_env_vars
54
54
  GlobalSettings.instance_variables.each do |setting|
55
- setting_name = setting.to_s[1..-1]
55
+ setting_name = setting.to_s[1..]
56
56
  if ENV[setting_name]
57
57
  puts "Setting #{setting_name} to #{ENV[setting_name]}"
58
58
  GlobalSettings.send("#{setting_name}=", ENV[setting_name])
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.6
4
+ version: 0.1.7
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-14 00:00:00.000000000 Z
11
+ date: 2021-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: webrick
70
+ name: puma
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.7.0
75
+ version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 1.7.0
82
+ version: '0'
83
83
  description: |-
84
84
  Create a virtual REST service through file structure. Customize it more
85
85
  through ERB and special file names