code42 0.2.7 → 0.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bf8ccbbf30229f5782e6820c7e65d7a231f2543
4
- data.tar.gz: 957d1a88845196fb072e784ff74378638f497c65
3
+ metadata.gz: b135cab63fe09fc1040dedc78ea9858c194af1fe
4
+ data.tar.gz: 84474930341cd9b4434fbdfa02b7beb889d7f3aa
5
5
  SHA512:
6
- metadata.gz: e0b5aaa0a70a0c2e253d009c78aec1f8e6268e85678fa66b3913b422285de5de3f60f761d2804e7374f0359f4749b536a27edd9cc8125440cd11341ffd446ae0
7
- data.tar.gz: 43ccc2d3d9727797a2fe5ba31b3b6edccbeca692f527b8659f05c87d793a6e9504e35441b0aae94606dc24c1bc0ad7c82c8d4da987b85926876143d544d62ad2
6
+ metadata.gz: 3e9d3c351cfa7088a79adcc35bb227e20f677bd8fbb73833ee2cf5e7b47ddbcef5d2078d6cf44d81610ee954c2e50bd04601d0bea20dce7ec54163cddf767c12
7
+ data.tar.gz: 6cca4e1cf4dce1645ef2287533496802c498f1b422f8882b7f9fdf6d97d565688d4684cb26f84073fb936f60d542f3e951a69de8f26ed3e1521c5963078028c8
@@ -27,6 +27,7 @@ require 'code42/product_license'
27
27
  require 'code42/server_settings'
28
28
  require 'code42/destination'
29
29
  require 'code42/server'
30
+ require 'code42/server_env'
30
31
  require 'code42/server_connection_string'
31
32
  require 'code42/store_point'
32
33
 
@@ -1,8 +1,8 @@
1
1
  module Code42
2
2
  module API
3
3
  module Destination
