Class: NexposeThycotic::ThycoticOperations

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose_thycotic/operations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = nil, comment = '') ⇒ ThycoticOperations

Returns a new instance of ThycoticOperations.



76
77
78
79
80
81
82
# File 'lib/nexpose_thycotic/operations.rb', line 76

def initialize(url = nil, comment = '')
  # log: true, log_level: :info
  @client = Savon.client(wsdl: url, ssl_verify_mode: :none)

  # Comment used when retrieving passwords
  @comment = comment
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



75
76
77
# File 'lib/nexpose_thycotic/operations.rb', line 75

def client
  @client
end

Instance Method Details

#authenticate(username, password) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/nexpose_thycotic/operations.rb', line 106

def authenticate(username, password)
  operation = :authenticate
  message = { username: username, password: password }
  auth_result = get_secret_result(operation, message)
  check_for_errors(auth_result)
  @token = auth_result[:token]
end

#check_for_errors(result) ⇒ Object



177
178
179
180
181
182
183
184
# File 'lib/nexpose_thycotic/operations.rb', line 177

def check_for_errors(result)
  errors = result[:errors]
  unless errors.blank?
    puts errors
    #TODO: Logging
    raise Exception.new(errors)
  end
end

#check_type(type) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/nexpose_thycotic/operations.rb', line 88

def check_type(type)
  case type
    when /.*unix.*/i then 'ssh'
    when /.*windows.*/i then 'cifs'
    when /.*ftp.*/i then 'ftp'
    when /.*400.*/i then 'as400'
    when /.*lotus.*/i then 'notes'
    when /.*Microsoft.*SQL.*Server.*/i then 'tds'
    when /.*Sybase.*SQL.*Server.*/i then 'sybase'
    when /.*mysql.*/i then 'mysql'
    when /.*DB2.*/i then 'db2'
    when /.*postgresql.*/i then 'postgresql'
    when /.*pop.*/i then 'pop'
    when /.*Simple.*Network.*Management.*/i then 'snmp'
    when /.*telnet.*/i then 'telnet'
  end
end

#get_secret(token, secret_id) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/nexpose_thycotic/operations.rb', line 157

def get_secret(token, secret_id)
  operation = :get_secret
  message = { token: token,
              secretId: secret_id,
              loadSettingsAndPermissions: false,
              "codeResponses" => {"CodeResponse" =>
                                      [{
                                           "ErrorCode" => "COMMENT",
                                           "Comment" => @comment
                                       }]
              }}
  secret_result = get_secret_result(operation, message)

  check_for_errors(secret_result)
  username = parse_field(secret_result, 'Username')
  password = parse_field(secret_result, 'Password')

  { username: username, password: password }
end

#get_secret_result(operation, message) ⇒ Object



120
121
122
123
124
# File 'lib/nexpose_thycotic/operations.rb', line 120

def get_secret_result(operation, message)
  secret = @client.call(operation, message: message)
  resp = secret.hash[:envelope][:body]["#{operation}_response".to_sym]
  resp["#{operation}_result".to_sym]
end

#get_secret_summaries(token, ip) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/nexpose_thycotic/operations.rb', line 126

def get_secret_summaries(token, ip)
  operation = :search_secrets_by_field_value
  message = {
    token: token,
    fieldName: 'machine',
    searchTerm: ip,
    showDeleted: true,
    showRestricted: true
  }
  secret_result = get_secret_result(operation, message)

  secrets = []
  unless secret_result[:secret_summaries].nil?
    summaries = secret_result[:secret_summaries][:secret_summary]

    # Ensure summaries is iterable
    summaries = [summaries] if summaries.is_a?(Hash)

    summaries.each do |secret|
      secret_info = {
        secret_id: secret[:secret_id],
        secret_type: secret[:secret_type_name],
        secret_name: secret[:secret_name]
      }
      secrets << secret_info
    end
  end

  secrets
end

#operationsObject



84
85
86
# File 'lib/nexpose_thycotic/operations.rb', line 84

def operations
  puts @client.operations
end

#parse_field(secret_response_result, field_name) ⇒ Object



114
115
116
117
118
# File 'lib/nexpose_thycotic/operations.rb', line 114

def parse_field(secret_response_result, field_name)
  items = secret_response_result[:secret][:items][:secret_item]
  item = items.find  { |i| i[:field_display_name].casecmp(field_name) == 0 }
  item[:value]
end