lumberg 2.0.0.pre12 → 2.0.0.pre15

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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/lib/lumberg/cpanel.rb +1 -0
  4. data/lib/lumberg/cpanel/mysql_db.rb +190 -0
  5. data/lib/lumberg/version.rb +1 -1
  6. data/lib/lumberg/whm/server.rb +21 -1
  7. data/spec/cpanel/contact_spec.rb +1 -1
  8. data/spec/cpanel/mysql_db_spec.rb +119 -0
  9. data/spec/spec_helper.rb +1 -1
  10. data/spec/vcr_cassettes/cpanel/contact/update.yml +21 -21
  11. data/spec/vcr_cassettes/cpanel/file_manager/disk_usage.yml +20 -20
  12. data/spec/vcr_cassettes/cpanel/file_manager/list.yml +21 -21
  13. data/spec/vcr_cassettes/cpanel/file_manager/operate.yml +40 -40
  14. data/spec/vcr_cassettes/cpanel/file_manager/show.yml +21 -21
  15. data/spec/vcr_cassettes/cpanel/file_manager/stat.yml +21 -21
  16. data/spec/vcr_cassettes/cpanel/mysql_db/add_db.yml +42 -0
  17. data/spec/vcr_cassettes/cpanel/mysql_db/add_host.yml +42 -0
  18. data/spec/vcr_cassettes/cpanel/mysql_db/add_user.yml +42 -0
  19. data/spec/vcr_cassettes/cpanel/mysql_db/add_user_db.yml +42 -0
  20. data/spec/vcr_cassettes/cpanel/mysql_db/check_db.yml +42 -0
  21. data/spec/vcr_cassettes/cpanel/mysql_db/del_db.yml +42 -0
  22. data/spec/vcr_cassettes/cpanel/mysql_db/del_host.yml +42 -0
  23. data/spec/vcr_cassettes/cpanel/mysql_db/del_user.yml +42 -0
  24. data/spec/vcr_cassettes/cpanel/mysql_db/del_user_db.yml +42 -0
  25. data/spec/vcr_cassettes/cpanel/mysql_db/init_cache.yml +42 -0
  26. data/spec/vcr_cassettes/cpanel/mysql_db/number_of_dbs.yml +42 -0
  27. data/spec/vcr_cassettes/cpanel/mysql_db/repair_db.yml +42 -0
  28. data/spec/vcr_cassettes/cpanel/mysql_db/update_privs.yml +42 -0
  29. data/spec/vcr_cassettes/whm/server/edit_hook.yml +44 -0
  30. data/spec/vcr_cassettes/whm/server/list_hooks.yml +44 -0
  31. data/spec/whm/server_spec.rb +18 -0
  32. metadata +246 -213
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc0111d920bd8ab37348ad04a2790e78de603643
4
- data.tar.gz: 6d5b5a3f897dd167db9c4c5c0bac45430fe9ec30
3
+ metadata.gz: d1058732139bcd1b3944f3db58e83fd31fe20ae6
4
+ data.tar.gz: b2c22aa8a40684b4c94bd3fe05b1567f77dc8133
5
5
  SHA512:
