Class: ALGOSEC_SDK::Client

Inherits:
Object
  • Object
show all
Includes:
BusinessFlowHelper, Rest
Defined in:
lib/algosec-sdk/client.rb

Overview

The client defines the connection to the AlgoSec and handles communication with it

Constant Summary

Constants included from Rest

Rest::RESPONSE_CODE_ACCEPTED, Rest::RESPONSE_CODE_BAD_REQUEST, Rest::RESPONSE_CODE_CREATED, Rest::RESPONSE_CODE_NOT_FOUND, Rest::RESPONSE_CODE_NO_CONTENT, Rest::RESPONSE_CODE_OK, Rest::RESPONSE_CODE_UNAUTHORIZED

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BusinessFlowHelper

#apply_application_draft, #create_application, #create_application_flow, #create_missing_network_objects, #create_missing_services, #create_network_object, #create_network_service, #decommission_application, #define_application_flows, #delete_flow_by_id, #get_app_id_by_name, #get_app_revision_id_by_name, #get_application_by_name, #get_application_flow_by_name, #get_application_flows, #get_application_flows_hash, #get_applications, #get_flow_connectivity, #implement_app_flows_plan, #login, #plan_application_flows, #search_network_object

Methods included from Rest

#init_http_client, #response_handler, #rest_api, #rest_delete, #rest_get, #rest_patch, #rest_post, #rest_put

Constructor Details

#initialize(options = {}) ⇒ Client

Create a client object

Parameters:

  • options (Hash) (defaults to: {})

    the options to configure the client

Options Hash (options):

  • :host (String) — default: ENV['ALGOSEC_HOST']

    URL, hostname, or IP address of the AlgoSec server

  • :user (String) — default: 'admin'

    Username to use for authentication with the AlgoSec server

  • :password (String)

    Password to use for authentication with the AlgoSec server

  • :logger (Logger) — default: Logger.new(STDOUT)

    Logger object to use. Must implement debug(String), info(String), warn(String), error(String), & level=

  • :log_level (Symbol) — default: :info

    Log level. Logger must define a constant with this name. ie Logger::INFO

  • :ssl_enabled (Boolean) — default: true

    Use ssl for requests?

  • :disable_proxy (Boolean) — default: false

    Disable usage of a proxy for requests?

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/algosec-sdk/client.rb', line 24

def initialize(options = {})
  options = Hash[options.map { |k, v| [k.to_sym, v] }] # Convert string hash keys to symbols
  @logger = options[:logger] || Logger.new(STDOUT)
  i[debug info warn error level=].each do |m|
    raise "Logger must respond to #{m} method " unless @logger.respond_to?(m)
  end
  @log_level = options[:log_level] || :info
  @logger.level = begin
                    @logger.class.const_get(@log_level.upcase)
                  rescue StandardError
                    @log_level
                  end
  @host = options[:host] || ENV['ALGOSEC_HOST']
  raise InvalidClient, 'Must set the host option' unless @host
  @host = 'https://' + @host unless @host.start_with?('http://', 'https://')
  @ssl_enabled = true # Default
  if ENV.key?('ALGOSEC_SSL_ENABLED')
    @ssl_enabled = case ENV['ALGOSEC_SSL_ENABLED']
                   when 'true', '1' then true
                   when 'false', '0' then false
                   else ENV['ALGOSEC_SSL_ENABLED']
                   end
  end
  @ssl_enabled = options[:ssl_enabled] unless options[:ssl_enabled].nil?
  unless [true, false].include?(@ssl_enabled)
    raise InvalidClient, "ssl_enabled option must be true or false. Got '#{@ssl_enabled}'"
  end
  unless @ssl_enabled
    @logger.warn "SSL is disabled for all requests to #{@host}!"\
                           ' We recommend you import the necessary certificates instead of disabling SSL.'
  end
  @disable_proxy = options[:disable_proxy]
  unless [true, false, nil].include?(@disable_proxy)
    raise InvalidClient, 'disable_proxy option must be true, false, or nil'
  end
  @logger.warn 'User option not set. Using default (admin)' unless options[:user] || ENV['ALGOSEC_USER']
  @user = options[:user] || ENV['ALGOSEC_USER'] || 'admin'
  @password = options[:password] || ENV['ALGOSEC_PASSWORD']
  raise InvalidClient, 'Must set the password option' unless @password
  init_http_client
end

Instance Attribute Details

#disable_proxyObject

Returns the value of attribute disable_proxy.



11
12
13
# File 'lib/algosec-sdk/client.rb', line 11

def disable_proxy
  @disable_proxy
end

#hostObject

Returns the value of attribute host.



11
12
13
# File 'lib/algosec-sdk/client.rb', line 11

def host
  @host
end

#http_clientObject

Returns the value of attribute http_client.



11
12
13
# File 'lib/algosec-sdk/client.rb', line 11

def http_client
  @http_client
end

#log_levelObject

Returns the value of attribute log_level.



11
12
13
# File 'lib/algosec-sdk/client.rb', line 11

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/algosec-sdk/client.rb', line 11

def logger
  @logger
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/algosec-sdk/client.rb', line 11

def password
  @password
end

#ssl_enabledObject

Returns the value of attribute ssl_enabled.



11
12
13
# File 'lib/algosec-sdk/client.rb', line 11

def ssl_enabled
  @ssl_enabled
end

#userObject

Returns the value of attribute user.



11
12
13
# File 'lib/algosec-sdk/client.rb', line 11

def user
  @user
end