Class: Heroku::Kensa::ManifestCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/heroku/kensa/check.rb

Constant Summary collapse

ValidPriceUnits =
%w[month dyno_hour]

Instance Attribute Summary

Attributes inherited from Check

#data, #screen

Instance Method Summary collapse

Methods inherited from Check

#api_requires?, #call, #check, #env, #error, #initialize, #run, #test, #to_proc, #url, #warning

Constructor Details

This class inherits a constructor from Heroku::Kensa::Check

Instance Method Details

#call!Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# 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