Module: Delphix

Includes:
Utils
Defined in:
lib/delphix.rb,
lib/delphix/utils.rb,
lib/delphix/client.rb,
lib/delphix/request.rb,
lib/delphix/version.rb,
lib/delphix/response.rb

Overview

The version number of the Delphix Gem

Returns:

  • (String)

Defined Under Namespace

Modules: Utils, Version Classes: Client, Request, Response

Constant Summary collapse

API_ENDPOINT =
'/resources/json/delphix'
HTTP_HEADERS =
{
  'Accept'       =>  'application/json; charset=UTF-8',
  'Content-Type' =>  'application/json; charset=UTF-8',
  'User-Agent'   =>  'Delphix-Ruby-Client/1.0.0'
}
VERSION =
Delphix::Version.string
@@timeout =

Default timeout value in seconds.

10
@@default_headers =

Default headers

{}

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#request_id, #utc_httpdate

Class Attribute Details

.api_passwdString

Returns password for authentication.

Returns:

  • (String)

    password for authentication



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

def api_passwd
  @api_passwd
end

.api_userString

Returns username to authenticate with.

Returns:

  • (String)

    username to authenticate with



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

def api_user
  @api_user
end

.api_versionHash

Returns containing the major, minor and micro version numbers.

Returns:

  • (Hash)

    containing the major, minor and micro version numbers.



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

def api_version
  @api_version
end

.last_requestHash

Returns retruns the last request.

Returns:

  • (Hash)

    retruns the last request



69
70
71
# File 'lib/delphix.rb', line 69

def last_request
  @last_request
end

.last_responseHash

Returns retruns the last response.

Returns:

  • (Hash)

    retruns the last response



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

def last_response
  @last_response
end

.serverString

Returns Delphix server address.

Returns:

  • (String)

    Delphix server address



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

def server
  @server
end

.sessionHash, ...

