code42 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/code42.gemspec +3 -0
  4. data/lib/code42.rb +66 -27
  5. data/lib/code42/api/destination.rb +18 -0
  6. data/lib/code42/api/diagnostic.rb +9 -0
  7. data/lib/code42/api/org.rb +5 -2
  8. data/lib/code42/api/product_license.rb +21 -0
  9. data/lib/code42/api/server.rb +21 -0
  10. data/lib/code42/api/server_connection_string.rb +9 -0
  11. data/lib/code42/api/server_settings.rb +13 -0
  12. data/lib/code42/api/store_point.rb +22 -0
  13. data/lib/code42/api/token.rb +7 -0
  14. data/lib/code42/client.rb +23 -31
  15. data/lib/code42/computer.rb +0 -2
  16. data/lib/code42/connection.rb +14 -26
  17. data/lib/code42/destination.rb +52 -0
  18. data/lib/code42/product_license.rb +12 -0
  19. data/lib/code42/server.rb +54 -0
  20. data/lib/code42/server_connection_string.rb +10 -0
  21. data/lib/code42/server_settings.rb +4 -0
  22. data/lib/code42/settings.rb +1 -1
  23. data/lib/code42/store_point.rb +63 -0
  24. data/lib/code42/version.rb +1 -1
  25. data/spec/cassettes/Code42_Client/_add_product_license/adds_a_product_license.yml +39 -0
  26. data/spec/cassettes/Code42_Client/_apply_mlk/applies_the_mlk.yml +77 -0
  27. data/spec/cassettes/Code42_Client/_create_destination/creates_a_destination.yml +40 -0
  28. data/spec/cassettes/Code42_Client/_create_server/creates_a_server.yml +38 -0
  29. data/spec/cassettes/Code42_Client/_destination/returns_a_destination.yml +37 -0
  30. data/spec/cassettes/Code42_Client/_destinations/returns_an_array_of_desinations.yml +37 -0
  31. data/spec/cassettes/Code42_Client/_org_share_destinations/returns_a_provider_key.yml +36 -0
  32. data/spec/cassettes/Code42_Client/_product_licenses/returns_an_array_of_product_licenses.yml +81 -0
  33. data/spec/cassettes/Code42_Client/_remove_product_license/removes_a_product_license.yml +104 -0
  34. data/spec/cassettes/Code42_Client/_server/returns_a_server.yml +37 -0
  35. data/spec/cassettes/Code42_Client/_server_connection_string/returns_a_connection_string.yml +36 -0
  36. data/spec/cassettes/Code42_Client/_server_settings/returns_a_server_settings_object.yml +37 -0
  37. data/spec/cassettes/Code42_Client/_servers/returns_an_array_of_servers.yml +37 -0
  38. data/spec/cassettes/Code42_Client/_update_product_license/updates_a_product_license.yml +76 -0
  39. data/spec/cassettes/Code42_Client/_update_server_settings/updates_server_settings.yml +70 -0
  40. data/spec/cassettes/Code42_StorePoint/_accept_new_devices/should_return_store_point_with_accept_new_devices_enabled.yml +75 -0
  41. data/spec/cassettes/Code42_StorePoint/_disable_balancing/should_return_store_point_with_balancing_enabled.yml +75 -0
  42. data/spec/cassettes/Code42_StorePoint/_disable_inbound_backup/should_return_store_point_with_inbound_backup_disabled.yml +75 -0
  43. data/spec/cassettes/Code42_StorePoint/_enable_balancing/should_return_store_point_with_balancing_enabled.yml +75 -0
  44. data/spec/cassettes/Code42_StorePoint/_enable_inbound_backup/should_return_store_point_with_inbound_backup_disabled.yml +75 -0
  45. data/spec/cassettes/Code42_StorePoint/_find_store_point_by_id/should_return_correct_store_point.yml +38 -0
  46. data/spec/cassettes/Code42_StorePoint/_find_store_point_by_name/should_return_correct_store_point.yml +38 -0
  47. data/spec/cassettes/Code42_StorePoint/_find_store_point_by_server_name/should_return_correct_store_point.yml +38 -0
  48. data/spec/cassettes/Code42_StorePoint/_reject_new_devices/should_return_store_point_with_accept_new_devices_disabled.yml +75 -0
  49. data/spec/code42/client_spec.rb +161 -57
  50. data/spec/code42/connection_spec.rb +10 -12
  51. data/spec/code42/extension_spec.rb +0 -2
  52. data/spec/code42/org_spec.rb +20 -22
  53. data/spec/code42/ping_spec.rb +1 -3
  54. data/spec/code42/product_license_spec.rb +34 -0
  55. data/spec/code42/resource_spec.rb +0 -2
  56. data/spec/code42/role_spec.rb +2 -4
  57. data/spec/code42/server_connection_string_spec.rb +34 -0
  58. data/spec/code42/server_spec.rb +66 -0
  59. data/spec/code42/settings_spec.rb +25 -27
  60. data/spec/code42/store_point_spec.rb +90 -0
  61. data/spec/code42/token_spec.rb +10 -15
  62. data/spec/code42/user_spec.rb +4 -6
  63. data/spec/spec_helper.rb +1 -1
  64. metadata +74 -4
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe Code42::Connection do
4
2
  subject(:connection) do
