Sha256: 73a3de7b56e3f905de10b345c016510ba04813008ee12ca84b450fc04d464ac4

Contents?: true

Size: 901 Bytes

Versions: 3

Compression:

Stored size: 901 Bytes

Contents

module MissionControl::Jobs::BasicAuthentication
  extend ActiveSupport::Concern

  included do
    before_action :authenticate_by_http_basic
  end

  private
    def authenticate_by_http_basic
      if http_basic_authentication_enabled?
        if http_basic_authentication_configured?
          http_basic_authenticate_or_request_with(**http_basic_authentication_credentials)
        else
          head :unauthorized
        end
      end
    end

    def http_basic_authentication_enabled?
      MissionControl::Jobs.http_basic_auth_enabled
    end

    def http_basic_authentication_configured?
      http_basic_authentication_credentials.values.all?(&:present?)
    end

    def http_basic_authentication_credentials
      {
        name: MissionControl::Jobs.http_basic_auth_user,
        password: MissionControl::Jobs.http_basic_auth_password
      }.transform_values(&:presence)
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mission_control-jobs-1.0.2 app/controllers/concerns/mission_control/jobs/basic_authentication.rb
mission_control-jobs-1.0.1 app/controllers/concerns/mission_control/jobs/basic_authentication.rb
mission_control-jobs-1.0.0 app/controllers/concerns/mission_control/jobs/basic_authentication.rb