Returns:

  • (Hash)

    retruns current session state

  • (#code)

    the response code from Delphix engine

  • (#headers)

    beautified with symbols and underscores

  • (#body)

    parsed response body

  • (#raw_body)

    un-parsed response body



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

def session
  @session
end

.verboseNothing

Returns enables verbosity.

Returns:

  • (Nothing)

    enables verbosity



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

def verbose
  @verbose
end

Class Method Details

.api_url(resource = nil) ⇒ URL

Returns the API endpoint for a given resource namespace by combining the server address with the appropriate HTTP headers.

Parameters:

  • resource (Resource) (defaults to: nil)

    namespace

Returns:

  • (URL)

    return the URL for the API endpoint



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

def self.api_url(resource = nil)
  'http://' + @server + resource
end

.clear_default_headersHash

Returns The HTTP headers sent with a POST/GET/DELETE.

Returns:

  • (Hash)

    The HTTP headers sent with a POST/GET/DELETE.



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

def self.clear_default_headers
  @@default_headers = {}
end

.cookiesHash

Establish a session with the Delphix engine and return an identifier through browser cookies. This session will be reused in subsequent calls, the same session credentials and state are preserved without requiring a re-authentication call. Sessions do not persisit between incovations.

Returns:

  • (Hash)

    cookies containing the new session cookies



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

def self.cookies
  @resp ||= Delphix.post session_url,
    type: 'APISession', version: @api_version
  @resp.cookies
end

.default_header(name, value) ⇒ Hash

Returns The result of the key/value pair.

Parameters:

  • name (String, Symbol)

    A string or symbol used to identify the key portion of the HTTP headers.

  • value (String, Symbol, Array)

    A string, symbol or array containing the values of the HTTP header.

Returns:

  • (Hash)

    The result of the key/value pair.



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

def self.default_header(name, value)
  @@default_headers[name] = value
end

.login(user = @api_user, passwd = @api_passwd) ⇒ Fixnum, ...

Authenticates the session so that API calls can be made. Only supports basic password authentication.

Parameters:

  • user (String) (defaults to: @api_user)

    user name to authenticate with

  • passwd (String) (defaults to: @api_passwd)

    password to authenticate with

Returns:

  • (Fixnum, #code)

    the response code from Delphix engine

  • (Hash, #headers)

    headers, beautified with symbols and underscores

  • (Hash, #body)

    body parsed response body where applicable (JSON responses are parsed to Objects/Associative Arrays)

  • (Hash, #raw_body)

    raw_body un-parsed response body



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

def self.(user = @api_user, passwd = @api_passwd)
  Delphix.post ,
    type: 'LoginRequest', username: user, password: passwd
end

.timeout(seconds) ⇒ undefined

Parameters:

  • seconds (Integer)

    Set the number of seconds to wait for an HTTP timeout.

Returns:

  • (undefined)


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

def self.timeout(seconds)
  @@timeout = seconds
end

Instance Method Details

#alertString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to alert.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#containerString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to container.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#databaseString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to database.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#deleteFixnum, ...

Delete an object on the system. For languages that don’t provide a native wrapper for DELETE, or for delete operations with optional input, all delete operations can also be invoked as POST to the same URL with /delete appended to it.

Parameters:

  • url, (String)

    (address or uri) to send request.

  • body, (String, Hash, Object)

    the request body.

  • callback, (Proc)

    asychronous callback method, invoked upon result.

Returns:

  • (Fixnum, #code)

    the response code from Delphix engine.

  • (Hash, #headers)

    The headers with keys as symbols.

  • (Hash, #body)

    body parsed response body where applicable.

  • (Hash, #raw_body)

    raw_body un-parsed response body.



160
161
162
163
164
165
# File 'lib/delphix/client.rb', line 160

[:get, :post, :delete].each do |method|
  define_singleton_method(method) do |url, parameters = {}, &callback|
    Client.request(method.to_sym, url, @@default_headers,
      parameters.to_json, @@timeout, &callback)
  end
end

#environmentString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to environment.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#getFixnum, ...

Retrieve data from the server where complex input is not needed. All GET requests are guaranteed to be read-only, but not all read-only requests are required to use GET. Simple input (strings, number, boolean values) can be passed as query parameters.

Parameters:

  • url, (String)

    (address or uri) to send request.

  • body, (String, Hash, Object)

    the request body.

  • callback, (Proc)

    asychronous callback method, invoked upon result.

Returns:

  • (Fixnum, #code)

    the response code from Delphix engine.

  • (Hash, #headers)

    The headers with keys as symbols.

  • (Hash, #body)

    body parsed response body where applicable.

  • (Hash, #raw_body)

    raw_body un-parsed response body.



160
161
162
163
164
165
# File 'lib/delphix/client.rb', line 160

[:get, :post, :delete].each do |method|
  define_singleton_method(method) do |url, parameters = {}, &callback|
    Client.request(method.to_sym, url, @@default_headers,
      parameters.to_json, @@timeout, &callback)
  end
end

#groupString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to group.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#hostString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to host.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#jobString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to job.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#loginString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to login.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#policyString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to policy.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#postFixnum, ...

Issue a read/write operation, or make a read-only call that requires complex input. The optional body of the call is expressed as JSON.

Parameters:

  • url, (String)

    (address or uri) to send request.

  • body, (String, Hash, Object)

    the request body.

  • callback, (Proc)

    asychronous callback method, invoked upon result.

Returns:

  • (Fixnum, #code)

    the response code from Delphix engine.

  • (Hash, #headers)

    The headers with keys as symbols.

  • (Hash, #body)

    body parsed response body where applicable.

  • (Hash, #raw_body)

    raw_body un-parsed response body.



160
161
162
163
164
165
# File 'lib/delphix/client.rb', line 160

[:get, :post, :delete].each do |method|
  define_singleton_method(method) do |url, parameters = {}, &callback|
    Client.request(method.to_sym, url, @@default_headers,
      parameters.to_json, @@timeout, &callback)
  end
end

#repositoryString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to repository.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#sessionString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to session.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#snapshotString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to snapshot.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#sourceString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to source.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#sourceconfigString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to sourceconfig.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#timeflowString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to timeflow.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end

#userString

A helper method to return the URL for the resource by using the resource_url shorthand.

Returns:

  • (String)

    The API path to user.



233
234
235
236
237
238
239
240
# File 'lib/delphix.rb', line 233

[ :alert, :container, :database, :environment, :group, :host, :job,
  :login, :policy, :repository, :session, :snapshot, :source,
  :sourceconfig, :timeflow, :user
].each do |name|
  define_singleton_method(name.to_s + '_url') do
    api_url('/resources/json/delphix/' + name.to_s)
  end
end