4
- def destinations
5
- objects_from_response(Code42::Destination, :get, 'destinations', key: 'destinations')
4
+ def destinations(name = nil)
5
+ objects_from_response(Code42::Destination, :get, "destinations#{"?name=#{name}" if name}", key: 'destinations')
6
6
  end
7
7
 
8
8
  def destination(id)
@@ -11,7 +11,7 @@ module Code42
11
11
 
12
12
  def create_destination(attrs)
13
13
  response = post('Destination', attrs)
14
- response && response['data'].is_a?(Array)
14
+ response['data'].first if response && response['data'].is_a?(Array)
15
15
  end
16
16
  end
17
17
  end
@@ -6,9 +6,9 @@ module Code42
6
6
  end
7
7
 
8
8
  def server(id, params = {})
9
- if id.is_a? Fixnum
9
+ if id.eql? 'this' or id.is_a? Fixnum
10
10
  object_from_response(Code42::Server, :get, "server/#{id}", params)
11
- elsif id.is_a? String
11
+ else
12
12
  servers(params.merge(q: id)).first
13
13
  end
14
14
  end
@@ -0,0 +1,9 @@
1
+ module Code42
2
+ module API
3
+ module ServerEnv
4
+ def server_env(params = {})
5
+ object_from_response(Code42::ServerEnv, :get, 'ServerEnv', params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,4 @@
1
+ require 'faraday'
1
2
  require 'forwardable'
2
3
  require 'json'
3
4
  Dir[File.dirname(__FILE__) + '/api/*.rb'].each { |file| require file }
@@ -13,6 +14,7 @@ module Code42
13
14
  include Code42::API::ServerSettings
14
15
  include Code42::API::Destination
15
16
  include Code42::API::Server
17
+ include Code42::API::ServerEnv
16
18
  include Code42::API::PasswordReset
17
19
  include Code42::API::StorePoint
18
20
  include Code42::API::Diagnostic
@@ -117,19 +119,20 @@ module Code42
117
119
  end
118
120
 
119
121
  def get(path, data = {}, &block)
120
- make_request(:get, path, data, &block)
122
+ # Spaces need to be URI encoded to +.
123
+ make_request(:get, path.gsub(/ +/, '+'), data, &block)
121
124
  end
122
125
 
123
126
  def post(path, data = {}, &block)
124
- make_request(:post, path, data, &block)
127
+ make_request(:post, path.gsub(/ +/, '+'), data, &block)
125
128
  end
126
129
 
127
130
  def put(path, data = {}, &block)
128
- make_request(:put, path, data, &block)
131
+ make_request(:put, path.gsub(/ +/, '+'), data, &block)
129
132
  end
130
133
 
131
134
  def delete(path, data = {}, &block)
132
- make_request(:delete, path, data, &block)
135
+ make_request(:delete, path.gsub(/ +/, '+'), data, &block)
133
136
  end
134
137
  end
135
138
  end
@@ -3,6 +3,7 @@ require 'faraday'
3
3
  require 'faraday_middleware'
4
4
  require 'logger'
5
5
  require 'code42/error'
6
+ require 'code42/faraday_middleware/parse_server_env'
6
7
 
7
8
  module Code42
8
9
  class Connection
@@ -46,6 +47,9 @@ module Code42
46
47
  f.adapter :net_http
47
48
 
48
49
  f.response :json
50
+
51
+ # Custom Faraday Middleware parser to parse the javascript returned from the /api/ServerEnv api.
52
+ f.use Code42::FaradayMiddleware::ParseServerEnv
49
53
  end
50
54
  end
51
55
 
@@ -0,0 +1,32 @@
1
+ require 'faraday_middleware/response_middleware'
2
+
3
+ module Code42
4
+ module FaradayMiddleware
5
+ class ParseServerEnv < ::FaradayMiddleware::ResponseMiddleware
6
+ dependency 'json'
7
+
8
+ define_parser do |body|
9
+ new_body = body.clone
10
+ new_body.gsub! "'", '"' # Remove single-quotes and replace with double-quotes. JSON parser cannot parse single quotes.
11
+ new_body.gsub! /(\w+):/, '"\1":' # Surround keys with double-quotes.
12
+ new_body.sub! 'window.serverEnv = ', '' # Trim off variable assignment.
13
+ new_body.chomp! ";\n" # Trim off tailing semicolon and newline characters.
14
+
15
+ # noinspection RubyStringKeysInHashInspection
16
+ begin
17
+ { 'data' => ::JSON.parse(new_body) }
18
+ rescue
19
+ body
20
+ end
21
+ end
22
+
23
+ SERVER_ENV_PATH = '/api/ServerEnv'
24
+ MIME_TYPE = 'text/javascript'
25
+
26
+ def parse_response?(env)
27
+ # noinspection RubyResolve
28
+ SERVER_ENV_PATH.casecmp(env.url.path) == 0 and env.response_headers['content-type'].include? MIME_TYPE
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ module Code42
2
+ class ServerEnv < Resource
3
+ attribute :version
4
+ attribute :product_version
5
+ attribute :client_product_version
6
+ attribute :sp_client_product_version
7
+ attribute :commerce_version
8
+
9
+ attribute :cluster_type
10
+ attribute :server_type
11
+
12
+ attribute :env
13
+ attribute :constants
14
+
15
+ attribute :server_id
16
+ attribute :server_guid
17
+ attribute :cluster_server_id
18
+
19
+ attribute :port_prefix
20
+ attribute :sso_auth_enabled
21
+ attribute :note
22
+
23
+ attribute :ssl
24
+ attribute :has_mlk
25
+ attribute :has_logged_in
26
+ attribute :default_admin_password
27
+ attribute :query_limited
28
+ attribute :stats_enabled
29
+ attribute :secure_keystore_locked
30
+ attribute :http_port
31
+ attribute :https_port
32
+ attribute :locale
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module Code42
2
- VERSION = "0.2.7"
2
+ VERSION = '0.2.8'
3
3
  end
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://10.10.47.82:4280/api/server/this
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ Authorization:
13
+ - Basic YWRtaW46YWRtaW4=
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: ''
18
+ headers:
19
+ Cache-Control:
20
+ - no-store
21
+ Pragma:
22
+ - no-cache
23
+ Content-Location:
24
+ - http://10.10.47.82:4280/api/v1/server/this
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Server:
30
+ - Jetty(7.6.3.v20120416)
31
+ body:
32
+ encoding: UTF-8
33
+ string: '{"metadata":{"timestamp":"2013-09-11T13:12:18.952-05:00","params":{}},"data":{"serverId":3,"guid":"600624193549107457","serverName":"more-03","type":"SERVER","version":"3.6.1.3","online":true,"outOfDate":false,"acceptingInboundBackup":"ALL","balancingData":"NONE","acceptingNewComputers":"ALL","dbEmpty":true,"clusterServerId":1,"destinationId":2,"destinationName":"CrashPlan
34
+ PROe Server","providerDestinationName":null,"primaryAddress":"10.10.47.82:4282","secondaryAddress":null,"websiteHost":"http://10.10.47.82:4280","storePointCount":1,"totalBytes":19674116096,"usedBytes":3819704320,"usedPercentage":19.0,"freeBytes":15854411776,"freePercentage":81.0,"coldBytes":0,"coldPercentageOfUsed":0.0,"coldPercentageOfTotal":0.0,"archiveBytes":0,"selectedBytes":0,"remainingBytes":0,"inboundBandwidth":0,"outboundBandwidth":0,"orgCount":0,"userCount":0,"licensedUserCount":0,"computerCount":0,"backupComputerCount":0,"onlineComputerCount":0,"backupSessionCount":0}}'
35
+ http_version:
36
+ recorded_at: Wed, 11 Sep 2013 18:31:08 GMT
37
+ recorded_with: VCR 2.5.0
@@ -34,11 +34,16 @@ describe Code42::Client, :vcr do
34
34
  end
35
35
 
36
36
  describe '#server' do
37
- it 'returns a server' do
37
+ it 'returns a server with id' do
38
38
  server = client.server(3)
39
39
  server.should be_a(Code42::Server)
40
40
  server.id.should == 3
41
41
  end
42
+ it 'returns a server with this' do
43
+ server = client.server('this')
44
+ server.should be_a(Code42::Server)
45
+ server.id.should == 3
46
+ end
42
47
  end
43
48
 
44
49
  describe '#update_server_settings' do
@@ -0,0 +1,110 @@
1
+ describe Code42::FaradayMiddleware::ParseServerEnv do
2
+ describe '#parse' do
3
+ let(:raw_javascript) do
4
+ <<-JAVASCRIPT.gsub(/^ +/, '')
5
+ window.serverEnv = {
6
+ \tversion: 1427864400430,
7
+ \tproductVersion: "4.3.0",
8
+ \tclientProductVersion: "4.2.0",
9
+ \tspClientProductVersion: "4.2.0",
10
+ \tcommerceVersion: "",
11
+
12
+ \tclusterType: {
13
+ \t\tconsumer: false,
14
+ \t\tbusiness: false,
15
+ \t\tenterprise: true
16
+ \t},
17
+
18
+ \tserverType: {
19
+ \t\tmaster: true,
20
+ \t\tstorage: false
21
+ \t},
22
+
23
+ \tenv: {
24
+ \t\tdev: true,
25
+ \t\tprd: false,
26
+ \t\tstg: false,
27
+ \t\tbeta: false
28
+ \t},
29
+
30
+ \tconstants: {
31
+ \t\tcpOrgId: 42,
32
+ \t\tproOrgId: 5
33
+ \t},
34
+
35
+ \tserverId: 3,
36
+ \tserverGuid: '7201',
37
+ \tclusterServerId: 1,
38
+ \tportPrefix: 72,
39
+ \tssoAuthEnabled: false,
40
+
41
+ \tNOTE: "ssl, queryLimited, hasLoggedIn, and defaultAdminPassword may/will change after login so this information should only be used on login or shortly after",
42
+ \tssl: true,
43
+ \thasMlk: true,
44
+ \thasLoggedIn: true,
45
+ \tdefaultAdminPassword: true,
46
+ \tqueryLimited: false,
47
+ \tstatsEnabled: true,
48
+ \tsecureKeystoreLocked: false,
49
+ \thttpPort: 7280,
50
+ \thttpsPort: 7285,
51
+ \tlocale: "en_US"
52
+ };
53
+ JAVASCRIPT
54
+ end
55
+ let(:expected_json) do
56
+ JSON.parse <<-JSON
57
+ {
58
+ "data": {
59
+ "version": 1427864400430,
60
+ "productVersion": "4.3.0",
61
+ "clientProductVersion": "4.2.0",
62
+ "spClientProductVersion": "4.2.0",
63
+ "commerceVersion": "",
64
+ "clusterType":
65
+ {
66
+ "consumer": false,
67
+ "business": false,
68
+ "enterprise": true
69
+ },
70
+ "serverType":
71
+ {
72
+ "master": true,
73
+ "storage": false
74
+ },
75
+ "env":
76
+ {
77
+ "dev": true, "prd": false, "stg": false, "beta": false
78
+ },
79
+ "constants":
80
+ {
81
+ "cpOrgId": 42,
82
+ "proOrgId": 5
83
+ },
84
+ "serverId": 3,
85
+ "serverGuid": "7201",
86
+ "clusterServerId": 1,
87
+ "portPrefix": 72,
88
+ "ssoAuthEnabled": false,
89
+ "NOTE": "ssl, queryLimited, hasLoggedIn, and defaultAdminPassword may/will change after login so this information should only be used on login or shortly after",
90
+ "ssl": true,
91
+ "hasMlk": true,
92
+ "hasLoggedIn": true,
93
+ "defaultAdminPassword": true,
94
+ "queryLimited": false,
95
+ "statsEnabled": true,
96
+ "secureKeystoreLocked": false,
97
+ "httpPort": 7280,
98
+ "httpsPort": 7285,
99
+ "locale": "en_US"
100
+ }
101
+ }
102
+ JSON
103
+ end
104
+
105
+ it 'should parse valid javascript into a valid json object' do
106
+ json = Code42::FaradayMiddleware::ParseServerEnv.new.parse raw_javascript
107
+ expect(json).to eql expected_json
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,56 @@
1
+ describe Code42::ServerEnv do
2
+ describe '#deserialize_and_initialize' do
3
+ let(:response_data) do
4
+ JSON.parse <<-JSON
5
+ {
6
+ "version": 1427864400430,
7
+ "productVersion": "4.3.0",
8
+ "clientProductVersion": "4.2.0",
9
+ "spClientProductVersion": "4.2.0",
10
+ "commerceVersion": "",
11
+ "clusterType":
12
+ {
13
+ "consumer": false,
14
+ "business": false,
15
+ "enterprise": true
16
+ },
17
+ "serverType":
18
+ {
19
+ "master": true,
20
+ "storage": false
21
+ },
22
+ "env":
23
+ {
24
+ "dev": true, "prd": false, "stg": false, "beta": false
25
+ },
26
+ "constants":
27
+ {
28
+ "cpOrgId": 42,
29
+ "proOrgId": 5
30
+ },
31
+ "serverId": 3,
32
+ "serverGuid": "7201",
33
+ "clusterServerId": 1,
34
+ "portPrefix": 72,
35
+ "ssoAuthEnabled": false,
36
+ "NOTE": "ssl, queryLimited, hasLoggedIn, and defaultAdminPassword may/will change after login so this information should only be used on login or shortly after",
37
+ "ssl": true,
38
+ "hasMlk": true,
39
+ "hasLoggedIn": true,
40
+ "defaultAdminPassword": true,
41
+ "queryLimited": false,
42
+ "statsEnabled": true,
43
+ "secureKeystoreLocked": false,
44
+ "httpPort": 7280,
45
+ "httpsPort": 7285,
46
+ "locale": "en_US"
47
+ }
48
+ JSON
49
+ end
50
+
51
+ it 'should serialize json object into a valid ServerEnv object' do
52
+ server_env = Code42::ServerEnv.deserialize_and_initialize(response_data)
53
+ expect(server_env.product_version).to eql '4.3.0'
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code42
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code 42
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-05 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -140,6 +140,7 @@ files:
140
140
  - lib/code42/api/role.rb
141
141
  - lib/code42/api/server.rb
142
142
  - lib/code42/api/server_connection_string.rb
143
+ - lib/code42/api/server_env.rb
143
144
  - lib/code42/api/server_settings.rb
144
145
  - lib/code42/api/store_point.rb
145
146
  - lib/code42/api/token.rb
@@ -152,6 +153,7 @@ files:
152
153
  - lib/code42/destination.rb
153
154
  - lib/code42/diagnostic.rb
154
155
  - lib/code42/error.rb
156
+ - lib/code42/faraday_middleware/parse_server_env.rb
155
157
  - lib/code42/org.rb
156
158
  - lib/code42/permission.rb
157
159
  - lib/code42/ping.rb
@@ -161,6 +163,7 @@ files:
161
163
  - lib/code42/role_collection.rb
162
164
  - lib/code42/server.rb
163
165
  - lib/code42/server_connection_string.rb
166
+ - lib/code42/server_env.rb
164
167
  - lib/code42/server_settings.rb
165
168
  - lib/code42/settings.rb
166
169
  - lib/code42/store_point.rb
@@ -195,7 +198,8 @@ files:
195
198
  - spec/cassettes/Code42_Client/_reset_password/when_sending_a_username/behaves_like_reset_password/is_successful.yml
196
199
  - spec/cassettes/Code42_Client/_reset_password/when_sending_a_view_url/behaves_like_reset_password/is_successful.yml
197
200
  - spec/cassettes/Code42_Client/_roles/returns_an_enumerable.yml
198
- - spec/cassettes/Code42_Client/_server/returns_a_server.yml
201
+ - spec/cassettes/Code42_Client/_server/returns_a_server_with_id.yml
202
+ - spec/cassettes/Code42_Client/_server/returns_a_server_with_this.yml
199
203
  - spec/cassettes/Code42_Client/_server_connection_string/returns_a_connection_string.yml
200
204
  - spec/cassettes/Code42_Client/_server_settings/returns_a_server_settings_object.yml
201
205
  - spec/cassettes/Code42_Client/_servers/returns_an_array_of_servers.yml
@@ -224,11 +228,13 @@ files:
224
228
  - spec/code42/connection_spec.rb
225
229
  - spec/code42/extension_spec.rb
226
230
  - spec/code42/org_spec.rb
231
+ - spec/code42/parse_server_env_spec.rb
227
232
  - spec/code42/ping_spec.rb
228
233
  - spec/code42/product_license_spec.rb
229
234
  - spec/code42/resource_spec.rb
230
235
  - spec/code42/role_spec.rb
231
236
  - spec/code42/server_connection_string_spec.rb
237
+ - spec/code42/server_env_spec.rb
232
238
  - spec/code42/server_spec.rb
233
239
  - spec/code42/settings_spec.rb
234
240
  - spec/code42/store_point_spec.rb
@@ -266,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
272
  version: '0'
267
273
  requirements: []
268
274
  rubyforge_project:
269
- rubygems_version: 2.0.3
275
+ rubygems_version: 2.2.2
270
276
  signing_key:
271
277
  specification_version: 4
272
278
  summary: '...'
@@ -298,7 +304,8 @@ test_files:
298
304
  - spec/cassettes/Code42_Client/_reset_password/when_sending_a_username/behaves_like_reset_password/is_successful.yml
299
305
  - spec/cassettes/Code42_Client/_reset_password/when_sending_a_view_url/behaves_like_reset_password/is_successful.yml
300
306
  - spec/cassettes/Code42_Client/_roles/returns_an_enumerable.yml
301
- - spec/cassettes/Code42_Client/_server/returns_a_server.yml
307
+ - spec/cassettes/Code42_Client/_server/returns_a_server_with_id.yml
308
+ - spec/cassettes/Code42_Client/_server/returns_a_server_with_this.yml
302
309
  - spec/cassettes/Code42_Client/_server_connection_string/returns_a_connection_string.yml
303
310
  - spec/cassettes/Code42_Client/_server_settings/returns_a_server_settings_object.yml
304
311
  - spec/cassettes/Code42_Client/_servers/returns_an_array_of_servers.yml
@@ -327,11 +334,13 @@ test_files:
327
334
  - spec/code42/connection_spec.rb
328
335
  - spec/code42/extension_spec.rb
329
336
  - spec/code42/org_spec.rb
337
+ - spec/code42/parse_server_env_spec.rb
330
338
  - spec/code42/ping_spec.rb
331
339
  - spec/code42/product_license_spec.rb
332
340
  - spec/code42/resource_spec.rb
333
341
  - spec/code42/role_spec.rb
334
342
  - spec/code42/server_connection_string_spec.rb
343
+ - spec/code42/server_env_spec.rb
335
344
  - spec/code42/server_spec.rb
336
345
  - spec/code42/settings_spec.rb
337
346
  - spec/code42/store_point_spec.rb
@@ -349,4 +358,3 @@ test_files:
349
358
  - spec/fixtures/user_roles.json
350
359
  - spec/fixtures/validate_token.json
351
360
  - spec/spec_helper.rb
352
- has_rdoc: