Class: OpenvasCli::VasLscCredential

Inherits:
VasBase
  • Object
show all
Defined in:
lib/openvas-cli/vas_lsc_credential.rb

Instance Attribute Summary collapse

Attributes inherited from VasBase

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VasBase

#destroy, #destroy!, get_by_id, #initialize, #new_record?, #reset_changes, #save, #save!, #to_key, #to_param, #update_attributes

Methods included from ConnAddin

included

Methods included from XmlAddin

included

Constructor Details

This class inherits a constructor from OpenvasCli::VasBase

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



16
17
18
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 16

def comment
  @comment
end

#in_useObject

Returns the value of attribute in_use.



17
18
19
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 17

def in_use
  @in_use
end

#loginObject

Returns the value of attribute login.



15
16
17
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 15

def 
  @login
end

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 14

def name
  @name
end

#packageObject

Returns the value of attribute package.



20
21
22
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 20

def package
  @package
end

#package_typeObject

Returns the value of attribute package_type.



21
22
23
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 21

def package_type
  @package_type
end

#passwordObject

Returns the value of attribute password.



22
23
24
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 22

def password
  @password
end

#password_confirmationObject

Returns the value of attribute password_confirmation.



23
24
25
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 23

def password_confirmation
  @password_confirmation
end

#public_keyObject

Returns the value of attribute public_key.



19
20
21
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 19

def public_key
  @public_key
end

#typeObject

Returns the value of attribute type.



18
19
20
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 18

def type
  @type
end

Class Method Details

.from_xml_node(node) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 112

def self.from_xml_node(node)
  ret              = VasLscCredential.new
  ret.id           = extract_value_from("@id", node)
  ret.name         = extract_value_from("name", node)
  ret.        = extract_value_from("login", node)
  ret.comment      = extract_value_from("comment", node)
  ret.in_use       = extract_value_from("in_use", node).to_i > 0
  ret.type         = extract_value_from("type", node)
  ret.public_key   = extract_value_from("public_key", node)
  ret.package      = extract_value_from("package", node)
  ret.package_type = extract_value_from("package/@format", node)
  
  node.xpath("targets/target").each { |t|
    ret.target_keys << extract_value_from("@id", t)
  }
  
  ret
end

.get_all(options = {}) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 90

def self.get_all(options={})
  params = {:sort_field => 'name'}
  params[:lsc_credential_id] = options[:id] if options[:id]
  req = Nokogiri::XML::Builder.new { |xml|
    xml.get_lsc_credentials(params)
  }
  
  ret = []

  begin
    resp = connection.send_receive(req.doc)
      
    resp.xpath("//lsc_credential").each { |cred|
      ret << from_xml_node(cred)
    }
  rescue VasExceptions::CommandException => e
    
  end
  
  ret
end

Instance Method Details

#create_or_updateObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 38

def create_or_update
  if @id
    #update
    req = Nokogiri::XML::Builder.new { |xml|
      xml.modify_lsc_credential(:lsc_credential_id => @id) {
        xml.name     { xml.text(@name) }
        xml.comment  { xml.text(@comment) } if @comment
        xml.    { xml.text(@login) }
        xml.password { xml.text(@password) } if @password
      } 
    }
  else
    #create
    req = Nokogiri::XML::Builder.new { |xml|
      xml.create_lsc_credential {
        xml.name     { xml.text(@name) }
        xml.comment  { xml.text(@comment) } if @comment
        xml.    { xml.text(@login) }
        xml.password { xml.text(@password) } if @password
      }
    }
  end
  
  begin
    resp = VasLscCredential.connection.send_receive(req.doc)
    @id = VasLscCredential.extract_value_from("create_lsc_credential_response/@id", resp) unless @id
    
    true
  rescue VasExceptions::CommandException => e
    errors[:command_failure] << e.message
    
    nil
  end
end

#delete_recordObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 73

def delete_record
  return unless @id
  req = Nokogiri::XML::Builder.new { |xml|
    xml.delete_lsc_credential( :lsc_credential_id => @id )
  }
  
  begin
    VasLscCredential.connection.send_receive(req.doc)
    
    true
  rescue VasExceptions::CommandException
    errors[:command_failure] << e.message
    
    nil
  end
end

#target_keysObject



30
31
32
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 30

def target_keys
  @target_keys ||= []
end

#targetsObject



34
35
36
# File 'lib/openvas-cli/vas_lsc_credential.rb', line 34

def targets
  @targets ||= []
end