hephaestus 0.5.2 → 0.6.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/.ruby-version +1 -1
- data/CHANGELOG.md +13 -0
- data/lib/hephaestus/app_builder.rb +3 -0
- data/lib/hephaestus/version.rb +1 -1
- data/templates/Dockerfile +1 -1
- data/templates/Gemfile.erb +3 -3
- data/templates/app/controllers/yetto_controller.rb +0 -11
- data/templates/app/jobs/update_yetto_job.rb +1 -3
- data/templates/app/lib/body_parameter/yetto_parameters.rb +1 -1
- data/templates/app/lib/plug_app/middleware/openapi_validation.rb +55 -26
- data/templates/app/services/yetto_service.rb +0 -7
- data/templates/test/support/webmocks/yetto_webmock.rb +0 -19
- data/templates/vendor/fly/fly-production.toml +12 -0
- data/templates/vendor/fly/fly-staging.toml +12 -0
- metadata +4 -6
- data/templates/app/lib/plug_app/middleware/not_found.rb +0 -41
- data/templates/app/lib/plug_app/switches/message_created.jsonc +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b58de861c02e9f029be16c4ffc63a7d328569e00d17b620fe192cbc9c4788579
|
4
|
+
data.tar.gz: 634c07e912d979106ff8eefc6eaed83c4331321652754edd95f6ee87af2e6706
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1517fe22cb5f81eca885f702051a9546aa3088e3cad6d3159190f9673368a601b59cd243505380bd6129cbdcc3ba9e1ddb8e771c90722efabfe51d534793277
|
7
|
+
data.tar.gz: a3d9dffb9397754e98696bb1c1ca10718026aeb5580a36342298da0e61476e0c78dbf16429a03823cd673fba8bdbdd56121d1b184098dd93195e174eb6a4ba1a
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.3.0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## [v0.6.0] - 19-12-2023
|
2
|
+
## What's Changed
|
3
|
+
* Remove switch logic from plugs by @gjtorikian in https://github.com/yettoapp/hephaestus/pull/15
|
4
|
+
|
5
|
+
|
6
|
+
**Full Changelog**: https://github.com/yettoapp/hephaestus/compare/v0.5.2...v0.6.0
|
7
|
+
## [v0.5.2] - 13-11-2023
|
8
|
+
## What's Changed
|
9
|
+
* Fix RAILS_ENV in fly-staging.toml by @balevine in https://github.com/yettoapp/hephaestus/pull/13
|
10
|
+
* Change dependabot checking to by @gjtorikian in https://github.com/yettoapp/hephaestus/pull/14
|
11
|
+
|
12
|
+
|
13
|
+
**Full Changelog**: https://github.com/yettoapp/hephaestus/compare/v0.5.1...v0.5.2
|
1
14
|
## [v0.5.1] - 31-10-2023
|
2
15
|
## What's Changed
|
3
16
|
* Remove excess :// characters from PROTOCOL by @balevine in https://github.com/yettoapp/hephaestus/pull/12
|
@@ -158,7 +158,10 @@ module Hephaestus
|
|
158
158
|
def replace_generic_variables
|
159
159
|
say(set_color("Replacing generic variable names...", :cyan))
|
160
160
|
replace_in_files(destination_root, /App(?!lication)/, short_app_name.capitalize)
|
161
|
+
|
161
162
|
replace_in_files(destination_root, %r{(?<!yetto|sw|plugs\.yetto\.)app(?!lication|/|roximate)}, short_app_name.downcase)
|
163
|
+
replace_in_file("test/support/api.rb", "/app/", "/#{short_app_name.downcase}/")
|
164
|
+
|
162
165
|
replace_in_files(destination_root, "PlugApp", app_name.underscore.camelcase)
|
163
166
|
replace_in_files(destination_root, "plug-app", app_name.dasherize)
|
164
167
|
replace_in_files("destination_root}/.github/workflows/test.yml", "plug-app", app_name.dasherize)
|
data/lib/hephaestus/version.rb
CHANGED
data/templates/Dockerfile
CHANGED
data/templates/Gemfile.erb
CHANGED
@@ -27,7 +27,7 @@ gem "hiredis", "~> 0.6"
|
|
27
27
|
gem "lograge", "~> 0.12"
|
28
28
|
|
29
29
|
# provides middleware to make OpenAPI parsing simpler
|
30
|
-
gem "openapi_first", "~> 0
|
30
|
+
gem "openapi_first", "~> 1.0"
|
31
31
|
|
32
32
|
# For Honeycomb.io
|
33
33
|
gem "opentelemetry-sdk", "~> 1.2"
|
@@ -68,7 +68,7 @@ group :development, :test do
|
|
68
68
|
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
69
69
|
gem "debug", platforms: [:mri, :mingw, :x64_mingw], require: false
|
70
70
|
|
71
|
-
gem "faker", "~>
|
71
|
+
gem "faker", "~> 3.0"
|
72
72
|
gem "rubocop", require: false
|
73
73
|
gem "rubocop-standard", require: false
|
74
74
|
end
|
@@ -113,7 +113,7 @@ group :test do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
group :ci do
|
116
|
-
gem "brakeman", "~>
|
116
|
+
gem "brakeman", "~> 6.0"
|
117
117
|
gem "bundle-audit", "~> 0.1"
|
118
118
|
end
|
119
119
|
|
@@ -11,22 +11,11 @@ class YettoController < ApplicationController
|
|
11
11
|
|
12
12
|
before_action :from_yetto?
|
13
13
|
|
14
|
-
AFTER_CREATE_MESSAGE_SWITCH = JSON.parse(Rails.root.join("app/lib/plug_app/switches/message_created.jsonc").read)
|
15
|
-
|
16
14
|
def event
|
17
15
|
case pparam_yetto_event
|
18
16
|
when Headers::Yetto::EVENT_AFTER_CREATE
|
19
17
|
case pparam_yetto_record_type
|
20
18
|
when Headers::Yetto::RECORD_TYPE_PLUG_INSTALLATION
|
21
|
-
create_inbox_switch_data = {
|
22
|
-
type: "create_inbox_switch",
|
23
|
-
inbox: { id: bparam_inbox_id },
|
24
|
-
plug_installation: { id: bparam_plug_installation_id },
|
25
|
-
payload: AFTER_CREATE_MESSAGE_SWITCH,
|
26
|
-
}
|
27
|
-
|
28
|
-
UpdateYettoJob.perform_later(create_inbox_switch_data)
|
29
|
-
|
30
19
|
no_content
|
31
20
|
when Headers::Yetto::RECORD_TYPE_MESSAGE
|
32
21
|
|
@@ -10,15 +10,13 @@ class UpdateYettoJob < ApplicationJob
|
|
10
10
|
def perform(params)
|
11
11
|
type = params.delete(:type)
|
12
12
|
|
13
|
-
|
13
|
+
params.fetch(:inbox, {}).fetch(:id, nil)
|
14
14
|
plug_installation_id = params.fetch(:plug_installation, {}).fetch(:id, nil)
|
15
15
|
message_id = params.fetch(:message, {}).fetch(:id, nil)
|
16
16
|
|
17
17
|
case type
|
18
18
|
when "update_plug_installation"
|
19
19
|
YettoService.update_installation(plug_installation_id, params)
|
20
|
-
when "create_inbox_switch"
|
21
|
-
YettoService.create_inbox_switch(inbox_id, plug_installation_id, params)
|
22
20
|
when "create_message_reply"
|
23
21
|
YettoService.create_message_reply(message_id, plug_installation_id, params)
|
24
22
|
when "add_message_metadata"
|
@@ -101,7 +101,7 @@ module BodyParameter
|
|
101
101
|
title = conversation.fetch(:title, "")
|
102
102
|
created_by_user = message.fetch(:created_by_user, {})
|
103
103
|
created_by_plug = message.fetch(:created_by_plug, {})
|
104
|
-
author =
|
104
|
+
author = created_by_user.presence || created_by_plug
|
105
105
|
name = author.fetch(:name, "")
|
106
106
|
metadata = message.fetch(:metadata, {}).to_unsafe_hash
|
107
107
|
|
@@ -12,42 +12,71 @@ module PlugApp
|
|
12
12
|
|
13
13
|
def initialize(app)
|
14
14
|
@app = app
|
15
|
-
@response_validator = OpenapiFirst::ResponseValidator.new(SPEC)
|
16
|
-
@request_validator = OpenapiFirst::RequestValidation.new(->(_env) {}, spec: SPEC, raise_error: true)
|
17
15
|
end
|
18
16
|
|
19
17
|
def call(env)
|
20
18
|
request = Rack::Request.new(env)
|
21
19
|
|
22
|
-
|
20
|
+
return @app.call(env) unless request.path.starts_with?(API_PATH_PREFIX) && request.path.exclude?("/settings")
|
21
|
+
|
22
|
+
begin
|
23
23
|
# force content-type to JSON
|
24
|
-
if env["CONTENT_TYPE"]
|
25
|
-
|
26
|
-
|
24
|
+
env["CONTENT_TYPE"] = "application/json" if env["CONTENT_TYPE"] != "application/json"
|
25
|
+
|
26
|
+
validated_request = SPEC.validate_request(request)
|
27
|
+
|
28
|
+
return @app.call(env) if validated_request.valid?
|
29
|
+
|
30
|
+
case validated_request.error
|
31
|
+
when OpenapiFirst::Schema::ValidationError
|
32
|
+
error_arr = format_arr(validated_request.error.errors.map(&:error))
|
33
|
+
Rails.logger.error(error_arr) if print_user_api_errors?
|
34
|
+
[PlugApp::HTTP::BAD_REQUEST_I, { "Content-Type" => "application/json" }, [error_arr]]
|
35
|
+
else
|
36
|
+
case validated_request.error.error_type
|
37
|
+
when :not_found
|
38
|
+
[PlugApp::HTTP::NOT_FOUND_I, { "Content-Type" => "application/json" }, [format_str("Not Found")]]
|
39
|
+
else
|
40
|
+
error_message = if validated_request.error.errors.present?
|
41
|
+
format_arr(validated_request.error.errors.map(&:error))
|
42
|
+
else
|
43
|
+
format_str(validated_request.error.message)
|
44
|
+
end
|
27
45
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# @response_validator.validate(request, response)
|
32
|
-
rescue OpenapiFirst::NotFoundError
|
33
|
-
PlugApp::Middleware::NotFound.new.call(env)
|
34
|
-
rescue OpenapiFirst::RequestInvalidError => e
|
35
|
-
error_hsh = ::ErrorSerializer.format(e.message)
|
36
|
-
Rails.logger.error(error_hsh) if print_user_api_errors?
|
37
|
-
return [PlugApp::HTTP::BAD_REQUEST_I, { "Content-Type" => "application/json" }, [error_hsh]]
|
38
|
-
rescue StandardError => e
|
39
|
-
raise e unless Rails.env.production?
|
40
|
-
|
41
|
-
logger.error(
|
42
|
-
"openapi.request_validation.error",
|
43
|
-
path: request.path,
|
44
|
-
method: request.env["REQUEST_METHOD"],
|
45
|
-
error_message: e.message,
|
46
|
-
)
|
46
|
+
Rails.logger.error(error_message) if print_user_api_errors?
|
47
|
+
[PlugApp::HTTP::BAD_REQUEST_I, { "Content-Type" => "application/json" }, [error_message]]
|
48
|
+
end
|
47
49
|
end
|
50
|
+
rescue StandardError => e
|
51
|
+
raise e unless Rails.env.production?
|
52
|
+
|
53
|
+
logger.error(
|
54
|
+
"openapi.request_validation.error",
|
55
|
+
path: request.path,
|
56
|
+
method: request.env["REQUEST_METHOD"],
|
57
|
+
error_message: e.message,
|
58
|
+
)
|
48
59
|
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private def format_str(error)
|
63
|
+
{
|
64
|
+
errors: [
|
65
|
+
{
|
66
|
+
message: error,
|
67
|
+
},
|
68
|
+
],
|
69
|
+
}.to_json
|
70
|
+
end
|
49
71
|
|
50
|
-
|
72
|
+
private def format_arr(errors)
|
73
|
+
{
|
74
|
+
errors: errors.each_with_object([]) do |error, arr|
|
75
|
+
arr << {
|
76
|
+
message: error,
|
77
|
+
}
|
78
|
+
end,
|
79
|
+
}.to_json
|
51
80
|
end
|
52
81
|
end
|
53
82
|
end
|
@@ -34,13 +34,6 @@ class YettoService
|
|
34
34
|
yetto_client.with_headers("Authorization" => "Bearer #{token}").patch("#{YETTO_API_VERSION_TLD}/installations/#{plug_installation_id}", json: plug_installation)
|
35
35
|
end
|
36
36
|
|
37
|
-
def create_inbox_switch(inbox_id, plug_installation_id, params)
|
38
|
-
payload = params[:payload]
|
39
|
-
token = perform_token_exchange(plug_installation_id)
|
40
|
-
|
41
|
-
yetto_client.with_headers("Authorization" => "Bearer #{token}").post("#{YETTO_API_VERSION_TLD}/inboxes/#{inbox_id}/switches", json: payload)
|
42
|
-
end
|
43
|
-
|
44
37
|
def update_message(message_id, plug_installation_id, params)
|
45
38
|
payload = params[:payload]
|
46
39
|
token = perform_token_exchange(plug_installation_id)
|
@@ -115,24 +115,5 @@ module Webmocks
|
|
115
115
|
body: {}.to_json,
|
116
116
|
)
|
117
117
|
end
|
118
|
-
|
119
|
-
def assert_requested_create_inbox_switch(inbox_id, plug_installation_id)
|
120
|
-
assert_requested_post_access_token(plug_installation_id)
|
121
|
-
assert_requested(:post, "#{::YettoService::YETTO_API_VERSION_TLD}/inboxes/#{inbox_id}/switches")
|
122
|
-
end
|
123
|
-
|
124
|
-
def stub_create_inbox_switch(inbox_id, plug_installation_id, payload)
|
125
|
-
stub_post_access_token(plug_installation_id)
|
126
|
-
|
127
|
-
stub_request(:post, "#{::YettoService::YETTO_API_VERSION_TLD}/inboxes/#{inbox_id}/switches")
|
128
|
-
.with(
|
129
|
-
body: payload,
|
130
|
-
)
|
131
|
-
.to_return(
|
132
|
-
status: 200,
|
133
|
-
headers: { content_type: "application/json; charset=utf-8" },
|
134
|
-
body: {}.to_json,
|
135
|
-
)
|
136
|
-
end
|
137
118
|
end
|
138
119
|
end
|
@@ -13,6 +13,18 @@ LD_PRELOAD_PATH = "/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"
|
|
13
13
|
web = "./bin/rails server"
|
14
14
|
worker = "bundle exec sidekiq"
|
15
15
|
|
16
|
+
[[vm]]
|
17
|
+
cpu_kind = "performance"
|
18
|
+
cpus = 2
|
19
|
+
memory = "4gb"
|
20
|
+
processes = ["web"]
|
21
|
+
|
22
|
+
[[vm]]
|
23
|
+
cpu_kind = "performance"
|
24
|
+
cpus = 1
|
25
|
+
memory = "2gb"
|
26
|
+
processes = ["worker"]
|
27
|
+
|
16
28
|
[http_service]
|
17
29
|
internal_port = 3000
|
18
30
|
force_https = true
|
@@ -9,6 +9,18 @@ LD_PRELOAD_PATH = "/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"
|
|
9
9
|
web = "./bin/rails server"
|
10
10
|
worker = "bundle exec sidekiq"
|
11
11
|
|
12
|
+
[[vm]]
|
13
|
+
cpu_kind = "shared"
|
14
|
+
cpus = 2
|
15
|
+
memory = "2gb"
|
16
|
+
processes = ["web"]
|
17
|
+
|
18
|
+
[[vm]]
|
19
|
+
cpu_kind = "shared"
|
20
|
+
cpus = 2
|
21
|
+
memory = "1gb"
|
22
|
+
processes = ["worker"]
|
23
|
+
|
12
24
|
[http_service]
|
13
25
|
internal_port = 3000
|
14
26
|
force_https = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hephaestus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -168,10 +168,8 @@ files:
|
|
168
168
|
- templates/app/lib/path_parameter/yetto_parameters.rb
|
169
169
|
- templates/app/lib/plug_app/http.rb
|
170
170
|
- templates/app/lib/plug_app/middleware/malformed_request.rb
|
171
|
-
- templates/app/lib/plug_app/middleware/not_found.rb
|
172
171
|
- templates/app/lib/plug_app/middleware/openapi_validation.rb
|
173
172
|
- templates/app/lib/plug_app/middleware/tracing_attributes.rb
|
174
|
-
- templates/app/lib/plug_app/switches/message_created.jsonc
|
175
173
|
- templates/app/lib/query_parameter.rb
|
176
174
|
- templates/app/serializers/error_serializer.rb
|
177
175
|
- templates/app/services/http_service.rb
|
@@ -244,14 +242,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
244
242
|
requirements:
|
245
243
|
- - ">="
|
246
244
|
- !ruby/object:Gem::Version
|
247
|
-
version: 3.
|
245
|
+
version: 3.3.0
|
248
246
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
249
247
|
requirements:
|
250
248
|
- - ">="
|
251
249
|
- !ruby/object:Gem::Version
|
252
250
|
version: 3.4.7
|
253
251
|
requirements: []
|
254
|
-
rubygems_version: 3.
|
252
|
+
rubygems_version: 3.5.6
|
255
253
|
signing_key:
|
256
254
|
specification_version: 4
|
257
255
|
summary: Generate a Rails app that can be used to create plugs for Yetto.
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# typed: false
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "openapi_first"
|
5
|
-
|
6
|
-
module PlugApp
|
7
|
-
module Middleware
|
8
|
-
# frozen_string_literal: true
|
9
|
-
|
10
|
-
# Rack::NotFound is a default endpoint. Optionally initialize with the
|
11
|
-
# path to a custom 404 page, to override the standard response body.
|
12
|
-
#
|
13
|
-
# Examples:
|
14
|
-
#
|
15
|
-
# Serve default 404 response:
|
16
|
-
# run Rack::NotFound.new
|
17
|
-
#
|
18
|
-
# Serve a custom 404 page:
|
19
|
-
# run Rack::NotFound.new('path/to/your/404.html')
|
20
|
-
|
21
|
-
class NotFound
|
22
|
-
F = ::File
|
23
|
-
|
24
|
-
def initialize(path = nil, content_type = "text/html")
|
25
|
-
if path.nil?
|
26
|
-
@content = "Not found\n"
|
27
|
-
else
|
28
|
-
@content = F.read(path)
|
29
|
-
@content = F.read(path)
|
30
|
-
end
|
31
|
-
@length = @content.bytesize.to_s
|
32
|
-
|
33
|
-
@content_type = content_type
|
34
|
-
end
|
35
|
-
|
36
|
-
def call(env)
|
37
|
-
[404, { "Content-Type" => @content_type, "Content-Length" => @length }, [@content]]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "Send internal comments to App",
|
3
|
-
"configuration": {
|
4
|
-
"version": "2023-03-06",
|
5
|
-
"events": {
|
6
|
-
"message.created": {
|
7
|
-
"conditions": {
|
8
|
-
"if": "{% data.message.visibility == 'internal' and data.message.text_content contains '@App' %}"
|
9
|
-
},
|
10
|
-
"actions": [
|
11
|
-
{
|
12
|
-
"name": "Send to App",
|
13
|
-
"uses": "send_to_plug",
|
14
|
-
"with": {
|
15
|
-
"plug_id": "{{ data.switch.created_by_plug.id }}",
|
16
|
-
"message": "{{ data.message }}",
|
17
|
-
"plug_installation": "{{ data.plug_installation }}",
|
18
|
-
"inbox": "{{ data.inbox }}"
|
19
|
-
}
|
20
|
-
}
|
21
|
-
]
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|
25
|
-
}
|