delphix 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/delphix.rb +34 -11
- data/lib/delphix/{web_client.rb → client.rb} +57 -55
- data/lib/delphix/{web_request.rb → request.rb} +22 -24
- data/lib/delphix/{web_response.rb → response.rb} +1 -1
- data/lib/delphix/utils.rb +0 -73
- data/lib/delphix/version.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2512981cc4075fb95b65652f26273053d430dbd
|
4
|
+
data.tar.gz: 499f97d8cb56b7a58ea1ae68cbf716a5ff97a4b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f6572b368ce8cc4aa68907361417e08e6cf16e82849b723dce1a056d3e252a3d751e35b0cbf65bd349bd2b78fbead4dd37609be469ce05adb992076a79009f3
|
7
|
+
data.tar.gz: 372545bd4756bd75d25a680552a58272f7ffb8d32161556ca68d4f3047e211cfe1c66493ad873281f05be47dd0194a079457b39513e2a37e50e9d6f4037e2998
|
data/lib/delphix.rb
CHANGED
@@ -20,9 +20,9 @@
|
|
20
20
|
require 'rest-client'
|
21
21
|
require 'hashie'
|
22
22
|
require_relative 'delphix/utils'
|
23
|
-
require_relative 'delphix/
|
24
|
-
require_relative 'delphix/
|
25
|
-
require_relative 'delphix/
|
23
|
+
require_relative 'delphix/client'
|
24
|
+
require_relative 'delphix/request'
|
25
|
+
require_relative 'delphix/response'
|
26
26
|
require_relative 'delphix/version'
|
27
27
|
|
28
28
|
# A library for supporting connections to the Delphix API. The module Delphix
|
@@ -52,9 +52,8 @@ module Delphix
|
|
52
52
|
|
53
53
|
API_ENDPOINT = '/resources/json/delphix'
|
54
54
|
HTTP_HEADERS = {
|
55
|
-
'Accept' => 'application/json; charset=UTF-8',
|
56
55
|
'Content-Type' => 'application/json; charset=UTF-8',
|
57
|
-
'User-Agent' => 'Delphix-Ruby-Client/
|
56
|
+
'User-Agent' => 'Delphix-Ruby-Client/' + Delphix::VERSION
|
58
57
|
}
|
59
58
|
|
60
59
|
# Default timeout value in seconds.
|
@@ -77,9 +76,6 @@ module Delphix
|
|
77
76
|
# @return [#body] parsed response body
|
78
77
|
# @return [#raw_body] un-parsed response body
|
79
78
|
attr_accessor :session
|
80
|
-
# @!attribute [rw] api_version
|
81
|
-
# @return [Hash] containing the major, minor and micro version numbers.
|
82
|
-
attr_accessor :api_version
|
83
79
|
# @!attribute [rw] server
|
84
80
|
# @return [String] Delphix server address
|
85
81
|
attr_accessor :server
|
@@ -89,11 +85,33 @@ module Delphix
|
|
89
85
|
# @!attribute [rw] api_passwd
|
90
86
|
# @return [String] password for authentication
|
91
87
|
attr_accessor :api_passwd
|
92
|
-
# @!attribute [rw] verbose
|
93
|
-
# @return [Nothing] enables verbosity
|
94
|
-
attr_accessor :verbose
|
95
88
|
end
|
96
89
|
|
90
|
+
# Defines custom setter that takes a string, splits on the `.` and setting
|
91
|
+
# the major, minor and micro versions.
|
92
|
+
#
|
93
|
+
# @param [String] name
|
94
|
+
# Name of the setter
|
95
|
+
#
|
96
|
+
# @param [String] version
|
97
|
+
# The version number, i.e. '1.2.3'
|
98
|
+
#
|
99
|
+
# @return [undefined]
|
100
|
+
#
|
101
|
+
def self.version_accessor(name, version = nil)
|
102
|
+
define_singleton_method("#{name}=") do |version|
|
103
|
+
instance_variable_set("@#{name}",
|
104
|
+
[:major, :minor, :micro].zip(version.split('.')).inject({}) {
|
105
|
+
|r, i| r[i[0]] = i[1]; r
|
106
|
+
}.merge(type: 'APIVersion')
|
107
|
+
)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# @!attribute [rw] api_version
|
112
|
+
# @return [Hash] containing the major, minor and micro version numbers.
|
113
|
+
self.version_accessor :api_version
|
114
|
+
|
97
115
|
# Returns the API endpoint for a given resource namespace by combining the
|
98
116
|
# server address with the appropriate HTTP headers.
|
99
117
|
#
|
@@ -106,6 +124,11 @@ module Delphix
|
|
106
124
|
'http://' + @server + resource
|
107
125
|
end
|
108
126
|
|
127
|
+
# Initiate a session with the Delphix appliance, get our cookies for the
|
128
|
+
# duration of this exchange.
|
129
|
+
#
|
130
|
+
# @return [undefined]
|
131
|
+
#
|
109
132
|
def self.session
|
110
133
|
Delphix.default_header(:cookies, cookies)
|
111
134
|
@session ||= login(@api_user, @api_passwd)
|
@@ -18,9 +18,23 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
module Delphix
|
21
|
-
class
|
21
|
+
class Client
|
22
|
+
include Delphix::Utils
|
23
|
+
|
24
|
+
# @param [Symnol] method
|
25
|
+
# A valid HTTP verb `:get`, `:post`, or `:delete`.
|
26
|
+
#
|
27
|
+
# @param [String] url
|
28
|
+
# The address or uri to send request.
|
29
|
+
#
|
30
|
+
# @param [String, Hash, Object] body
|
31
|
+
# The request Body.
|
32
|
+
#
|
33
|
+
# @param [Proc] callback
|
34
|
+
# Asychronous callback method to be invoked upon result.
|
35
|
+
#
|
22
36
|
def self.request(method, url, headers, body, timeout, &callback)
|
23
|
-
request = Delphix::
|
37
|
+
request = Delphix::Request.new(method, url, headers, body)
|
24
38
|
|
25
39
|
if callback
|
26
40
|
Thread.new do
|
@@ -67,12 +81,13 @@ module Delphix
|
|
67
81
|
response = e.response
|
68
82
|
end
|
69
83
|
|
70
|
-
Delphix::
|
84
|
+
Delphix::Response.new(response)
|
71
85
|
end
|
72
86
|
end
|
73
87
|
|
74
88
|
# @param [String, Symbol] name
|
75
89
|
# A string or symbol used to identify the key portion of the HTTP headers.
|
90
|
+
#
|
76
91
|
# @param [String, Symbol, Array] value
|
77
92
|
# A string, symbol or array containing the values of the HTTP header.
|
78
93
|
#
|
@@ -99,66 +114,53 @@ module Delphix
|
|
99
114
|
@@timeout = seconds
|
100
115
|
end
|
101
116
|
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
117
|
+
# @!method get
|
118
|
+
# Retrieve data from the server where complex input is not needed. All GET
|
119
|
+
# requests are guaranteed to be read-only, but not all read-only requests
|
120
|
+
# are required to use GET. Simple input (strings, number, boolean values)
|
121
|
+
# can be passed as query parameters.
|
122
|
+
#
|
123
|
+
# @param [String] url, (address or uri) to send request.
|
124
|
+
# @param [String, Hash, Object] body, the request body.
|
125
|
+
# @param [Proc] callback, asychronous callback method, invoked upon result.
|
126
|
+
#
|
127
|
+
# @return [Fixnum, #code] the response code from Delphix engine.
|
128
|
+
# @return [Hash, #headers] The headers with keys as symbols.
|
129
|
+
# @return [Hash, #body] body parsed response body where applicable.
|
130
|
+
# @return [Hash, #raw_body] raw_body un-parsed response body.
|
131
|
+
#
|
132
|
+
# @!method post
|
133
|
+
# Issue a read/write operation, or make a read-only call that requires
|
134
|
+
# complex input. The optional body of the call is expressed as JSON.
|
135
|
+
#
|
136
|
+
# @param [String] url, (address or uri) to send request.
|
137
|
+
# @param [String, Hash, Object] body, the request body.
|
138
|
+
# @param [Proc] callback, asychronous callback method, invoked upon result.
|
105
139
|
#
|
106
|
-
#
|
140
|
+
# @return [Fixnum, #code] the response code from Delphix engine.
|
141
|
+
# @return [Hash, #headers] The headers with keys as symbols.
|
142
|
+
# @return [Hash, #body] body parsed response body where applicable.
|
143
|
+
# @return [Hash, #raw_body] raw_body un-parsed response body.
|
107
144
|
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
# POST - Issue a read/write operation, or make a read-only call that
|
114
|
-
# requires complex input. The optional body of the call is
|
115
|
-
# expressed as JSON.
|
116
|
-
# DELETE - Delete an object on the system. For languages that don't provide
|
117
|
-
# a native wrapper for DELETE, or for delete operations with
|
118
|
-
# optional input, all delete operations can also be invoked as POST
|
119
|
-
# to the same URL with /delete appended to it.
|
145
|
+
# @!method delete
|
146
|
+
# Delete an object on the system. For languages that don't provide a native
|
147
|
+
# wrapper for DELETE, or for delete operations with optional input, all
|
148
|
+
# delete operations can also be invoked as POST to the same URL with
|
149
|
+
# /delete appended to it.
|
120
150
|
#
|
121
|
-
#
|
122
|
-
#
|
151
|
+
# @param [String] url, (address or uri) to send request.
|
152
|
+
# @param [String, Hash, Object] body, the request body.
|
153
|
+
# @param [Proc] callback, asychronous callback method, invoked upon result.
|
123
154
|
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
# @return [Fixnum, #code] the response code from Delphix engine
|
129
|
-
# @return [Hash, #headers] headers, beautified with symbols and underscores
|
130
|
-
# @return [Hash, #body] body parsed response body where applicable (JSON
|
131
|
-
# responses are parsed to Objects/Associative Arrays)
|
132
|
-
# @return [Hash, #raw_body] raw_body un-parsed response body
|
155
|
+
# @return [Fixnum, #code] the response code from Delphix engine.
|
156
|
+
# @return [Hash, #headers] The headers with keys as symbols.
|
157
|
+
# @return [Hash, #body] body parsed response body where applicable.
|
158
|
+
# @return [Hash, #raw_body] raw_body un-parsed response body.
|
133
159
|
#
|
134
|
-
# @api semipublic
|
135
160
|
[:get, :post, :delete].each do |method|
|
136
161
|
define_singleton_method(method) do |url, parameters = {}, &callback|
|
137
|
-
|
162
|
+
Client.request(method.to_sym, url, @@default_headers,
|
138
163
|
parameters.to_json, @@timeout, &callback)
|
139
164
|
end
|
140
165
|
end
|
141
|
-
|
142
|
-
module InstanceMethods
|
143
|
-
private
|
144
|
-
|
145
|
-
# Returns the current api endpoint, if present.
|
146
|
-
#
|
147
|
-
# @return [nil, String] the current endpoint
|
148
|
-
def endpoint
|
149
|
-
nil
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# @!classmethods
|
154
|
-
module ClassMethods
|
155
|
-
# When present, lets you specify the api for the given client.
|
156
|
-
#
|
157
|
-
# @param [String, nil] value the endpoint to use.
|
158
|
-
# @example Setting a string endpoint endpoint '/resources/json/delphix'
|
159
|
-
# @example Unsetting the string endpoint endpoint nil
|
160
|
-
def endpoint(value = nil)
|
161
|
-
define_method(:endpoint) { value }
|
162
|
-
end
|
163
|
-
end
|
164
166
|
end
|
@@ -20,7 +20,7 @@
|
|
20
20
|
require 'addressable/uri'
|
21
21
|
|
22
22
|
module Delphix
|
23
|
-
class
|
23
|
+
class Request
|
24
24
|
include Delphix::Utils
|
25
25
|
|
26
26
|
# @!attribute [r] method
|
@@ -49,17 +49,24 @@ module Delphix
|
|
49
49
|
@headers[name] = value
|
50
50
|
end
|
51
51
|
|
52
|
+
# @param [Symnol] method
|
53
|
+
# A valid HTTP verb `GET`, `POST`, `PUT`, `PATCH` or `DELETE`.
|
54
|
+
#
|
55
|
+
# @param [String] url
|
56
|
+
# Endpoint (address or uri) to send request.
|
57
|
+
#
|
58
|
+
# @param [String, Hash, Object] body
|
59
|
+
# The request Body.
|
60
|
+
#
|
61
|
+
# @param [Proc] callback
|
62
|
+
# Asychronous callback method to be invoked upon result.
|
63
|
+
#
|
52
64
|
def initialize(method, url, headers = {}, body = nil)
|
53
65
|
@method = method
|
54
66
|
|
55
|
-
if
|
56
|
-
if body.
|
57
|
-
|
58
|
-
url += '&'
|
59
|
-
else
|
60
|
-
url += '?'
|
61
|
-
end
|
62
|
-
|
67
|
+
if method == :get
|
68
|
+
if body.respond_to?(:keys) && body.respond_to?(:[]) && body.length > 0
|
69
|
+
url += url.include?('?') ? '&' : '?'
|
63
70
|
uri = Addressable::URI.new
|
64
71
|
uri.query_values = body
|
65
72
|
url += uri.query
|
@@ -68,24 +75,15 @@ module Delphix
|
|
68
75
|
@body = body
|
69
76
|
end
|
70
77
|
|
71
|
-
|
72
|
-
|
78
|
+
if url =~ URI.regexp
|
79
|
+
@url = url.gsub(/\s+/, '%20')
|
80
|
+
else
|
81
|
+
raise "Invalid URL: #{url}"
|
73
82
|
end
|
74
83
|
|
75
|
-
@
|
76
|
-
|
77
|
-
@headers = {
|
78
|
-
'Date' => utc_httpdate,
|
79
|
-
'Request-ID' => request_id
|
80
|
-
}
|
81
|
-
|
84
|
+
@headers = { 'Date' => utc_httpdate, 'Request-ID' => request_id }
|
82
85
|
headers.each_pair { |key, value| @headers[key.downcase] = value }
|
83
|
-
|
84
|
-
Delphix.last_request = {
|
85
|
-
headers: @headers,
|
86
|
-
method: @method,
|
87
|
-
url: @url
|
88
|
-
}
|
86
|
+
Delphix.last_request = { headers: @headers, method: @method, url: @url }
|
89
87
|
begin
|
90
88
|
Delphix.last_request[:body] = JSON.parse(@body) if body.length > 2
|
91
89
|
rescue Exception
|
data/lib/delphix/utils.rb
CHANGED
@@ -38,76 +38,3 @@ module Delphix
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
|
-
class Hash
|
43
|
-
# A hash is blank if it's empty:
|
44
|
-
#
|
45
|
-
# @example
|
46
|
-
# {}.blank? # => true
|
47
|
-
# { key: 'value' }.blank? # => false
|
48
|
-
#
|
49
|
-
# @api public
|
50
|
-
alias_method :blank?, :empty?
|
51
|
-
|
52
|
-
# Returns a new hash with all keys downcased and converted
|
53
|
-
# to symbols.
|
54
|
-
#
|
55
|
-
# @return [Hash]
|
56
|
-
#
|
57
|
-
def normalize_keys
|
58
|
-
transform_keys { |key| key.downcase.to_sym rescue key }
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns a new Hash, recursively downcasing and converting all
|
62
|
-
# keys to symbols.
|
63
|
-
#
|
64
|
-
# @return [Hash]
|
65
|
-
#
|
66
|
-
def recursively_normalize_keys
|
67
|
-
recursively_transform_keys { |key| key.downcase.to_sym rescue key }
|
68
|
-
end
|
69
|
-
|
70
|
-
# Returns a new hash with all keys converted using the block operation.
|
71
|
-
#
|
72
|
-
# @example
|
73
|
-
# hash = { name: 'Tigie', age: '15' }
|
74
|
-
# hash.transform_keys{ |key| key.to_s.upcase }
|
75
|
-
# # => { "AGE" => "15", "NAME" => "Tigie" }
|
76
|
-
#
|
77
|
-
# @return [Hash]
|
78
|
-
#
|
79
|
-
# @api public
|
80
|
-
def transform_keys
|
81
|
-
enum_for(:transform_keys) unless block_given?
|
82
|
-
result = self.class.new
|
83
|
-
each_key do |key|
|
84
|
-
result[yield(key)] = self[key]
|
85
|
-
end
|
86
|
-
result
|
87
|
-
end
|
88
|
-
|
89
|
-
# Returns a new hash, recursively converting all keys by the
|
90
|
-
# block operation.
|
91
|
-
#
|
92
|
-
# @return [Hash]
|
93
|
-
#
|
94
|
-
def recursively_transform_keys(&block)
|
95
|
-
_recursively_transform_keys_in_object(self, &block)
|
96
|
-
end
|
97
|
-
|
98
|
-
private # P R O P R I E T À P R I V A T A divieto di accesso
|
99
|
-
|
100
|
-
# support methods for recursively transforming nested hashes and arrays
|
101
|
-
def _recursively_transform_keys_in_object(object, &block)
|
102
|
-
case object
|
103
|
-
when Hash
|
104
|
-
object.each_with_object({}) do |(key, val), result|
|
105
|
-
result[yield(key)] = _recursively_transform_keys_in_object(val, &block)
|
106
|
-
end
|
107
|
-
when Array
|
108
|
-
object.map { |e| _recursively_transform_keys_in_object(e, &block) }
|
109
|
-
else
|
110
|
-
object
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
data/lib/delphix/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delphix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Harding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hoodie
|
@@ -139,11 +139,11 @@ files:
|
|
139
139
|
- Rakefile
|
140
140
|
- delphix.gemspec
|
141
141
|
- lib/delphix.rb
|
142
|
+
- lib/delphix/client.rb
|
143
|
+
- lib/delphix/request.rb
|
144
|
+
- lib/delphix/response.rb
|
142
145
|
- lib/delphix/utils.rb
|
143
146
|
- lib/delphix/version.rb
|
144
|
-
- lib/delphix/web_client.rb
|
145
|
-
- lib/delphix/web_request.rb
|
146
|
-
- lib/delphix/web_response.rb
|
147
147
|
homepage: https://github.com/riddopic/delphix
|
148
148
|
licenses:
|
149
149
|
- Apache 2.0
|