class Heroku::Kensa::ManifestCheck

Constants

ValidPriceUnits

Public Instance Methods

call!() click to toggle source
# File lib/heroku/kensa/check.rb, line 86
def call!
  test "manifest id key"
  check "if exists" do
    data.has_key?("id")
  end
  check "is a string" do
    data["id"].is_a?(String)
  end
  check "is not blank" do
    !data["id"].empty?
  end

  test "manifest api key"
  check "if exists" do
    data.has_key?("api")
  end
  check "is a hash" do
    data["api"].is_a?(Hash)
  end
  check "has a list of regions" do
    data["api"].has_key?("regions") &&
      data["api"]["regions"].is_a?(Array)
  end
  check "contains at least the US region" do
    data["api"]["regions"].include?("us") ||
      data["api"]["regions"].include?("*")
  end
  check "contains only valid region names" do
    data["api"]["regions"].all? { |reg| Manifest::REGIONS.include? reg }
  end
  check "contains password" do
    data["api"].has_key?("password") && data["api"]["password"] != ""
  end
  check "contains test url" do
    data["api"].has_key?("test")
  end
  check "contains production url" do
    data["api"].has_key?("production")
  end

  if data['api']['production'].is_a? Hash
    check "production url uses SSL" do
      data['api']['production']['base_url'] =~ /^https:/
    end
    check "sso url uses SSL" do
      data['api']['production']['sso_url'] =~ /^https:/
    end
  else
    check "production url uses SSL" do
      data['api']['production'] =~ /^https:/
    end
  end

  if data["api"].has_key?("config_vars")
    check "contains config_vars array" do
      data["api"]["config_vars"].is_a?(Array)
    end
    check "all config vars are uppercase strings" do
      data["api"]["config_vars"].each do |k, v|
        if k =~ /^[A-Z][0-9A-Z_]+$/
          true
        else
          error "#{k.inspect} is not a valid ENV key"
        end
      end
    end
    check "all config vars are prefixed with the addon id" do
      data["api"]["config_vars"].each do |k|
        prefix = data["api"]["config_vars_prefix"] || data['id'].upcase.gsub('-', '_')
        if k =~ /^#{prefix}_/
          true
        else
          error "#{k} is not a valid ENV key - must be prefixed with #{prefix}_"
        end
      end
    end
  end

  check "deprecated fields" do
    if data["api"].has_key?("username")
      error "username is deprecated: Please authenticate using the add-on id."
    end
    true
  end
end