Class: Contrast::Components::Api::Interface

Inherits:
Object
  • Object
show all
Includes:
ComponentBase, Contrast::Config::BaseConfiguration
Defined in:
lib/contrast/components/api.rb

Overview

A wrapper build around the Common Agent Configuration project to allow for Api keys to be mapped with their values contained in their parent_configuration_spec.yaml.

Constant Summary collapse

CANON_NAME =
'api'
PROXY_NAME =
"#{ CANON_NAME }.proxy".cs__freeze
CONFIG_VALUES =
%w[api_key user_name service_key url].cs__freeze
DEFAULT_URL =
'https://app.contrastsecurity.com/Contrast'

Constants included from Contrast::Config::BaseConfiguration

Contrast::Config::BaseConfiguration::AT_UNDERSCORE

Constants included from ComponentBase

ComponentBase::ENABLE

Constants included from Contrast::Config::Diagnostics::Tools

Contrast::Config::Diagnostics::Tools::CHECK

Constants included from Contrast::Config::Diagnostics::SingletonTools

Contrast::Config::Diagnostics::SingletonTools::API_CREDENTIALS, Contrast::Config::Diagnostics::SingletonTools::CONTRAST_MARK

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Contrast::Config::BaseConfiguration

#to_contrast_hash

Methods included from ComponentBase

#canon_name, #config_values, #false?, #file_exists?, #stringify_array, #true?, #valid_cert?

Methods included from Contrast::Config::Diagnostics::Tools

#add_effective_config_values, #add_single_effective_value

Methods included from Contrast::Config::Diagnostics::SingletonTools

#flatten_settings, #to_config_values, #update_config, #value_to_s

Constructor Details

#initialize(hsh = {}) ⇒ Interface

Returns a new instance of Interface.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/contrast/components/api.rb', line 34

def initialize hsh = {}
  return unless hsh

  @api_key = hsh[:api_key]
  @url = hsh[:url]
  @user_name = hsh[:user_name]
  @service_key = hsh[:service_key]
  @_proxy = Contrast::Config::ApiProxyConfiguration.new(hsh[:proxy])
  @_request_audit = Contrast::Config::RequestAuditConfiguration.new(hsh[:request_audit])
  @_certificate = Contrast::Config::CertificationConfiguration.new(hsh[:certificate])
end

Instance Attribute Details

#api_keyString

Returns:



25
26
27
# File 'lib/contrast/components/api.rb', line 25

def api_key
  @api_key
end

#service_keyString

Returns:



29
30
31
# File 'lib/contrast/components/api.rb', line 29

def service_key
  @service_key
end

#urlObject



46
47
48
# File 'lib/contrast/components/api.rb', line 46

def url
  @url.nil? ? DEFAULT_URL : @url
end

#user_nameString

Returns:



27
28
29
# File 'lib/contrast/components/api.rb', line 27

def user_name
  @user_name
end

Instance Method Details

#api_urlObject



71
72
73
74
75
76
77
# File 'lib/contrast/components/api.rb', line 71

def api_url
  @_api_url ||= begin
    tmp = Contrast::CONFIG.api.url
    tmp += '/Contrast' unless tmp.end_with?('/Contrast')
    tmp
  end
end

#certificateContrast::Config::CertificationConfiguration



65
66
67
68
69
# File 'lib/contrast/components/api.rb', line 65

def certificate
  return @_certificate unless @_certificate.nil?

  @_certificate = Contrast::Config::CertificationConfiguration.new
end

#certification_ca_fileObject



115
116
117
# File 'lib/contrast/components/api.rb', line 115

def certification_ca_file
  @_certification_ca_file ||= ::Contrast::CONFIG.api.certificate.ca_file
end

#certification_cert_fileObject



119
120
121
# File 'lib/contrast/components/api.rb', line 119

def certification_cert_file
  @_certification_cert_file ||= ::Contrast::CONFIG.api.certificate.cert_file
end

#certification_enableObject



111
112
113
# File 'lib/contrast/components/api.rb', line 111

def certification_enable
  @_certification_enable ||= certification_truly_enabled?(::Contrast::CONFIG.api.certificate)
end

#certification_key_fileObject



123
124
125
# File 'lib/contrast/components/api.rb', line 123

def certification_key_file
  @_certification_key_file ||= ::Contrast::CONFIG.api.certificate.key_file
end

#proxyContrast::Config::ApiProxyConfiguration



51
52
53
54
55
# File 'lib/contrast/components/api.rb', line 51

def proxy
  return @_proxy unless @_proxy.nil?

  @_proxy = Contrast::Config::ApiProxyConfiguration.new
end

#proxy_enableObject



79
80
81
82
83
# File 'lib/contrast/components/api.rb', line 79

def proxy_enable
  return @_proxy_enable unless @_proxy_enable.nil?

  @_proxy_enable = true?(::Contrast::CONFIG.api.proxy.enable)
end

#proxy_urlObject



85
86
87
# File 'lib/contrast/components/api.rb', line 85

def proxy_url
  proxy.url
end

#request_auditContrast::Config::RequestAuditConfiguration



58
59
60
61
62
# File 'lib/contrast/components/api.rb', line 58

def request_audit
  return @_request_audit unless @_request_audit.nil?

  @_request_audit = Contrast::Config::RequestAuditConfiguration.new
end

#request_audit_enableObject



89
90
91
92
93
# File 'lib/contrast/components/api.rb', line 89

def request_audit_enable
  return @_request_audit_enable unless @_request_audit_enable.nil?

  @_request_audit_enable = true?(::Contrast::CONFIG.api.request_audit.enable)
end

#request_audit_pathObject



107
108
109
# File 'lib/contrast/components/api.rb', line 107

def request_audit_path
  @_request_audit_path ||= ::Contrast::CONFIG.api.request_audit.path.to_s
end

#request_audit_requestsObject



95
96
97
98
99
# File 'lib/contrast/components/api.rb', line 95

def request_audit_requests
  return @_request_audit_requests unless @_request_audit_requests.nil?

  @_request_audit_requests = true?(::Contrast::CONFIG.api.request_audit.requests)
end

#request_audit_responsesObject



101
102
103
104
105
# File 'lib/contrast/components/api.rb', line 101

def request_audit_responses
  return @_request_audit_responses unless @_request_audit_responses.nil?

  @_request_audit_responses = true?(::Contrast::CONFIG.api.request_audit.responses)
end

#to_effective_config(effective_config) ⇒ Object

Converts current configuration to effective config values class and appends them to EffectiveConfig class.

Parameters:



131
132
133
134
135
136
# File 'lib/contrast/components/api.rb', line 131

def to_effective_config effective_config
  add_effective_config_values(effective_config, CONFIG_VALUES, CANON_NAME, CANON_NAME)
  effective_proxy(effective_config)
  request_audit&.to_effective_config(effective_config)
  certificate&.to_effective_config(effective_config)
end