Class: API::Account

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

Class Method Summary collapse

Class Method Details

.add(account_title: nil, account_type: nil, account_name: nil, personal_account: nil, password: nil, ipaddress: nil, notes: nil, tags: nil, folder_id: nil, account_expiration_date: nil, distinguished_name: nil, account_alias: nil, domain_name: nil) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/puppet/functions/api.rb', line 91

def self.add(account_title: nil, account_type: nil, account_name: nil, personal_account: nil, password: nil, ipaddress: nil, notes: nil, tags: nil, folder_id: nil, account_expiration_date: nil, distinguished_name: nil, account_alias: nil, domain_name: nil)
  server = Init.initialized
  return nil if server == false

  if .nil?
    Logger.log(ERROR, 'Required Account type')
    return nil
  elsif .nil?
    Logger.log(ERROR, 'Required Account title')
    return nil
  end
  Logger.log(DEBUG, 'Creating account in abi')
  params = {}
  params['account_title'] = 
  params['account_type'] = 
  params['account_name'] =  unless .nil?
  params['personal_account'] =  unless .nil?
  params['ipaddress'] = ipaddress unless ipaddress.nil?
  params['notes'] = notes unless notes.nil?
  params['tags'] = tags unless tags.nil?
  params['folder_id'] = folder_id unless folder_id.nil?
  params['password'] = password unless password.nil?
  params['account_expiration_date'] =  unless .nil?
  params['distinguished_name'] = distinguished_name unless distinguished_name.nil?
  params['account_alias'] =  unless .nil?
  params['domain_name'] = domain_name unless domain_name.nil?
   = Request.new.raise_request(params, '/api/add_account', POST)
  return nil unless 

  Logger.log(DEBUG, ['message']) if ['message']
  
rescue StandardError => e
  Logger.log(ERROR, "Failed to add account: #{e.message}")
  nil
end

.edit(account_id:, account_type:, account_title: nil, account_name: nil, personal_account: nil, password: nil, ipaddress: nil, notes: nil, tags: nil, folder_id: nil, account_expiration_date: nil, distinguished_name: nil, account_alias: nil, domain_name: nil) ⇒ Object



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
156
157
158
159
160
161
162
# File 'lib/puppet/functions/api.rb', line 127

def self.edit(account_id:, account_type:, account_title: nil, account_name: nil, personal_account: nil, password: nil, ipaddress: nil, notes: nil, tags: nil, folder_id: nil, account_expiration_date: nil, distinguished_name: nil, account_alias: nil, domain_name: nil)
  server = Init.initialized
  return nil if server == false

  if .nil? || .nil?
    Logger.log(ERROR, 'Required account ID and Account type')
    return nil
  end
  Logger.log(DEBUG, 'Updating account in abi')
  params = {}
  params['account_id'] = 
  params['account_type'] = 
  params['account_title'] =  unless .nil?
  params['account_name'] =  unless .nil?
  params['password'] = password unless password.nil?
  params['ipaddress'] = ipaddress unless ipaddress.nil?
  params['personal_account'] =  unless .nil?
  params['notes'] = notes unless notes.nil?
  params['tags'] = tags unless tags.nil?
  params['folder_id'] = folder_id unless folder_id.nil?
  params['account_expiration_date'] =  unless .nil?
  params['distinguished_name'] = distinguished_name unless distinguished_name.nil?
  params['account_alias'] =  unless .nil?
  params['domain_name'] = domain_name unless domain_name.nil?
   = Request.new.raise_request(params, '/api/edit_account', PUT)
  if 
    Logger.log(DEBUG, ['message']) if ['message']
    
  else
    Logger.log(ERROR, 'Failed to update account')
    nil
  end
rescue StandardError => e
  Logger.log(ERROR, "Could not update account: #{e}")
  nil
end

.get(account_id: nil, account_title: nil, account_name: nil, account_type: nil, ticket_id: nil, reason: nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/puppet/functions/api.rb', line 59

def self.get(account_id: nil, account_title: nil, account_name: nil, account_type: nil, ticket_id: nil, reason: nil)
  unless API.server_url && API.authtoken
    if server_url.nil? || authtoken.nil?
      Logger.log(ERROR,
                 'Abi is not initialized. Server URL and authtoken are required to initialize Abi')
      return nil
    else
      Init.new(server_url: server_url, authtoken: authtoken, org: org, certificate: certificate)
    end
  end
  if .nil? && .nil? && .nil? && .nil?
    Logger.log(ERROR, 'At least one of account_id, account_title, account_name is required')
    return nil
  end
  Logger.log(INFO, 'Fetching account data')
  params = {}
  params['account_id'] =  unless .nil?
  params['account_title'] =  unless .nil?
  params['account_name'] =  unless .nil?
  params['account_type'] =  unless .nil?
  params['ticket_id'] = ticket_id unless ticket_id.nil?
  params['reason'] = reason unless reason.nil?
   = Request.new.raise_request(params, '/secretsmanagement/get_account', GET)
  return nil unless 

  Logger.log(INFO, ['message']) if ['message']
  
rescue StandardError => e
  Logger.log(ERROR, "Failed to fetch account data: #{e.message}")
  nil
end