├── VERSION
├── .ruby-version
├── spec
├── dummy
│ ├── log
│ │ ├── .keep
│ │ ├── development.log
│ │ └── test.log
│ ├── tmp
│ │ ├── .keep
│ │ ├── pids
│ │ │ └── .keep
│ │ ├── storage
│ │ │ └── .keep
│ │ └── development_secret.txt
│ ├── db
│ │ └── test.sqlite3
│ ├── lib
│ │ └── assets
│ │ │ └── .keep
│ ├── storage
│ │ └── .keep
│ ├── public
│ │ ├── favicon.ico
│ │ ├── apple-touch-icon.png
│ │ ├── apple-touch-icon-precomposed.png
│ │ ├── 500.html
│ │ ├── 422.html
│ │ └── 404.html
│ ├── app
│ │ ├── assets
│ │ │ ├── images
│ │ │ │ └── .keep
│ │ │ └── stylesheets
│ │ │ │ └── application.css
│ │ ├── models
│ │ │ ├── concerns
│ │ │ │ └── .keep
│ │ │ └── application_record.rb
│ │ ├── controllers
│ │ │ ├── concerns
│ │ │ │ └── .keep
│ │ │ └── application_controller.rb
│ │ ├── views
│ │ │ └── layouts
│ │ │ │ ├── mailer.text.erb
│ │ │ │ ├── mailer.html.erb
│ │ │ │ └── application.html.erb
│ │ ├── helpers
│ │ │ └── application_helper.rb
│ │ ├── channels
│ │ │ └── application_cable
│ │ │ │ ├── channel.rb
│ │ │ │ └── connection.rb
│ │ ├── mailers
│ │ │ └── application_mailer.rb
│ │ └── jobs
│ │ │ └── application_job.rb
│ ├── config
│ │ ├── lock_password
│ │ ├── environment.rb
│ │ ├── cable.yml
│ │ ├── routes.rb
│ │ ├── boot.rb
│ │ ├── initializers
│ │ │ ├── filter_parameter_logging.rb
│ │ │ ├── permissions_policy.rb
│ │ │ ├── inflections.rb
│ │ │ └── content_security_policy.rb
│ │ ├── database.yml
│ │ ├── application.rb
│ │ ├── locales
│ │ │ └── en.yml
│ │ ├── storage.yml
│ │ ├── puma.rb
│ │ └── environments
│ │ │ ├── development.rb
│ │ │ ├── test.rb
│ │ │ └── production.rb
│ ├── bin
│ │ ├── rake
│ │ ├── rails
│ │ └── setup
│ ├── config.ru
│ └── Rakefile
├── resources
│ └── lock_password
├── generator_spec.rb
├── spec_helper.rb
└── lock_spec.rb
├── lib
├── lock
│ ├── railties
│ │ └── tasks.rake
│ ├── version.rb
│ ├── railtie.rb
│ └── engine.rb
├── tasks
│ └── lock_tasks.rake
├── generators
│ └── lock
│ │ └── create_password_file
│ │ ├── USAGE
│ │ └── create_password_file_generator.rb
└── lock.rb
├── app
├── views
│ └── lock
│ │ ├── refused.html.erb
│ │ ├── unlock.html.erb
│ │ └── login.html.erb
└── controllers
│ ├── lock_controller.rb
│ └── lock_application_controller.rb
├── .rspec
├── logo.png
├── .document
├── Rakefile
├── sig
└── lock.rbs
├── bin
├── setup
└── console
├── Gemfile
├── config
└── routes.rb
├── .gitignore
├── .rubocop.yml
├── .github
└── workflows
│ ├── ruby.yml
│ └── release.yml
├── LICENSE.txt
├── MIT-LICENSE
├── CHANGELOG.md
├── lock.gemspec
├── .rubocop_todo.yml
├── README.md
└── CODE_OF_CONDUCT.md
/VERSION:
--------------------------------------------------------------------------------
1 | 0.1.0
--------------------------------------------------------------------------------
/.ruby-version:
--------------------------------------------------------------------------------
1 | 3.1.3
2 |
--------------------------------------------------------------------------------
/spec/dummy/log/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/tmp/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lib/lock/railties/tasks.rake:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/db/test.sqlite3:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/lib/assets/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/storage/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/tmp/pids/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/tmp/storage/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/log/development.log:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/public/favicon.ico:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/app/assets/images/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/app/models/concerns/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/views/lock/refused.html.erb:
--------------------------------------------------------------------------------
1 | This page is locked.
--------------------------------------------------------------------------------
/spec/dummy/public/apple-touch-icon-precomposed.png:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spec/dummy/app/views/layouts/mailer.text.erb:
--------------------------------------------------------------------------------
1 | <%= yield %>
2 |
--------------------------------------------------------------------------------
/.rspec:
--------------------------------------------------------------------------------
1 | --format documentation
2 | --color
3 | --require spec_helper
4 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/charlotte-ruby/lock/HEAD/logo.png
--------------------------------------------------------------------------------
/spec/dummy/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /* Application styles */
2 |
--------------------------------------------------------------------------------
/.document:
--------------------------------------------------------------------------------
1 | lib/**/*.rb
2 | bin/*
3 | -
4 | features/**/*.feature
5 | LICENSE.txt
6 |
--------------------------------------------------------------------------------
/spec/resources/lock_password:
--------------------------------------------------------------------------------
1 | $2a$10$ye9WvPHamKpt955kCAECzet2ieUHrT3jHFgYu0vUb5.U6HHhzRnAa
--------------------------------------------------------------------------------
/app/views/lock/unlock.html.erb:
--------------------------------------------------------------------------------
1 | Unlocked!
2 |
3 | <%=link_to "Go to home page", "/" %>
--------------------------------------------------------------------------------
/spec/dummy/config/lock_password:
--------------------------------------------------------------------------------
1 | $2a$10$ye9WvPHamKpt955kCAECzet2ieUHrT3jHFgYu0vUb5.U6HHhzRnAa
--------------------------------------------------------------------------------
/lib/lock/version.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Lock
4 | VERSION = "0.1.2"
5 | end
6 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "bundler/setup"
4 |
5 | require "bundler/gem_tasks"
6 |
--------------------------------------------------------------------------------
/spec/dummy/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module ApplicationHelper
4 | end
5 |
--------------------------------------------------------------------------------
/lib/lock/railtie.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Lock
4 | class Railtie < ::Rails::Railtie
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/sig/lock.rbs:
--------------------------------------------------------------------------------
1 | module Lock
2 | VERSION: String
3 | # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4 | end
5 |
--------------------------------------------------------------------------------
/lib/tasks/lock_tasks.rake:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 | # desc "Explaining what the task does"
3 | # task :lock do
4 | # # Task goes here
5 | # end
6 |
--------------------------------------------------------------------------------
/spec/dummy/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationController < ActionController::Base
4 | end
5 |
--------------------------------------------------------------------------------
/spec/dummy/app/models/application_record.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationRecord < ActiveRecord::Base
4 | primary_abstract_class
5 | end
6 |
--------------------------------------------------------------------------------
/spec/dummy/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | require_relative "../config/boot"
5 | require "rake"
6 | Rake.application.run
7 |
--------------------------------------------------------------------------------
/spec/dummy/tmp/development_secret.txt:
--------------------------------------------------------------------------------
1 | 67cc0040c6da39c045457a4c6436feb26b5c74a9efba6adaeb97f103b7b5a3eae82d8609368b632eb0eb5b7d2ed806718e9a2daeacbf0d1ec81baff7f82c3ab3
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -euo pipefail
3 | IFS=$'\n\t'
4 | set -vx
5 |
6 | bundle install
7 |
8 | # Do any other automated setup that you need to do here
9 |
--------------------------------------------------------------------------------
/spec/dummy/app/channels/application_cable/channel.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module ApplicationCable
4 | class Channel < ActionCable::Channel::Base
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/spec/dummy/app/channels/application_cable/connection.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module ApplicationCable
4 | class Connection < ActionCable::Connection::Base
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/spec/dummy/app/mailers/application_mailer.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationMailer < ActionMailer::Base
4 | default from: "from@example.com"
5 | layout "mailer"
6 | end
7 |
--------------------------------------------------------------------------------
/app/views/lock/login.html.erb:
--------------------------------------------------------------------------------
1 |
2 | <%= form_tag unlock_url do %>
3 | <%=password_field_tag "password" %>
4 | <%=submit_tag "Unlock"%>
5 | <% end %>
6 |
--------------------------------------------------------------------------------
/spec/dummy/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | APP_PATH = File.expand_path("../config/application", __dir__)
5 | require_relative "../config/boot"
6 | require "rails/commands"
7 |
--------------------------------------------------------------------------------
/spec/dummy/config/environment.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Load the Rails application.
4 | require_relative "application"
5 |
6 | # Initialize the Rails application.
7 | Rails.application.initialize!
8 |
--------------------------------------------------------------------------------
/lib/generators/lock/create_password_file/USAGE:
--------------------------------------------------------------------------------
1 | Description:
2 | The lock generator is used to create an encrypted password and store it in config/lock_password
3 |
4 | Example:
5 | rails g lock:create_password_file mypassword
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source "http://rubygems.org"
4 |
5 | gemspec
6 |
7 | gem "bundler", "~> 2.3"
8 | gem "rake", "~> 13.0"
9 | gem "rspec", "~> 3.1.0"
10 | gem "rubocop", "~> 1.21"
11 | gem "sqlite3"
12 |
--------------------------------------------------------------------------------
/spec/dummy/config.ru:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # This file is used by Rack-based servers to start the application.
4 |
5 | require_relative "config/environment"
6 |
7 | run Rails.application
8 | Rails.application.load_server
9 |
--------------------------------------------------------------------------------
/spec/dummy/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: async
3 |
4 | test:
5 | adapter: test
6 |
7 | production:
8 | adapter: redis
9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10 | channel_prefix: dummy_production
11 |
--------------------------------------------------------------------------------
/spec/dummy/config/routes.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | Rails.application.routes.draw do
4 | # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
5 |
6 | # Defines the root path route ("/")
7 | # root "articles#index"
8 | end
9 |
--------------------------------------------------------------------------------
/spec/dummy/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Add your own tasks in files placed in lib/tasks ending in .rake,
4 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
5 |
6 | require_relative "config/application"
7 |
8 | Rails.application.load_tasks
9 |
--------------------------------------------------------------------------------
/spec/dummy/config/boot.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Set up gems listed in the Gemfile.
4 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
5 |
6 | require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
7 | $LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
8 |
--------------------------------------------------------------------------------
/app/controllers/lock_controller.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class LockController < ApplicationController
4 | def unlock
5 | if Lock.passwords_match?(params[:password])
6 | session[:lock_opened] = true
7 | else
8 | redirect_to action: :login
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | Rails.application.routes.draw do
4 | match "lock/login", to: "lock#login", as: "lock_login", via: :get
5 | match "lock/refused", to: "lock#refused", as: "unlock_refused", via: :get
6 | match "lock/unlock", to: "lock#unlock", as: "unlock", via: :post
7 | end
8 |
--------------------------------------------------------------------------------
/spec/dummy/app/views/layouts/mailer.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.bundle/
2 | /.yardoc
3 | /_yardoc/
4 | /coverage/
5 | /doc/
6 | /log/*.log
7 | /pkg/
8 | /spec/reports/
9 | /spec/dummy/db/*.sqlite3
10 | /spec/dummy/db/*.sqlite3-*
11 | /spec/dummy/log/*.log
12 | /spec/dummy/storage/
13 | /spec/dummy/tmp/
14 | /tmp/
15 | Gemfile.lock
16 |
17 | # rspec failure tracking
18 | .rspec_status
19 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | inherit_from: .rubocop_todo.yml
2 |
3 | AllCops:
4 | TargetRubyVersion: 2.6
5 | SuggestExtensions: false
6 |
7 | Style/StringLiterals:
8 | Enabled: true
9 | EnforcedStyle: double_quotes
10 |
11 | Style/StringLiteralsInInterpolation:
12 | Enabled: true
13 | EnforcedStyle: double_quotes
14 |
15 | Layout/LineLength:
16 | Max: 120
17 |
--------------------------------------------------------------------------------
/spec/dummy/app/jobs/application_job.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationJob < ActiveJob::Base
4 | # Automatically retry jobs that encountered a deadlock
5 | # retry_on ActiveRecord::Deadlocked
6 |
7 | # Most jobs are safe to ignore if the underlying records are no longer available
8 | # discard_on ActiveJob::DeserializationError
9 | end
10 |
--------------------------------------------------------------------------------
/lib/lock/engine.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Lock
4 | class Engine < ::Rails::Engine
5 | initializer "lock.extend_application_controller" do
6 | ActiveSupport.on_load(:action_controller) do
7 | include LockApplicationController::InstanceMethods
8 | extend LockApplicationController::ClassMethods
9 | end
10 | end
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/spec/dummy/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Dummy
5 |
6 | <%= csrf_meta_tags %>
7 | <%= csp_meta_tag %>
8 |
9 | <%= stylesheet_link_tag "application" %>
10 |
11 |
12 |
13 | <%= yield %>
14 |
15 |
16 |
--------------------------------------------------------------------------------
/lib/lock.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "bcrypt"
4 | require "lock/engine"
5 | require "lock/railtie"
6 |
7 | module Lock
8 | def self.passwords_match?(password)
9 | hashed_combo = IO.read("#{Rails.root}/config/lock_password")
10 | salt = hashed_combo[0, 29]
11 | hashed_combo == BCrypt::Engine.hash_secret(password, salt)
12 | rescue StandardError
13 | false
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | require "bundler/setup"
5 | require "lock"
6 |
7 | # You can add fixtures and/or initialization code here to make experimenting
8 | # with your gem easier. You can also use a different console, if you like.
9 |
10 | # (If you use this, don't forget to add pry to your Gemfile!)
11 | # require "pry"
12 | # Pry.start
13 |
14 | require "irb"
15 | IRB.start(__FILE__)
16 |
--------------------------------------------------------------------------------
/.github/workflows/ruby.yml:
--------------------------------------------------------------------------------
1 | name: ruby
2 | "on":
3 | push:
4 | branches:
5 | - master
6 | pull_request:
7 | jobs:
8 | build-and-run-tests:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: actions/checkout@v3
12 | - name: Set up Ruby
13 | uses: ruby/setup-ruby@v1
14 | with:
15 | bundler-cache: true
16 | - name: Run tests
17 | run: bundle exec rspec spec
18 | - name: Run rubocop
19 | run: bundle exec rubocop
20 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Be sure to restart your server when you modify this file.
4 |
5 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of
6 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported
7 | # notations and behaviors.
8 | Rails.application.config.filter_parameters += %i[
9 | passw secret token _key crypt salt certificate otp ssn
10 | ]
11 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/permissions_policy.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 | # Define an application-wide HTTP permissions policy. For further
3 | # information see https://developers.google.com/web/updates/2018/06/feature-policy
4 | #
5 | # Rails.application.config.permissions_policy do |f|
6 | # f.camera :none
7 | # f.gyroscope :none
8 | # f.microphone :none
9 | # f.usb :none
10 | # f.fullscreen :self
11 | # f.payment :self, "https://secure.example.com"
12 | # end
13 |
--------------------------------------------------------------------------------
/lib/generators/lock/create_password_file/create_password_file_generator.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "bcrypt"
4 |
5 | module Lock
6 | class CreatePasswordFileGenerator < Rails::Generators::Base
7 | argument :password, type: :string
8 | source_root File.expand_path("templates", __dir__)
9 |
10 | def create_password_file
11 | password_salt = BCrypt::Engine.generate_salt
12 | password_hash = BCrypt::Engine.hash_secret(password, password_salt)
13 | create_file "config/lock_password", password_hash
14 | end
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/app/controllers/lock_application_controller.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module LockApplicationController
4 | module ClassMethods
5 | def lock(opts = {})
6 | before_filter { |c| c.lock_filter opts[:actions] }
7 | end
8 | end
9 |
10 | module InstanceMethods
11 | def lock_filter(actions = nil)
12 | redirect_to unlock_refused_url if locked_action?(actions) && (session[:lock_opened] != true)
13 | # otherwise proceed to where ya going
14 | end
15 |
16 | def locked_action?(actions)
17 | return false if controller_name == "lock"
18 |
19 | actions.blank? or actions.include?(controller_name.to_s) or actions.include?("#{controller_name}##{action_name}")
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/spec/dummy/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite. Versions 3.8.0 and up are supported.
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem "sqlite3"
6 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: db/development.sqlite3
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: db/test.sqlite3
22 |
23 | production:
24 | <<: *default
25 | database: db/production.sqlite3
26 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 | # Be sure to restart your server when you modify this file.
3 |
4 | # Add new inflection rules using the following format. Inflections
5 | # are locale specific, and you may define rules for as many different
6 | # locales as you wish. All of these examples are active by default:
7 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
8 | # inflect.plural /^(ox)$/i, "\\1en"
9 | # inflect.singular /^(ox)en/i, "\\1"
10 | # inflect.irregular "person", "people"
11 | # inflect.uncountable %w( fish sheep )
12 | # end
13 |
14 | # These inflection rules are supported but not enabled by default:
15 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
16 | # inflect.acronym "RESTful"
17 | # end
18 |
--------------------------------------------------------------------------------
/spec/dummy/config/application.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require_relative "boot"
4 |
5 | require "rails/all"
6 |
7 | # Require the gems listed in Gemfile, including any gems
8 | # you've limited to :test, :development, or :production.
9 | Bundler.require(*Rails.groups)
10 | require "lock"
11 |
12 | module Dummy
13 | class Application < Rails::Application
14 | config.load_defaults Rails::VERSION::STRING.to_f
15 |
16 | # Configuration for the application, engines, and railties goes here.
17 | #
18 | # These settings can be overridden in specific environments using the files
19 | # in config/environments, which are processed later.
20 | #
21 | # config.time_zone = "Central Time (US & Canada)"
22 | # config.eager_load_paths << Rails.root.join("extras")
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/spec/dummy/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t "hello"
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t("hello") %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # The following keys must be escaped otherwise they will not be retrieved by
20 | # the default I18n backend:
21 | #
22 | # true, false, on, off, yes, no
23 | #
24 | # Instead, surround them with single quotes.
25 | #
26 | # en:
27 | # "true": "foo"
28 | #
29 | # To learn more, please read the Rails Internationalization guide
30 | # available at https://guides.rubyonrails.org/i18n.html.
31 |
32 | en:
33 | hello: "Hello world"
34 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: release
2 | on:
3 | push:
4 | branches: [master]
5 | jobs:
6 | release:
7 | runs-on: ubuntu-latest
8 | env:
9 | GEM_NAME: lock
10 | steps:
11 | - uses: google-github-actions/release-please-action@v3
12 | id: release
13 | with:
14 | token: ${{ secrets.GITHUB_TOKEN }}
15 | release-type: ruby
16 | package-name: "${{ env.GEM_NAME }}"
17 | - uses: actions/checkout@v3
18 | - name: install ruby
19 | if: "${{ steps.release.outputs.release_created }}"
20 | uses: ruby/setup-ruby@v1
21 | with:
22 | bundler-cache: true
23 | - name: bundle
24 | if: "${{ steps.release.outputs.release_created }}"
25 | run: |
26 | bundle config unset --local deployment
27 | bundle
28 | - name: publish gem
29 | if: "${{ steps.release.outputs.release_created }}"
30 | uses: dawidd6/action-publish-gem@v1
31 | with:
32 | api_key: "${{secrets.RUBYGEMS_API_KEY}}"
33 | github_token: "${{secrets.GITHUB_TOKEN}}"
34 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011 cowboycoded
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/MIT-LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2022 Matt McMahand
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/spec/dummy/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | require "fileutils"
5 |
6 | # path to your application root.
7 | APP_ROOT = File.expand_path("..", __dir__)
8 |
9 | def system!(*args)
10 | system(*args) || abort("\n== Command #{args} failed ==")
11 | end
12 |
13 | FileUtils.chdir APP_ROOT do
14 | # This script is a way to set up or update your development environment automatically.
15 | # This script is idempotent, so that you can run it at any time and get an expectable outcome.
16 | # Add necessary setup steps to this file.
17 |
18 | puts "== Installing dependencies =="
19 | system! "gem install bundler --conservative"
20 | system("bundle check") || system!("bundle install")
21 |
22 | # puts "\n== Copying sample files =="
23 | # unless File.exist?("config/database.yml")
24 | # FileUtils.cp "config/database.yml.sample", "config/database.yml"
25 | # end
26 |
27 | puts "\n== Preparing database =="
28 | system! "bin/rails db:prepare"
29 |
30 | puts "\n== Removing old logs and tempfiles =="
31 | system! "bin/rails log:clear tmp:clear"
32 |
33 | puts "\n== Restarting application server =="
34 | system! "bin/rails restart"
35 | end
36 |
--------------------------------------------------------------------------------
/spec/generator_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "spec_helper"
4 | require "systemu"
5 | require "lock"
6 |
7 | RSpec.describe Lock do
8 | before(:each) do
9 | delete_lockdown_file
10 | Dir.chdir(File.expand_path("dummy", __dir__))
11 | end
12 |
13 | let(:lock_file) { File.expand_path("#{Rails.root}/config/lock_password") }
14 |
15 | it "should generate a password file if none exists" do
16 | output = systemu("rails g lock:create_password_file ieatpasswordslikeyouforbreakfast")[1]
17 | result = output.match(%r{create.*config/lock_password})
18 |
19 | expect(result).not_to eq(nil)
20 | expect(IO.read(lock_file).size.to_i).to eq(60)
21 | end
22 |
23 | it "should generate ask you to overwrite existing password file" do
24 | unless File.exist? "#{Rails.root}/config/lock_password"
25 | File.open("#{Rails.root}/config/lock_password", "w") do |f|
26 | f.write("abc")
27 | end
28 | end
29 |
30 | Dir.chdir(File.expand_path("dummy", __dir__))
31 |
32 | output = systemu("rails g lock:create_password_file ieatpasswordslikeyouforbreakfast")[1]
33 | result = output.match(/conflict/)
34 |
35 | expect(result).not_to eq(nil)
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/spec/dummy/config/storage.yml:
--------------------------------------------------------------------------------
1 | test:
2 | service: Disk
3 | root: <%= Rails.root.join("tmp/storage") %>
4 |
5 | local:
6 | service: Disk
7 | root: <%= Rails.root.join("storage") %>
8 |
9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10 | # amazon:
11 | # service: S3
12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14 | # region: us-east-1
15 | # bucket: your_own_bucket-<%= Rails.env %>
16 |
17 | # Remember not to checkin your GCS keyfile to a repository
18 | # google:
19 | # service: GCS
20 | # project: your_project
21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22 | # bucket: your_own_bucket-<%= Rails.env %>
23 |
24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25 | # microsoft:
26 | # service: AzureStorage
27 | # storage_account_name: your_account_name
28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29 | # container: your_container_name-<%= Rails.env %>
30 |
31 | # mirror:
32 | # service: Mirror
33 | # primary: local
34 | # mirrors: [ amazon, google, microsoft ]
35 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/content_security_policy.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 | # Be sure to restart your server when you modify this file.
3 |
4 | # Define an application-wide content security policy
5 | # For further information see the following documentation
6 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
7 |
8 | # Rails.application.configure do
9 | # config.content_security_policy do |policy|
10 | # policy.default_src :self, :https
11 | # policy.font_src :self, :https, :data
12 | # policy.img_src :self, :https, :data
13 | # policy.object_src :none
14 | # policy.script_src :self, :https
15 | # policy.style_src :self, :https
16 | # # Specify URI for violation reports
17 | # # policy.report_uri "/csp-violation-report-endpoint"
18 | # end
19 | #
20 | # # Generate session nonces for permitted importmap and inline scripts
21 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
22 | # config.content_security_policy_nonce_directives = %w(script-src)
23 | #
24 | # # Report CSP violations to a specified URI. See:
25 | # # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
26 | # # config.content_security_policy_report_only = true
27 | # end
28 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [Unreleased]
2 |
3 | ## [0.1.2](https://github.com/charlotte-ruby/lock/compare/v0.1.2...v0.1.2) (2022-12-11)
4 |
5 |
6 | ### Features
7 |
8 | * tweak release action ([38a56b8](https://github.com/charlotte-ruby/lock/commit/38a56b817ae3c4349c527c7f5d201764d3b12380))
9 |
10 |
11 | ### Bug Fixes
12 |
13 | * bump ruby version ([360d0a9](https://github.com/charlotte-ruby/lock/commit/360d0a98d956c2a03de3c18e85be9615bd61470c))
14 | * update README in Gem::Specification ([28f0453](https://github.com/charlotte-ruby/lock/commit/28f0453c4783f8fed6a796f9fcdaf0f8274a9989))
15 |
16 |
17 | ## [0.1.1](https://github.com/charlotte-ruby/lock/compare/v0.1.0...v0.1.1) (2022-12-11)
18 |
19 |
20 | ### Features
21 |
22 | * gem updates ([64028bc](https://github.com/charlotte-ruby/lock/commit/64028bcf9a0e6f2ced69a1c3bd6e9142ea048fa4))
23 | * tweak release action ([38a56b8](https://github.com/charlotte-ruby/lock/commit/38a56b817ae3c4349c527c7f5d201764d3b12380))
24 | * whoops ([f716aed](https://github.com/charlotte-ruby/lock/commit/f716aedcca66fad1f4202d21b4137d90840d43ca))
25 |
26 |
27 | ### Bug Fixes
28 |
29 | * bump ruby version ([360d0a9](https://github.com/charlotte-ruby/lock/commit/360d0a98d956c2a03de3c18e85be9615bd61470c))
30 |
31 |
32 | ### Miscellaneous Chores
33 |
34 | * release 0.1.1 ([afa0ead](https://github.com/charlotte-ruby/lock/commit/afa0ead1e11e95be535e514f245e4d93d212b999))
35 |
36 | ## [0.1.0] - 2022-02-27
37 |
38 | - Initial release
39 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "rubygems"
4 | require "bundler/setup"
5 | require "pry"
6 |
7 | ENV["RAILS_ENV"] = "test"
8 |
9 | require_relative "dummy/config/environment"
10 |
11 | require "rails/all"
12 | # require "rspec/rails"
13 |
14 | require "rails/plugin/test"
15 |
16 | Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f }
17 |
18 | ActiveRecord::Migrator.migrations_paths = [File.expand_path("../spec/dummy/db/migrate", __dir__)]
19 |
20 | require "rails/test_help"
21 |
22 | # Load fixtures from the engine
23 | if ActiveSupport::TestCase.respond_to?(:fixture_path=)
24 | ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
25 | ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
26 | ActiveSupport::TestCase.file_fixture_path = "#{ActiveSupport::TestCase.fixture_path}/files"
27 | ActiveSupport::TestCase.fixtures :all
28 | end
29 |
30 | require "lock"
31 |
32 | RSpec.configure do |config|
33 | config.expect_with :rspec do |expectations|
34 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35 | end
36 |
37 | config.mock_with :rspec do |mocks|
38 | mocks.verify_partial_doubles = true
39 | end
40 |
41 | # config.shared_context_metadata_behavior = :apply_to_host_groups
42 | # config.filter_run_when_matching :focus
43 | end
44 |
45 | def copy_password_template_file
46 | FileUtils.copy("#{File.dirname(__FILE__)}/resources/lock_password", "#{Rails.root}/config/lock_password")
47 | end
48 |
49 | def delete_lockdown_file
50 | FileUtils.rm("#{Rails.root}/config/lock_password") if File.exist? "#{Rails.root}/config/lock_password"
51 | end
52 |
--------------------------------------------------------------------------------
/lock.gemspec:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require_relative "lib/lock/version"
4 |
5 | Gem::Specification.new do |spec|
6 | spec.name = "lock"
7 | spec.version = Lock::VERSION
8 | spec.authors = %w[cowboycoded invalidusrname]
9 | spec.email = ["john.mcaliley@gmail.com"]
10 |
11 | spec.summary = "Restrict access to controllers or actions using a single password"
12 | spec.description = <<-ENDOFSTRING
13 | Simple engine that can lock down controllers/actions with a password.
14 | Useful for locking a new feature (or an entire site)
15 | while it is being beta tested
16 | ENDOFSTRING
17 |
18 | spec.homepage = "http://github.com/charlotte-ruby/lock"
19 | spec.license = "MIT"
20 | spec.required_ruby_version = ">= 2.7.5"
21 |
22 | spec.metadata["homepage_uri"] = spec.homepage
23 | spec.metadata["source_code_uri"] = spec.homepage
24 | spec.metadata["changelog_uri"] = File.join(spec.homepage, "blob/master/CHANGELOG.md")
25 |
26 | spec.extra_rdoc_files = ["LICENSE.txt", "README.md"]
27 |
28 | # Specify which files should be added to the gem when it is released.
29 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30 | spec.files = Dir.chdir(File.expand_path(__dir__)) do
31 | `git ls-files -z`.split("\x0").reject do |f|
32 | (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
33 | end
34 | end
35 | spec.bindir = "exe"
36 | spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
37 | spec.require_paths = ["lib"]
38 |
39 | spec.add_dependency "bcrypt", "~> 3.1.5"
40 | spec.add_dependency "rails", ">= 5"
41 | # spec.add_development_dependency "rspec-rails"
42 | spec.add_development_dependency "pry"
43 | spec.add_development_dependency "systemu"
44 | end
45 |
--------------------------------------------------------------------------------
/.rubocop_todo.yml:
--------------------------------------------------------------------------------
1 | # This configuration was generated by
2 | # `rubocop --auto-gen-config`
3 | # on 2022-02-27 17:41:58 UTC using RuboCop version 1.25.1.
4 | # The point is for the user to remove these configuration records
5 | # one by one as the offenses are removed from the code base.
6 | # Note that changes in the inspected code, or installation of new
7 | # versions of RuboCop, may require this file to be generated again.
8 |
9 | # Offense count: 1
10 | # Configuration parameters: Include.
11 | # Include: **/*.gemspec
12 | Gemspec/RequiredRubyVersion:
13 | Exclude:
14 | - 'lock.gemspec'
15 |
16 | # Offense count: 1
17 | # Cop supports --auto-correct.
18 | # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
19 | # URISchemes: http, https
20 | Layout/LineLength:
21 | Max: 177
22 |
23 | # Offense count: 1
24 | # Configuration parameters: AllowComments.
25 | Lint/EmptyFile:
26 | Exclude:
27 | - 'lib/lock/railties/tasks.rake'
28 |
29 | # Offense count: 1
30 | # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
31 | # IgnoredMethods: refine
32 | Metrics/BlockLength:
33 | Max: 32
34 |
35 | # Offense count: 6
36 | # Configuration parameters: AllowedConstants.
37 | Style/Documentation:
38 | Exclude:
39 | - 'spec/**/*'
40 | - 'test/**/*'
41 | - 'app/controllers/lock_application_controller.rb'
42 | - 'app/controllers/lock_controller.rb'
43 | - 'lib/generators/lock/create_password_file/create_password_file_generator.rb'
44 | - 'lib/lock.rb'
45 | - 'lib/lock/engine.rb'
46 |
47 | # Offense count: 1
48 | # Cop supports --auto-correct.
49 | # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
50 | # URISchemes: http, https
51 | Layout/LineLength:
52 | Max: 177
53 |
--------------------------------------------------------------------------------
/spec/lock_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | def get_ac(controller_name, action_name)
4 | ApplicationController.class_eval { attr_accessor :controller_name, :action_name }
5 |
6 | ac = ApplicationController.new
7 | ac.controller_name = controller_name
8 | ac.action_name = action_name
9 | ac
10 | end
11 |
12 | RSpec.describe Lock do
13 | it "has a version number" do
14 | expect(Lock::VERSION).not_to be nil
15 | end
16 |
17 | it "should match passwords" do
18 | copy_password_template_file
19 |
20 | expect(Lock.passwords_match?("mypassword")).to be_truthy
21 | expect(Lock.passwords_match?("mypasswor2")).to be(false)
22 | end
23 |
24 | it "should make methods available in the app controller" do
25 | expect(ApplicationController.instance_methods).to include(:lock_filter)
26 | expect(ApplicationController.instance_methods).to include(:locked_action?)
27 | end
28 |
29 | it "should return false for any lock controller actions" do
30 | ac = get_ac("lock", "login")
31 |
32 | expect(ac.locked_action?([])).to be(false)
33 | end
34 |
35 | it "should return true for any controller (except lock) if blank actions array is specified" do
36 | ac = get_ac("not_lock", "login")
37 |
38 | expect(ac.locked_action?([])).to be(true)
39 | end
40 |
41 | it "should return true for all actions if only controller is specified" do
42 | ac = get_ac("widgets", "new")
43 |
44 | expect(ac.locked_action?(["widgets"])).to be(true)
45 |
46 | ac = get_ac("widgets", "index")
47 |
48 | expect(ac.locked_action?(["widgets"])).to be(true)
49 | end
50 |
51 | it "should return true for specific actions, but not others" do
52 | ac = get_ac("widgets", "new")
53 |
54 | expect(ac.locked_action?(["widgets#new"])).to be(true)
55 |
56 | ac = get_ac("widgets", "index")
57 |
58 | expect(ac.locked_action?(["widgets#new"])).to be(false)
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/spec/dummy/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
We're sorry, but something went wrong.
62 |
63 |
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/spec/dummy/config/puma.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Puma can serve each request in a thread from an internal thread pool.
4 | # The `threads` method setting takes two numbers: a minimum and maximum.
5 | # Any libraries that use thread pools should be configured to match
6 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
7 | # and maximum; this matches the default thread size of Active Record.
8 | #
9 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
10 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
11 | threads min_threads_count, max_threads_count
12 |
13 | # Specifies the `worker_timeout` threshold that Puma will use to wait before
14 | # terminating a worker in development environments.
15 | #
16 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
17 |
18 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
19 | #
20 | port ENV.fetch("PORT", 3000)
21 |
22 | # Specifies the `environment` that Puma will run in.
23 | #
24 | environment ENV.fetch("RAILS_ENV", "development")
25 |
26 | # Specifies the `pidfile` that Puma will use.
27 | pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid")
28 |
29 | # Specifies the number of `workers` to boot in clustered mode.
30 | # Workers are forked web server processes. If using threads and workers together
31 | # the concurrency of the application would be max `threads` * `workers`.
32 | # Workers do not work on JRuby or Windows (both of which do not support
33 | # processes).
34 | #
35 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
36 |
37 | # Use the `preload_app!` method when specifying a `workers` number.
38 | # This directive tells Puma to first boot the application and load code
39 | # before forking the application. This takes advantage of Copy On Write
40 | # process behavior so workers use less memory.
41 | #
42 | # preload_app!
43 |
44 | # Allow puma to be restarted by `bin/rails restart` command.
45 | plugin :tmp_restart
46 |
--------------------------------------------------------------------------------
/spec/dummy/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The change you wanted was rejected.
62 |
Maybe you tried to change something you didn't have access to.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/spec/dummy/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "active_support/core_ext/integer/time"
4 |
5 | Rails.application.configure do
6 | # Settings specified here will take precedence over those in config/application.rb.
7 |
8 | # In the development environment your application's code is reloaded any time
9 | # it changes. This slows down response time but is perfect for development
10 | # since you don't have to restart the web server when you make code changes.
11 | config.cache_classes = false
12 |
13 | # Do not eager load code on boot.
14 | config.eager_load = false
15 |
16 | # Show full error reports.
17 | config.consider_all_requests_local = true
18 |
19 | # Enable server timing
20 | config.server_timing = true
21 |
22 | # Enable/disable caching. By default caching is disabled.
23 | # Run rails dev:cache to toggle caching.
24 | if Rails.root.join("tmp/caching-dev.txt").exist?
25 | config.action_controller.perform_caching = true
26 | config.action_controller.enable_fragment_cache_logging = true
27 |
28 | config.cache_store = :memory_store
29 | config.public_file_server.headers = {
30 | "Cache-Control" => "public, max-age=#{2.days.to_i}"
31 | }
32 | else
33 | config.action_controller.perform_caching = false
34 |
35 | config.cache_store = :null_store
36 | end
37 |
38 | # Store uploaded files on the local file system (see config/storage.yml for options).
39 | config.active_storage.service = :local
40 |
41 | # Don't care if the mailer can't send.
42 | config.action_mailer.raise_delivery_errors = false
43 |
44 | config.action_mailer.perform_caching = false
45 |
46 | # Print deprecation notices to the Rails logger.
47 | config.active_support.deprecation = :log
48 |
49 | # Raise exceptions for disallowed deprecations.
50 | config.active_support.disallowed_deprecation = :raise
51 |
52 | # Tell Active Support which deprecation messages to disallow.
53 | config.active_support.disallowed_deprecation_warnings = []
54 |
55 | # Raise an error on page load if there are pending migrations.
56 | config.active_record.migration_error = :page_load
57 |
58 | # Highlight code that triggered database queries in logs.
59 | config.active_record.verbose_query_logs = true
60 |
61 | # Raises error for missing translations.
62 | # config.i18n.raise_on_missing_translations = true
63 |
64 | # Annotate rendered view with file names.
65 | # config.action_view.annotate_rendered_view_with_filenames = true
66 |
67 | # Uncomment if you wish to allow Action Cable access from any origin.
68 | # config.action_cable.disable_request_forgery_protection = true
69 | end
70 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "active_support/core_ext/integer/time"
4 |
5 | # The test environment is used exclusively to run your application's
6 | # test suite. You never need to work with it otherwise. Remember that
7 | # your test database is "scratch space" for the test suite and is wiped
8 | # and recreated between test runs. Don't rely on the data there!
9 |
10 | Rails.application.configure do
11 | # Settings specified here will take precedence over those in config/application.rb.
12 |
13 | # Turn false under Spring and add config.action_view.cache_template_loading = true.
14 | config.cache_classes = true
15 |
16 | # Eager loading loads your whole application. When running a single test locally,
17 | # this probably isn't necessary. It's a good idea to do in a continuous integration
18 | # system, or in some way before deploying your code.
19 | config.eager_load = ENV["CI"].present?
20 |
21 | # Configure public file server for tests with Cache-Control for performance.
22 | config.public_file_server.enabled = true
23 | config.public_file_server.headers = {
24 | "Cache-Control" => "public, max-age=#{1.hour.to_i}"
25 | }
26 |
27 | # Show full error reports and disable caching.
28 | config.consider_all_requests_local = true
29 | config.action_controller.perform_caching = false
30 | config.cache_store = :null_store
31 |
32 | # Raise exceptions instead of rendering exception templates.
33 | config.action_dispatch.show_exceptions = false
34 |
35 | # Disable request forgery protection in test environment.
36 | config.action_controller.allow_forgery_protection = false
37 |
38 | # Store uploaded files on the local file system in a temporary directory.
39 | # config.active_storage.service = :test
40 |
41 | # config.action_mailer.perform_caching = false
42 |
43 | # Tell Action Mailer not to deliver emails to the real world.
44 | # The :test delivery method accumulates sent emails in the
45 | # ActionMailer::Base.deliveries array.
46 | # config.action_mailer.delivery_method = :test
47 |
48 | # Print deprecation notices to the stderr.
49 | config.active_support.deprecation = :stderr
50 |
51 | # Raise exceptions for disallowed deprecations.
52 | config.active_support.disallowed_deprecation = :raise
53 |
54 | # Tell Active Support which deprecation messages to disallow.
55 | config.active_support.disallowed_deprecation_warnings = []
56 |
57 | # Raises error for missing translations.
58 | # config.i18n.raise_on_missing_translations = true
59 |
60 | # Annotate rendered view with file names.
61 | # config.action_view.annotate_rendered_view_with_filenames = true
62 | end
63 |
--------------------------------------------------------------------------------
/spec/dummy/log/test.log:
--------------------------------------------------------------------------------
1 | [1m[35m (0.6ms)[0m [1m[34mSELECT sqlite_version(*)[0m
2 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
3 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
4 | [1m[35m (0.7ms)[0m [1m[34mSELECT sqlite_version(*)[0m
5 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
6 | [1m[35m (0.6ms)[0m [1m[34mSELECT sqlite_version(*)[0m
7 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
8 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
9 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
10 | [1m[35m (0.6ms)[0m [1m[34mSELECT sqlite_version(*)[0m
11 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
12 | [1m[35m (0.6ms)[0m [1m[34mSELECT sqlite_version(*)[0m
13 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
14 | [1m[35m (0.8ms)[0m [1m[34mSELECT sqlite_version(*)[0m
15 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
16 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
17 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
18 | [1m[35m (0.6ms)[0m [1m[34mSELECT sqlite_version(*)[0m
19 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
20 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
21 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
22 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
23 | [1m[35m (0.6ms)[0m [1m[34mSELECT sqlite_version(*)[0m
24 | [1m[35m (0.7ms)[0m [1m[34mSELECT sqlite_version(*)[0m
25 | [1m[35m (0.6ms)[0m [1m[34mSELECT sqlite_version(*)[0m
26 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
27 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
28 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
29 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
30 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
31 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
32 | [1m[35m (0.6ms)[0m [1m[34mSELECT sqlite_version(*)[0m
33 | [1m[35m (0.4ms)[0m [1m[34mSELECT sqlite_version(*)[0m
34 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
35 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
36 | [1m[35m (0.8ms)[0m [1m[34mSELECT sqlite_version(*)[0m
37 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
38 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
39 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
40 | [1m[35m (0.6ms)[0m [1m[34mSELECT sqlite_version(*)[0m
41 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
42 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
43 | [1m[35m (0.7ms)[0m [1m[34mSELECT sqlite_version(*)[0m
44 | [1m[35m (0.5ms)[0m [1m[34mSELECT sqlite_version(*)[0m
45 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # Lock
4 |
5 | [](https://github.com/charlotte-ruby/lock/actions/workflows/ruby.yml)
6 |
7 | A simple Rails Engine that lets you lock down controllers, specific actions or an entire site with a password. This engine is useful for locking down new features
8 | or your entire site in production while your app is being beta tested. This is not a full-blown user authentication engine, nor is it intended to be.
9 |
10 | ## Install the gem
11 |
12 | Add to your Gemfile
13 |
14 | ```
15 | bundle add 'lock'
16 | ```
17 |
18 | Install with bundler
19 |
20 | ```
21 | bundle install
22 | ```
23 |
24 | ## Generate password file
25 |
26 | The following command will generate /config/lock_password, which contains an encrypted password. Lock uses this for authentication
27 |
28 | ```
29 | rails g lock:create_password_file yourpasswordhere
30 | ```
31 |
32 | ## Lock your app
33 |
34 | You lock your app in the ApplicationController (/app/controllers/application_controller.rb).
35 |
36 | If you want to lock your entire app use this:
37 |
38 | ```ruby
39 | ApplicationController < ActionController::Base
40 | lock
41 | end
42 | ```
43 |
44 | If you want to lock specific actions inside the widgets_controller use this:
45 |
46 |
47 | ```ruby
48 | ApplicationController < ActionController::Base
49 | lock actions: ["widgets#new", "widgets#index"]
50 | end
51 | ```
52 |
53 | If you want to lock all actions in a controller, you can just leave off the # sign and action name. The following will lock all actions in the widgets_controller
54 |
55 | ```ruby
56 | ApplicationController < ActionController::Base
57 | lock actions: ["widgets"]
58 | end
59 | ```
60 |
61 | ## Unlock your app
62 |
63 | 1. Use the lock login url - /lock/login
64 | 2. Type in your password (from the generator) and press unlock
65 |
66 | ## Override the views
67 |
68 | You may want to customize the views to fit your app. The easiest way to achieve this is to create the lock views directory - /app/views/lock, and
69 | add your own view files. The views should be named:
70 |
71 | ```
72 | /app/views/lock/refused.html.erb #message shown to users when they access a locked page
73 | /app/views/lock/login.html.erb #login form
74 | /app/views/lock/unlock.html.erb #shows a confirmation message after you unlock it
75 | ```
76 |
77 | If you choose to override the login page, you will need to create a form that posts to /lock/unlock and uses a password field
78 | named "password".
79 |
80 | By default, these views will render inside your default layout. To create a custom layout for these files, just add /app/views/layouts/lock.html.erb
81 | The layout must contain a yield.
82 |
83 | ## Contributing to lock
84 |
85 | * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
86 | * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
87 | * Fork the project
88 | * Start a feature/bugfix branch
89 | * Commit and push until you are happy with your contribution
90 | * Make sure to add tests for it. Patches without tests will be ignored
91 | * Please try not to mess with the Rakefile, version, or history.
92 |
93 | Copyright
94 | ---------
95 |
96 | Copyright (c) 2011-2022 cowboycoded and the Charlotte Ruby User Group. See LICENSE.txt for
97 | further details.
98 |
99 |
--------------------------------------------------------------------------------
/spec/dummy/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "active_support/core_ext/integer/time"
4 |
5 | Rails.application.configure do
6 | # Settings specified here will take precedence over those in config/application.rb.
7 |
8 | # Code is not reloaded between requests.
9 | config.cache_classes = true
10 |
11 | # Eager load code on boot. This eager loads most of Rails and
12 | # your application in memory, allowing both threaded web servers
13 | # and those relying on copy on write to perform better.
14 | # Rake tasks automatically ignore this option for performance.
15 | config.eager_load = true
16 |
17 | # Full error reports are disabled and caching is turned on.
18 | config.consider_all_requests_local = false
19 | config.action_controller.perform_caching = true
20 |
21 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
22 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
23 | # config.require_master_key = true
24 |
25 | # Disable serving static files from the `/public` folder by default since
26 | # Apache or NGINX already handles this.
27 | config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
28 |
29 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
30 | # config.asset_host = "http://assets.example.com"
31 |
32 | # Specifies the header that your server uses for sending files.
33 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
34 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
35 |
36 | # Store uploaded files on the local file system (see config/storage.yml for options).
37 | # config.active_storage.service = :local
38 |
39 | # Mount Action Cable outside main process or domain.
40 | # config.action_cable.mount_path = nil
41 | # config.action_cable.url = "wss://example.com/cable"
42 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
43 |
44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
45 | # config.force_ssl = true
46 |
47 | # Include generic and useful information about system operation, but avoid logging too much
48 | # information to avoid inadvertent exposure of personally identifiable information (PII).
49 | config.log_level = :info
50 |
51 | # Prepend all log lines with the following tags.
52 | config.log_tags = [:request_id]
53 |
54 | # Use a different cache store in production.
55 | # config.cache_store = :mem_cache_store
56 |
57 | # Use a real queuing backend for Active Job (and separate queues per environment).
58 | # config.active_job.queue_adapter = :resque
59 | # config.active_job.queue_name_prefix = "dummy_production"
60 |
61 | config.action_mailer.perform_caching = false
62 |
63 | # Ignore bad email addresses and do not raise email delivery errors.
64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
65 | # config.action_mailer.raise_delivery_errors = false
66 |
67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
68 | # the I18n.default_locale when a translation cannot be found).
69 | config.i18n.fallbacks = true
70 |
71 | # Don't log any deprecations.
72 | config.active_support.report_deprecations = false
73 |
74 | # Use default logging formatter so that PID and timestamp are not suppressed.
75 | config.log_formatter = ::Logger::Formatter.new
76 |
77 | # Use a different logger for distributed setups.
78 | # require "syslog/logger"
79 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
80 |
81 | if ENV["RAILS_LOG_TO_STDOUT"].present?
82 | logger = ActiveSupport::Logger.new($stdout)
83 | logger.formatter = config.log_formatter
84 | config.logger = ActiveSupport::TaggedLogging.new(logger)
85 | end
86 |
87 | # Do not dump schema after migrations.
88 | config.active_record.dump_schema_after_migration = false
89 | end
90 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8 |
9 | ## Our Standards
10 |
11 | Examples of behavior that contributes to a positive environment for our community include:
12 |
13 | * Demonstrating empathy and kindness toward other people
14 | * Being respectful of differing opinions, viewpoints, and experiences
15 | * Giving and gracefully accepting constructive feedback
16 | * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17 | * Focusing on what is best not just for us as individuals, but for the overall community
18 |
19 | Examples of unacceptable behavior include:
20 |
21 | * The use of sexualized language or imagery, and sexual attention or
22 | advances of any kind
23 | * Trolling, insulting or derogatory comments, and personal or political attacks
24 | * Public or private harassment
25 | * Publishing others' private information, such as a physical or email
26 | address, without their explicit permission
27 | * Other conduct which could reasonably be considered inappropriate in a
28 | professional setting
29 |
30 | ## Enforcement Responsibilities
31 |
32 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33 |
34 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35 |
36 | ## Scope
37 |
38 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39 |
40 | ## Enforcement
41 |
42 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at matt@invalid8.com. All complaints will be reviewed and investigated promptly and fairly.
43 |
44 | All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45 |
46 | ## Enforcement Guidelines
47 |
48 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49 |
50 | ### 1. Correction
51 |
52 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53 |
54 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55 |
56 | ### 2. Warning
57 |
58 | **Community Impact**: A violation through a single incident or series of actions.
59 |
60 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61 |
62 | ### 3. Temporary Ban
63 |
64 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65 |
66 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67 |
68 | ### 4. Permanent Ban
69 |
70 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71 |
72 | **Consequence**: A permanent ban from any sort of public interaction within the community.
73 |
74 | ## Attribution
75 |
76 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78 |
79 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80 |
81 | [homepage]: https://www.contributor-covenant.org
82 |
83 | For answers to common questions about this code of conduct, see the FAQ at
84 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
85 |
--------------------------------------------------------------------------------