roda-gen 1.0.0
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 +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/bin/roda +11 -0
- data/lib/roda-gen.rb +3 -0
- data/lib/roda_gen/app_name.rb +29 -0
- data/lib/roda_gen/cli.rb +122 -0
- data/lib/roda_gen/generators/daemon.rb +78 -0
- data/lib/roda_gen/generators/migration.rb +68 -0
- data/lib/roda_gen/generators/migration_numbering.rb +21 -0
- data/lib/roda_gen/generators/model.rb +75 -0
- data/lib/roda_gen/generators/project.rb +145 -0
- data/lib/roda_gen/generators/route.rb +71 -0
- data/lib/roda_gen/generators/templates/daemon/bin/%daemon_name%.tt +13 -0
- data/lib/roda_gen/generators/templates/daemon/lib/daemon/%daemon_name%.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/daemon/spec/daemons/%daemon_name%_spec.rb.tt +18 -0
- data/lib/roda_gen/generators/templates/migration/db/migrate/%migration_filename%.rb.tt +6 -0
- data/lib/roda_gen/generators/templates/model/db/migrate/%migration_filename%.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/model/models/%resource_name%.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/model/spec/models/%resource_name%_spec.rb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/%app_name%.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/.bundle/config.tt +3 -0
- data/lib/roda_gen/generators/templates/project/.erb_lint.yml.tt +29 -0
- data/lib/roda_gen/generators/templates/project/.gitignore.tt +19 -0
- data/lib/roda_gen/generators/templates/project/.reek.yml.tt +45 -0
- data/lib/roda_gen/generators/templates/project/.rspec.tt +4 -0
- data/lib/roda_gen/generators/templates/project/.rubocop.yml.tt +119 -0
- data/lib/roda_gen/generators/templates/project/.ruby-version.tt +1 -0
- data/lib/roda_gen/generators/templates/project/.rubycritic.yml.tt +15 -0
- data/lib/roda_gen/generators/templates/project/Gemfile.tt +109 -0
- data/lib/roda_gen/generators/templates/project/Procfile.dev.tt +7 -0
- data/lib/roda_gen/generators/templates/project/README.md.tt +891 -0
- data/lib/roda_gen/generators/templates/project/Rakefile.tt +3 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/admin.js.tt +84 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/app.js.tt +29 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/push.js.tt +53 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/upload.js.tt +200 -0
- data/lib/roda_gen/generators/templates/project/assets/stylesheets/app.css.tt +52 -0
- data/lib/roda_gen/generators/templates/project/assets/stylesheets/typography.css.tt +85 -0
- data/lib/roda_gen/generators/templates/project/bin/console.tt +2 -0
- data/lib/roda_gen/generators/templates/project/bin/dev.tt +8 -0
- data/lib/roda_gen/generators/templates/project/bin/gdpr_worker.tt +13 -0
- data/lib/roda_gen/generators/templates/project/bin/push_sender.tt +13 -0
- data/lib/roda_gen/generators/templates/project/bin/setup.tt +224 -0
- data/lib/roda_gen/generators/templates/project/bin/shrine_clean_cache.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/boot.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/config/console.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/database.rb.tt +45 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/00_environments.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/01_logger.rb.tt +46 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/02_app_config.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/10_database.rb.tt +3 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/15_mail.rb.tt +53 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/20_redis.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/25_rack_attack.rb.tt +96 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/30_i18n.rb.tt +37 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/35_listen_job.rb.tt +4 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/37_shrine.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/40_routing.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/41_render.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/43_static.rb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/44_sessions.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/45_security.rb.tt +49 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/46_flash.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/47_json.rb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/48_errors.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/49_misc.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/50_mailer.rb.tt +52 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/51_locale_kit.rb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/52_consent_kit.rb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/55_audit_log.rb.tt +16 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/56_form_helper.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/57_rodauth.rb.tt +304 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/60_web_push.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/61_flipper.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/62_split.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/config/puma.rb.tt +24 -0
- data/lib/roda_gen/generators/templates/project/config/settings/development.yml.tt +9 -0
- data/lib/roda_gen/generators/templates/project/config/settings/production.yml.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/settings/test.yml.tt +9 -0
- data/lib/roda_gen/generators/templates/project/config/settings.yml.tt +45 -0
- data/lib/roda_gen/generators/templates/project/config.ru.tt +36 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_account_profiles.rb.tt +66 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_accounts.rb.tt +70 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_audit_log.rb.tt +185 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_authorization.rb.tt +68 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_countries.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_calling_codes.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_exit_codes.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_languages.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_time_zones.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_currencies.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_gdpr_requests.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_languages.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_push_subscriptions.rb.tt +16 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_rodauth_features.rb.tt +105 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_settings.rb.tt +60 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_countries.csv.tt +250 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_currencies.csv.tt +162 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_languages.csv.tt +144 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_calling_codes.csv.tt +237 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_exit_codes.csv.tt +239 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_languages.csv.tt +226 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_time_zones.csv.tt +369 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/03_setting_system_defaults.yml.tt +35 -0
- data/lib/roda_gen/generators/templates/project/db/seeds.rb.tt +69 -0
- data/lib/roda_gen/generators/templates/project/deploy/Caddyfile.tt +69 -0
- data/lib/roda_gen/generators/templates/project/deploy/logrotate/%app_name%-caddy.tt +11 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.service.tt +21 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.timer.tt +16 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-gdpr-worker.service.tt +25 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-push-sender.service.tt +25 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.service.tt +21 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.timer.tt +16 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%.service.tt +36 -0
- data/lib/roda_gen/generators/templates/project/helpers/audit_helper.rb.tt +59 -0
- data/lib/roda_gen/generators/templates/project/helpers/authorization_helper.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/helpers/current_account_helper.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/helpers/feature_flag_helper.rb.tt +34 -0
- data/lib/roda_gen/generators/templates/project/helpers/form_helper.rb.tt +50 -0
- data/lib/roda_gen/generators/templates/project/helpers/http_cache_helper.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/helpers/logger_helper.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/helpers/split_helper.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/lib/audit_context.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/lib/audit_lookup.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/base.rb.tt +104 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/gdpr_worker.rb.tt +53 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/push_sender.rb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/shrine_cache_cleaner.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/lib/deploy_check.rb.tt +96 -0
- data/lib/roda_gen/generators/templates/project/lib/filtered_logger.rb.tt +54 -0
- data/lib/roda_gen/generators/templates/project/lib/gdpr.rb.tt +106 -0
- data/lib/roda_gen/generators/templates/project/lib/rbac_audit.rb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/.rubocop.yml.tt +4 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/audit.rake.tt +85 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/console.rake.tt +8 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/db.rake.tt +104 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/deploy.rake.tt +38 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/flags.rake.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/gdpr.rake.tt +31 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/parser_current_shim.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/quality.rake.tt +84 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/secrets.rake.tt +154 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/spec.rake.tt +136 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/split.rake.tt +27 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/tailwind.rake.tt +35 -0
- data/lib/roda_gen/generators/templates/project/locales/de.yml.tt +325 -0
- data/lib/roda_gen/generators/templates/project/locales/en.yml.tt +321 -0
- data/lib/roda_gen/generators/templates/project/locales/es.yml.tt +326 -0
- data/lib/roda_gen/generators/templates/project/locales/fr.yml.tt +329 -0
- data/lib/roda_gen/generators/templates/project/locales/it.yml.tt +325 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/de.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/en.yml.tt +6 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/es.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/fr.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/it.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/sv.yml.tt +274 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/tru.yml.tt +274 -0
- data/lib/roda_gen/generators/templates/project/locales/sv.yml.tt +319 -0
- data/lib/roda_gen/generators/templates/project/locales/tru.yml.tt +294 -0
- data/lib/roda_gen/generators/templates/project/log/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/models/account.rb.tt +50 -0
- data/lib/roda_gen/generators/templates/project/models/account_privilege.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/models/account_profile.rb.tt +115 -0
- data/lib/roda_gen/generators/templates/project/models/account_role.rb.tt +14 -0
- data/lib/roda_gen/generators/templates/project/models/audit_action.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/models/audit_actor_type.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/models/audit_log.rb.tt +257 -0
- data/lib/roda_gen/generators/templates/project/models/audit_status.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/models/country.rb.tt +17 -0
- data/lib/roda_gen/generators/templates/project/models/country_calling_code.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/country_exit_code.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/country_language.rb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/models/country_time_zone.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/currency.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/gdpr_request.rb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/models/gender.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/language.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/models/privilege.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/models/push_subscription.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/models/role.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/models/role_privilege.rb.tt +14 -0
- data/lib/roda_gen/generators/templates/project/models/setting_system_default.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/models/setting_user_value.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/models/settings.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/models/signup_form_data.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/models.rb.tt +6 -0
- data/lib/roda_gen/generators/templates/project/package.json.tt +13 -0
- data/lib/roda_gen/generators/templates/project/public/apple-touch-icon.png +0 -0
- data/lib/roda_gen/generators/templates/project/public/favicon.ico +0 -0
- data/lib/roda_gen/generators/templates/project/public/favicon.svg.tt +5 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Italic-Variable.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Variable.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-BoldItalic.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Italic.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NOTICE.md +17 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/manifest.webmanifest.tt +12 -0
- data/lib/roda_gen/generators/templates/project/public/robots.txt.tt +4 -0
- data/lib/roda_gen/generators/templates/project/public/service-worker.js.tt +27 -0
- data/lib/roda_gen/generators/templates/project/routes/account.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/routes/admin.rb.tt +118 -0
- data/lib/roda_gen/generators/templates/project/routes/gdpr.rb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/routes/heartbeat.rb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/routes/legal.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/routes/profile.rb.tt +56 -0
- data/lib/roda_gen/generators/templates/project/routes/push.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/role_boundary_spec.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/spec_helper.rb.tt +146 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/support/auth_helpers.rb.tt +71 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/auth_spec.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/consent_nojs_spec.rb.tt +60 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/create_account_form_spec.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/otp_lifecycle_spec.rb.tt +67 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/profile_form_spec.rb.tt +17 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/upload_spec.rb.tt +102 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/wcag/auth_pages_spec.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/wcag/legal_pages_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/base_spec.rb.tt +106 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/gdpr_worker_spec.rb.tt +72 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/push_sender_spec.rb.tt +74 -0
- data/lib/roda_gen/generators/templates/project/spec/locale_parity_spec.rb.tt +58 -0
- data/lib/roda_gen/generators/templates/project/spec/models/account_profile_spec.rb.tt +180 -0
- data/lib/roda_gen/generators/templates/project/spec/models/account_spec.rb.tt +104 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_actor_type_spec.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_log_spec.rb.tt +398 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_status_spec.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/spec/models/authorization_spec.rb.tt +82 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_calling_code_spec.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_exit_code_spec.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_language_spec.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_spec.rb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_time_zone_spec.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/spec/models/currency_spec.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/spec/models/deploy_check_spec.rb.tt +143 -0
- data/lib/roda_gen/generators/templates/project/spec/models/gdpr_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/models/language_spec.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/spec/models/rbac_audit_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/models/setting_system_default_spec.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/spec/models/setting_user_value_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/models/settings_spec.rb.tt +63 -0
- data/lib/roda_gen/generators/templates/project/spec/models/signup_form_data_spec.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/spec/spec_helper.rb.tt +93 -0
- data/lib/roda_gen/generators/templates/project/spec/support/audit_log_helpers.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/support/audit_lookup_shared_examples.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/spec/support/auth_helpers.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/support/faker.rb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/spec/web/admin_spec.rb.tt +155 -0
- data/lib/roda_gen/generators/templates/project/spec/web/audit_log_spec.rb.tt +159 -0
- data/lib/roda_gen/generators/templates/project/spec/web/auth_spec.rb.tt +492 -0
- data/lib/roda_gen/generators/templates/project/spec/web/authorization_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/web/boot_spec.rb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/spec/web/consent_banner_spec.rb.tt +46 -0
- data/lib/roda_gen/generators/templates/project/spec/web/feature_flag_helper_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/web/flags_spec.rb.tt +67 -0
- data/lib/roda_gen/generators/templates/project/spec/web/gdpr_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/heartbeat_spec.rb.tt +65 -0
- data/lib/roda_gen/generators/templates/project/spec/web/host_allowlist_spec.rb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/spec/web/legal_spec.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/spec/web/locale_resolver_spec.rb.tt +34 -0
- data/lib/roda_gen/generators/templates/project/spec/web/logger_helper_spec.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/spec/web/logger_spec.rb.tt +82 -0
- data/lib/roda_gen/generators/templates/project/spec/web/otp_audit_spec.rb.tt +147 -0
- data/lib/roda_gen/generators/templates/project/spec/web/profile_spec.rb.tt +97 -0
- data/lib/roda_gen/generators/templates/project/spec/web/push_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_runtime_spec.rb.tt +52 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_spec.rb.tt +81 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rbac_audit_spec.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/web/request_id_spec.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/web/role_boundary_spec.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/web/session_skip_spec.rb.tt +74 -0
- data/lib/roda_gen/generators/templates/project/spec/web/split_helper_spec.rb.tt +38 -0
- data/lib/roda_gen/generators/templates/project/spec/web/type_routing_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/upload_zone_spec.rb.tt +91 -0
- data/lib/roda_gen/generators/templates/project/tmp/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/vendor/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/views/403.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/404.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/500.erb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/views/_head_meta.erb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/views/_impersonate_picker.erb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/views/_language_switcher.erb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/views/_locked_accounts.erb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/views/_upload_zone.erb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/views/account/profile.erb.tt +149 -0
- data/lib/roda_gen/generators/templates/project/views/admin/flags.erb.tt +51 -0
- data/lib/roda_gen/generators/templates/project/views/consent_kit/_banner.erb.tt +59 -0
- data/lib/roda_gen/generators/templates/project/views/consent_kit/_preferences.erb.tt +87 -0
- data/lib/roda_gen/generators/templates/project/views/gdpr/erased.erb.tt +6 -0
- data/lib/roda_gen/generators/templates/project/views/gdpr/index.erb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/views/layout.erb.tt +112 -0
- data/lib/roda_gen/generators/templates/project/views/legal/contact.erb.tt +44 -0
- data/lib/roda_gen/generators/templates/project/views/legal/cookies.erb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/views/legal/disclaimer.erb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/views/legal/privacy.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/account_unlocked.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/data_erased.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/data_export.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/add-recovery-codes.erb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/change-login.erb.tt +44 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/change-password.erb.tt +41 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/close-account.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/confirm-password.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/create-account.erb.tt +183 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/login.erb.tt +51 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/logout.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-auth.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-disable.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-setup.erb.tt +48 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock-not-available.erb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock.erb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-auth.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-codes.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/remember.erb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password-request.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password.erb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-auth.erb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-disable.erb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-manage.erb.tt +36 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account-request.erb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account-resend.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account.erb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-login-change.erb.tt +8 -0
- data/lib/roda_gen/generators/templates/route/routes/%plural%.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/route/spec/web/%plural%_spec.rb.tt +36 -0
- data/lib/roda_gen/generators/templates/route/views/%plural%/index.erb.tt +11 -0
- data/lib/roda_gen/generators/templates/route/views/%plural%/show.erb.tt +7 -0
- data/lib/roda_gen/generators/templates/upload/db/migrate/%migration_filename%.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/upload/helpers/upload_serving.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/upload/models/%resource_name%.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/upload/models/%resource_name%_uploader.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/upload/routes/%plural%.rb.tt +44 -0
- data/lib/roda_gen/generators/templates/upload/spec/web/%plural%_spec.rb.tt +56 -0
- data/lib/roda_gen/generators/templates/upload/views/%plural%/index.erb.tt +18 -0
- data/lib/roda_gen/generators/upload.rb +83 -0
- data/lib/roda_gen/project_context.rb +30 -0
- data/lib/roda_gen/version.rb +5 -0
- data/lib/roda_gen.rb +16 -0
- metadata +497 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Idempotent, re-running on an already-set-up project is fine
|
|
3
|
+
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
|
|
6
|
+
cd "$(dirname "$0")/.."
|
|
7
|
+
|
|
8
|
+
if [ "${RACK_ENV:-}" = "production" ]; then
|
|
9
|
+
cat <<'EOF'
|
|
10
|
+
bin/setup is a development-onboarding script and refuses to run with RACK_ENV=production.
|
|
11
|
+
|
|
12
|
+
For production setup, run the following manually. Steps 1-2 are SQL — run
|
|
13
|
+
them as a postgres superuser inside psql (sudo -u postgres psql). Step 3 is
|
|
14
|
+
shell — run from the project directory with RACK_ENV=production set.
|
|
15
|
+
|
|
16
|
+
-- 1. Create application roles. Passwords come from your prod
|
|
17
|
+
-- config/settings/production.local.yml, database.app_url (the app role,
|
|
18
|
+
-- used for migrations + writes) and database.url (the web role, used by
|
|
19
|
+
-- the running app).
|
|
20
|
+
EOF
|
|
21
|
+
cat <<EOF
|
|
22
|
+
CREATE ROLE "<%= @app.snake %>_app" LOGIN PASSWORD '<from database.app_url>';
|
|
23
|
+
CREATE ROLE "<%= @app.snake %>_web" LOGIN PASSWORD '<from database.url>';
|
|
24
|
+
|
|
25
|
+
-- 2. Create the production database, owned by the app role. PG 15+
|
|
26
|
+
-- only lets the owner create objects in the public schema.
|
|
27
|
+
CREATE DATABASE <%= @app.snake %>_production
|
|
28
|
+
OWNER <%= @app.snake %>_app
|
|
29
|
+
ENCODING 'UTF8'
|
|
30
|
+
TEMPLATE template0
|
|
31
|
+
LOCALE 'sv_SE.UTF-8';
|
|
32
|
+
|
|
33
|
+
# 3. Migrate + seed reference data + bootstrap audit partitions.
|
|
34
|
+
bundle exec rake db:up
|
|
35
|
+
bundle exec rake db:seed
|
|
36
|
+
bundle exec rake audit:add_next[5] # current + 4 future periods
|
|
37
|
+
EOF
|
|
38
|
+
exit 0
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
echo "→ bundle install"
|
|
42
|
+
bundle install
|
|
43
|
+
|
|
44
|
+
echo "→ generate gitignored settings/{development,test}.local.yml"
|
|
45
|
+
bundle exec rake secrets:install
|
|
46
|
+
|
|
47
|
+
# The app refuses non-socket Redis URLs (config/initializers/20_redis.rb),
|
|
48
|
+
# so catch a missing socket here, before anything else runs
|
|
49
|
+
echo "→ check Redis socket"
|
|
50
|
+
redis_url() {
|
|
51
|
+
RACK_ENV="$1" bundle exec ruby -e '
|
|
52
|
+
require "config"
|
|
53
|
+
Config.setup do |c|
|
|
54
|
+
c.const_name = "S"
|
|
55
|
+
c.use_env = true
|
|
56
|
+
c.env_prefix = "SETTINGS"
|
|
57
|
+
c.env_separator = "__"
|
|
58
|
+
c.fail_on_missing = false
|
|
59
|
+
end
|
|
60
|
+
Config.load_and_set_settings(
|
|
61
|
+
Config.setting_files("config", ENV.fetch("RACK_ENV", "development"))
|
|
62
|
+
)
|
|
63
|
+
print S.redis.url.to_s
|
|
64
|
+
' 2>/dev/null
|
|
65
|
+
}
|
|
66
|
+
for env in development test; do
|
|
67
|
+
url=$(redis_url "$env")
|
|
68
|
+
case "$url" in
|
|
69
|
+
unix://*) sock="${url#unix://}"; sock="${sock%%\?*}" ;;
|
|
70
|
+
*)
|
|
71
|
+
echo "→ redis.url for $env is not a unix:// socket URL: ${url:-<empty>}" >&2
|
|
72
|
+
echo " Set redis.url in config/settings/$env.yml ($env.local.yml and" >&2
|
|
73
|
+
echo " SETTINGS__REDIS__URL override it) and re-run bin/setup." >&2
|
|
74
|
+
exit 1 ;;
|
|
75
|
+
esac
|
|
76
|
+
if [ ! -S "$sock" ]; then
|
|
77
|
+
echo "→ Redis socket $sock not found ($env redis.url)" >&2
|
|
78
|
+
echo " Point redis.url in config/settings/$env.yml ($env.local.yml and" >&2
|
|
79
|
+
echo " SETTINGS__REDIS__URL override it) at your redis-server's unix socket" >&2
|
|
80
|
+
echo " and re-run bin/setup." >&2
|
|
81
|
+
exit 1
|
|
82
|
+
fi
|
|
83
|
+
done
|
|
84
|
+
|
|
85
|
+
if ! command -v npm >/dev/null 2>&1; then
|
|
86
|
+
cat <<'MSG' >&2
|
|
87
|
+
|
|
88
|
+
bin/setup needs npm (it installs Tailwind + daisyUI + @tailwindcss/typography
|
|
89
|
+
for the CSS build, and Playwright for browser specs). Install Node.js and
|
|
90
|
+
re-run, or run `bundle install`, set up the DB by hand from the README's
|
|
91
|
+
Database users section, and accept that bin/dev's css watch + browser specs
|
|
92
|
+
won't work.
|
|
93
|
+
MSG
|
|
94
|
+
exit 1
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
echo "→ npm install (Tailwind + daisyUI + typography for CSS build)"
|
|
98
|
+
npm install --no-fund --no-audit
|
|
99
|
+
|
|
100
|
+
echo "→ build CSS"
|
|
101
|
+
bundle exec rake tailwind:build
|
|
102
|
+
|
|
103
|
+
# template0 (not template1) when overriding the locale, since template1 inherits the cluster's default
|
|
104
|
+
PG_ENCODING="${PG_ENCODING:-UTF8}"
|
|
105
|
+
PG_LOCALE="${PG_LOCALE:-sv_SE.UTF-8}"
|
|
106
|
+
|
|
107
|
+
if command -v createdb >/dev/null 2>&1; then
|
|
108
|
+
|
|
109
|
+
# createdb's error for a missing OS locale is cryptic, catch it up front.
|
|
110
|
+
# The Swedish default is deliberate, override per host with PG_LOCALE=…
|
|
111
|
+
if command -v locale >/dev/null 2>&1 &&
|
|
112
|
+
! locale -a 2>/dev/null | tr '[:upper:]' '[:lower:]' | tr -d '-' |
|
|
113
|
+
grep -qx "$(printf %s "$PG_LOCALE" | tr '[:upper:]' '[:lower:]' | tr -d '-')"; then
|
|
114
|
+
echo "→ locale $PG_LOCALE is not available on this host" >&2
|
|
115
|
+
echo " Generate it (Debian: uncomment it in /etc/locale.gen, run locale-gen)" >&2
|
|
116
|
+
echo " or re-run as PG_LOCALE=<an available UTF-8 locale> bin/setup" >&2
|
|
117
|
+
exit 1
|
|
118
|
+
fi
|
|
119
|
+
|
|
120
|
+
# PG 15+ only lets the DB owner create objects in public, so the app role owns the DB
|
|
121
|
+
|
|
122
|
+
read_cred() {
|
|
123
|
+
bundle exec ruby -ruri -e '
|
|
124
|
+
require "config"
|
|
125
|
+
Config.setup do |c|
|
|
126
|
+
c.const_name = "S"
|
|
127
|
+
c.use_env = true
|
|
128
|
+
c.env_prefix = "SETTINGS"
|
|
129
|
+
c.env_separator = "__"
|
|
130
|
+
c.fail_on_missing = false
|
|
131
|
+
end
|
|
132
|
+
Config.load_and_set_settings(
|
|
133
|
+
Config.setting_files("config", ENV.fetch("RACK_ENV", "development"))
|
|
134
|
+
)
|
|
135
|
+
url = ARGV[0].split(".").reduce(S) { |s, k| s&.public_send(k) }
|
|
136
|
+
u = URI.parse(url.to_s)
|
|
137
|
+
print [u.user, u.password].join("\t") if u.user
|
|
138
|
+
' "$1" 2>/dev/null
|
|
139
|
+
}
|
|
140
|
+
IFS=$'\t' read -r app_user app_pass <<<"$(read_cred database.app_url)" || true
|
|
141
|
+
IFS=$'\t' read -r web_user web_pass <<<"$(read_cred database.url)" || true
|
|
142
|
+
|
|
143
|
+
# -X skips ~/.psqlrc so personal settings (\timing) can't pollute the tested output
|
|
144
|
+
role_exists() { [ "$(psql -X -tAc "SELECT 1 FROM pg_roles WHERE rolname = '$1'" postgres 2>/dev/null)" = 1 ]; }
|
|
145
|
+
|
|
146
|
+
pg_create_role() { # name password
|
|
147
|
+
local name="$1" pass="${2//\'/\'\'}" # double any single quotes for the SQL literal
|
|
148
|
+
[ -n "$name" ] || return 0
|
|
149
|
+
if role_exists "$name"; then
|
|
150
|
+
echo "→ role ${name} already exists"
|
|
151
|
+
elif psql -X -qc "CREATE ROLE \"${name}\" LOGIN PASSWORD '${pass}'" postgres >/dev/null 2>&1; then
|
|
152
|
+
echo "→ created role ${name}"
|
|
153
|
+
else
|
|
154
|
+
echo "→ could not create role ${name} (superuser needed?) — create it yourself, see README"
|
|
155
|
+
fi
|
|
156
|
+
}
|
|
157
|
+
pg_create_role "${app_user:-}" "${app_pass:-}"
|
|
158
|
+
pg_create_role "${web_user:-}" "${web_pass:-}"
|
|
159
|
+
|
|
160
|
+
owner_args=""
|
|
161
|
+
if [ -n "${app_user:-}" ] && role_exists "$app_user"; then
|
|
162
|
+
owner_args="-O ${app_user}"
|
|
163
|
+
fi
|
|
164
|
+
# Test DB is created by rake test:db
|
|
165
|
+
db="<%= @app.snake %>_development"
|
|
166
|
+
if createdb_err=$(createdb -E "$PG_ENCODING" -T template0 --locale="$PG_LOCALE" $owner_args "$db" 2>&1); then
|
|
167
|
+
echo "→ created $db ($PG_ENCODING / $PG_LOCALE)${owner_args:+, owner ${app_user}}"
|
|
168
|
+
elif [[ "$createdb_err" == *"already exists"* ]]; then
|
|
169
|
+
echo "→ $db already exists (skipping createdb)"
|
|
170
|
+
else
|
|
171
|
+
echo "→ createdb failed: $createdb_err" >&2
|
|
172
|
+
exit 1
|
|
173
|
+
fi
|
|
174
|
+
else
|
|
175
|
+
echo "→ createdb not on PATH; create the dev DB manually before continuing"
|
|
176
|
+
fi
|
|
177
|
+
|
|
178
|
+
echo "→ migrate development DB"
|
|
179
|
+
bundle exec rake db:up
|
|
180
|
+
|
|
181
|
+
echo "→ seed development DB with ISO reference data (countries, languages, currencies, …)"
|
|
182
|
+
bundle exec rake db:seed
|
|
183
|
+
|
|
184
|
+
echo "→ seed development DB with the current + next 4 audit_log partitions"
|
|
185
|
+
bundle exec rake audit:add_next[5]
|
|
186
|
+
|
|
187
|
+
# playwright-ruby-client gem and the playwright npm CLI must match
|
|
188
|
+
pw_gem_version="$(bundle exec ruby -e "require 'playwright'; print Playwright::COMPATIBLE_PLAYWRIGHT_VERSION")"
|
|
189
|
+
pw_npm_version="$(node -p "require('./package.json').devDependencies.playwright")"
|
|
190
|
+
if [ "$pw_gem_version" != "$pw_npm_version" ]; then
|
|
191
|
+
echo "→ playwright-ruby-client expects playwright@${pw_gem_version} but package.json pins ${pw_npm_version}." >&2
|
|
192
|
+
echo "→ Update package.json's devDependencies.playwright to ${pw_gem_version} and re-run bin/setup." >&2
|
|
193
|
+
exit 1
|
|
194
|
+
fi
|
|
195
|
+
|
|
196
|
+
echo "→ install Playwright Firefox binary (one-time, ~85 MB)"
|
|
197
|
+
npx playwright install firefox
|
|
198
|
+
echo " (chromium + webkit: \`npx playwright install chromium webkit\`)"
|
|
199
|
+
|
|
200
|
+
if git rev-parse --git-dir >/dev/null 2>&1; then
|
|
201
|
+
untracked=""
|
|
202
|
+
for f in Gemfile.lock package-lock.json; do
|
|
203
|
+
git ls-files --error-unmatch "$f" >/dev/null 2>&1 || [ ! -f "$f" ] || untracked="$untracked $f"
|
|
204
|
+
done
|
|
205
|
+
if [ -n "$untracked" ]; then
|
|
206
|
+
cat <<EOF
|
|
207
|
+
|
|
208
|
+
→ Commit your reproducible baseline:
|
|
209
|
+
git add$untracked
|
|
210
|
+
git commit -m "Lock dependency baseline from initial bin/setup"
|
|
211
|
+
|
|
212
|
+
Until these are committed, a fresh \`bundle install\` / \`npm install\`
|
|
213
|
+
on another machine can resolve to different versions inside the
|
|
214
|
+
Gemfile / package.json ranges.
|
|
215
|
+
EOF
|
|
216
|
+
fi
|
|
217
|
+
fi
|
|
218
|
+
|
|
219
|
+
cat <<EOF
|
|
220
|
+
|
|
221
|
+
Setup complete.
|
|
222
|
+
bin/dev # start web + tailwind --watch (foreman)
|
|
223
|
+
bundle exec rake test:all # run specs
|
|
224
|
+
EOF
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Least-privileged web role, the cleaner only needs SELECT on setting_system_defaults
|
|
5
|
+
ENV['DATABASE_ROLE'] = 'web'
|
|
6
|
+
|
|
7
|
+
require_relative '../<%= @app.snake %>'
|
|
8
|
+
# In development the web process gets models through rack-unreloader;
|
|
9
|
+
# a daemon boots outside it and has to load them itself.
|
|
10
|
+
require_relative '../models'
|
|
11
|
+
require_relative '../lib/daemon/shrine_cache_cleaner'
|
|
12
|
+
|
|
13
|
+
Daemons::ShrineCacheCleaner.cleanup!
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
|
|
5
|
+
# Roda's :environments plugin treats an unknown RACK_ENV as a no-op, so the app
|
|
6
|
+
# would boot with development defaults (insecure cookies, no SMTP, no freeze)
|
|
7
|
+
ALLOWED_RACK_ENVS = %w[development test production].freeze
|
|
8
|
+
rack_env = ENV.fetch('RACK_ENV', 'development')
|
|
9
|
+
unless ALLOWED_RACK_ENVS.include?(rack_env)
|
|
10
|
+
abort "RACK_ENV=#{rack_env.inspect} is not recognised, must be one of: #{ALLOWED_RACK_ENVS.join(', ')}"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Before Bundler.require so the load-path cache covers gem requires too
|
|
14
|
+
require 'bootsnap'
|
|
15
|
+
Bootsnap.setup(
|
|
16
|
+
cache_dir: 'tmp/cache',
|
|
17
|
+
development_mode: rack_env != 'production',
|
|
18
|
+
load_path_cache: true,
|
|
19
|
+
compile_cache_iseq: true,
|
|
20
|
+
compile_cache_yaml: true
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
Bundler.require(:default, rack_env.to_sym)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
ENV['DATABASE_ROLE'] = 'app'
|
|
4
|
+
|
|
5
|
+
require_relative '../<%= @app.snake %>'
|
|
6
|
+
|
|
7
|
+
# Development leaves models, routes and helpers to rack-unreloader, which the REPL does not run
|
|
8
|
+
if ENV.fetch('RACK_ENV', 'development') == 'development'
|
|
9
|
+
require_relative '../models'
|
|
10
|
+
DB.sql_log_level = :debug
|
|
11
|
+
DB.loggers << <%= @app.camel %>.logger
|
|
12
|
+
Dir["#{__dir__}/../routes/*.rb"].each { |f| require f }
|
|
13
|
+
Dir["#{__dir__}/../helpers/*.rb"].each { |f| require f }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
puts "<%= @app.human %> console — RACK_ENV=#{ENV.fetch('RACK_ENV', 'development')}"
|
|
17
|
+
puts 'Available: ' \
|
|
18
|
+
"#{<%= @app.camel %>} (app class), " \
|
|
19
|
+
"#{<%= @app.camel %>Mailer} (mailer), " \
|
|
20
|
+
'DB (Sequel database), models in models/, helpers in helpers/'
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_support/core_ext/object/blank'
|
|
4
|
+
require 'sequel'
|
|
5
|
+
|
|
6
|
+
# Rake tasks load this file without the initializers loop
|
|
7
|
+
require_relative 'initializers/02_app_config'
|
|
8
|
+
|
|
9
|
+
# DATABASE_ROLE=app owns the schema (rake, daemons, console, test boot set it),
|
|
10
|
+
# the default web role has DML on app tables only
|
|
11
|
+
connection_url = if ENV['DATABASE_ROLE'] == 'app' && <%= @app.camel %>Config.database&.app_url.present?
|
|
12
|
+
<%= @app.camel %>Config.database.app_url
|
|
13
|
+
else
|
|
14
|
+
<%= @app.camel %>Config.database&.url
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
raise '<%= @app.camel %>Config.database.url is not set — run rake secrets:install' if connection_url.blank?
|
|
18
|
+
|
|
19
|
+
# Also used for ADMIN_DB in spec_helper.rb
|
|
20
|
+
module Database
|
|
21
|
+
PG_EXTENSIONS = %i[
|
|
22
|
+
pg_auto_parameterize pg_array pg_interval pg_range pg_multirange
|
|
23
|
+
pg_enum pg_timestamptz pg_extended_date_support pg_json
|
|
24
|
+
].freeze
|
|
25
|
+
|
|
26
|
+
def self.connect(url)
|
|
27
|
+
db = Sequel.connect(url)
|
|
28
|
+
db.extension(*PG_EXTENSIONS)
|
|
29
|
+
db
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
DB = Database.connect(connection_url)
|
|
34
|
+
|
|
35
|
+
Sequel::Model.db = DB
|
|
36
|
+
Sequel::Model.plugin :auto_validations
|
|
37
|
+
Sequel::Model.plugin :require_valid_schema
|
|
38
|
+
# Audit-log payloads diff through column_changes
|
|
39
|
+
Sequel::Model.plugin :dirty
|
|
40
|
+
|
|
41
|
+
if ENV.fetch('RACK_ENV', 'development') == 'development'
|
|
42
|
+
Sequel::Model.cache_associations = false
|
|
43
|
+
else
|
|
44
|
+
Sequel::Model.plugin :subclasses
|
|
45
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'logger'
|
|
4
|
+
require 'time'
|
|
5
|
+
require_relative '../../helpers/logger_helper'
|
|
6
|
+
require_relative '../../lib/filtered_logger'
|
|
7
|
+
|
|
8
|
+
# No per-request log line, Caddy covers production
|
|
9
|
+
class <%= @app.camel %>
|
|
10
|
+
# Append when enabling a Rodauth feature with a sensitive param,
|
|
11
|
+
# spec/web/logger_spec.rb guards the list
|
|
12
|
+
SENSITIVE_PARAMS = %w[
|
|
13
|
+
password password_confirmation
|
|
14
|
+
password-confirm new-password login-confirm
|
|
15
|
+
otp otp_secret otp_raw_secret
|
|
16
|
+
recovery-code
|
|
17
|
+
key
|
|
18
|
+
_csrf
|
|
19
|
+
].freeze
|
|
20
|
+
|
|
21
|
+
log_sink = if test? && !ENV['LOG']
|
|
22
|
+
File.open(File::NULL, 'w')
|
|
23
|
+
else
|
|
24
|
+
$stdout
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
base_logger = Logger.new(log_sink)
|
|
28
|
+
base_logger.level = production? ? Logger::INFO : Logger::DEBUG
|
|
29
|
+
base_logger.formatter = proc do |severity, time, _progname, message|
|
|
30
|
+
body = message.is_a?(String) ? message : message.inspect
|
|
31
|
+
"#{time.utc.iso8601} #{severity} #{body}\n"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
opts[:logger] = FilteredLogger.new(base_logger, SENSITIVE_PARAMS)
|
|
35
|
+
|
|
36
|
+
# Caddy owns the access log in production; development has no Caddy,
|
|
37
|
+
# so log requests here, through the filter so tokens in query strings
|
|
38
|
+
# (the Rodauth verify and reset key) never reach the terminal
|
|
39
|
+
plugin :common_logger, opts[:logger], method: :debug if development?
|
|
40
|
+
|
|
41
|
+
def self.logger = opts[:logger]
|
|
42
|
+
|
|
43
|
+
# 30_i18n.rb's before hook needs :hooks loaded first
|
|
44
|
+
plugin :hooks
|
|
45
|
+
plugin LoggerHelper
|
|
46
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# config-5.6.x's Options#add_source! references Pathname without requiring it,
|
|
4
|
+
# RuboCop on Ruby 4 thinks Pathname is autoloaded
|
|
5
|
+
require 'pathname' # rubocop:disable Lint/RedundantRequireStatement -- config-5.6.x needs it
|
|
6
|
+
require 'config'
|
|
7
|
+
|
|
8
|
+
Config.setup do |c|
|
|
9
|
+
c.const_name = '<%= @app.camel %>Config'
|
|
10
|
+
c.use_env = true
|
|
11
|
+
c.env_prefix = 'SETTINGS'
|
|
12
|
+
c.env_separator = '__'
|
|
13
|
+
c.fail_on_missing = false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
Config.load_and_set_settings(
|
|
17
|
+
Config.setting_files(File.expand_path('..', __dir__), ENV.fetch('RACK_ENV', 'development'))
|
|
18
|
+
)
|
|
19
|
+
<%= @app.camel %>Config.freeze!
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'mail'
|
|
5
|
+
|
|
6
|
+
class <%= @app.camel %>
|
|
7
|
+
# simplecov:disable — env-gated, no test run boots this block
|
|
8
|
+
configure :development do
|
|
9
|
+
mail_dir = File.expand_path('../../tmp/mail', __dir__)
|
|
10
|
+
FileUtils.mkdir_p(mail_dir)
|
|
11
|
+
Mail.defaults { delivery_method :file, location: mail_dir }
|
|
12
|
+
end
|
|
13
|
+
# simplecov:enable
|
|
14
|
+
|
|
15
|
+
configure :test do
|
|
16
|
+
Mail.defaults { delivery_method :test }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# simplecov:disable — env-gated, no test run boots this block
|
|
20
|
+
configure :production do
|
|
21
|
+
smtp = <%= @app.camel %>Config.mail.accounts.default.smtp
|
|
22
|
+
Mail.defaults do
|
|
23
|
+
delivery_method :smtp,
|
|
24
|
+
address: smtp.address,
|
|
25
|
+
port: smtp.port,
|
|
26
|
+
user_name: smtp.user_name,
|
|
27
|
+
password: smtp.password,
|
|
28
|
+
authentication: smtp.authentication.to_sym,
|
|
29
|
+
enable_starttls_auto: smtp.enable_starttls_auto
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
# simplecov:enable
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Application log of every delivery — the operator's "did the mail go
|
|
36
|
+
# out". Registered on the Mail gem itself so Rodauth's mails are covered
|
|
37
|
+
# too, not only <%= @app.camel %>Mailer's. Recipient and subject only, never bodies.
|
|
38
|
+
class MailLogObserver
|
|
39
|
+
def self.delivered_email(mail)
|
|
40
|
+
<%= @app.camel %>.logger.info("mail sent to=#{mail.to&.join(',')} subject=#{mail.subject.inspect}")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
Mail.register_observer(MailLogObserver)
|
|
44
|
+
|
|
45
|
+
# Multipart bodies (the GDPR export attachment) lose the mailer plugin's
|
|
46
|
+
# content_type charset and Mail warns per send; interceptors run before
|
|
47
|
+
# encoding, so every message gets an explicit charset here
|
|
48
|
+
class MailCharsetInterceptor
|
|
49
|
+
def self.delivering_email(mail)
|
|
50
|
+
mail.charset ||= 'UTF-8'
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
Mail.register_interceptor(MailCharsetInterceptor)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'redis'
|
|
4
|
+
require 'connection_pool'
|
|
5
|
+
|
|
6
|
+
redis_url = <%= @app.camel %>Config.redis.url
|
|
7
|
+
|
|
8
|
+
# Unix socket only, keeps port and auth out of the threat model
|
|
9
|
+
raise "redis.url must be a unix:// socket URL, got #{redis_url.inspect}" unless redis_url.start_with?('unix://')
|
|
10
|
+
|
|
11
|
+
REDIS_OPTIONS = { url: redis_url }.freeze
|
|
12
|
+
|
|
13
|
+
REDIS = ConnectionPool.new(size: 5, timeout: 5) { Redis.new(REDIS_OPTIONS) }
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rack/attack'
|
|
4
|
+
require 'active_support/notifications'
|
|
5
|
+
require 'active_support/cache/redis_cache_store'
|
|
6
|
+
|
|
7
|
+
# rack-attack looks ActiveSupport::Notifications up once, at require time,
|
|
8
|
+
# which happened before ActiveSupport was loaded here. Hand it the notifier
|
|
9
|
+
# it missed, or the log subscriber at the bottom never fires
|
|
10
|
+
Rack::Attack.notifier ||= ActiveSupport::Notifications
|
|
11
|
+
|
|
12
|
+
# Must sit OUTSIDE Rack::Session in the stack, so throttled requests never deserialize a session
|
|
13
|
+
class <%= @app.camel %>
|
|
14
|
+
# simplecov:disable — env-gated, no test run boots this block
|
|
15
|
+
configure :production do
|
|
16
|
+
use Rack::Attack
|
|
17
|
+
end
|
|
18
|
+
# simplecov:enable
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Shared store so throttle counters stay in sync across Puma workers
|
|
22
|
+
Rack::Attack.cache.store = ActiveSupport::Cache::RedisCacheStore.new(redis: REDIS)
|
|
23
|
+
|
|
24
|
+
Rack::Attack.throttle('req/ip', limit: 60, period: 60, &:ip)
|
|
25
|
+
|
|
26
|
+
# Every credential, token or 2FA-bearing Rodauth route, session-protected ones included.
|
|
27
|
+
# When adding one, also append it to spec/web/rack_attack_spec.rb
|
|
28
|
+
AUTH_POST_PATHS = %w[
|
|
29
|
+
/account/login
|
|
30
|
+
/account/create-account
|
|
31
|
+
/account/confirm-password
|
|
32
|
+
/account/change-password
|
|
33
|
+
/account/change-login
|
|
34
|
+
/account/close-account
|
|
35
|
+
/account/reset-password-request
|
|
36
|
+
/account/reset-password
|
|
37
|
+
/account/verify-account
|
|
38
|
+
/account/verify-account-resend
|
|
39
|
+
/account/verify-login-change
|
|
40
|
+
/account/unlock-account-request
|
|
41
|
+
/account/unlock-account
|
|
42
|
+
/account/otp-setup
|
|
43
|
+
/account/otp-auth
|
|
44
|
+
/account/otp-disable
|
|
45
|
+
/account/otp-unlock
|
|
46
|
+
/account/recovery-codes
|
|
47
|
+
/account/recovery-auth
|
|
48
|
+
].freeze
|
|
49
|
+
|
|
50
|
+
# Rack::Attack sits outside LocaleKit, so /sv/account/login would miss AUTH_POST_PATHS unstripped
|
|
51
|
+
class << Rack::Attack
|
|
52
|
+
def auth_post?(req)
|
|
53
|
+
return false unless req.post?
|
|
54
|
+
|
|
55
|
+
AUTH_POST_PATHS.include?(LocaleKit.strip_locale_prefix(req.path))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
Rack::Attack.throttle('auth-post/ip', limit: 5, period: 20) do |req|
|
|
60
|
+
req.ip if Rack::Attack.auth_post?(req)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Per-email throttle defeats IP rotation against a single account
|
|
64
|
+
Rack::Attack.throttle('auth-post/email', limit: 6, period: 60) do |req|
|
|
65
|
+
next unless Rack::Attack.auth_post?(req)
|
|
66
|
+
|
|
67
|
+
email = req.params['login']
|
|
68
|
+
email.to_s.downcase.strip if email && !email.empty?
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# RateLimit-* headers per https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/
|
|
72
|
+
# plus plain retry-after, which this responder must emit itself: setting a custom
|
|
73
|
+
# throttled_responder bypasses Rack::Attack's retry_after_header option
|
|
74
|
+
Rack::Attack.throttled_responder = lambda do |request|
|
|
75
|
+
match_data = request.env['rack.attack.match_data']
|
|
76
|
+
now = match_data[:epoch_time]
|
|
77
|
+
retry_after = match_data[:period] - (now % match_data[:period])
|
|
78
|
+
headers = {
|
|
79
|
+
'content-type' => 'text/plain',
|
|
80
|
+
'retry-after' => retry_after.to_s,
|
|
81
|
+
'ratelimit-limit' => match_data[:limit].to_s,
|
|
82
|
+
'ratelimit-remaining' => '0',
|
|
83
|
+
'ratelimit-reset' => (now + retry_after).to_s
|
|
84
|
+
}
|
|
85
|
+
[429, headers, ["Throttled\n"]]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Regex so a new blocklist or track rule needs no extra subscribe call
|
|
89
|
+
ActiveSupport::Notifications.subscribe(/\.rack_attack\z/) do |name, _start, _finish, _id, payload|
|
|
90
|
+
req = payload[:request]
|
|
91
|
+
kind = name.split('.').first # "throttle" | "blocklist" | "safelist" | "track"
|
|
92
|
+
rule = req.env['rack.attack.matched']
|
|
93
|
+
<%= @app.camel %>.logger.warn(
|
|
94
|
+
"rack-attack #{kind}=#{rule} ip=#{req.ip} #{req.request_method} #{req.path}"
|
|
95
|
+
)
|
|
96
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'i18n'
|
|
4
|
+
require 'i18n/backend/fallbacks'
|
|
5
|
+
require 'i18n/backend/pluralization'
|
|
6
|
+
require 'twitter_cldr'
|
|
7
|
+
|
|
8
|
+
LOCALES_DIR = File.expand_path('../../locales', __dir__)
|
|
9
|
+
|
|
10
|
+
# Subdirs (locales/rodauth/...) extend gem translations and do not count toward available_locales
|
|
11
|
+
I18n.load_path |= Dir["#{LOCALES_DIR}/**/*.yml"]
|
|
12
|
+
I18n.default_locale = <%= @app.camel %>Config.i18n.default_locale.to_sym
|
|
13
|
+
I18n.available_locales = Dir["#{LOCALES_DIR}/*.yml"]
|
|
14
|
+
.map { File.basename(it, '.yml').to_sym }
|
|
15
|
+
.sort
|
|
16
|
+
I18n.enforce_available_locales = true
|
|
17
|
+
|
|
18
|
+
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
|
|
19
|
+
I18n.fallbacks = I18n::Locale::Fallbacks.new(<%= @app.camel %>Config.i18n.default_locale.to_sym)
|
|
20
|
+
|
|
21
|
+
# Simple backend only ships :one/:other
|
|
22
|
+
I18n::Backend::Simple.include(I18n::Backend::Pluralization)
|
|
23
|
+
I18n.available_locales.each do |locale|
|
|
24
|
+
rule = ->(n) { TwitterCldr::Formatters::Plurals::Rules.rule_for(n, locale) }
|
|
25
|
+
I18n.backend.store_translations(locale, i18n: { plural: { rule: rule } })
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class <%= @app.camel %>
|
|
29
|
+
define_method(:t) { |*args, **kwargs| ::I18n.t(*args, **kwargs) }
|
|
30
|
+
|
|
31
|
+
# simplecov:disable — env-gated, no test run boots this block
|
|
32
|
+
configure :development do
|
|
33
|
+
# rack-unreloader only watches .rb
|
|
34
|
+
before { ::I18n.backend.reload! }
|
|
35
|
+
end
|
|
36
|
+
# simplecov:enable
|
|
37
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'shrine'
|
|
4
|
+
require 'shrine/storage/file_system'
|
|
5
|
+
|
|
6
|
+
# Outside public/, delivery goes through the authenticated serve_shrine_file route
|
|
7
|
+
Shrine.storages = {
|
|
8
|
+
cache: Shrine::Storage::FileSystem.new('upload', prefix: 'cache'),
|
|
9
|
+
store: Shrine::Storage::FileSystem.new('upload', prefix: 'store')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Shrine.plugin :sequel
|
|
13
|
+
Shrine.plugin :determine_mime_type
|
|
14
|
+
Shrine.plugin :validation_helpers
|
|
15
|
+
Shrine.plugin :rack_file
|
|
16
|
+
Shrine.plugin :cached_attachment_data
|
|
17
|
+
Shrine.plugin :restore_cached_data
|
|
18
|
+
Shrine.plugin :derivatives
|
|
19
|
+
# Mounts nothing by itself, roda g upload mounts it at /<plural>/cache
|
|
20
|
+
Shrine.plugin :upload_endpoint
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class <%= @app.camel %>
|
|
4
|
+
plugin :hash_branches
|
|
5
|
+
plugin :hash_paths
|
|
6
|
+
plugin :hash_branch_view_subdir
|
|
7
|
+
plugin :named_routes
|
|
8
|
+
plugin :all_verbs
|
|
9
|
+
plugin :typecast_params
|
|
10
|
+
plugin :typecast_params_sized_integers
|
|
11
|
+
plugin :Integer_matcher_max
|
|
12
|
+
plugin :halt
|
|
13
|
+
plugin :pass
|
|
14
|
+
|
|
15
|
+
plugin :type_routing, types: {
|
|
16
|
+
csv: 'text/csv',
|
|
17
|
+
pdf: 'application/pdf',
|
|
18
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
19
|
+
}
|
|
20
|
+
end
|