Class: UltraVault::Agent
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- UltraVault::Agent
- 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
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#os_type ⇒ Object
readonly
Returns the value of attribute os_type.
-
#port_number ⇒ Object
readonly
Returns the value of attribute port_number.
Class Method Summary collapse
-
.all ⇒ [UltraVault::Agent]
Returns all agents for the current user.
- .check_all_params_are_present(params) ⇒ Object
- .check_params(params) ⇒ Object
- .check_params_are_legal(params) ⇒ Object
- .check_params_strict(params) ⇒ Object
-
.create(params) ⇒ UltraVault::Agent
Returns a newly created agent with the given params.
- .do_check_params(strict, params) ⇒ Object
-
.find_by_id(agent_id) ⇒ UltraVault::Agent
Returns an agent, if found.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy the current agent @ return [UltraVault::Agent] deleted agent.
-
#disk_safes ⇒ [UltraVault::DiskSafe]
Disksafes belonging to this agent.
-
#initialize(params) ⇒ Agent
constructor
A new instance of Agent.
-
#update(params) ⇒ UltraVault::Agent
Update the current agent.
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
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/ultravault/data_objects/agent.rb', line 3 def description @description end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
3 4 5 |
# File 'lib/ultravault/data_objects/agent.rb', line 3 def hostname @hostname end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/ultravault/data_objects/agent.rb', line 3 def id @id end |
#os_type ⇒ Object (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_number ⇒ Object (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.
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 |
.check_params_are_legal(params) ⇒ Object
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.
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.
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
#destroy ⇒ Object
Destroy the current agent @ return [UltraVault::Agent] deleted agent
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.
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
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 |