Method: Fog::KeyManager::OpenStack::Real#supported_version

Defined in:
lib/fog/key_manager/openstack.rb

#supported_version(supported_versions, uri, auth_token, connection_options = {}) ⇒ Object



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
# File 'lib/fog/key_manager/openstack.rb', line 120

def supported_version(supported_versions, uri, auth_token, connection_options = {})
  connection = Fog::Core::Connection.new("#{uri.scheme}://#{uri.host}:#{uri.port}", false, connection_options)
  response = connection.request({ :expects => [200, 204, 300],
                                  :headers => {'Content-Type' => 'application/json',
                                               'Accept' => 'application/json',
                                               'X-Auth-Token' => auth_token},
                                  :method => 'GET'
                                })

  body = Fog::JSON.decode(response.body)
  version = nil

  versions =  body.fetch('versions',{}).fetch('values',[])
  versions.each do |v|
    if v.fetch('id', "").match(supported_versions) &&
      ['current', 'supported', 'stable'].include?(v.fetch('status','').downcase)
      version = v['id']
    end
  end

  if !version  || version.empty?
    raise Fog::OpenStack::Errors::ServiceUnavailable.new(
            "OpenStack service only supports API versions #{supported_versions.inspect}")
  end

  version
end