micro_api 0.1.1 → 0.1.3
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/README.md +15 -1
- data/app/controllers/micro_api/static_controller.rb +9 -0
- data/lib/generators/micro_api/install/install_generator.rb +25 -6
- data/lib/micro_api/engine.rb +26 -0
- data/lib/micro_api/version.rb +1 -1
- data/spec/dummy/config/application.rb +3 -1
- data/spec/dummy/config/routes.rb +9 -0
- data/spec/requests/micro_api/static_healthz_spec.rb +6 -5
- data/spec/requests/micro_api/static_version_spec.rb +2 -1
- metadata +20 -10
- data/spec/dummy/log/development.log +0 -2609
- data/spec/dummy/tmp/development_secret.txt +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99a6cfc6d82c9d35036f0b7fffb1a7076ad78593e731ee1a025e68fcb60d82dd
|
4
|
+
data.tar.gz: 41a25e79645d7f6bb5b9f3135bbb0436ab96ac15f2492512d47c4b6b7ecd9aca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d7f1a612213b649bbe000fef4878674733fa2834406d3151e64b0d8fc25d2575166832a6db26e435b6d1be1fa4ce78e23e82373e73da1d429ec28ca392dee5d
|
7
|
+
data.tar.gz: 917ab03be4c3901914ab3c1c21c339fa09eae405889891f7209fe0f70e965782f08fbfeecef2d5012baa76e8451b5153aaa3a9aff982f89afcbc2aa8f18b0995
|
data/README.md
CHANGED
@@ -2,7 +2,16 @@
|
|
2
2
|
This is a Rails plugin that would like to help the startup of rails applications oriented to microservices or, in general, application deployed on the cloud.
|
3
3
|
|
4
4
|
## Usage
|
5
|
-
How to use my plugin
|
5
|
+
How to use my plugin in a existing project
|
6
|
+
```bash
|
7
|
+
bundle add micro_api
|
8
|
+
```
|
9
|
+
|
10
|
+
|
11
|
+
```bash
|
12
|
+
gem install micro_api
|
13
|
+
```
|
14
|
+
|
6
15
|
|
7
16
|
## Installation
|
8
17
|
Add this line to your application's Gemfile:
|
@@ -10,6 +19,11 @@ Add this line to your application's Gemfile:
|
|
10
19
|
```ruby
|
11
20
|
gem "micro_api"
|
12
21
|
```
|
22
|
+
from localpath
|
23
|
+
```ruby
|
24
|
+
gem 'micro_api', path: '/gems/micro_api'
|
25
|
+
```
|
26
|
+
|
13
27
|
|
14
28
|
And then execute:
|
15
29
|
```bash
|
@@ -9,6 +9,7 @@ module MicroApi
|
|
9
9
|
ac: Rails.application.class.to_s.split("::").first, # app code
|
10
10
|
cenv: ENV.fetch("CLOUD_ENV", "local"), # cloud env
|
11
11
|
env: Rails.env, # rails env
|
12
|
+
av: app_version,
|
12
13
|
itag: ENV.fetch("IMAGE_TAG", nil), # image tag
|
13
14
|
}
|
14
15
|
end
|
@@ -17,5 +18,13 @@ module MicroApi
|
|
17
18
|
exception = ActionController::RoutingError.new("No route matches [#{request.method}] #{request.path}")
|
18
19
|
render json: { error: exception.message }, status: :not_found
|
19
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def app_version
|
25
|
+
Rails.application.class::VERSION
|
26
|
+
rescue StandardError
|
27
|
+
nil
|
28
|
+
end
|
20
29
|
end
|
21
30
|
end
|
@@ -30,8 +30,13 @@ module MicroApi
|
|
30
30
|
|
31
31
|
desc "This generator add row in application.rb file"
|
32
32
|
def generate_micro_api_application
|
33
|
-
|
34
|
-
|
33
|
+
application_list = ["\n"]
|
34
|
+
application_list << "config.active_record.default_timezone = :utc" if defined?(ActiveRecord)
|
35
|
+
application_list << "config.time_zone = 'CET'"
|
36
|
+
|
37
|
+
inject_into_file 'config/application.rb', before: /\n end$/ do
|
38
|
+
application_list.join("\n ").gsub(" \n", "\n")
|
39
|
+
end
|
35
40
|
end
|
36
41
|
|
37
42
|
desc "This generator creates an initializer file at config/initializers"
|
@@ -40,10 +45,24 @@ module MicroApi
|
|
40
45
|
template "staging.rb", "#{Rails.root}/config/environments/staging.rb"
|
41
46
|
end
|
42
47
|
|
43
|
-
desc "This generator add
|
44
|
-
def
|
45
|
-
|
46
|
-
|
48
|
+
desc "This generator add 'api namespace' rows in routes.rb file"
|
49
|
+
def generate_micro_api_route_api_namespace
|
50
|
+
inject_into_file 'config/routes.rb', before: " # Defines the root path route" do
|
51
|
+
" namespace :api, defaults: { format: :json } do\n end\n\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "This generator add final rows in routes.rb file"
|
56
|
+
def generate_micro_api_route_last
|
57
|
+
routes_list = [
|
58
|
+
"\n",
|
59
|
+
"mount MicroApi::Engine, at: MicroApi.routes_path, as: '#{MicroApi.routes_path}'",
|
60
|
+
"match '*path', to: 'micro_api/static#no_route_matches', via: :all"
|
61
|
+
]
|
62
|
+
|
63
|
+
inject_into_file 'config/routes.rb', before: /\nend$/ do
|
64
|
+
routes_list.join("\n ").gsub(" \n", "\n")
|
65
|
+
end
|
47
66
|
end
|
48
67
|
end
|
49
68
|
end
|
data/lib/micro_api/engine.rb
CHANGED
@@ -1,8 +1,34 @@
|
|
1
|
+
require 'lograge'
|
2
|
+
|
1
3
|
module MicroApi
|
2
4
|
class Engine < ::Rails::Engine
|
3
5
|
isolate_namespace MicroApi
|
4
6
|
config.generators.api_only = true
|
5
7
|
|
8
|
+
initializer "micro_api.lograge.init" do |app|
|
9
|
+
app.configure do
|
10
|
+
config.lograge.enabled = true
|
11
|
+
config.lograge.base_controller_class = "ActionController::API"
|
12
|
+
config.lograge.formatter = Lograge::Formatters::Json.new
|
13
|
+
config.colorize_logging = false
|
14
|
+
config.lograge.logger = ActiveSupport::Logger.new($stdout)
|
15
|
+
|
16
|
+
config.lograge.ignore_custom = lambda do |event|
|
17
|
+
event.payload[:path] == "#{MicroApi.routes_path}/healthz" && event.payload[:request].remote_ip =~ /^10\./
|
18
|
+
end
|
19
|
+
config.lograge.custom_payload do |controller|
|
20
|
+
{
|
21
|
+
level: :info,
|
22
|
+
log_type: :rails,
|
23
|
+
request_id: controller.request.request_id,
|
24
|
+
host: controller.request.host,
|
25
|
+
remote_ip: controller.request.remote_ip,
|
26
|
+
image_tag: ENV['IMAGE_TAG']
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
6
32
|
config.generators do |g|
|
7
33
|
g.test_framework :rspec,
|
8
34
|
controller_specs: true,
|
data/lib/micro_api/version.rb
CHANGED
@@ -21,6 +21,8 @@ require "micro_api"
|
|
21
21
|
|
22
22
|
module Dummy
|
23
23
|
class Application < Rails::Application
|
24
|
+
VERSION = '1.2.3'.freeze
|
25
|
+
|
24
26
|
config.load_defaults Rails::VERSION::STRING.to_f
|
25
27
|
|
26
28
|
# Configuration for the application, engines, and railties goes here.
|
@@ -38,6 +40,6 @@ module Dummy
|
|
38
40
|
|
39
41
|
config.hosts << "www.example.com"
|
40
42
|
|
41
|
-
config.time_zone =
|
43
|
+
config.time_zone = 'CET'
|
42
44
|
end
|
43
45
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
+
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
3
|
+
|
4
|
+
namespace :api, defaults: { format: :json } do
|
5
|
+
end
|
6
|
+
|
7
|
+
# Defines the root path route ("/")
|
8
|
+
# root "articles#index"
|
9
|
+
|
2
10
|
# mount MicroApi::Engine => "/micro_api"
|
11
|
+
|
3
12
|
mount MicroApi::Engine, at: MicroApi.routes_path, as: '/mse'
|
4
13
|
match '*path', to: 'micro_api/static#no_route_matches', via: :all
|
5
14
|
end
|
@@ -4,6 +4,12 @@ RSpec.describe "Statics" do
|
|
4
4
|
describe "GET /healthz" do
|
5
5
|
before { @route = get("#{MicroApi.routes_path}/healthz") }
|
6
6
|
|
7
|
+
it "returns http success", type: :request do
|
8
|
+
expect(response).to have_http_status(:success)
|
9
|
+
expect(response.header['Content-Type']).to include 'application/json'
|
10
|
+
expect(json).to have_key('status')
|
11
|
+
end
|
12
|
+
|
7
13
|
it "routes /micro_api/version to the static controller", type: :routing do
|
8
14
|
expect(@route).to route_to(
|
9
15
|
controller: 'micro_api/static',
|
@@ -11,10 +17,5 @@ RSpec.describe "Statics" do
|
|
11
17
|
format: :json
|
12
18
|
)
|
13
19
|
end
|
14
|
-
it "returns http success", type: :request do
|
15
|
-
expect(response).to have_http_status(:success)
|
16
|
-
expect(response.header['Content-Type']).to include 'application/json'
|
17
|
-
expect(json).to have_key('status')
|
18
|
-
end
|
19
20
|
end
|
20
21
|
end
|
@@ -7,7 +7,8 @@ RSpec.describe "Statics" do
|
|
7
7
|
it "returns http success", type: :request do
|
8
8
|
expect(response).to have_http_status(:success)
|
9
9
|
expect(response.header['Content-Type']).to include 'application/json'
|
10
|
-
expect(json.keys).to contain_exactly('ac', 'cenv', 'env', 'itag')
|
10
|
+
expect(json.keys).to contain_exactly('ac', 'cenv', 'env', 'itag', 'av')
|
11
|
+
expect(json['av']).to eq('1.2.3'.freeze)
|
11
12
|
end
|
12
13
|
|
13
14
|
it "routes /micro_api/version to the static controller", type: :routing do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: micro_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: lograge
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rails
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,8 +121,6 @@ files:
|
|
107
121
|
- spec/dummy/config/locales/en.yml
|
108
122
|
- spec/dummy/config/puma.rb
|
109
123
|
- spec/dummy/config/routes.rb
|
110
|
-
- spec/dummy/log/development.log
|
111
|
-
- spec/dummy/tmp/development_secret.txt
|
112
124
|
- spec/generator/micro_api/installs_generator_spec.rb
|
113
125
|
- spec/rails_helper.rb
|
114
126
|
- spec/requests/micro_api/static_healthz_spec.rb
|
@@ -125,7 +137,7 @@ metadata:
|
|
125
137
|
homepage_uri: https://github.com/lelered/micro_api
|
126
138
|
source_code_uri: https://github.com/lelered/micro_api
|
127
139
|
changelog_uri: https://github.com/lelered/micro_api/blob/main/CHANGELOG.md
|
128
|
-
post_install_message:
|
140
|
+
post_install_message:
|
129
141
|
rdoc_options: []
|
130
142
|
require_paths:
|
131
143
|
- lib
|
@@ -140,8 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
152
|
- !ruby/object:Gem::Version
|
141
153
|
version: '0'
|
142
154
|
requirements: []
|
143
|
-
rubygems_version: 3.4.
|
144
|
-
signing_key:
|
155
|
+
rubygems_version: 3.4.19
|
156
|
+
signing_key:
|
145
157
|
specification_version: 4
|
146
158
|
summary: Engine plugin for Ruby on Rails applications
|
147
159
|
test_files:
|
@@ -163,8 +175,6 @@ test_files:
|
|
163
175
|
- spec/dummy/config/puma.rb
|
164
176
|
- spec/dummy/config/routes.rb
|
165
177
|
- spec/dummy/config.ru
|
166
|
-
- spec/dummy/log/development.log
|
167
|
-
- spec/dummy/tmp/development_secret.txt
|
168
178
|
- spec/generator/micro_api/installs_generator_spec.rb
|
169
179
|
- spec/rails_helper.rb
|
170
180
|
- spec/requests/micro_api/static_healthz_spec.rb
|