5
3
  Code42::Connection.new(
@@ -12,34 +10,34 @@ describe Code42::Connection do
12
10
  )
13
11
  end
14
12
 
15
- describe "#token" do
16
- it "sets authorization headers" do
17
- connection.token = "0jdeqya6xroz713tn1hxp6d8p1-1t5839d7lwfxr0g84jf1nqp2vi"
18
- expect(connection.headers['Authorization']).to eq "TOKEN 0jdeqya6xroz713tn1hxp6d8p1-1t5839d7lwfxr0g84jf1nqp2vi"
13
+ describe '#token' do
14
+ it 'sets authorization headers' do
15
+ connection.token = '0jdeqya6xroz713tn1hxp6d8p1-1t5839d7lwfxr0g84jf1nqp2vi'
16
+ expect(connection.headers['Authorization']).to eq 'TOKEN 0jdeqya6xroz713tn1hxp6d8p1-1t5839d7lwfxr0g84jf1nqp2vi'
19
17
  end
20
18
  end
21
19
 
22
- it "should set host to example.com" do
20
+ it 'should set host to example.com' do
23
21
  expect(connection.host).to eq 'example.com'
24
22
  end
25
23
 
26
- it "should set port to 1234" do
24
+ it 'should set port to 1234' do
27
25
  expect(connection.port).to eq 1234
28
26
  end
29
27
 
30
- it "should set scheme to http" do
28
+ it 'should set scheme to http' do
31
29
  expect(connection.scheme).to eq 'http'
32
30
  end
33
31
 
34
- it "should set api_root to /api/v2" do
32
+ it 'should set api_root to /api/v2' do
35
33
  expect(connection.path_prefix).to eq '/api/v2'
36
34
  end
37
35
 
38
- it "should set username to fred" do
36
+ it 'should set username to fred' do
39
37
  expect(connection.username).to eq 'fred'
40
38
  end
41
39
 
42
- it "should set password to letmein" do
40
+ it 'should set password to letmein' do
43
41
  expect(connection.password).to eq 'letmein'
44
42
  end
45
43
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  module Code42Extension
4
2
  module ClientMethods
5
3
  def some_method
@@ -1,18 +1,16 @@
1
- require 'spec_helper'
2
-
3
1
  describe Code42::Org do
4
2
  let(:valid_attributes) do
