Class: StudioApi::Appliance::GpgKey

Inherits:
ActiveResource::Base
  • Object
show all
Extended by:
StudioResource
Defined in:
lib/studio_api/appliance.rb

Overview

Represents GPGKey assigned to appliance

Class Method Summary collapse

Methods included from StudioResource

collection_path, element_path, extended, studio_connection, studio_connection=

Class Method Details

.create(appliance_id, name, key, options = {}) ⇒ Object

upload new GPG key to appliance

Examples:

Load from file

File.open ("/etc/my.cert") do |file|
  StudioApi::Appliance::GpgKey.create 1234, "my new cool key", file, :target => "rpm"
end

Parameters:

  • appliance_id (#to_i)

    id of appliance to which load gpg key

  • name (#to_s)

    of gpg key

  • opened (File, String)

    file containing key or key in string

  • options (Hash) (defaults to: {})

    additional options keys as it allow studio API



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/studio_api/appliance.rb', line 121

def self.create (appliance_id, name, key, options={})
  options[:target] ||= "rpm"
  data = {}
  if key.is_a?(IO) && key.respond_to?(:path) #if key is string, that pass it in request, if not pack it in body
    data[:file] = key
  else
    options[:key] = key.to_s
  end
  request_str = "/appliances/#{appliance_id.to_i}/gpg_keys?name=#{name}"
  request_str = Util.add_options request_str, options, false
  response = GenericRequest.new(studio_connection).post request_str, data
  self.new Hash.from_xml(response)["gpg_key"]
end