Class: API::Accounts

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/functions/api.rb

Class Method Summary collapse

Class Method Details

.delete(reason:, account_ids: [], delete_permanently: nil) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/puppet/functions/api.rb', line 191

def self.delete(reason:, account_ids: [], delete_permanently: nil)
  Logger.log(DEBUG, 'Deleting accounts from abi')
  server = Init.initialized
  return nil if server == false

  if .empty? || .nil?
    Logger.log(ERROR, 'Required account IDs')
    return nil
  end
  Logger.log(DEBUG, 'Deleting accounts from abi')
  params = {}
  params['account_ids'] = 
  params['reason'] = reason unless reason.nil?
  params['delete_permanently'] = delete_permanently unless delete_permanently.nil?
  response = Request.new.raise_request(params, '/api/delete_accounts', DELETE)
  if response
    Logger.log(DEBUG, response['message']) if response['message']
    response
  else
    Logger.log(ERROR, 'Failed to delete accounts')
    nil
  end
rescue StandardError => e
  Logger.log(ERROR, "Could not delete accounts: #{e}")
  nil
end

.get(account_ids: [], accounts: []) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/puppet/functions/api.rb', line 166

def self.get(account_ids: [], accounts: [])
  Logger.log(DEBUG, 'Fetching accounts from abi')
  server = Init.initialized
  return nil if server == false

  params = {}
  if 
    params['account_ids'] = 
  elsif accounts
    params['accounts'] = accounts
  else
    Logger.log(ERROR, 'Account IDs or accounts data required')
    return nil
  end
  Logger.log(DEBUG, 'Fetching accounts from Abi')
  accounts_data = Request.new.raise_request(params, '/secretsmanagement/get_accounts', POST)
  return nil unless accounts_data

  Logger.log(DEBUG, accounts_data['message']) if accounts_data['message']
  accounts_data
rescue StandardError => e
  Logger.log(ERROR, "Could not fetch accounts: #{e}")
  nil
end