Module: Delphix

Defined in:
lib/delphix.rb

Defined Under Namespace

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authenticate!(username, password) ⇒ Object



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

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



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

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

.debugObject



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

def debug
  @debug || false
end

.debug=(new_value) ⇒ Object



125
126
127
# File 'lib/delphix.rb', line 125

def debug=(new_value) 
  @debug = new_value
end

.default_urlObject



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

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



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

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

.env_optionsObject



147
148
149
# File 'lib/delphix.rb', line 147

def env_options
  {}
end

.env_urlObject



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

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

.environmentsObject



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

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



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

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

.groupsObject



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

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



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

def options
  @options ||= env_options
end

.options=(new_options) ⇒ Object



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

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



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

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



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

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

.repositoriesObject



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

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



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

def reset_connection!
  @connection = nil
end

.urlObject



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

def url
  @url ||= env_url
  @url
end

.url=(new_url) ⇒ Object



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

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

Instance Method Details

#sourcesObject



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

def sources
end

#targetsObject



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

def targets
end