5
3
  {
6
- "orgId" => 123,
7
- "orgUid" => "ADMIN",
8
- "orgName" => "ADMIN",
9
- "status" => "Active",
10
- "active" => true,
11
- "blocked" => false,
12
- "parentOrgId" => nil,
13
- "type" => "ENTERPRISE",
14
- "creationDate" => "2006-05-23T15:11:39.159-05:00",
15
- "modificationDate" => "2010-03-09T15:06:37.724-06:00"
4
+ 'orgId' => 123,
5
+ 'orgUid' => 'ADMIN',
6
+ 'orgName' => 'ADMIN',
7
+ 'status' => 'Active',
8
+ 'active' => true,
9
+ 'blocked' => false,
10
+ 'parentOrgId' => nil,
11
+ 'type' => 'ENTERPRISE',
12
+ 'creationDate' => '2006-05-23T15:11:39.159-05:00',
13
+ 'modificationDate' => '2010-03-09T15:06:37.724-06:00'
16
14
  }
17
15
  end
18
16
 
@@ -20,8 +18,8 @@ describe Code42::Org do
20
18
  Code42::Org.from_response(valid_attributes)
21
19
  end
22
20
 
23
- describe ".serialize" do
24
- it "serializes data correctly" do
21
+ describe '.serialize' do
22
+ it 'serializes data correctly' do
25
23
  data = {
26
24
  name: 'Target'
27
25
  }
@@ -31,30 +29,30 @@ describe Code42::Org do
31
29
  end
32
30
  end
33
31
 
34
- describe "#id" do
35
- it "returns the correct id" do
32
+ describe '#id' do
33
+ it 'returns the correct id' do
36
34
  org.id.should eq 123
37
35
  end
38
36
  end
39
37
 
40
- describe "#created_at" do
41
- it "returns a DateTime object" do
38
+ describe '#created_at' do
39
+ it 'returns a DateTime object' do
42
40
  org.created_at.should be_a DateTime
43
41
  end
44
42
 
45
- it "returns the correct date" do
43
+ it 'returns the correct date' do
46
44
  org.created_at.day.should eq 23
47
45
  org.created_at.month.should eq 5
48
46
  org.created_at.year.should eq 2006
49
47
  end
50
48
  end
51
49
 
52
- describe "#updated_at" do
53
- it "returns a DateTime object" do
50
+ describe '#updated_at' do
51
+ it 'returns a DateTime object' do
54
52
  org.updated_at.should be_a DateTime
55
53
  end
56
54
 
57
- it "returns the correct date" do
55
+ it 'returns the correct date' do
58
56
  org.updated_at.day.should eq 9
59
57
  org.updated_at.month.should eq 3
60
58
  org.updated_at.year.should eq 2010
@@ -1,8 +1,6 @@
1
- require 'spec_helper'
2
-
3
1
  describe Code42::Ping do
4
2
  let(:valid_attributes) do
5
- { "success" => true }
3
+ { 'success' => true }
6
4
  end
7
5
 
8
6
  subject(:ping) do
@@ -0,0 +1,34 @@
1
+
2
+
3
+ describe Code42::ProductLicense do
4
+
5
+ let(:valid_attributes) do
6
+ {
7
+ id: 1234,
8
+ creation_date: DateTime.new,
9
+ expiration_date: DateTime.new,
10
+ product_license: 'asdfasdfasdfasdf'
11
+ }
12
+ end
13
+
14
+ subject(:product_license) { Code42::ProductLicense.new valid_attributes }
15
+
16
+ let(:client) do
17
+ client = double(Code42::Client)
18
+ allow(client).to receive(:remove_product_license) { 'Product license removed' }
19
+ client
20
+ end
21
+
22
+ describe '#id' do
23
+ it 'returns the license id' do
24
+ expect(product_license.id).to eql valid_attributes[:id]
25
+ end
26
+ end
27
+
28
+ describe '#remove' do
29
+ it 'removes the product license' do
30
+ allow(product_license).to receive(:client) { client }
31
+ expect(product_license.remove).to eql 'Product license removed'
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  module Code42
4
2
  describe Resource do