6
- metadata.gz: 2efa9329e069727d7dceb376b4aa65bb3ee6ddbcb63e880b40ed0112a8c697afb47322f6be722e2a6456f97b0c96ce93bb116e2b5c2e061f1d799d657ce3c9e6
7
- data.tar.gz: f65a390f02fa51ea81c31fc2a907382ba55eac4f997ae0883e1cf66ac4a8f2ea74e23fcce1e53c1b9e63803caf23ca3eba9f6ffbc9266da7fdcde4cf449374ae
6
+ metadata.gz: b059b3b57831808727e710316de9e3c9207a75cab47f7d31ce495383f165f30de1bca88e0aba73010fe7c4120a8b24abc0a8a79deb6959dc0ff90f0348a4ce6a
7
+ data.tar.gz: 232cec8379afc5d0aba63577d538a2aeec35fd647db9fda07898d703b13d0e780dfcab3c4ce63a0c73413379a5206621b4b384100f5e3acf6585816e37be3ff3
data/README.md CHANGED
@@ -321,6 +321,7 @@ email.add_forwarder(
321
321
  end
322
322
  end
323
323
  ```
324
+
324
325
  - In many cases, you'll name your methods to match up
325
326
  with the documented cPanel API methods. However, the documented method
326
327
  names are sometimes a bit lengthy, confusing, or otherwise unwiedly; feel
@@ -27,5 +27,6 @@ module Lumberg
27
27
  require "lumberg/cpanel/mysql"
28
28
  require "lumberg/cpanel/domain_keys"
29
29
  require "lumberg/cpanel/ftp"
30
+ require "lumberg/cpanel/mysql_db"
30
31
  end
31
32
  end
@@ -0,0 +1,190 @@
1
+ module Lumberg
2
+ module Cpanel
3
+ # Public: Allows you to manage MySQL Databases, users and other related settings.
4
+ class MysqlDb < Base
5
+ def self.api_module; "Mysql"; end
6
+
7
+ # Public: Add a new MySQL database to a cPanel account.
8
+ #
9
+ # options - Hash options for API call params (default: {}).
10
+ # :dbname - String name of the MySQL database to add.
11
+ #
12
+ # Returns Hash API response.
13
+ def add_db(options = {})
14
+ perform_request({
15
+ api_function: 'adddb',
16
+ 'arg-0' => options.delete(:dbname)
17
+ }.merge(default_options(options)))
18
+ end
19
+
20
+ # Public: Create a new MySQL user.
21
+ #
22
+ # options - Hash options for API call params (default: {}).
23
+ # :username - String MySQL user to create.
24
+ # :password - String password for the new MySQL user.
25
+ #
26
+ # Returns Hash API respone.
27
+ def add_user(options = {})
28
+ perform_request({
29
+ api_function: 'adduser',
30
+ 'arg-0' => options.delete(:username),
31
+ 'arg-1' => options.delete(:password)
32
+ }.merge(default_options(options)))
33
+ end
34
+
35
+ # Public: Grant a user permission to access a cPanel account's database.
36
+ #
37
+ # options - Hash options for API call params (default: {})
38
+ # :dbname - String name of the database to allow the user to access.
39
+ # :dbuser - String MySQL user who should be given access to the database.
40
+ # :perms_list - A space-separated String containing a list of permissions
41
+ # to grant to the user
42
+ # (e.g. "all" or "alter drop create delete insert update lock" )
43
+ #
44
+ # Returns Hash API respone.
45
+ def add_user_db(options = {})
46
+ perform_request({
47
+ api_function: 'adduserdb',
48
+ 'arg-0' => options.delete(:dbname),
49
+ 'arg-1' => options.delete(:dbuser),
50
+ 'arg-2' => options.delete(:perms_list)
51
+ }.merge(default_options(options)))
52
+ end
53
+
54
+ # Public: Retrieve the number of database users an account has created.
55
+ #
56
+ # Returns Hash API response.
57
+ def number_of_dbs(options = {})
58
+ perform_request({
59
+ api_function: 'number_of_dbs'
60
+ }.merge(default_options(options)))
61
+ end
62
+
63
+ # Public: Run a MySQL database check.
64
+ #
65
+ # options - Hash options for API call params (default: {}).
66
+ # :dbname - String name of the MySQL database to check.
67
+ #
68
+ # Returns Hash API response.
69
+ def check_db(options = {})
70
+ perform_request({
71
+ api_function: 'checkdb',
72
+ 'arg-0' => options.delete(:dbname)
73
+ }.merge(default_options(options)))
74
+ end
75
+
76
+ # Public: Run a MySQL database repair.
77
+ #
78
+ # options - Hash options for API call params (default: {}).
79
+ # :dbname - String name of the MySQL database to repair.
80
+ #
81
+ # Returns Hash API response.
82
+ def repair_db(options = {})
83
+ perform_request({
84
+ api_function: 'repairdb',
85
+ 'arg-0' => options.delete(:dbname)
86
+ }.merge(default_options(options)))
87
+ end
88
+
89
+ # Public: Force an update of MySQL privileges and passwords.
90
+ #
91
+ # options - Hash options for API call params (default: {})
92
+ #
93
+ # Returns Hash API response.
94
+ def update_privs(options = {})
95
+ perform_request({
96
+ api_function: 'updateprivs'
97
+ }.merge(default_options(options)))
98
+ end
99
+
100
+ # Public: Refresh the cache of MySQL information. This includes users,
101
+ # databases, routines and other related information.
102
+ #
103
+ # options - Hash options for API call params (default: {})
104
+ #
105
+ # Returns Hash API response.
106
+ def init_cache(options = {})
107
+ perform_request({
108
+ api_function: 'initcache'
109
+ }.merge(default_options(options)))
110
+ end
111
+
112
+ # Public: Disallow a MySQL user from accessing a database.
113
+ #
114
+ # options - Hash options for API call params (default: {})
115
+ # :dbname - String MySQL database from which to remove the user's permissions.
116
+ # :dbuser - String name of the MySQL user to remove.
117
+ #
118
+ # Returns Hash API response.
119
+ def del_user_db(options = {})
120
+ perform_request({
121
+ api_function: 'deluserdb',
122
+ 'arg-0' => options.delete(:dbname),
123
+ 'arg-1' => options.delete(:dbuser)
124
+ }.merge(default_options(options)))
125
+ end
126
+
127
+ # Public: Remove a user from MySQL.
128
+ #
129
+ # options - Hash options for API call params (default: {})
130
+ # :dbuser - String name of the MySQL user to remove.
131
+ # This value must be prefixed with the cPanel username.
132
+ # (e.g. cpuser_dbuser)
133
+ #
134
+ # Returns Hash API response.
135
+ def del_user(options = {})
136
+ perform_request({
137
+ api_function: 'deluser',
138
+ 'arg-0' => options.delete(:dbuser)
139
+ }.merge(default_options(options)))
140
+ end
141
+
142
+ # Public: Remove a database from MySQL.
143
+ #
144
+ # options - Hash options for API call params (default: {}).
145
+ # :dbname - String name of the MySQL database to remove.
146
+ # This value must be prefixed with the cPanel username
147
+ # (e.g., cpuser_dbname).
148
+ #
149
+ # Returns Hash API response.
150
+ def del_db(options = {})
151
+ perform_request({
152
+ api_function: 'deldb',
153
+ 'arg-0' => options.delete(:dbname)
154
+ }.merge(default_options(options)))
155
+ end
156
+
157
+ # Public: Authorize a remote host to access a cPanel account's MySQL users.
158
+ #
159
+ # options - Hash options for API call params (default: {})
160
+ # :hostname - String IP address or hostname that should be provided access.
161
+ #
162
+ # Returns Hash API response.
163
+ def add_host(options = {})
164
+ perform_request({
165
+ api_function: 'addhost',
166
+ 'arg-0' => options.delete(:hostname)
167
+ }.merge(default_options(options)))
168
+ end
169
+
170
+ # Public: Remove host access permissions from MySQL.
171
+ #
172
+ # options - Hash options for API call params (default: {})
173
+ # :host - String IP address or hostname that should be provided access.
174
+ #
175
+ # Returns Hash API response.
176
+ def del_host(options = {})
177
+ perform_request({
178
+ api_function: 'delhost',
179
+ 'arg-0' => options.delete(:host)
180
+ }.merge(default_options(options)))
181
+ end
182
+
183
+ private
184
+
185
+ def default_options(options)
186
+ { api_version: 1, response_key: 'data' }.merge(options)
187
+ end
188
+ end
189
+ end
190
+ end
@@ -1,3 +1,3 @@
1
1
  module Lumberg
2
- VERSION = '2.0.0.pre12'
2
+ VERSION = '2.0.0.pre15'
3
3
  end
@@ -1,4 +1,4 @@
1
- Faraday.register_middleware :response, format_whm: Lumberg::FormatWhm
1
+ Faraday::Response.register_middleware format_whm: Lumberg::FormatWhm
2
2
 
3
3
  module Lumberg
4
4
  module Whm
@@ -170,6 +170,26 @@ module Lumberg
170
170
  perform_request('reboot', {response_key: "reboot"})
171
171
  end
172
172
 
173
+ def list_hooks
174
+ request = perform_request('list_hooks',
175
+ response_key: 'data',
176
+ :'api.version' => 1)
177
+
178
+ request[:success] = request.has_key?(:params)
179
+
180
+ request
181
+ end
182
+
183
+ def edit_hook(options = {})
184
+ request = perform_request('edit_hook',
185
+ options.merge(:'api.version' => 1,
186
+ response_key: 'metadata'))
187
+
188
+ request[:success] = request[:params][:reason] == 'OK'
189
+
190
+ request
191
+ end
192
+
173
193
  def account
174
194
  @account ||= Account.new(server: self)
175
195
  end
@@ -29,7 +29,7 @@ module Lumberg
29
29
  let(:email_address) { "testing@lumberg-test.com" }
30
30
  let(:result) { Hash.new }
31
31
 
32
- use_vcr_cassette("cpanel/contact/update", record: :new_episodes)
32
+ use_vcr_cassette("cpanel/contact/update")
33
33
 
34
34
  context "configure contact email address and enables notifications" do
35
35
  it "should setup email address and bandwidth limit notification" do
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ module Lumberg
4
+ describe Cpanel::MysqlDb do
5
+ let(:server) { Whm::Server.new(host: @whm_host, hash: @whm_hash) }
6
+ let(:api_username) { "lumberg" }
7
+ let(:mysql_db) do
8
+ described_class.new(
9
+ server: server,
10
+ api_username: api_username
11
+ )
12
+ end
13
+
14
+ describe "#add_db" do
15
+ use_vcr_cassette("cpanel/mysql_db/add_db")
16
+
17
+ it "adds a db" do
18
+ mysql_db.add_db(dbname: 'cpanel')[:params][:result].should_not be_nil
19
+ end
20
+ end
21
+
22
+ describe "#add_user" do
23
+ use_vcr_cassette("cpanel/mysql_db/add_user")
24
+
25
+ it "adds a user" do
26
+ mysql_db.add_user(username: 'first', password: 'first_pass')[:params][:result].should_not be_nil
27
+ end
28
+ end
29
+
30
+ describe "#add_user_db" do
31
+ use_vcr_cassette("cpanel/mysql_db/add_user_db")
32
+
33
+ it "adds a user to a db" do
34
+ mysql_db.add_user_db(dbname: 'lumberg_cpanel', dbuser: 'lumberg_first',
35
+ perms_list: 'all')[:params][:result].should_not be_nil
36
+ end
37
+ end
38
+
39
+ describe "#number_of_dbs" do
40
+ use_vcr_cassette("cpanel/mysql_db/number_of_dbs")
41
+
42
+ it "gets number of dbs" do
43
+ mysql_db.number_of_dbs[:params][:result].should eq("1")
44
+ end
45
+ end
46
+
47
+ describe "#check_db" do
48
+ use_vcr_cassette("cpanel/mysql_db/check_db")
49
+
50
+ it "checks db" do
51
+ mysql_db.check_db(dbname: 'lumberg_cpanel')[:params][:result].should_not be_nil
52
+ end
53
+ end
54
+
55
+ describe "#repair_db" do
56
+ use_vcr_cassette("cpanel/mysql_db/repair_db")
57
+
58
+ it "repairs the db" do
59
+ mysql_db.repair_db(dbname: 'lumberg_cpanel')[:params][:result].should_not be_nil
60
+ end
61
+ end
62
+
63
+ describe "#update_privs" do
64
+ use_vcr_cassette("cpanel/mysql_db/update_privs")
65
+
66
+ it "updates privileges" do
67
+ mysql_db.update_privs[:params][:result].should_not be_nil
68
+ end
69
+ end
70
+
71
+ describe "#init_cache" do
72
+ use_vcr_cassette("cpanel/mysql_db/init_cache")
73
+
74
+ it "refreshes the cache of MySQL information" do
75
+ mysql_db.init_cache[:params][:result].should_not be_nil
76
+ end
77
+ end
78
+
79
+ describe "#del_user_db" do
80
+ use_vcr_cassette("cpanel/mysql_db/del_user_db")
81
+
82
+ it "disallows a user from accessing a db" do
83
+ mysql_db.del_user_db(dbname: 'lumberg_cpanel', dbuser: 'lumberg_first')[:params][:result].should_not be_nil
84
+ end
85
+ end
86
+
87
+ describe "#del_user" do
88
+ use_vcr_cassette("cpanel/mysql_db/del_user")
89
+
90
+ it "deletes a user" do
91
+ mysql_db.del_user(dbuser: 'lumberg_first')[:params][:result].should_not be_nil
92
+ end
93
+ end
94
+
95
+ describe "#del_db" do
96
+ use_vcr_cassette("cpanel/mysql_db/del_db")
97
+
98
+ it "deletes a db" do
99
+ mysql_db.del_db(dbname: 'lumberg_cpanel')[:params][:result].should_not be_nil
100
+ end
101
+ end
102
+
103
+ describe "#add_host" do
104
+ use_vcr_cassette("cpanel/mysql_db/add_host")
105
+
106
+ it "adds a host" do
107
+ mysql_db.add_host(hostname: 'cpanel_test.com')[:params][:result].should_not be_nil
108
+ end
109
+ end
110
+
111
+ describe "#del_host" do
112
+ use_vcr_cassette("cpanel/mysql_db/del_host")
113
+
114
+ it "deletes a host" do
115
+ mysql_db.del_host(host: 'cpanel_test.com')[:params][:result].should_not be_nil
116
+ end
117
+ end
118
+ end
119
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'rspec'
3
3
  require 'lumberg'
4
4
  require 'lumberg/exceptions'
5
+ require 'webmock/rspec'
5
6
  require 'vcr'
6
7
  require 'timeout'
7
8
 
@@ -36,4 +37,3 @@ RSpec.configure do |c|
36
37
  end
37
38
  end
38
39
  end
39
-
@@ -1,40 +1,40 @@
1
- ---
2
- http_interactions:
3
- - request:
1
+ ---
2
+ http_interactions:
3
+ - request:
4
4
  method: get
5
- uri: https://myhost.com:2087/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_func=savecontactinfo&cpanel_jsonapi_module=CustInfo&cpanel_jsonapi_user=lumberg&email=testing@lumberg-test.com&notify_bandwidth_limit=1&notify_disk_limit&notify_email_quota_limit
6
- body:
5
+ uri: https://myhost.com:2087/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_func=savecontactinfo&cpanel_jsonapi_module=CustInfo&cpanel_jsonapi_user=lumberg&email=testing@lumberg-test.com&notify_bandwidth_limit=1&notify_disk_limit=&notify_email_quota_limit=
6
+ body:
7
7
  string: ""
8
- headers:
9
- Authorization:
8
+ headers:
9
+ Authorization:
10
10
  - WHM root:iscool
11
- Accept:
11
+ Accept:
12
12
  - "*/*"
13
- User-Agent:
13
+ User-Agent:
14
14
  - Faraday v0.8.7
15
- response:
16
- status:
15
+ response:
16
+ status:
17
17
  code: 200
18
18
  message: OK
19
- headers:
20
- Date:
19
+ headers:
20
+ Date:
21
21
  - Thu, 16 May 2013 06:22:30 GMT
22
- Server:
22
+ Server:
23
23
  - cpsrvd/11.36.0.4
24
- Content-Length:
24
+ Content-Length:
25
25
  - "1008"
26
- Connection:
26
+ Connection:
27
27
  - Keep-Alive
28
- X-Keep-Alive-Count:
28
+ X-Keep-Alive-Count:
29
29
  - "1"
30
- Keep-Alive:
30
+ Keep-Alive:
31
31
  - timeout=70, max=200
32
- Content-Type:
32
+ Content-Type:
33
33
  - application/json; charset="utf-8"
34
- body:
34
+ body:
35
35
  string: |
36
36
  {"cpanelresult":{"event":{"result":1},"module":"CustInfo","apiversion":2,"data":[{"display_value":"off","descp":"Send notifications to your contact email address when you are reaching your disk quota.","value":0,"name":"notify_disk_limit"},{"display_value":"testing@lumberg-test.com","descp":"Email address that you can be contacted at. This should be an email address that is not on your account if you have one.","value":"testing@lumberg-test.com","name":"email"},{"display_value":"off","descp":"Send notifications to your contact email address when one of your email accounts approaches or is over quota.","value":0,"name":"notify_email_quota_limit"},{"display_value":"","descp":"If you wish to provide a second email address to receive notifications, enter it here.","value":"","name":"second_email"},{"display_value":"on","descp":"Send notifications to your contact email address when you are reaching your bandwidth usage limit.","value":1,"name":"notify_bandwidth_limit"}],"func":"savecontactinfo"}}
37
37
 
38
- http_version:
38
+ http_version:
39
39
  recorded_at: Thu, 16 May 2013 06:17:43 GMT
40
40
  recorded_with: VCR 2.0.1