Module: Delphix

Defined in:
lib/delphix.rb

Defined Under Namespace

Modules: Base, Error, Util Classes: BaseArray, Connection, Database, Environment, Group, Repository, VDB

Class Method Summary collapse

Class Method Details

.authenticate!(username, password) ⇒ Object


18
19
20
21
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
# File 'lib/delphix.rb', line 18

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


127
128
129
# File 'lib/delphix.rb', line 127

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

.debugObject


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

def debug
  @debug || false
end

.debug=(new_value) ⇒ Object


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

def debug=(new_value)
  @debug = new_value
end

.default_urlObject


139
140
141
# File 'lib/delphix.rb', line 139

def default_url
  'http://localhost'
end

.delete(endpoint, payload) ⇒ Object

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


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

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

.env_optionsObject


143
144
145
# File 'lib/delphix.rb', line 143

def env_options
  {}
end

.env_urlObject


135
136
137
# File 'lib/delphix.rb', line 135

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

.environmentsObject


51
52
53
54
55
56
57
58
# File 'lib/delphix.rb', line 51

def environments
  envs = BaseArray.new
  result = get('/resources/json/delphix/environment', nil)['result']
  result.each do |env|
    envs << Environment.new(env['reference'],env)
  end
  envs
end

.get(endpoint, payload) ⇒ Object

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


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

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

.groupsObject


60
61
62
63
64
65
66
67
# File 'lib/delphix.rb', line 60

def groups
  groups = BaseArray.new
  result = get('/resources/json/delphix/group', nil)['result']
  result.each do |group|
    groups << Group.new(group['reference'],group)
  end
  groups
end

.optionsObject


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

def options
  @options ||= env_options
end

.options=(new_options) ⇒ Object


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

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

.post(endpoint, payload) ⇒ Object

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


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

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

.put(endpoint, payload) ⇒ Object

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


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

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

.repositoriesObject


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

def repositories
  repos = BaseArray.new
  result = get('/resources/json/delphix/repository', nil)['result']
  result.each do |repo|
    repos << Repository.new(repo['reference'],repo)
  end
  repos
end

.reset_connection!Object


131
132
133
# File 'lib/delphix.rb', line 131

def reset_connection!
  @connection = nil
end

.urlObject


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

def url
  @url ||= env_url
  @url
end

.url=(new_url) ⇒ Object


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

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