5
3
  describe '#serialize' do
@@ -1,7 +1,5 @@
1
- require 'spec_helper'
2
-
3
1
  describe Code42::Role do
4
- describe "#deserialize_and_initialize" do
2
+ describe '#deserialize_and_initialize' do
5
3
  let(:response_data) do
6
4
  data = <<-JSON
7
5
  {
@@ -20,7 +18,7 @@ describe Code42::Role do
20
18
  JSON.parse(data)
21
19
  end
22
20
 
23
- it "should translate roleId to id" do
21
+ it 'should translate roleId to id' do
24
22
  role = Code42::Role.deserialize_and_initialize(response_data)
25
23
  role.id.should eq 3
26
24
  end
@@ -0,0 +1,34 @@
1
+
2
+ describe Code42::ServerConnectionString do
3
+
4
+ let(:valid_attributes) do
5
+ {
6
+ server_id: 2,
7
+ connection_string: 'asdfasdf'
8
+ }
9
+ end
10
+
11
+ subject(:server_connection_string) { Code42::ServerConnectionString.new(valid_attributes) }
12
+
13
+ describe '#server_id' do
14
+ it 'returns the server_id' do
15
+ expect(server_connection_string.server_id).to eql valid_attributes[:server_id]
16
+ end
17
+ end
18
+
19
+ describe '#connection_string' do
20
+ it 'returns the connection string' do
21
+ expect(server_connection_string.connection_string).to eql valid_attributes[:connection_string]
22
+ end
23
+ end
24
+
25
+ describe '#server' do
26
+ it 'returns the server for the associated id' do
27
+ allow(server_connection_string).to receive(:server) { Code42::Server.new(id: valid_attributes[:server_id]) }
28
+
29
+ resp = server_connection_string.server
30
+ expect(resp).to be_a Code42::Server
31
+ expect(resp.id).to eql valid_attributes[:server_id]
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,66 @@
1
+ describe Code42::Server do
2
+ let(:valid_attributes) do
3
+ {
4
+ id: 1234,
5
+ guid: 12345,
6
+ name: 'test_server',
7
+ type: 'SERVER',
8
+ version: '3.6.3',
9
+ online: true,
10
+ out_of_date: false,
11
+ accepting_inbound_backup: true,
12
+ balancing_data: true,
13
+ accepting_new_computers: true,
14
+ db_empty: false,
15
+ cluster_server_id: 42,
16
+ destination_id: 21,
17
+ destination_name: 'destination',
18
+ provider_destination_name: 'provider_destination',
19
+ primary_address: '127.0.0.1',
20
+ secondary_address: '192.168.1.150',
21
+ website_host: '127.0.0.1:4280',
22
+ store_point_count: 2,
23
+ total_bytes: 1234567890,
24
+ used_bytes: 123456789,
25
+ used_percentage: 10,
26
+ free_bytes: 1234567890 - 123456789,
27
+ free_percentage: 90,
28
+ cold_bytes: 0,
29
+ cold_percentage_of_used: 0,
30
+ cold_percentage_of_total: 0,
31
+ archive_bytes: 0,
32
+ selected_bytes: 0,
33
+ remaining_bytes: 0,
34
+ inbound_bandwidth: 0,
35
+ outbound_bandwidth: 0,
36
+ org_count: 10,
37
+ user_count: 100,
38
+ licensed_user_count: 99,
39
+ computer_count: 150,
40
+ backup_computer_count: 100,
41
+ online_computer_count: 5,
42
+ backup_session_count: 5
43
+ }
44
+ end
45
+
46
+ subject(:server) { Code42::Server.new valid_attributes }
47
+
48
+ let(:client) do
49
+ client = double(Code42::Client)
50
+ allow(client).to receive(:server_connection_string) { 'asdfasdf' }
51
+ client
52
+ end
53
+
54
+ describe '#id' do
55
+ it 'should return correct id' do
56
+ server.id.should == 1234
57
+ end
58
+ end
59
+
60
+ describe '#connection_string' do
61
+ it 'should return the server connection string' do
62
+ allow(server).to receive(:client) { client }
63
+ expect(server.connection_string).to eql 'asdfasdf'
64
+ end
65
+ end
66
+ end
@@ -1,17 +1,15 @@
1
- require 'spec_helper'
2
-
3
1
  describe Code42::Settings do
4
2
  subject(:settings) { Code42::Settings.new }
5
3
 
6
- describe "#host" do
7
- it "should return configured host" do
8
- settings.host = "example.com"
9
- settings.host.should == "example.com"
4
+ describe '#host' do
5
+ it 'should return configured host' do
6
+ settings.host = 'example.com'
7
+ settings.host.should == 'example.com'
10
8
  end
11
9
  end
12
10
 
13
- describe "#base_url" do
14
- it "should build base_url properly" do
11
+ describe '#base_url' do
12
+ it 'should build base_url properly' do
15
13
  settings.https = true
16
14
  settings.host = 'example.com'
17
15
  settings.port = 123
@@ -19,14 +17,14 @@ describe Code42::Settings do
19
17
  settings.base_url.should eq 'https://example.com:123/api'
20
18
  end
21
19
 
22
- it "should raise an exception if settings invalid" do
20
+ it 'should raise an exception if settings invalid' do
23
21
  settings.host = 'example.com'
24
22
  expect { settings.base_url }.to raise_error(Code42::Error)
25
23
  end
26
24
  end
27
25
 
28
- describe "#valid?" do
29
- it "should return true if required properties are defined" do
26
+ describe '#valid?' do
27
+ it 'should return true if required properties are defined' do
30
28
  settings.host = 'example.com'
31
29
  settings.port = 123
32
30
  settings.api_root = '/api'
@@ -42,61 +40,61 @@ describe Code42::Settings do
42
40
  end
43
41
  end
44
42
 
45
- describe "#scheme" do
46
- it "should be http if https is false" do
43
+ describe '#scheme' do
44
+ it 'should be http if https is false' do
47
45
  settings.https = false
48
46
  settings.scheme.should eq 'http'
49
47
  end
50
48
 
51
- it "should be https if https is true" do
49
+ it 'should be https if https is true' do
52
50
  settings.https = true
53
51
  settings.scheme.should == 'https'
54
52
  settings.scheme.should eq 'https'
55
53
  end
56
54
  end
57
55
 
58
- describe "#port" do
59
- it "should return configured port" do
56
+ describe '#port' do
57
+ it 'should return configured port' do
60
58
  settings.port = 123
61
59
  settings.port.should eq 123
62
60
  end
63
61
  end
64
62
 
65
- describe "#https" do
66
- it "should return the https boolean" do
63
+ describe '#https' do
64
+ it 'should return the https boolean' do
67
65
  settings.https = true
68
66
  settings.https.should be_true
69
67
  end
70
68
 
71
- it "should default to true" do
69
+ it 'should default to true' do
72
70
  settings = Code42::Settings.new
73
71
  settings.https.should be_true
74
72
  end
75
73
  end
76
74
 
77
- describe "#api_root" do
78
- it "should return the api root" do
75
+ describe '#api_root' do
76
+ it 'should return the api root' do
79
77
  settings.api_root = '/api/v3'
80
78
  settings.api_root.should eq '/api/v3'
81
79
  end
82
80
  end
83
81
 
84
- describe "#username" do
85
- it "should return the username" do
82
+ describe '#username' do
83
+ it 'should return the username' do
86
84
  settings.username = 'bob'
87
85
  settings.username.should eq 'bob'
88
86
  end
89
87
  end
90
88
 
91
- describe "#password" do
92
- it "should return the password" do
89
+ describe '#password' do
90
+ it 'should return the password' do
93
91
  settings.password = 'bob'
94
92
  settings.password.should eq 'bob'
95
93
  end
96
94
  end
97
95
 
98
- describe "#all" do
99
- it "should return a hash of all settings" do
96
+ describe '#all' do
97
+ it 'should return a hash of all settings' do
100
98
  settings = Code42::Settings.new(
101
99
  host: 'example.com',
102
100
  port: 123,
@@ -0,0 +1,90 @@
1
+ describe Code42::StorePoint, :vcr do
2
+
3
+ subject(:client) do
4
+ Code42::Client.new(
5
+ host: 'localhost',
6
+ port: 4280,
7
+ https: false,
8
+ api_root: '/api',
9
+ username: 'admin',
10
+ password: 'admin',
11
+ verify_https: false,
12
+ debug: true
13
+ )
14
+ end
15
+
16
+ let(:valid_attributes) do
17
+ {
18
+ :id => 2,
19
+ :name => '651951667247317249_Default',
20
+ :server_name => 'test_storage_node',
21
+ :destination_name => 'local-storage',
22
+ :org_count => 0,
23
+ :accepting_inbound_backup => true,
24
+ :accepting_inbound_computers => true,
25
+ :balancing_data => true
26
+ }
27
+ end
28
+
29
+ describe '#find_store_point_by_id' do
30
+ it 'should return correct store point' do
31
+ client.find_store_point_by_id(valid_attributes[:id]).id.should == 2
32
+ end
33
+ end
34
+
35
+ describe '#find_store_point_by_name' do
36
+ it 'should return correct store point' do
37
+ store_points = client.find_store_points_by_name(valid_attributes[:name])
38
+ expect(store_points.first.name).to eql '651951667247317249_Default'
39
+ end
40
+ end
41
+
42
+ describe '#find_store_point_by_server_name' do
43
+ it 'should return correct store point' do
44
+ store_points = client.find_store_points_by_name(valid_attributes[:server_name])
45
+ expect(store_points.first.server_name).to eql 'test_storage_node'
46
+ end
47
+ end
48
+
49
+ describe '#disable_inbound_backup' do
50
+ it 'should return store point with inbound backup disabled' do
51
+ store_point = client.find_store_point_by_id(valid_attributes[:id]).disable_inbound_backup
52
+ store_point.accepting_inbound_backup.should == false
53
+ end
54
+ end
55
+
56
+ describe '#enable_inbound_backup' do
57
+ it 'should return store point with inbound backup disabled' do
58
+ store_point = client.find_store_point_by_id(valid_attributes[:id]).enable_inbound_backup
59
+ store_point.accepting_inbound_backup.should == true
60
+ end
61
+ end
62
+
63
+ describe '#disable_balancing' do
64
+ it 'should return store point with balancing enabled' do
65
+ store_point = client.find_store_point_by_id(valid_attributes[:id]).disable_balancing
66
+ store_point.balancing_data.should == false
67
+ end
68
+ end
69
+
70
+ describe '#enable_balancing' do
71
+ it 'should return store point with balancing enabled' do
72
+ store_point = client.find_store_point_by_id(valid_attributes[:id]).enable_balancing
73
+ store_point.balancing_data.should == true
74
+ end
75
+ end
76
+
77
+ describe '#reject_new_devices' do
78
+ it 'should return store point with accept new devices disabled' do
79
+ store_point = client.find_store_point_by_id(valid_attributes[:id]).reject_new_devices
80
+ store_point.accepting_new_computers.should == false
81
+ end
82
+ end
83
+
84
+ describe '#accept_new_devices' do
85
+ it 'should return store point with accept new devices enabled' do
86
+ store_point = client.find_store_point_by_id(valid_attributes[:id]).accept_new_devices
87
+ store_point.accepting_new_computers.should == true
88
+ end
89
+ end
90
+ end