Class: Fog::KeyManager::OpenStack::Real

Inherits:
Object
  • Object
show all
Includes:
OpenStack::Core
Defined in:
lib/fog/key_manager/openstack.rb,
lib/fog/key_manager/openstack/requests/get_secret.rb,
lib/fog/key_manager/openstack/requests/list_secrets.rb,
lib/fog/key_manager/openstack/requests/create_secret.rb,
lib/fog/key_manager/openstack/requests/delete_secret.rb,
lib/fog/key_manager/openstack/requests/get_container.rb,
lib/fog/key_manager/openstack/requests/list_containers.rb,
lib/fog/key_manager/openstack/requests/create_container.rb,
lib/fog/key_manager/openstack/requests/delete_container.rb,
lib/fog/key_manager/openstack/requests/get_secret_payload.rb,
lib/fog/key_manager/openstack/requests/get_secret_metadata.rb

Instance Attribute Summary

Attributes included from OpenStack::Core

#auth_token, #auth_token_expiration, #current_tenant, #current_user, #current_user_id, #openstack_cache_ttl, #openstack_domain_id, #openstack_domain_name, #openstack_identity_prefix, #openstack_project_domain, #openstack_project_domain_id, #openstack_project_id, #openstack_user_domain, #openstack_user_domain_id, #unscoped_token

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OpenStack::Core

#credentials, #initialize_identity, #reload

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



51
52
53
54
55
56
57
58
59
60
61
62
63
# 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

Class Method Details

.not_found_classObject



47
48
49
# File 'lib/fog/key_manager/openstack.rb', line 47

def self.not_found_class
  Fog::KeyManager::OpenStack::NotFound
end

Instance Method Details

#create_container(options) ⇒ Object



5
6
7
8
9
10
11
12
# 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) ⇒ Object



5
6
7
8
9
10
11
12
# 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) ⇒ Object



5
6
7
8
9
10
11
# 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) ⇒ Object



5
6
7
8
9
10
11
# 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) ⇒ Object



5
6
7
8
9
10
11
# 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) ⇒ Object



5
6
7
8
9
10
11
# 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) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/key_manager/openstack/requests/get_secret_metadata.rb', line 5

def (uuid)
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => "secrets/#{uuid}/metadata",
  )
end

#get_secret_payload(uuid) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# 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 = {}) ⇒ Object



5
6
7
8
9
10
11
12
# 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 = {}) ⇒ Object



5
6
7
8
9
10
11
12
# 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_pathObject



65
66
67
68
69
70
# 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 = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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