schemaless_rest_api 0.4.2 → 0.5.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49fba7a856b268a6077d6597c20687d0d056cce2049fb5c0590da046acebf91f
|
4
|
+
data.tar.gz: 2ac45839af0b7d4e273812bcf6a4a9d3f750d958285c3f9fcfccf143ee4d8c57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c545f176d807dff6894b10a54aba45737968157247261b1a973ae471ec60155834a8847a43edb3c2ee50ad2a2b562846f5513479112402f3013b7da6a84a0c2
|
7
|
+
data.tar.gz: 35f4ed2bc211ac4bf163296b69c29362a7d13a3c705898e7a5a07438d3c8b071907acfd0792fb9b84e81519e74b6cfd95276156948ae422d27886a13ebb7421c
|
Binary file
|
@@ -14,29 +14,34 @@ class RestServer < Sinatra::Base
|
|
14
14
|
helpers ServerUtils
|
15
15
|
|
16
16
|
before do
|
17
|
-
@request_id = SecureRandom.uuid
|
18
|
-
headers["X-
|
17
|
+
@request_id = SecureRandom.uuid
|
18
|
+
headers["X-Correlation-Id"] = @request_id
|
19
19
|
headers["Access-Control-Allow-Origin"] = "*"
|
20
|
-
log({ msg: "Request"}) if
|
20
|
+
log({ msg: "Request" }) if request.fullpath != ""
|
21
21
|
end
|
22
22
|
|
23
|
-
after do
|
24
|
-
log({ msg: "Response", status: response.status }) if
|
23
|
+
after do
|
24
|
+
log({ msg: "Response", status: response.status }) if request.fullpath != ""
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
get "/favicon.ico" do
|
28
|
+
send_file File.join(__dir__, "rest.ico")
|
29
|
+
end
|
30
|
+
|
31
|
+
SWAGGER_FILES = %w[index.css swagger.html swagger-initializer.js swagger-ui-bundle.js swagger-ui-standalone-preset.js
|
32
|
+
swagger-ui.css]
|
28
33
|
|
29
34
|
SWAGGER_FILES.each do |filename|
|
30
35
|
get "/#{filename.gsub(".html", "")}" do
|
31
|
-
if filename.end_with?
|
36
|
+
if filename.end_with? ".json"
|
32
37
|
content_type :json
|
33
|
-
elsif filename.end_with?
|
38
|
+
elsif filename.end_with? ".css"
|
34
39
|
content_type :css
|
35
|
-
elsif filename.end_with?
|
40
|
+
elsif filename.end_with? ".js"
|
36
41
|
content_type :js
|
37
42
|
end
|
38
43
|
|
39
|
-
File.read("
|
44
|
+
File.read(File.join(__dir__, "swagger", filename))
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
@@ -79,7 +84,7 @@ class RestServer < Sinatra::Base
|
|
79
84
|
else
|
80
85
|
Entities.models[model][id] = data
|
81
86
|
end
|
82
|
-
log({msg: "Created #{id}"})
|
87
|
+
log({ msg: "Created #{id}" })
|
83
88
|
[201, JSON.generate({ id: id })]
|
84
89
|
end
|
85
90
|
|
@@ -1,22 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# typed:
|
3
|
+
# typed: false
|
4
4
|
|
5
|
+
# Helper methods added to RestServer
|
5
6
|
module ServerUtils
|
6
7
|
def log(messages)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
messages.each do |key, value|
|
14
|
-
log_msg[key] = value
|
15
|
-
end
|
16
|
-
SchemalessRestApi.logger.info(log_msg)
|
17
|
-
else
|
18
|
-
message = messages.values.join(", ")
|
19
|
-
SchemalessRestApi.logger.info "#{message}, #{request.request_method} #{request.fullpath}, CorrelationId: #{@request_id}"
|
20
|
-
end
|
8
|
+
if SchemalessRestApi.log_type == :ougai
|
9
|
+
log_structured(messages)
|
10
|
+
else
|
11
|
+
message = messages.values.join(", ")
|
12
|
+
SchemalessRestApi.logger.info "#{message}, #{request.request_method} #{request.fullpath}, CorrelationId: #{@request_id}"
|
13
|
+
end
|
21
14
|
end
|
22
|
-
|
15
|
+
|
16
|
+
private def log_structured(messages)
|
17
|
+
log_msg = {
|
18
|
+
method: request.request_method,
|
19
|
+
path: request.fullpath,
|
20
|
+
correlationId: @request_id
|
21
|
+
}
|
22
|
+
messages.each do |key, value|
|
23
|
+
log_msg[key] = value
|
24
|
+
end
|
25
|
+
SchemalessRestApi.logger.info(log_msg)
|
26
|
+
end
|
27
|
+
end
|
data/lib/schemaless_rest_api.rb
CHANGED
@@ -11,16 +11,18 @@ require "ougai"
|
|
11
11
|
require "json"
|
12
12
|
require "securerandom"
|
13
13
|
|
14
|
+
ENV["APP_ENV"] ||= "production"
|
15
|
+
|
14
16
|
# Global params for Schemalass REST API
|
15
17
|
module SchemalessRestApi
|
16
|
-
if ENV["Log"] ==
|
18
|
+
if ENV["Log"] == "structured"
|
17
19
|
@logger = Ougai::Logger.new($stdout)
|
18
20
|
@log_type = :ougai
|
19
21
|
else
|
20
22
|
@logger = Logger.new($stdout)
|
21
23
|
@log_type = :basic
|
22
24
|
end
|
23
|
-
|
25
|
+
|
24
26
|
class << self
|
25
27
|
# @return Logger
|
26
28
|
attr_accessor :logger
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemaless_rest_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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-06-
|
11
|
+
date: 2024-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/schemaless_rest_api.rb
|
123
123
|
- lib/schemaless_rest_api/entities.rb
|
124
124
|
- lib/schemaless_rest_api/mongo_client.rb
|
125
|
+
- lib/schemaless_rest_api/rest.ico
|
125
126
|
- lib/schemaless_rest_api/rest_server.rb
|
126
127
|
- lib/schemaless_rest_api/server_utils.rb
|
127
128
|
- lib/schemaless_rest_api/swagger/index.css
|