Module: Delphix

Defined in:
lib/delphix.rb

Defined Under Namespace

Modules: Base, Error, Util Classes: BaseArray, Connection, Database, Environment, Group, Job, Repository, Response, Source, SourceConfig

Class Method Summary collapse

Class Method Details

.authenticate!(username, password) ⇒ Object



22
23
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
# File 'lib/delphix.rb', line 22

def authenticate!(username,password)

  case
    when !username.is_a?(String)
      raise ArgumentError, "Expected a String, got: '#{username}'"
    when !password.is_a?(String)
      raise ArgumentError, "Expected a String, got: '#{password}'"
  end

  reset_connection!

  # create a session
  session = {
    :type => 'APISession',
    :version => {
      :type => 'APIVersion', # Delphix Engine 4.3.1.x and above
      :major => 1,
      :minor => 6,
      :micro => 0
    }
  }
  post('/resources/json/delphix/session', session.to_json)

  # authenticate the session
  auth = {
    :type => 'LoginRequest',
    :username => username,
    :password => password
  }
  post('/resources/json/delphix/login', auth.to_json)

end

.connectionObject



104
105
106
# File 'lib/delphix.rb', line 104

def connection
  @connection ||= Connection.new(url, options)
end

.debugObject



94
95
96
# File 'lib/delphix.rb', line 94

def debug
  @debug || false
end

.debug=(new_value) ⇒ Object



98
99
100
# File 'lib/delphix.rb', line 98

def debug=(new_value)
  @debug = new_value
end

.default_urlObject



116
117
118
# File 'lib/delphix.rb', line 116

def default_url
  'http://localhost'
end

.delete(endpoint, payload = nil) ⇒ Object

a generic delete method, used when there is not specialized method to invoke an API call



71
72
73
# File 'lib/delphix.rb', line 71

def delete(endpoint, payload=nil)
  connection.delete( endpoint, {}, :body => payload)
end

.env_optionsObject



120
121
122
# File 'lib/delphix.rb', line 120

def env_options
  {}
end

.env_urlObject



112
113
114
# File 'lib/delphix.rb', line 112

def env_url
  ENV['DELPHIX_URL'] || default_url
end

.get(endpoint, payload = nil) ⇒ Object

a generic get method, used when there is not specialized method to invoke an API call



56
57
58
# File 'lib/delphix.rb', line 56

def get(endpoint, payload=nil)
  connection.get( endpoint, {}, :body => payload)
end

.optionsObject



85
86
87
# File 'lib/delphix.rb', line 85

def options
  @options ||= env_options
end

.options=(new_options) ⇒ Object



89
90
91
92
# File 'lib/delphix.rb', line 89

def options=(new_options)
  @options = env_options.merge(new_options || {})
  reset_connection!
end

.post(endpoint, payload = nil) ⇒ Object

a generic post method, used when there is not specialized method to invoke an API call



61
62
63
# File 'lib/delphix.rb', line 61

def post(endpoint, payload=nil)
  connection.post( endpoint, {}, :body => payload)
end

.put(endpoint, payload = nil) ⇒ Object

a generic put method, used when there is not specialized method to invoke an API call



66
67
68
# File 'lib/delphix.rb', line 66

def put(endpoint, payload=nil)
  connection.put( endpoint, {}, :body => payload)
end

.reset_connection!Object



108
109
110
# File 'lib/delphix.rb', line 108

def reset_connection!
  @connection = nil
end

.urlObject



75
76
77
78
# File 'lib/delphix.rb', line 75

def url
  @url ||= env_url
  @url
end

.url=(new_url) ⇒ Object



80
81
82
83
# File 'lib/delphix.rb', line 80

def url=(new_url)
  @url = new_url
  reset_connection!
end