plesk_lib 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +89 -0
  7. data/Rakefile +1 -0
  8. data/lib/plesk_lib.rb +29 -0
  9. data/lib/plesk_lib/account.rb +14 -0
  10. data/lib/plesk_lib/actions/base.rb +61 -0
  11. data/lib/plesk_lib/actions/change_customer_password.rb +27 -0
  12. data/lib/plesk_lib/actions/create_account.rb +23 -0
  13. data/lib/plesk_lib/actions/create_customer.rb +21 -0
  14. data/lib/plesk_lib/actions/create_reseller.rb +22 -0
  15. data/lib/plesk_lib/actions/create_service_plan.rb +327 -0
  16. data/lib/plesk_lib/actions/create_subscription.rb +55 -0
  17. data/lib/plesk_lib/actions/get_statistics.rb +61 -0
  18. data/lib/plesk_lib/actions/list_customers.rb +51 -0
  19. data/lib/plesk_lib/actions/list_service_plans.rb +60 -0
  20. data/lib/plesk_lib/actions/list_subscriptions.rb +42 -0
  21. data/lib/plesk_lib/customer.rb +4 -0
  22. data/lib/plesk_lib/reseller.rb +5 -0
  23. data/lib/plesk_lib/server.rb +23 -0
  24. data/lib/plesk_lib/service_plan.rb +17 -0
  25. data/lib/plesk_lib/subscription.rb +14 -0
  26. data/lib/plesk_lib/version.rb +3 -0
  27. data/plesk_lib.gemspec +30 -0
  28. data/spec/actions/change_customer_password_spec.rb +29 -0
  29. data/spec/actions/create_customer_spec.rb +50 -0
  30. data/spec/actions/create_reseller_spec.rb +35 -0
  31. data/spec/actions/create_service_plan_spec.rb +33 -0
  32. data/spec/actions/create_subscription_spec.rb +21 -0
  33. data/spec/actions/get_statistics_spec.rb +15 -0
  34. data/spec/actions/list_customers_spec.rb +31 -0
  35. data/spec/actions/list_service_plans_spec.rb +31 -0
  36. data/spec/actions/list_subscriptions.rb +31 -0
  37. data/spec/customer_spec.rb +21 -0
  38. data/spec/reseller_spec.rb +22 -0
  39. data/spec/server_spec.rb +48 -0
  40. data/spec/spec_helper.rb +28 -0
  41. data/spec/vcr/customer/change_password_existing_user.yml +57 -0
  42. data/spec/vcr/customer/change_password_missing_user.yml +57 -0
  43. data/spec/vcr/customer/list_customers.yml +57 -0
  44. data/spec/vcr/customer/list_customers_filtered.yml +57 -0
  45. data/spec/vcr/customer/minimal.yml +112 -0
  46. data/spec/vcr/customer/minimal_exists.yml +112 -0
  47. data/spec/vcr/customer/minimal_with_owner.yml +58 -0
  48. data/spec/vcr/reseller/minimal.yml +58 -0
  49. data/spec/vcr/reseller/minimal_exists.yml +58 -0
  50. data/spec/vcr/server/get_statistics.yml +57 -0
  51. data/spec/vcr/service_plan/create_minimal.yml +58 -0
  52. data/spec/vcr/service_plan/create_minimal_with_owner.yml +58 -0
  53. data/spec/vcr/service_plan/list_admin.yml +57 -0
  54. data/spec/vcr/service_plan/list_all.yml +57 -0
  55. data/spec/vcr/subscription/create.yml +57 -0
  56. data/spec/vcr/subscription/list_subscriptions.yml +57 -0
  57. data/spec/vcr/subscription/list_subscriptions_filtered.yml +57 -0
  58. metadata +257 -0
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe PleskLib::Actions::CreateReseller do
4
+ let(:reseller_attributes) do
5
+ { password: 'reseller_secret', phone: '0000000000',
6
+ email: 'noreply@ausupport.com.au', country: 'AU',
7
+ person_name: 'Reseller Name', company_name: 'Reseller Company',
8
+ service_plan_id: 2 }
9
+ end
10
+
11
+ let(:server) { PleskLib::Server.new('10.0.0.158', 'admin', 'ccsnDxnWy2j0') }
12
+ let(:reseller) { PleskLib::Reseller.new('reseller99', reseller_attributes) }
13
+
14
+ context 'when login is available on the plesk server' do
15
+ it 'should create a reseller' do
16
+ VCR.use_cassette 'reseller/minimal', match_requests_on: [:method, :uri, :body] do
17
+ action = PleskLib::Actions::CreateReseller.new(reseller)
18
+ action.execute_on(server)
19
+
20
+ action.plesk_id.to_i.should > 0
21
+ end
22
+ end
23
+ end
24
+
25
+ context 'when login is already taken' do
26
+ it 'should raise a LoginAlreadyTaken exception' do
27
+ VCR.use_cassette 'reseller/minimal_exists', match_requests_on: [:method, :uri, :body] do
28
+ action = PleskLib::Actions::CreateReseller.new(reseller)
29
+ expect {
30
+ action.execute_on(server)
31
+ }.to raise_error(PleskLib::LoginAlreadyTaken)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe PleskLib::Actions::CreateServicePlan do
4
+ let(:service_plan_config) { { mailboxes: 3, domains: 3, traffic: 3, storage: 3 } }
5
+ let(:server) { PleskLib::Server.new('10.0.0.158', 'admin', 'ccsnDxnWy2j0') }
6
+ let(:service_plan) { PleskLib::ServicePlan.new('An Admin Service Plan', service_plan_config) }
7
+
8
+ it 'should create a service plan' do
9
+ VCR.use_cassette 'service_plan/create_minimal', match_requests_on: [:method, :uri, :body] do
10
+ action = PleskLib::Actions::CreateServicePlan.new(service_plan)
11
+ action.execute_on(server)
12
+
13
+ action.plesk_id.to_i.should > 0
14
+ action.guid.length.should == 36 #guid is 36 characters long
15
+ end
16
+ end
17
+
18
+ context 'when a reseller is given' do
19
+ let(:service_plan_config) { { mailboxes: 3, domains: 3, traffic: 3,
20
+ storage: 3, external_id: 'external-3',
21
+ owner_id: 3 } }
22
+ let(:service_plan) { PleskLib::ServicePlan.new('A New Reseller Service Plan', service_plan_config) }
23
+ it 'should create a service plan for a reseller' do
24
+ VCR.use_cassette 'service_plan/create_minimal_with_owner', match_requests_on: [:method, :uri, :body] do
25
+ action = PleskLib::Actions::CreateServicePlan.new(service_plan)
26
+ action.execute_on(server)
27
+
28
+ action.plesk_id.to_i.should > 0
29
+ action.guid.length.should == 36 #guid is 36 characters long
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe PleskLib::Actions::CreateSubscription do
4
+ let(:server) { PleskLib::Server.new('10.0.0.158', 'admin', 'ccsnDxnWy2j0') }
5
+ let(:subscription) { PleskLib::Subscription.new({ name: 'foo-domain.de',
6
+ ip_address: '10.0.0.158',
7
+ owner_id: 3,
8
+ service_plan_id: 10,
9
+ ftp_login: 'ftp01',
10
+ ftp_password: 'ftpPass01' }) }
11
+
12
+ it 'should create a reseller' do
13
+ VCR.use_cassette 'subscription/create', match_requests_on: [:method, :uri, :body] do
14
+ action = PleskLib::Actions::CreateSubscription.new(subscription)
15
+ action.execute_on(server)
16
+
17
+ action.plesk_id.to_i.should > 0
18
+ action.guid.length.should == 36
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe PleskLib::Actions::GetStatistics do
4
+ let(:server) { PleskLib::Server.new('10.0.0.158', 'admin', 'ccsnDxnWy2j0') }
5
+
6
+ it 'should return a statistics hash' do
7
+ VCR.use_cassette 'server/get_statistics', match_requests_on: [:method, :uri, :body] do
8
+ action = PleskLib::Actions::GetStatistics.new
9
+ action.execute_on(server)
10
+
11
+ action.statistics.should_not be_empty
12
+ action.statistics[:objects].should_not be_empty
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe PleskLib::Actions::ListCustomers do
4
+ let(:server) { PleskLib::Server.new('10.0.0.158', 'admin', 'ccsnDxnWy2j0') }
5
+
6
+ it 'should list all customers' do
7
+ VCR.use_cassette 'customer/list_customers', match_requests_on: [:method, :uri, :body] do
8
+ action = PleskLib::Actions::ListCustomers.new
9
+ action.execute_on(server)
10
+
11
+ action.customers.count.should == 4
12
+ action.customers.each do |customer|
13
+ customer.login.should_not be_empty
14
+ customer.status.should == 0
15
+ end
16
+ end
17
+ end
18
+
19
+ it 'should list customers of owner 3' do
20
+ VCR.use_cassette 'customer/list_customers_filtered', match_requests_on: [:method, :uri, :body] do
21
+ action = PleskLib::Actions::ListCustomers.new(3)
22
+ action.execute_on(server)
23
+
24
+ action.customers.count.should == 2
25
+ action.customers.each do |customer|
26
+ customer.login.should_not be_empty
27
+ customer.status.should == 0
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe PleskLib::Actions::ListServicePlans do
4
+ let(:server) { PleskLib::Server.new('10.0.0.158', 'admin', 'ccsnDxnWy2j0') }
5
+
6
+ it 'should list all service plans' do
7
+ VCR.use_cassette 'service_plan/list_all', match_requests_on: [:method, :uri, :body] do
8
+ action = PleskLib::Actions::ListServicePlans.new
9
+ action.execute_on(server)
10
+
11
+ action.service_plans.count.should == 9
12
+ action.service_plans.each do |service_plan|
13
+ service_plan.id.should be_present
14
+ service_plan.guid.length.should == 36
15
+ end
16
+ end
17
+ end
18
+
19
+ it 'should list the admin service plans' do
20
+ VCR.use_cassette 'service_plan/list_admin', match_requests_on: [:method, :uri, :body] do
21
+ action = PleskLib::Actions::ListServicePlans.new(1)
22
+ action.execute_on(server)
23
+
24
+ action.service_plans.count.should == 6
25
+ action.service_plans.each do |service_plan|
26
+ service_plan.id.should be_present
27
+ service_plan.guid.length.should == 36
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe PleskLib::Actions::ListSubscriptions do
4
+ let(:server) { PleskLib::Server.new('10.0.0.158', 'admin', 'ccsnDxnWy2j0') }
5
+
6
+ it 'should list all subscriptions' do
7
+ VCR.use_cassette 'subscription/list_subscriptions', match_requests_on: [:method, :uri, :body] do
8
+ action = PleskLib::Actions::ListSubscriptions.new
9
+ action.execute_on(server)
10
+
11
+ action.subscriptions.count.should == 3
12
+ action.subscriptions.each do |subscription|
13
+ subscription.id.to_i.should > 0
14
+ subscription.guid.length.should == 36
15
+ end
16
+ end
17
+ end
18
+
19
+ it 'should list subscriptions of owner 4' do
20
+ VCR.use_cassette 'subscription/list_subscriptions_filtered', match_requests_on: [:method, :uri, :body] do
21
+ action = PleskLib::Actions::ListSubscriptions.new(4)
22
+ action.execute_on(server)
23
+
24
+ action.subscriptions.count.should == 2
25
+ action.subscriptions.each do |subscription|
26
+ subscription.id.to_i.should > 0
27
+ subscription.guid.length.should == 36
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe PleskLib::Customer do
4
+ context 'with login and password given to intializer' do
5
+ subject { PleskLib::Customer.new('the_login', { password: 'the_password' }) }
6
+
7
+ it { should respond_to(:company_name) }
8
+ it { should respond_to(:person_name) }
9
+ it { should respond_to(:login) }
10
+ it { should respond_to(:password) }
11
+
12
+ its(:login) { should eql 'the_login' }
13
+ its(:password) { should eql 'the_password' }
14
+
15
+ it 'should be initializable with only the login' do
16
+ expect {
17
+ PleskLib::Customer.new('the_login')
18
+ }.not_to raise_error
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe PleskLib::Reseller do
4
+ context 'with login and password given to intializer' do
5
+ subject { PleskLib::Reseller.new('the_login', { password: 'the_password' }) }
6
+
7
+ it { should respond_to(:company_name) }
8
+ it { should respond_to(:person_name) }
9
+ it { should respond_to(:login) }
10
+ it { should respond_to(:password) }
11
+ it { should respond_to(:service_plan_id) }
12
+
13
+ its(:login) { should eql 'the_login' }
14
+ its(:password) { should eql 'the_password' }
15
+
16
+ it 'should be initializable with only the login' do
17
+ expect {
18
+ PleskLib::Reseller.new('the_login')
19
+ }.not_to raise_error
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe PleskLib::Server do
4
+ subject { PleskLib::Server.new('10.0.0.1', 'admin', 'secret') }
5
+
6
+ its(:host) { should eql '10.0.0.1' }
7
+ its(:username) { should eql 'admin' }
8
+ its(:password) { should eql 'secret' }
9
+
10
+ describe '#create_customer' do
11
+ it 'uses the PleskLib::Actions::CreateCustomer action' do
12
+ customer = double(:customer)
13
+ PleskLib::Actions::CreateCustomer.should_receive(:new).with(customer).and_call_original
14
+ PleskLib::Actions::CreateCustomer.any_instance.should_receive(:execute_on).with(subject)
15
+
16
+ subject.create_customer(customer)
17
+ end
18
+ end
19
+
20
+ describe '#create_reseller' do
21
+ it 'uses the PleskLib::Actions::CreateReseller action' do
22
+ reseller = double(:reseller)
23
+ PleskLib::Actions::CreateReseller.should_receive(:new).with(reseller).and_call_original
24
+ PleskLib::Actions::CreateReseller.any_instance.should_receive(:execute_on).with(subject)
25
+
26
+ subject.create_reseller(reseller)
27
+ end
28
+ end
29
+
30
+ describe '#change_customer_password' do
31
+ it 'uses the PleskLib::Actions::ChangeCustomerPassword action' do
32
+ customer = double(:customer)
33
+ PleskLib::Actions::ChangeCustomerPassword.should_receive(:new).with(customer, 'new_password').and_call_original
34
+ PleskLib::Actions::ChangeCustomerPassword.any_instance.should_receive(:execute_on).with(subject)
35
+
36
+ subject.change_customer_password(customer, 'new_password')
37
+ end
38
+ end
39
+
40
+ describe '#get_statistics' do
41
+ it 'uses the PleskLib::Actions::GetStatistics action' do
42
+ PleskLib::Actions::GetStatistics.should_receive(:new).and_call_original
43
+ PleskLib::Actions::GetStatistics.any_instance.should_receive(:execute_on).with(subject)
44
+
45
+ subject.get_statistics
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'plesk_lib'
9
+ require 'webmock/rspec'
10
+ require 'vcr'
11
+ require 'pry'
12
+
13
+ RSpec.configure do |config|
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.run_all_when_everything_filtered = true
16
+ # config.filter_run :focus
17
+
18
+ # Run specs in random order to surface order dependencies. If you find an
19
+ # order dependency and want to debug it, you can fix the order by providing
20
+ # the seed, which is printed after each run.
21
+ # --seed 1234
22
+ config.order = 'random'
23
+ end
24
+
25
+ VCR.configure do |c|
26
+ c.cassette_library_dir = File.expand_path('../vcr', __FILE__)
27
+ c.hook_into :webmock
28
+ end
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://10.0.0.158:8443/enterprise/control/agent.php
6
+ body:
7
+ encoding: UTF-8
8
+ string: <?xml version="1.0" encoding="UTF-8"?><packet version="1.6.3.5"><customer><set><filter><login>user91</login></filter><values><gen_info><passwd>new_password</passwd></gen_info></values></set></customer></packet>
9
+ headers:
10
+ http_auth_login:
11
+ - admin
12
+ http_auth_passwd:
13
+ - ccsnDxnWy2j0
14
+ content-type:
15
+ - text/xml
16
+ accept-encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ accept:
19
+ - "*/*"
20
+ user-agent:
21
+ - Ruby
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ server:
28
+ - sw-cp-server
29
+ date:
30
+ - Wed, 12 Mar 2014 20:17:26 GMT
31
+ content-type:
32
+ - text/xml
33
+ transfer-encoding:
34
+ - chunked
35
+ connection:
36
+ - close
37
+ p3p:
38
+ - CP="NON COR CURa ADMa OUR NOR UNI COM NAV STA"
39
+ last-modified:
40
+ - Wed, 12 Mar 2014 20:17:26 GMT
41
+ expires:
42
+ - Thu, 19 Nov 1981 08:52:00 GMT
43
+ cache-control:
44
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
45
+ pragma:
46
+ - no-cache
47
+ set-cookie:
48
+ - PHPSESSID=184c4beab99b0cc115749f6e00a95e9b; path=/; secure; httponly
49
+ - locale=en-US; expires=Thu, 12-Mar-2015 20:17:26 GMT; path=/
50
+ body:
51
+ encoding: UTF-8
52
+ string: |
53
+ <?xml version="1.0" encoding="UTF-8"?>
54
+ <packet version="1.6.3.5"><customer><set><result><status>ok</status><filter-id>user91</filter-id><id>11</id></result></set></customer></packet>
55
+ http_version: '1.1'
56
+ recorded_at: Sat, 15 Mar 2014 14:24:16 GMT
57
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://10.0.0.158:8443/enterprise/control/agent.php
6
+ body:
7
+ encoding: UTF-8
8
+ string: <?xml version="1.0" encoding="UTF-8"?><packet version="1.6.3.5"><customer><set><filter><login>unknownuser</login></filter><values><gen_info><passwd>new_password</passwd></gen_info></values></set></customer></packet>
9
+ headers:
10
+ http_auth_login:
11
+ - admin
12
+ http_auth_passwd:
13
+ - ccsnDxnWy2j0
14
+ content-type:
15
+ - text/xml
16
+ accept-encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ accept:
19
+ - "*/*"
20
+ user-agent:
21
+ - Ruby
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ server:
28
+ - sw-cp-server
29
+ date:
30
+ - Wed, 12 Mar 2014 20:18:10 GMT
31
+ content-type:
32
+ - text/xml
33
+ transfer-encoding:
34
+ - chunked
35
+ connection:
36
+ - close
37
+ p3p:
38
+ - CP="NON COR CURa ADMa OUR NOR UNI COM NAV STA"
39
+ last-modified:
40
+ - Wed, 12 Mar 2014 20:18:09 GMT
41
+ expires:
42
+ - Thu, 19 Nov 1981 08:52:00 GMT
43
+ cache-control:
44
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
45
+ pragma:
46
+ - no-cache
47
+ set-cookie:
48
+ - PHPSESSID=d5e0d8ca4bc8935a16135e3642ae7175; path=/; secure; httponly
49
+ - locale=en-US; expires=Thu, 12-Mar-2015 20:18:09 GMT; path=/
50
+ body:
51
+ encoding: UTF-8
52
+ string: |
53
+ <?xml version="1.0" encoding="UTF-8"?>
54
+ <packet version="1.6.3.5"><customer><set><result><status>error</status><errcode>1013</errcode><errtext>client does not exist</errtext><filter-id>unknownuser</filter-id></result></set></customer></packet>
55
+ http_version: '1.1'
56
+ recorded_at: Sat, 15 Mar 2014 14:24:59 GMT
57
+ recorded_with: VCR 2.8.0