-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use a safer gsub_file
and update/remove file gsubs that were no longer doing anything
#533
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,6 @@ | |
empty_directory_with_keep_file "app/services" | ||
|
||
# Configure the default mailer to use the our default from address | ||
gsub_file "app/mailers/application_mailer.rb", | ||
"default from: '[email protected]'", | ||
"default from: Rails.application.config.app.mail_from" | ||
gsub_file! "app/mailers/application_mailer.rb", | ||
/default from: ['"]from@example\.com['"]/, | ||
"default from: Rails.application.config.app.mail_from" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,14 @@ | |
RUBY | ||
end | ||
|
||
gsub_file "config/environments/production.rb", | ||
"# config.force_ssl = true", | ||
<<~RUBY | ||
## | ||
# `force_ssl` defaults to on. Set `force_ssl` to false if (and only if) RAILS_FORCE_SSL=false, otherwise set it to true. | ||
# | ||
config.force_ssl = ENV.fetch("RAILS_FORCE_SSL", "true").downcase != "false" | ||
RUBY | ||
gsub_file! "config/environments/production.rb", | ||
"config.force_ssl = true", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Rails 7.1 now ships with this just enabled, but I think it's worth us keeping an env variable for toggling it just in case |
||
<<~RUBY | ||
## | ||
# `force_ssl` defaults to on. Set `force_ssl` to false if (and only if) RAILS_FORCE_SSL=false, otherwise set it to true. | ||
# | ||
config.force_ssl = ENV.fetch("RAILS_FORCE_SSL", "true").downcase != "false" | ||
RUBY | ||
|
||
insert_into_file "config/environments/production.rb", | ||
after: /# config\.action_mailer\.raise_deliv.*\n/ do | ||
|
@@ -42,13 +42,13 @@ | |
RUBY | ||
end | ||
|
||
gsub_file "config/environments/production.rb", | ||
"config.log_level = :info", | ||
'config.log_level = ENV.fetch("LOG_LEVEL", "info").to_sym' | ||
gsub_file! "config/environments/production.rb", | ||
'ENV.fetch("RAILS_LOG_LEVEL", "info")', | ||
'ENV.fetch("RAILS_LOG_LEVEL", ENV.fetch("LOG_LEVEL", "info"))' | ||
|
||
gsub_file "config/environments/production.rb", | ||
"ActiveSupport::Logger.new(STDOUT)", | ||
"ActiveSupport::Logger.new($stdout)" | ||
gsub_file! "config/environments/production.rb", | ||
"ActiveSupport::Logger.new(STDOUT)", | ||
"ActiveSupport::Logger.new($stdout)" | ||
|
||
insert_into_file "config/environments/production.rb", | ||
after: /.*config\.public_file_server\.enabled.*\n/ do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,9 @@ | |
copy_file "variants/backend-base/config/initializers/check_env.rb", "config/initializers/check_env.rb" | ||
copy_file "variants/backend-base/config/initializers/sentry.rb", "config/initializers/sentry.rb" | ||
|
||
gsub_file "config/initializers/filter_parameter_logging.rb", /\[:password\]/ do | ||
"%w[password secret session cookie csrf]" | ||
end | ||
gsub_file! "config/initializers/filter_parameter_logging.rb", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this relates to #529 - technically I've fixed this gsub so we're now adding to the existing values, but we still want to re-review our options |
||
/ {2}:passw, :secret, /, | ||
" :passw, :secret, :session, :cookie, :csrf, " | ||
|
||
apply "variants/backend-base/config/environments/development.rb" | ||
apply "variants/backend-base/config/environments/production.rb" | ||
|
@@ -59,7 +59,7 @@ | |
EO_ROUTES | ||
|
||
if File.exist? "config/storage.yml" | ||
gsub_file "config/storage.yml", /# service: S3/ do | ||
gsub_file! "config/storage.yml", /# service: S3/ do | ||
<<~YAML | ||
# service: S3 | ||
# upload: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,29 +10,26 @@ | |
TERMINAL.puts_header "Generating User model with devise" | ||
run "bundle exec rails generate devise User" | ||
|
||
gsub_file "app/models/user.rb", | ||
":validatable", | ||
":validatable, :lockable" | ||
gsub_file! "app/models/user.rb", | ||
":validatable", | ||
":validatable, :lockable" | ||
|
||
devise_migration_filename = Dir.children("db/migrate").find { |filename| filename.end_with?("_devise_create_users.rb") } | ||
devise_migration_path = "db/migrate/#{devise_migration_filename}" | ||
|
||
TERMINAL.puts_header "Tweaking auto-generated devise migration '#{devise_migration_path}'" | ||
gsub_file devise_migration_path, | ||
" # t.integer :failed_attempts", | ||
" t.integer :failed_attempts" | ||
gsub_file devise_migration_path, | ||
" # t.string :unlock_token", | ||
" t.string :unlock_token" | ||
gsub_file devise_migration_path, | ||
" # t.datetime :locked_at", | ||
" t.datetime :locked_at" | ||
gsub_file devise_migration_path, | ||
" # add_index :users, :unlock_token", | ||
" add_index :users, :unlock_token" | ||
gsub_file devise_migration_path, | ||
/ # add_index :users, :unlock_token.+/, | ||
" add_index :users, :unlock_token, unique: true" | ||
gsub_file! devise_migration_path, | ||
" # t.integer :failed_attempts", | ||
" t.integer :failed_attempts" | ||
gsub_file! devise_migration_path, | ||
" # t.string :unlock_token", | ||
" t.string :unlock_token" | ||
gsub_file! devise_migration_path, | ||
" # t.datetime :locked_at", | ||
" t.datetime :locked_at" | ||
gsub_file! devise_migration_path, | ||
" # add_index :users, :unlock_token", | ||
" add_index :users, :unlock_token" | ||
|
||
TERMINAL.puts_header "Running db migration" | ||
run "bundle exec rails db:migrate" | ||
|
@@ -45,51 +42,51 @@ | |
# | ||
TERMINAL.puts_header "Tweaking config/initializers/devise.rb" | ||
|
||
gsub_file "config/initializers/devise.rb", | ||
" config.mailer_sender = '[email protected]'", | ||
" config.mailer_sender = Rails.application.config.app.mail_from" | ||
gsub_file! "config/initializers/devise.rb", | ||
" config.mailer_sender = '[email protected]'", | ||
" config.mailer_sender = Rails.application.config.app.mail_from" | ||
|
||
gsub_file "config/initializers/devise.rb", | ||
" # config.scoped_views = false", | ||
" config.scoped_views = true" | ||
gsub_file! "config/initializers/devise.rb", | ||
" # config.scoped_views = false", | ||
" config.scoped_views = true" | ||
|
||
gsub_file "config/initializers/devise.rb", | ||
" config.password_length = 6..128", | ||
" config.password_length = 16..128" | ||
gsub_file! "config/initializers/devise.rb", | ||
" config.password_length = 6..128", | ||
" config.password_length = 16..128" | ||
|
||
gsub_file "config/initializers/devise.rb", | ||
" # config.paranoid = true", | ||
" config.paranoid = true" | ||
gsub_file! "config/initializers/devise.rb", | ||
" # config.paranoid = true", | ||
" config.paranoid = true" | ||
|
||
gsub_file "config/initializers/devise.rb", | ||
/ # config.secret_key = '.+'/, | ||
" # config.secret_key = 'do_not_put_secrets_in_source_control_please'" | ||
gsub_file! "config/initializers/devise.rb", | ||
/ # config.secret_key = '.+'/, | ||
" # config.secret_key = 'do_not_put_secrets_in_source_control_please'" | ||
|
||
gsub_file "config/initializers/devise.rb", | ||
/ # config.lock_strategy = .+/, | ||
" config.lock_strategy = :failed_attempts" | ||
gsub_file! "config/initializers/devise.rb", | ||
/ # config.lock_strategy = .+/, | ||
" config.lock_strategy = :failed_attempts" | ||
|
||
gsub_file "config/initializers/devise.rb", | ||
/ # config.unlock_strategy = .+/, | ||
" config.unlock_strategy = :email" | ||
gsub_file! "config/initializers/devise.rb", | ||
/ # config.unlock_strategy = .+/, | ||
" config.unlock_strategy = :email" | ||
|
||
gsub_file "config/initializers/devise.rb", | ||
" # config.parent_mailer = 'ActionMailer::Base'", | ||
" config.parent_mailer = 'ApplicationMailer'" | ||
gsub_file! "config/initializers/devise.rb", | ||
" # config.parent_mailer = 'ActionMailer::Base'", | ||
" config.parent_mailer = 'ApplicationMailer'" | ||
|
||
gsub_file "config/initializers/devise.rb", | ||
/ # config.maximum_attempts = .+/, | ||
<<-EO_CHUNK | ||
gsub_file! "config/initializers/devise.rb", | ||
/ # config.maximum_attempts = .+/, | ||
<<-EO_CHUNK | ||
# | ||
# https://www.nzism.gcsb.govt.nz/ism-document/#1887 recommends 3 as a default. FYI to | ||
# be fully compliant with https://www.nzism.gcsb.govt.nz/ism-document/#1887 then only | ||
# Administrators should be able to unlock. | ||
config.maximum_attempts = 3 | ||
EO_CHUNK | ||
EO_CHUNK | ||
|
||
gsub_file "config/initializers/devise.rb", | ||
/ # config.last_attempt_warning = .+/, | ||
" config.last_attempt_warning = true" | ||
gsub_file! "config/initializers/devise.rb", | ||
/ # config.last_attempt_warning = .+/, | ||
" config.last_attempt_warning = true" | ||
|
||
## | ||
# Add a block to config/routes.rb demonstrating how to create authenticated | ||
|
@@ -140,13 +137,13 @@ | |
|
||
copy_file "app/controllers/users/sessions_controller.rb" | ||
|
||
gsub_file "config/routes.rb", | ||
"devise_for :users", | ||
<<~EO_DEVISE | ||
devise_for :users, controllers: { | ||
sessions: "users/sessions" | ||
} | ||
EO_DEVISE | ||
gsub_file! "config/routes.rb", | ||
"devise_for :users", | ||
<<~EO_DEVISE | ||
devise_for :users, controllers: { | ||
sessions: "users/sessions" | ||
} | ||
EO_DEVISE | ||
|
||
insert_into_file "app/models/user.rb", before: /^end/ do | ||
<<~'RUBY' | ||
|
@@ -202,14 +199,14 @@ def authenticatable_salt | |
copy_file "spec/requests/session_cookie_expiry_spec.rb" | ||
|
||
# tell pundit not to check that authorization was called on devise controllers | ||
gsub_file("app/controllers/application_controller.rb", | ||
"after_action :verify_authorized, except: :index", | ||
"after_action :verify_authorized, except: :index, unless: :devise_controller?" | ||
) | ||
gsub_file("app/controllers/application_controller.rb", | ||
"after_action :verify_policy_scoped, only: :index", | ||
"after_action :verify_policy_scoped, only: :index, unless: :devise_controller?" | ||
) | ||
gsub_file!("app/controllers/application_controller.rb", | ||
"after_action :verify_authorized, except: :index", | ||
"after_action :verify_authorized, except: :index, unless: :devise_controller?" | ||
) | ||
gsub_file!("app/controllers/application_controller.rb", | ||
"after_action :verify_policy_scoped, only: :index", | ||
"after_action :verify_policy_scoped, only: :index, unless: :devise_controller?" | ||
) | ||
|
||
TERMINAL.puts_header "Running rubocop -A to fix formatting in files generated by devise" | ||
run "bundle exec rubocop -A -c ./.rubocop.yml" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this is no longer matching because of the quotes, but Rubocop can automatically fix this anyway now