Class: UltraVault::Agent

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/ultravault/data_objects/agent.rb

Constant Summary collapse

USAGE =
"Valid arguments - :hostname, :port_number, :description, :os_type"
USE_ALL =
"All arguments required."
REQUIRED_PARAMS =
[:hostname, :port_number, :description, :os_type]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Agent

Returns a new instance of Agent.



5
6
7
8
9
10
11
12
# File 'lib/ultravault/data_objects/agent.rb', line 5

def initialize(params)
  @description = params[:description]
  @hostname = params[:hostname]
  @id = params[:id]
  @os_type = params[:os_type]
  @port_number = params[:port_number]
  super(params)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/ultravault/data_objects/agent.rb', line 3

def description
  @description
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



3
4
5
# File 'lib/ultravault/data_objects/agent.rb', line 3

def hostname
  @hostname
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/ultravault/data_objects/agent.rb', line 3

def id
  @id
end

#os_typeObject (readonly)

Returns the value of attribute os_type.



3
4
5
# File 'lib/ultravault/data_objects/agent.rb', line 3

def os_type
  @os_type
end

#port_numberObject (readonly)

Returns the value of attribute port_number.



3
4
5
# File 'lib/ultravault/data_objects/agent.rb', line 3

def port_number
  @port_number
end

Class Method Details

.all[UltraVault::Agent]

Returns all agents for the current user.

Returns:

Raises:

  • (Savon::SOAP::Fault)

    errors from the soap transaction



39
40
41
# File 'lib/ultravault/data_objects/agent.rb', line 39

def self.all
  UltraVault::AgentService.new.all_agents
end

.check_all_params_are_present(params) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/ultravault/data_objects/agent.rb', line 98

def check_all_params_are_present(params)
  REQUIRED_PARAMS.each do |key|
    unless params.keys.include?(key)
      raise ArgumentError.new("#{USAGE}. #{USE_ALL}") 
    end
  end
end

.check_params(params) ⇒ Object



76
77
78
# File 'lib/ultravault/data_objects/agent.rb', line 76

def check_params(params)
  do_check_params(false, params)
end


90
91
92
93
94
95
96
# File 'lib/ultravault/data_objects/agent.rb', line 90

def check_params_are_legal(params)
  params.keys.each do |key|
    unless REQUIRED_PARAMS.include?(key)
      raise ArgumentError.new(USAGE)
    end
  end
end

.check_params_strict(params) ⇒ Object



80
81
82
# File 'lib/ultravault/data_objects/agent.rb', line 80

def check_params_strict(params)
  do_check_params(true, params)
end

.create(params) ⇒ UltraVault::Agent

Returns a newly created agent with the given params.

Returns:

Raises:

  • (Savon::SOAP::Fault)

    errors from the soap transaction



47
48
49
50
# File 'lib/ultravault/data_objects/agent.rb', line 47

def self.create(params)
  Agent.check_params_strict(params)
  UltraVault::AgentService.new.create_agent(params)
end

.do_check_params(strict, params) ⇒ Object



84
85
86
87
88
# File 'lib/ultravault/data_objects/agent.rb', line 84

def do_check_params(strict, params)
  check_params_are_legal(params)
  check_all_params_are_present(params) if strict
  true
end

.find_by_id(agent_id) ⇒ UltraVault::Agent

Returns an agent, if found.

Parameters:

  • agent_id (String)

    the UUID of the agent

Returns:

Raises:

  • (Savon::SOAP::Fault)

    errors from the soap transaction



31
32
33
# File 'lib/ultravault/data_objects/agent.rb', line 31

def self.find_by_id(agent_id)
  UltraVault::AgentService.new.find_agent_by_id(agent_id)
end

Instance Method Details

#destroyObject

Destroy the current agent @ return [UltraVault::Agent] deleted agent

Raises:

  • (Savon::SOAP::Fault)

    errors from the soap transaction



65
66
67
68
# File 'lib/ultravault/data_objects/agent.rb', line 65

def destroy
  UltraVault::AgentService.new.destroy_agent(self.id)
  self
end

#disk_safes[UltraVault::DiskSafe]

Disksafes belonging to this agent.

Returns:

Raises:

  • (Savon::SOAP::Fault)

    errors from the soap transaction



18
19
20
21
22
23
24
# File 'lib/ultravault/data_objects/agent.rb', line 18

def disk_safes
  if UltraVault.config.api_version > 1
    @disk_safes ||= UltraVault::DiskSafe.all.map { |disk_safe| disk_safe if disk_safe.agent_id == id }.compact
  else
    @disk_safes ||= UltraVault::DiskSafe.find_all_by_agent_id(id)
  end
end

#update(params) ⇒ UltraVault::Agent

Update the current agent

Returns:

Raises:

  • (Savon::SOAP::Fault)

    errors from the soap transaction



56
57
58
59
60
# File 'lib/ultravault/data_objects/agent.rb', line 56

def update(params)
  Agent.check_params(params)
  self.marshal_load(self.marshal_dump.merge(params))
  UltraVault::AgentService.new.update_agent(self.marshal_dump)
end