Module: WallixRestClient

Defined in:
lib/wallix_rest_client.rb,
lib/wallix_rest_client/version.rb

Overview

Gem to use the Wallix Admin Bastion REST API

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
'0.6.0'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



10
11
12
# File 'lib/wallix_rest_client.rb', line 10

def configuration
  @configuration
end

Class Method Details

.build_http(uri) ⇒ Object

Build http object with ssl or not



45
46
47
48
49
50
51
# File 'lib/wallix_rest_client.rb', line 45

def build_http(uri)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = (uri.scheme == 'https')
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless configuration.options[:verify_ssl]

  http
end

.build_query_params(query_params) ⇒ Object

Build query parameters



69
70
71
72
73
74
75
# File 'lib/wallix_rest_client.rb', line 69

def build_query_params(query_params)
  if query_params.empty?
    ''
  else
    '?' + URI.encode_www_form(query_params)
  end
end

.build_request(type, uri) ⇒ Object

Build request object with appropriate headers



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/wallix_rest_client.rb', line 54

def build_request(type, uri)
  request = type.new(uri.request_uri)

  case configuration.options[:auth]
  when :basic
    request.basic_auth(configuration.user, configuration.secret)
  when :apikey
    request['X-Auth-User'] = configuration.user
    request['X-Auth-Key'] = configuration.secret
  end

  request
end

.get(path, resource, query_params = {}) ⇒ Object

Get requests handler



95
96
97
# File 'lib/wallix_rest_client.rb', line 95

def get(path, resource, query_params = {})
  run_request(path, resource, Net::HTTP::Get, query_params)
end

.get_approvals_requests_target(target = nil, query_params = {}) ⇒ Object

Wallix API methods



34
35
36
# File 'lib/wallix_rest_client.rb', line 34

def self.get_approvals_requests_target(target = nil, query_params = {})
  get 'approvals/requests/target/', target, query_params
end

.get_targetpasswords_checkout(target = nil, query_params = {}) ⇒ Object



38
39
40
# File 'lib/wallix_rest_client.rb', line 38

def self.get_targetpasswords_checkout(target = nil, query_params = {})
  get 'targetpasswords/checkout/', target, query_params
end

.post(path, resource, query_params = {}, post_params = {}) ⇒ Object

Post requests handler



100
101
102
# File 'lib/wallix_rest_client.rb', line 100

def post(path, resource, query_params = {}, post_params = {})
  run_request(path, resource, Net::HTTP::Post, query_params, post_params)
end

.run_request(path, resource, type, query_params = {}, post_params = {}) ⇒ Object

Run the HTTP request



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/wallix_rest_client.rb', line 78

def run_request(path, resource, type, query_params = {}, post_params = {})
  uri = URI::join(
    configuration.base_uri, '/api/', path,
    URI.encode_www_form_component(resource.to_s, enc=Encoding::UTF_8),
    build_query_params(query_params)
  )

  http = build_http(uri)
  request = build_request(type, uri)

  # Add post data if applicable
  request.set_form_data(post_params) unless post_params.empty?

  http.request(request)
end

.setup {|configuration| ... } ⇒ Object

Yields:



13
14
15
16
# File 'lib/wallix_rest_client.rb', line 13

def self.setup
  @configuration ||= Configuration.new
  yield(configuration)
end