Sha256: c36759376f9c878517373190fa4aa02ca715dab246d8c93af433ae7fb232f5fb

Contents?: true

Size: 1.99 KB

Versions: 36

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true
require "padrino-core"
require "redcarpet"

Tilt.prefer Tilt::RedcarpetTemplate

module PactBroker
  module Doc
    module Controllers
      class App < Padrino::Application

        set :root, File.join(File.dirname(__FILE__), "..")
        set :show_exceptions, true

        MAPPINGS = {
          "webhooks-create" => "webhooks",
          "webhooks-webhooks" => "webhooks",
          "webhook" => "webhooks",
          "can-i-deploy-pacticipant-version-to-tag" => "can-i-deploy",
          "can-i-deploy-pacticipant-version-to-environment" => "can-i-deploy",
          "pacticipant" => "pacticipants"
        }.freeze

        helpers do
          def view_name_for rel_name, context = nil
            view_name = MAPPINGS[rel_name] || rel_name
            context ? "#{context}/#{view_name}" : view_name
          end

          def resource_exists? rel_name, context = nil
            File.exist? File.join(self.class.root, "views", "#{view_name_for(rel_name, context)}.markdown")
          end
        end

        get ":rel_name" do
          rel_name = params[:rel_name]
          context = params[:context]
          view_params = {:layout_engine => :haml, layout: :'layouts/main', locals: { base_url: base_url }}
          if resource_exists? rel_name, context
            markdown view_name_for(rel_name, context).to_sym, view_params, {}
          elsif resource_exists? rel_name
            markdown view_name_for(rel_name).to_sym, view_params, {}
          else
            markdown :not_found, view_params, {}
          end
        end

        private

        def base_url
          # Using the X-Forwarded headers in the UI can leave the app vulnerable
          # https://www.acunetix.com/blog/articles/automated-detection-of-host-header-attacks/
          # Either use the explicitly configured base url or an empty string,
          # rather than request.base_url, which uses the X-Forwarded headers.
          env["pactbroker.base_url"] || ""
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.111.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.109.1 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.109.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.108.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.107.1 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.107.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.106.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.105.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.104.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.103.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.102.2 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.102.1 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.102.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.101.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.100.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.99.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.98.0 lib/pact_broker/doc/controllers/app.rb
pact_broker-2.97.0 lib/pact_broker/doc/controllers/app.rb