class Fog::KeyManager::OpenStack::Real

Public Class Methods

new(options = {}) click to toggle source
# File lib/fog/key_manager/openstack.rb, line 51
def initialize(options = {})
  initialize_identity options

  @openstack_service_type           = options[:openstack_service_type] || ['key-manager']
  @openstack_service_name           = options[:openstack_service_name]
  @connection_options               = options[:connection_options] || {}

  authenticate
  set_api_path

  @persistent = options[:persistent] || false
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end
not_found_class() click to toggle source
# File lib/fog/key_manager/openstack.rb, line 47
def self.not_found_class
  Fog::KeyManager::OpenStack::NotFound
end

Public Instance Methods

create_container(options) click to toggle source
# File lib/fog/key_manager/openstack/requests/create_container.rb, line 5
def create_container(options)
  request(
    :body    => Fog::JSON.encode(options),
    :expects => [201],
    :method  => 'POST',
    :path    => 'containers'
  )
end
create_secret(options) click to toggle source
# File lib/fog/key_manager/openstack/requests/create_secret.rb, line 5
def create_secret(options)
  request(
    :body    => Fog::JSON.encode(options),
    :expects => [201],
    :method  => 'POST',
    :path    => 'secrets'
  )
end
delete_container(id) click to toggle source
# File lib/fog/key_manager/openstack/requests/delete_container.rb, line 5
def delete_container(id)
  request(
    :expects => [204],
    :method  => 'DELETE',
    :path    => "containers/#{id}"
  )
end
delete_secret(id) click to toggle source
# File lib/fog/key_manager/openstack/requests/delete_secret.rb, line 5
def delete_secret(id)
  request(
    :expects => [204],
    :method  => 'DELETE',
    :path    => "secrets/#{id}"
  )
end
get_container(uuid) click to toggle source
# File lib/fog/key_manager/openstack/requests/get_container.rb, line 5
def get_container(uuid)
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => "containers/#{uuid}",
  )
end
get_secret(uuid) click to toggle source
# File lib/fog/key_manager/openstack/requests/get_secret.rb, line 5
def get_secret(uuid)
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => "secrets/#{uuid}",
  )
end
get_secret_metadata(uuid) click to toggle source
# File lib/fog/key_manager/openstack/requests/get_secret_metadata.rb, line 5
def get_secret_metadata(uuid)
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => "secrets/#{uuid}/metadata",
  )
end
get_secret_payload(uuid) click to toggle source
# File lib/fog/key_manager/openstack/requests/get_secret_payload.rb, line 5
def get_secret_payload(uuid)
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => "secrets/#{uuid}/payload",
    :headers => {
      'Accept' => '*/*'
    }
  )
end
list_containers(options = {}) click to toggle source
# File lib/fog/key_manager/openstack/requests/list_containers.rb, line 5
def list_containers(options = {})
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => 'containers',
    :query   => options
  )
end
list_secrets(options = {}) click to toggle source
# File lib/fog/key_manager/openstack/requests/list_secrets.rb, line 5
def list_secrets(options = {})
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => 'secrets',
    :query   => options
  )
end
set_api_path() click to toggle source
# File lib/fog/key_manager/openstack.rb, line 65
def set_api_path
  @path.sub!(%r{/$}, '')
  unless @path.match(SUPPORTED_VERSIONS)
    @path = supported_version(SUPPORTED_VERSIONS, @openstack_management_uri, @auth_token, @connection_options)
  end
end
supported_version(supported_versions, uri, auth_token, connection_options = {}) click to toggle source
# File lib/fog/key_manager/openstack.rb, line 72
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.blank?
    raise Fog::OpenStack::Errors::ServiceUnavailable.new(
            "OpenStack service only supports API versions #{supported_versions.inspect}")
  end

  version
end