Class: API::Init

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_url:, authtoken:, org: nil, certificate: nil) ⇒ Init

Returns a new instance of Init.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/puppet/functions/api.rb', line 33

def initialize(server_url:, authtoken:, org: nil, certificate: nil)
  if server_url.nil? || authtoken.nil? || server_url.strip.empty? || authtoken.strip.empty?
    Logger.log(ERROR, 'Server URL and authtoken are required to initialize Abi')
    return nil
  end
  unless server_url.start_with?('http://', 'https://')
    Logger.log(ERROR, 'Invalid server URL. It must start with http:// or https://')
    return nil
  end
  API.server_url = server_url.strip
  API.authtoken = authtoken.strip
  API.org = org unless org.to_s.strip.empty? || org.nil?
  API.certificate = certificate
  Logger.log(INFO, 'Abi initialized successfully')
end

Class Method Details

.initializedObject



49
50
51
52
53
54
55
# File 'lib/puppet/functions/api.rb', line 49

def self.initialized
  if API.server_url.nil? || API.authtoken.nil?
    false
  elsif API.server_url.start_with?('https://', 'http://')
    true
  end
end