securial 2.0.0 → 2.1.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/lib/securial/cli.rb +26 -0
- data/lib/securial/engine.rb +1 -1
- data/lib/securial/engine_initializers.rb +0 -7
- data/lib/securial/version.rb +1 -1
- metadata +3 -9
- data/lib/generators/factory_bot/model/model_generator.rb +0 -32
- data/lib/generators/factory_bot/templates/factory.erb +0 -7
- data/lib/securial/factories/securial/role_assignments.rb +0 -6
- data/lib/securial/factories/securial/roles.rb +0 -18
- data/lib/securial/factories/securial/sessions.rb +0 -12
- data/lib/securial/factories/securial/users.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9c7a709db9d2a74edcd0d7d4046d280049a2d83fe63fbb8aa5d15b209ac39aa
|
4
|
+
data.tar.gz: 520a658e2797e57cdcb7ef1d365324b84ba2c57e2e1197974c7d76f516d7977e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf133510e6d9923775356f1ce0d8674289dafc8cc52e0f87faf10a156b9c24285d62d07fa5db4c32363f82bd40c714266c70c8694016d6cbf46bedcc58aab1af
|
7
|
+
data.tar.gz: f150c5a04805ea5a8d92b0833dd1e926265d8fb574534e3f146b7865c9c49b38514b8edf8069be7ee5e3f92b752eff52e05191d123abb30ac69f5db4cd359c7b
|
data/lib/securial/cli.rb
CHANGED
@@ -14,6 +14,8 @@
|
|
14
14
|
# $ securial new myapi --api --database=postgresql
|
15
15
|
#
|
16
16
|
require "optparse"
|
17
|
+
require "yaml"
|
18
|
+
require "erb"
|
17
19
|
|
18
20
|
# rubocop:disable Rails/Exit, Rails/Output
|
19
21
|
|
@@ -171,6 +173,7 @@ module Securial
|
|
171
173
|
puts "🏗️ Creating new Rails app: #{app_name}"
|
172
174
|
|
173
175
|
create_rails_app(app_name, rails_options)
|
176
|
+
update_database_yml_host(app_name)
|
174
177
|
add_securial_gem(app_name)
|
175
178
|
install_gems(app_name)
|
176
179
|
install_securial(app_name)
|
@@ -189,6 +192,29 @@ module Securial
|
|
189
192
|
run(rails_command)
|
190
193
|
end
|
191
194
|
|
195
|
+
# Adds DB_HOST env. variable to as default host in `database.yml`.
|
196
|
+
#
|
197
|
+
# @param app_name [String] name of the Rails application
|
198
|
+
# @return [void]
|
199
|
+
#
|
200
|
+
def update_database_yml_host(app_name)
|
201
|
+
db_config_path = File.join(app_name, "config", "database.yml")
|
202
|
+
raw = File.read(db_config_path)
|
203
|
+
rendered = ERB.new(raw).result
|
204
|
+
config = YAML.safe_load(rendered, aliases: true) || {}
|
205
|
+
|
206
|
+
config["default"] ||= {}
|
207
|
+
return if config["default"]["adapter"].blank?
|
208
|
+
return unless ["mysql2", "postgresql"].include?(config["default"]["adapter"])
|
209
|
+
config["default"]["host"] = "<%= ENV.fetch(\"DB_HOST\", \"localhost\") %>"
|
210
|
+
config["default"]["username"] = "<%= ENV.fetch(\"DB_USERNAME\") { \"postgres\" } %>"
|
211
|
+
config["default"]["password"] = "<%= ENV.fetch(\"DB_PASSWORD\") { \"postgres\" } %>"
|
212
|
+
|
213
|
+
# Dump YAML manually to preserve formatting
|
214
|
+
yaml = config.to_yaml.gsub(/['"](<%= .*? %>)['"]/, '\1') # Unquote the ERB
|
215
|
+
File.write(db_config_path, yaml)
|
216
|
+
end
|
217
|
+
|
192
218
|
# Adds the Securial gem to the application's Gemfile.
|
193
219
|
#
|
194
220
|
# @param app_name [String] name of the Rails application
|
data/lib/securial/engine.rb
CHANGED
@@ -9,13 +9,6 @@ module Securial
|
|
9
9
|
]
|
10
10
|
end
|
11
11
|
|
12
|
-
initializer "securial.factory_bot", after: "factory_bot.set_factory_paths" do
|
13
|
-
if defined?(FactoryBot)
|
14
|
-
FactoryBot.definition_file_paths << Engine.root.join("lib", "securial", "factories")
|
15
|
-
require_relative "../generators/factory_bot/model/model_generator"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
12
|
initializer "securial.security.request_rate_limiter" do |app|
|
20
13
|
if Securial.configuration.rate_limiting_enabled
|
21
14
|
Securial::Security::RequestRateLimiter.apply!
|
data/lib/securial/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: securial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aly Badawy
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-07-
|
10
|
+
date: 2025-07-10 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|
@@ -149,8 +149,6 @@ files:
|
|
149
149
|
- db/migrate/20250604123805_create_securial_role_assignments.rb
|
150
150
|
- db/migrate/20250604184841_create_securial_sessions.rb
|
151
151
|
- db/migrate/20250606182648_seed_roles_and_users.rb
|
152
|
-
- lib/generators/factory_bot/model/model_generator.rb
|
153
|
-
- lib/generators/factory_bot/templates/factory.erb
|
154
152
|
- lib/generators/securial/install/install_generator.rb
|
155
153
|
- lib/generators/securial/install/templates/securial_initializer.erb
|
156
154
|
- lib/generators/securial/install/views_generator.rb
|
@@ -179,10 +177,6 @@ files:
|
|
179
177
|
- lib/securial/error/auth.rb
|
180
178
|
- lib/securial/error/base_securial_error.rb
|
181
179
|
- lib/securial/error/config.rb
|
182
|
-
- lib/securial/factories/securial/role_assignments.rb
|
183
|
-
- lib/securial/factories/securial/roles.rb
|
184
|
-
- lib/securial/factories/securial/sessions.rb
|
185
|
-
- lib/securial/factories/securial/users.rb
|
186
180
|
- lib/securial/helpers.rb
|
187
181
|
- lib/securial/helpers/key_transformer.rb
|
188
182
|
- lib/securial/helpers/normalizing_helper.rb
|
@@ -207,7 +201,7 @@ licenses:
|
|
207
201
|
- MIT
|
208
202
|
metadata:
|
209
203
|
homepage_uri: https://github.com/AlyBadawy/Securial/wiki
|
210
|
-
release_date: '2025-07-
|
204
|
+
release_date: '2025-07-10'
|
211
205
|
allowed_push_host: https://rubygems.org
|
212
206
|
source_code_uri: https://github.com/AlyBadawy/Securial
|
213
207
|
documentation_uri: https://alybadawy.github.io/Securial/_index.html
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require "rails/generators"
|
2
|
-
require "rails/generators/named_base"
|
3
|
-
|
4
|
-
# @!ignore
|
5
|
-
module FactoryBot
|
6
|
-
module Generators
|
7
|
-
class ModelGenerator < Rails::Generators::NamedBase
|
8
|
-
source_root File.expand_path("../templates", __dir__)
|
9
|
-
|
10
|
-
argument :attributes, type: :array, default: [], banner: "field[:type] field[:type]"
|
11
|
-
|
12
|
-
def create_factory_file
|
13
|
-
template "factory.erb", File.join("lib/securial/factories/securial", "#{file_name.pluralize}.rb")
|
14
|
-
end
|
15
|
-
|
16
|
-
# Helper method accessible in the template
|
17
|
-
def securial_attribute_defaults
|
18
|
-
{
|
19
|
-
string: '"MyString"',
|
20
|
-
text: '"MyText"',
|
21
|
-
integer: "1",
|
22
|
-
float: "1.5",
|
23
|
-
decimal: '"9.99"',
|
24
|
-
datetime: "Time.zone.now",
|
25
|
-
time: "Time.zone.now",
|
26
|
-
date: "Time.zone.now",
|
27
|
-
boolean: "false",
|
28
|
-
}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :securial_role, class: "Securial::Role" do
|
3
|
-
role_name { "MyString" }
|
4
|
-
hide_from_profile { false }
|
5
|
-
|
6
|
-
trait :admin do
|
7
|
-
role_name { "Admin" }
|
8
|
-
end
|
9
|
-
|
10
|
-
trait :user do
|
11
|
-
role_name { "User" }
|
12
|
-
end
|
13
|
-
|
14
|
-
trait :hidden do
|
15
|
-
hide_from_profile { true }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :securial_session, class: "Securial::Session" do
|
3
|
-
ip_address { "127.0.0.1" }
|
4
|
-
user_agent { "Ruby/RSpec" }
|
5
|
-
refresh_count { 1 }
|
6
|
-
refresh_token { SecureRandom.hex(64) }
|
7
|
-
last_refreshed_at { Time.current }
|
8
|
-
refresh_token_expires_at { 1.week.from_now }
|
9
|
-
revoked { false }
|
10
|
-
association :user, factory: :securial_user
|
11
|
-
end
|
12
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
FactoryBot.define do
|
2
|
-
factory :securial_user, class: "Securial::User" do
|
3
|
-
email_address { Faker::Internet.email }
|
4
|
-
password { "Password_.1" }
|
5
|
-
password_confirmation { "Password_.1" }
|
6
|
-
first_name { Faker::Name.first_name }
|
7
|
-
last_name { Faker::Name.last_name }
|
8
|
-
phone { Faker::PhoneNumber.cell_phone }
|
9
|
-
username { Faker::Internet.username(specifier: 3..20) }
|
10
|
-
bio { Faker::Lorem.paragraph }
|
11
|
-
|
12
|
-
trait :admin do
|
13
|
-
admin_role = Securial.configuration.admin_role.to_s.strip.titleize
|
14
|
-
roles { [Securial::Role.find_or_create_by(role_name: admin_role)] }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|