fog-proxmox 0.13.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +34 -49
- data/.github/workflows/release.yml +38 -0
- data/.rubocop.yml +11 -10
- data/.rubocop_todo.yml +255 -0
- data/CHANGELOG.md +8 -0
- data/README.md +35 -4
- data/Rakefile +8 -35
- data/bin/console +2 -4
- data/bin/setup +2 -4
- data/docs/compute.md +23 -7
- data/docs/identity.md +31 -6
- data/examples/compute.rb +11 -11
- data/examples/identity.rb +28 -15
- data/fog-proxmox.gemspec +8 -6
- data/lib/fog/proxmox/attributes.rb +3 -2
- data/lib/fog/proxmox/auth/token/access_ticket.rb +96 -0
- data/lib/fog/proxmox/auth/token/user_token.rb +107 -0
- data/lib/fog/proxmox/auth/token.rb +94 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/disk.rb +21 -3
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/disks.rb +6 -2
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/interface.rb +5 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/interfaces.rb +2 -2
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/node.rb +3 -5
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/nodes.rb +2 -2
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/server.rb +29 -18
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/server_config.rb +17 -4
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/servers.rb +6 -6
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/snapshots.rb +2 -2
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/storage.rb +3 -2
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/storages.rb +3 -3
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/tasks.rb +2 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/volume.rb +8 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/volumes.rb +3 -3
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/action_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/clone_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_backup.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_spice.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_term.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_vnc.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_volume.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_node_statistics.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_server_config.rb +14 -14
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_server_status.rb +17 -17
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_snapshot_config.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_vnc.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_volume.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_nodes.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_servers.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_snapshots.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_storages.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_tasks.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_volumes.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/log_task.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/migrate_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/move_disk.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/move_volume.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/next_vmid.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/resize_container.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/resize_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/rollback_snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/status_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/stop_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/template_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/update_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/update_snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox.rb → proxmox/compute.rb} +31 -16
- data/lib/fog/proxmox/core.rb +76 -64
- data/lib/fog/proxmox/errors.rb +2 -1
- data/lib/fog/proxmox/hash.rb +2 -4
- data/lib/fog/proxmox/helpers/controller_helper.rb +3 -4
- data/lib/fog/proxmox/helpers/cpu_helper.rb +55 -9
- data/lib/fog/proxmox/helpers/disk_helper.rb +51 -25
- data/lib/fog/proxmox/helpers/ip_helper.rb +21 -20
- data/lib/fog/proxmox/helpers/nic_helper.rb +37 -27
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/domain.rb +7 -3
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/domain_type.rb +0 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/domains.rb +2 -3
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/group.rb +6 -2
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/groups.rb +2 -2
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/permission.rb +5 -4
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/permissions.rb +4 -2
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/pool.rb +4 -4
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/pools.rb +5 -5
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/principal.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/role.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/roles.rb +2 -2
- data/lib/fog/proxmox/identity/models/token.rb +72 -0
- data/lib/fog/proxmox/identity/models/token_info.rb +41 -0
- data/lib/fog/proxmox/identity/models/tokens.rb +54 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/user.rb +24 -2
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/users.rb +2 -2
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/change_password.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/check_permissions.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/create_token.rb +40 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_user.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/delete_token.rb +40 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_user.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/get_token_info.rb +41 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_user.rb +1 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_domains.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_groups.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_permissions.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_pools.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_roles.rb +0 -0
- data/lib/fog/proxmox/identity/requests/list_tokens.rb +41 -0
- data/lib/fog/proxmox/identity/requests/list_user_permissions.rb +44 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_users.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/read_version.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_permissions.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/update_token.rb +41 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_user.rb +0 -0
- data/lib/fog/{identity/proxmox.rb → proxmox/identity.rb} +31 -17
- data/lib/fog/{network/proxmox → proxmox/network}/models/network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/models/networks.rb +2 -2
- data/lib/fog/{network/proxmox → proxmox/network}/models/node.rb +2 -1
- data/lib/fog/{network/proxmox → proxmox/network}/models/nodes.rb +2 -2
- data/lib/fog/{network/proxmox → proxmox/network}/requests/create_network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/delete_network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/get_network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/get_node.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/list_networks.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/list_nodes.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/power_node.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/update_network.rb +0 -0
- data/lib/fog/{network/proxmox.rb → proxmox/network.rb} +21 -14
- data/lib/fog/{storage/proxmox.rb → proxmox/storage.rb} +1 -1
- data/lib/fog/proxmox/string.rb +4 -3
- data/lib/fog/proxmox/version.rb +1 -1
- data/lib/fog/proxmox.rb +14 -76
- data/spec/compute_spec.rb +4 -4
- data/spec/fixtures/proxmox/compute/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/compute/containers.yml +1752 -7568
- data/spec/fixtures/proxmox/compute/nodes.yml +24 -30
- data/spec/fixtures/proxmox/compute/servers.yml +5015 -10683
- data/spec/fixtures/proxmox/compute/snapshots.yml +479 -1719
- data/spec/fixtures/proxmox/compute/storages.yml +32 -40
- data/spec/fixtures/proxmox/compute/tasks.yml +118 -338
- data/spec/fixtures/proxmox/identity/auth.yml +10 -12
- data/spec/fixtures/proxmox/identity/auth_access_ticket.yml +77 -0
- data/spec/fixtures/proxmox/identity/auth_user_token.yml +77 -0
- data/spec/fixtures/proxmox/identity/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/identity/domains.yml +145 -181
- data/spec/fixtures/proxmox/identity/groups.yml +72 -90
- data/spec/fixtures/proxmox/identity/permissions.yml +297 -189
- data/spec/fixtures/proxmox/identity/pools.yml +176 -421
- data/spec/fixtures/proxmox/identity/read_version.yml +7 -9
- data/spec/fixtures/proxmox/identity/roles.yml +69 -87
- data/spec/fixtures/proxmox/identity/tokens.yml +494 -0
- data/spec/fixtures/proxmox/identity/users.yml +149 -187
- data/spec/fixtures/proxmox/network/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/network/networks.yml +99 -96
- data/spec/hash_spec.rb +2 -1
- data/spec/helpers/controller_helper_spec.rb +135 -123
- data/spec/helpers/cpu_helper_spec.rb +57 -45
- data/spec/helpers/disk_helper_spec.rb +281 -187
- data/spec/helpers/ip_helper_spec.rb +155 -138
- data/spec/helpers/nic_helper_spec.rb +122 -114
- data/spec/identity_spec.rb +123 -29
- data/spec/network_spec.rb +3 -3
- data/spec/proxmox_vcr.rb +24 -22
- data/spec/spec_helper.rb +4 -3
- data/tasks/audit.rake +25 -0
- data/tasks/lint.rake +22 -0
- data/tasks/test.rake +65 -0
- metadata +205 -174
- data/.codeclimate.yml +0 -14
- data/spec/fixtures/proxmox/compute/identity_ticket.yml +0 -40
- data/spec/fixtures/proxmox/identity/identity_ticket.yml +0 -40
- data/spec/fixtures/proxmox/identity/renew.yml +0 -40
- data/spec/fixtures/proxmox/network/identity_ticket.yml +0 -40
data/spec/identity_spec.rb
CHANGED
@@ -22,18 +22,76 @@ require_relative './proxmox_vcr'
|
|
22
22
|
|
23
23
|
describe Fog::Proxmox::Identity do
|
24
24
|
before :all do
|
25
|
-
Excon.defaults[:ssl_ca_file] = 'spec/fixtures/proxmox/pve.home'
|
26
25
|
@proxmox_vcr = ProxmoxVCR.new(
|
27
26
|
vcr_directory: 'spec/fixtures/proxmox/identity',
|
28
27
|
service_class: Fog::Proxmox::Identity
|
29
28
|
)
|
30
29
|
@service = @proxmox_vcr.service
|
31
|
-
@
|
30
|
+
@proxmox_url = @proxmox_vcr.url
|
32
31
|
@username = @proxmox_vcr.username
|
33
32
|
@password = @proxmox_vcr.password
|
33
|
+
@tokenid = @proxmox_vcr.tokenid
|
34
|
+
@token = @proxmox_vcr.token
|
34
35
|
end
|
35
36
|
|
36
|
-
it '
|
37
|
+
it 'authenticates with access ticket' do
|
38
|
+
VCR.use_cassette('auth_access_ticket') do
|
39
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url,
|
40
|
+
proxmox_auth_method: Fog::Proxmox::Auth::Token::AccessTicket::NAME, proxmox_username: @username, proxmox_password: @password)
|
41
|
+
_(proc do
|
42
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url,
|
43
|
+
proxmox_auth_method: Fog::Proxmox::Auth::Token::AccessTicket::NAME, proxmox_username: @username, proxmox_password: 'wrong_password')
|
44
|
+
end).must_raise Excon::Errors::Unauthorized
|
45
|
+
_(proc do
|
46
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url, proxmox_username: @username, proxmox_password: @password)
|
47
|
+
end).must_raise ArgumentError
|
48
|
+
_(proc do
|
49
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url,
|
50
|
+
proxmox_auth_method: Fog::Proxmox::Auth::Token::AccessTicket::NAME, proxmox_password: @password)
|
51
|
+
end).must_raise Fog::Proxmox::Auth::Token::AccessTicket::URIError
|
52
|
+
_(proc do
|
53
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url,
|
54
|
+
proxmox_auth_method: Fog::Proxmox::Auth::Token::AccessTicket::NAME, proxmox_username: @username)
|
55
|
+
end).must_raise Fog::Proxmox::Auth::Token::AccessTicket::URIError
|
56
|
+
_(proc do
|
57
|
+
Fog::Proxmox::Identity.new(proxmox_auth_method: Fog::Proxmox::Auth::Token::AccessTicket::NAME,
|
58
|
+
proxmox_username: @username, proxmox_password: 'wrong_password')
|
59
|
+
end).must_raise ArgumentError
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'authenticates with user token' do
|
64
|
+
VCR.use_cassette('auth_user_token') do
|
65
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url,
|
66
|
+
proxmox_auth_method: Fog::Proxmox::Auth::Token::UserToken::NAME, proxmox_userid: @username, proxmox_tokenid: @tokenid, proxmox_token: @token)
|
67
|
+
_(proc do
|
68
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url,
|
69
|
+
proxmox_auth_method: Fog::Proxmox::Auth::Token::UserToken::NAME, proxmox_userid: @username, proxmox_tokenid: @tokenid, proxmox_token: 'wrong_token')
|
70
|
+
end).must_raise Excon::Errors::Unauthorized
|
71
|
+
_(proc do
|
72
|
+
Fog::Proxmox::Identity.new(proxmox_auth_method: Fog::Proxmox::Auth::Token::UserToken::NAME,
|
73
|
+
proxmox_userid: @username, proxmox_tokenid: @tokenid, proxmox_token: 'wrong_token')
|
74
|
+
end).must_raise ArgumentError
|
75
|
+
_(proc do
|
76
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url, proxmox_userid: @username, proxmox_tokenid: @tokenid,
|
77
|
+
proxmox_token: 'wrong_token')
|
78
|
+
end).must_raise ArgumentError
|
79
|
+
_(proc do
|
80
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url,
|
81
|
+
proxmox_auth_method: Fog::Proxmox::Auth::Token::UserToken::NAME, proxmox_userid: @username, proxmox_token: @token)
|
82
|
+
end).must_raise Fog::Proxmox::Auth::Token::UserToken::URIError
|
83
|
+
_(proc do
|
84
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url,
|
85
|
+
proxmox_auth_method: Fog::Proxmox::Auth::Token::UserToken::NAME, proxmox_tokenid: @tokenid, proxmox_token: @token)
|
86
|
+
end).must_raise Fog::Proxmox::Auth::Token::UserToken::URIError
|
87
|
+
_(proc do
|
88
|
+
Fog::Proxmox::Identity.new(proxmox_url: @proxmox_url,
|
89
|
+
proxmox_auth_method: Fog::Proxmox::Auth::Token::UserToken::NAME, proxmox_userid: @username, proxmox_tokenid: @tokenid)
|
90
|
+
end).must_raise Fog::Proxmox::Auth::Token::UserToken::URIError
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'checks access ticket with path and privs' do
|
37
95
|
VCR.use_cassette('auth') do
|
38
96
|
principal = { username: @username, password: @password, privs: ['User.Modify'], path: 'access', otp: 'proxmox01' }
|
39
97
|
permissions = @service.check_permissions(principal)
|
@@ -44,26 +102,6 @@ describe Fog::Proxmox::Identity do
|
|
44
102
|
end
|
45
103
|
end
|
46
104
|
|
47
|
-
it 'renew expired ticket' do
|
48
|
-
VCR.use_cassette('renew') do
|
49
|
-
@connection_options = {}
|
50
|
-
# ignore enterprise proxy
|
51
|
-
@connection_options[:disable_proxy] = true if ENV['DISABLE_PROXY'] == 'true'
|
52
|
-
# ignore dev certificates on servers
|
53
|
-
@connection_options[:ssl_verify_peer] = false if ENV['SSL_VERIFY_PEER'] == 'false'
|
54
|
-
connection_params = {
|
55
|
-
pve_url: @pve_url,
|
56
|
-
pve_username: @username,
|
57
|
-
pve_password: @password,
|
58
|
-
pve_ticket_lifetime: - (100 * 60 * 60), # ticket has expired from 100 hours
|
59
|
-
connection_options: @connection_options
|
60
|
-
}
|
61
|
-
_(Fog::Proxmox.credentials_has_expired?).must_equal false
|
62
|
-
Fog::Proxmox.authenticate(connection_params)
|
63
|
-
_(Fog::Proxmox.credentials_has_expired?).must_equal true
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
105
|
it 'reads server version' do
|
68
106
|
VCR.use_cassette('read_version') do
|
69
107
|
version = @service.read_version
|
@@ -207,7 +245,7 @@ describe Fog::Proxmox::Identity do
|
|
207
245
|
_(proc do
|
208
246
|
@service.domains.create(ldap_hash)
|
209
247
|
end).must_raise Excon::Errors::InternalServerError
|
210
|
-
#
|
248
|
+
# Create 2nd time must fails
|
211
249
|
_(proc do
|
212
250
|
@service.domains.create(ad_hash)
|
213
251
|
end).must_raise Excon::Errors::InternalServerError
|
@@ -217,10 +255,10 @@ describe Fog::Proxmox::Identity do
|
|
217
255
|
ldap.update
|
218
256
|
# Find by id
|
219
257
|
ad = @service.domains.get ad_hash[:realm]
|
220
|
-
|
258
|
+
_(ad).wont_be_nil
|
221
259
|
ad.type.tfa = 'type=yubico,id=1,key=2,url=http://localhost'
|
222
260
|
ad.update
|
223
|
-
#
|
261
|
+
# all groups
|
224
262
|
domains_all = @service.domains.all
|
225
263
|
_(domains_all).wont_be_nil
|
226
264
|
_(domains_all).wont_be_empty
|
@@ -246,8 +284,12 @@ describe Fog::Proxmox::Identity do
|
|
246
284
|
lastname: 'Sinclar',
|
247
285
|
email: 'bobsinclar@proxmox.com'
|
248
286
|
}
|
249
|
-
|
250
|
-
|
287
|
+
role_hash = {
|
288
|
+
roleid: 'PVETestAdmin',
|
289
|
+
privs: 'User.Modify,Group.Allocate'
|
290
|
+
}
|
291
|
+
@service.roles.create(role_hash)
|
292
|
+
role = @service.roles.get(role_hash[:roleid])
|
251
293
|
_(role).wont_be_nil
|
252
294
|
@service.users.create(bob_hash)
|
253
295
|
bob = @service.users.get bob_hash[:userid]
|
@@ -258,6 +300,10 @@ describe Fog::Proxmox::Identity do
|
|
258
300
|
permissions = @service.permissions.all
|
259
301
|
_(permissions).wont_be_empty
|
260
302
|
_(permissions).must_include permission
|
303
|
+
# Read user permissions
|
304
|
+
_(bob.permissions).wont_be_empty
|
305
|
+
_(bob.permissions.keys).must_include '/access'
|
306
|
+
_(bob.permissions.keys).must_include '/access/groups'
|
261
307
|
# Remove ACL to users
|
262
308
|
permissions.destroy(type: 'user', roleid: role.roleid, path: '/access', ugid: bob.userid)
|
263
309
|
permission = @service.permissions.get('user', role.roleid, '/access', bob.userid)
|
@@ -266,7 +312,8 @@ describe Fog::Proxmox::Identity do
|
|
266
312
|
bob.destroy
|
267
313
|
# Add ACL to groups
|
268
314
|
group1 = @service.groups.create(groupid: 'group1', comment: 'Group 1')
|
269
|
-
permission = @service.permissions.create(type: 'group', roleid: role.roleid, path: '/access',
|
315
|
+
permission = @service.permissions.create(type: 'group', roleid: role.roleid, path: '/access',
|
316
|
+
ugid: group1.groupid)
|
270
317
|
_(permission).wont_be_nil
|
271
318
|
# Read new permission
|
272
319
|
permissions = @service.permissions.all
|
@@ -278,6 +325,8 @@ describe Fog::Proxmox::Identity do
|
|
278
325
|
_(permissions).must_be_empty
|
279
326
|
group1.destroy
|
280
327
|
role.destroy
|
328
|
+
role = @service.roles.get(role_hash[:roleid])
|
329
|
+
_(role).must_be_nil
|
281
330
|
end
|
282
331
|
end
|
283
332
|
|
@@ -319,4 +368,49 @@ describe Fog::Proxmox::Identity do
|
|
319
368
|
_(pool).must_be_nil
|
320
369
|
end
|
321
370
|
end
|
371
|
+
|
372
|
+
it 'CRUD user tokens' do
|
373
|
+
VCR.use_cassette('tokens') do
|
374
|
+
# Get user
|
375
|
+
bob_hash = {
|
376
|
+
userid: 'bobsinclar@pve',
|
377
|
+
password: 'bobsinclar1',
|
378
|
+
firstname: 'Bob',
|
379
|
+
lastname: 'Sinclar',
|
380
|
+
email: 'bobsinclar@proxmox.com'
|
381
|
+
}
|
382
|
+
token_hash = {
|
383
|
+
userid: bob_hash[:userid],
|
384
|
+
tokenid: 'bobsinclar1'
|
385
|
+
}
|
386
|
+
@service.users.create(bob_hash)
|
387
|
+
bob = @service.users.get token_hash[:userid]
|
388
|
+
_(bob).wont_be_nil
|
389
|
+
# Create Token
|
390
|
+
token = bob.tokens.create(token_hash)
|
391
|
+
token_info = token.info
|
392
|
+
_(token_info).wont_be_nil
|
393
|
+
# all user tokens
|
394
|
+
tokens_all = bob.tokens.all
|
395
|
+
_(tokens_all).wont_be_nil
|
396
|
+
_(tokens_all).wont_be_empty
|
397
|
+
_(tokens_all).must_include token
|
398
|
+
# Find token info by tokenid
|
399
|
+
token_get = bob.tokens.get(token_hash[:tokenid])
|
400
|
+
_(token_get).wont_be_nil
|
401
|
+
_(token_get).must_equal token
|
402
|
+
# Update
|
403
|
+
token.comment = 'test'
|
404
|
+
token.expire = 0
|
405
|
+
token.privsep = 0
|
406
|
+
token.update
|
407
|
+
# Delete
|
408
|
+
token.destroy
|
409
|
+
token = bob.tokens.get token_hash[:tokenid]
|
410
|
+
_(token).must_be_nil
|
411
|
+
bob.destroy
|
412
|
+
bob = @service.users.get bob_hash[:userid]
|
413
|
+
_(bob).must_be_nil
|
414
|
+
end
|
415
|
+
end
|
322
416
|
end
|
data/spec/network_spec.rb
CHANGED
@@ -27,11 +27,11 @@ describe Fog::Proxmox::Network do
|
|
27
27
|
service_class: Fog::Proxmox::Network
|
28
28
|
)
|
29
29
|
@service = @proxmox_vcr.service
|
30
|
-
@
|
30
|
+
@proxmox_url = @proxmox_vcr.url
|
31
31
|
@username = @proxmox_vcr.username
|
32
32
|
@password = @proxmox_vcr.password
|
33
|
-
@
|
34
|
-
@
|
33
|
+
@tokenid = @proxmox_vcr.tokenid
|
34
|
+
@token = @proxmox_vcr.token
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'CRUD networks' do
|
data/spec/proxmox_vcr.rb
CHANGED
@@ -20,35 +20,34 @@
|
|
20
20
|
|
21
21
|
# There are basically two modes of operation for these specs.
|
22
22
|
#
|
23
|
-
# 1. ENV[
|
23
|
+
# 1. ENV[PROXMOX_URL] exists: talk to an actual Proxmox server and record HTTP
|
24
24
|
# traffic in VCRs at "spec/debug" (credentials are read from the conventional
|
25
|
-
# environment variables:
|
25
|
+
# environment variables: PROXMOX_URL, PROXMOX_USERNAME, PROXMOX_PASSWORD)
|
26
26
|
# 2. otherwise (Travis etc.): use VCRs at "spec/fixtures/proxmox/#{service}"
|
27
27
|
|
28
28
|
require 'vcr'
|
29
|
+
require 'fog/proxmox/auth/token'
|
29
30
|
|
30
31
|
class ProxmoxVCR
|
31
32
|
attr_reader :username,
|
32
33
|
:password,
|
33
|
-
:
|
34
|
-
:
|
34
|
+
:tokenid,
|
35
|
+
:token,
|
35
36
|
:service,
|
36
|
-
:url
|
37
|
-
:path,
|
38
|
-
:deadline
|
37
|
+
:url
|
39
38
|
|
40
39
|
def initialize(options)
|
41
40
|
@vcr_directory = options[:vcr_directory]
|
42
41
|
@service_class = options[:service_class]
|
43
42
|
@connection_options = options[:connection_options] || {}
|
44
43
|
|
45
|
-
use_recorded = !ENV.key?('
|
44
|
+
use_recorded = !ENV.key?('PROXMOX_URL') || ENV['USE_VCR'] == 'true'
|
46
45
|
|
47
46
|
if use_recorded
|
48
47
|
Fog.interval = 0
|
49
48
|
@url = 'https://192.168.56.101:8006/api2/json'
|
50
49
|
else
|
51
|
-
@url = ENV['
|
50
|
+
@url = ENV['PROXMOX_URL']
|
52
51
|
end
|
53
52
|
|
54
53
|
VCR.configure do |config|
|
@@ -65,27 +64,30 @@ class ProxmoxVCR
|
|
65
64
|
config.debug_logger = nil # use $stderr to debug
|
66
65
|
end
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
# ignore dev certificates on servers
|
72
|
-
@connection_options[:ssl_verify_peer] = false if ENV['SSL_VERIFY_PEER'] == 'false'
|
73
|
-
|
74
|
-
VCR.use_cassette('identity_ticket') do
|
75
|
-
Fog::Proxmox.clear_credentials
|
67
|
+
VCR.use_cassette('common_auth') do
|
68
|
+
Fog::Proxmox.clear_token_cache
|
76
69
|
|
70
|
+
@auth_method = Fog::Proxmox::Auth::Token::AccessTicket::NAME
|
77
71
|
@username = 'root@pam'
|
78
72
|
@password = 'proxmox01'
|
73
|
+
@tokenid = 'root1'
|
74
|
+
@token = 'ed6402b4-641d-46b1-b20a-33ba9ba12f54'
|
79
75
|
|
80
76
|
unless use_recorded
|
81
|
-
@
|
82
|
-
@
|
77
|
+
@auth_method = ENV['PROXMOX_AUTH_METHOD'] || options[:auth_method] || @auth_method
|
78
|
+
@username = ENV['PROXMOX_USERNAME'] || options[:username] || @username
|
79
|
+
@password = ENV['PROXMOX_PASSWORD'] || options[:password] || @password
|
80
|
+
@tokenid = ENV['PROXMOX_TOKENID'] || options[:tokenid] || @tokenid
|
81
|
+
@token = ENV['PROXMOX_TOKEN'] || options[:token] || @token
|
83
82
|
end
|
84
83
|
|
85
84
|
connection_params = {
|
86
|
-
|
87
|
-
|
88
|
-
|
85
|
+
proxmox_url: @url,
|
86
|
+
proxmox_auth_method: @auth_method,
|
87
|
+
proxmox_username: @username,
|
88
|
+
proxmox_password: @password,
|
89
|
+
proxmox_tokenid: @tokenid,
|
90
|
+
proxmox_token: @token,
|
89
91
|
connection_options: @connection_options
|
90
92
|
}
|
91
93
|
|
data/spec/spec_helper.rb
CHANGED
@@ -23,9 +23,10 @@ require 'simplecov'
|
|
23
23
|
SimpleCov.start do
|
24
24
|
add_filter '/spec/'
|
25
25
|
add_group 'Core', 'lib/fog/proxmox'
|
26
|
-
add_group '
|
27
|
-
add_group '
|
28
|
-
add_group '
|
26
|
+
add_group 'Auth', 'lib/fog/proxmox/auth'
|
27
|
+
add_group 'Identity', 'lib/fog/proxmox/identity'
|
28
|
+
add_group 'Compute', 'lib/fog/proxmox/compute'
|
29
|
+
add_group 'Network', 'lib/fog/proxmox/network'
|
29
30
|
end
|
30
31
|
|
31
32
|
require 'minitest/autorun'
|
data/tasks/audit.rake
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Tristan Robert
|
4
|
+
|
5
|
+
# This file is part of Fog::Proxmox.
|
6
|
+
|
7
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
|
12
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'bundler/audit/task'
|
21
|
+
|
22
|
+
Bundler::Audit::Task.new
|
23
|
+
|
24
|
+
desc 'Run audit vulnerabilities'
|
25
|
+
task audit: 'bundle:audit'
|
data/tasks/lint.rake
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Tristan Robert
|
4
|
+
|
5
|
+
# This file is part of Fog::Proxmox.
|
6
|
+
|
7
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
|
12
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'rubocop/rake_task'
|
21
|
+
|
22
|
+
RuboCop::RakeTask.new
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Tristan Robert
|
4
|
+
|
5
|
+
# This file is part of Fog::Proxmox.
|
6
|
+
|
7
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
|
12
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
namespace :spec do
|
21
|
+
desc 'Run fog-proxmox spec/*'
|
22
|
+
Rake::TestTask.new do |t|
|
23
|
+
t.name = 'all'
|
24
|
+
t.description = 'Run all specs'
|
25
|
+
t.libs.push %w[lib spec]
|
26
|
+
t.pattern = 'spec/**/*_spec.rb'
|
27
|
+
t.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Run fog-proxmox spec/helpers/*'
|
31
|
+
Rake::TestTask.new do |t|
|
32
|
+
t.name = 'helpers'
|
33
|
+
t.description = 'Run helpers tests'
|
34
|
+
t.libs.push %w[lib spec]
|
35
|
+
t.pattern = 'spec/helpers/**/*_spec.rb'
|
36
|
+
t.verbose = true
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'Run fog-proxmox spec/compute'
|
40
|
+
Rake::TestTask.new do |t|
|
41
|
+
t.name = 'compute'
|
42
|
+
t.description = 'Run compute API tests'
|
43
|
+
t.libs.push %w[lib spec]
|
44
|
+
t.pattern = 'spec/**/compute_spec.rb'
|
45
|
+
t.verbose = true
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'Run fog-proxmox spec/identity'
|
49
|
+
Rake::TestTask.new do |t|
|
50
|
+
t.name = 'identity'
|
51
|
+
t.description = 'Run identity API tests'
|
52
|
+
t.libs.push %w[lib spec]
|
53
|
+
t.pattern = 'spec/**/identity_spec.rb'
|
54
|
+
t.verbose = true
|
55
|
+
end
|
56
|
+
|
57
|
+
desc 'Run fog-proxmox spec/network'
|
58
|
+
Rake::TestTask.new do |t|
|
59
|
+
t.name = 'network'
|
60
|
+
t.description = 'Run network API tests'
|
61
|
+
t.libs.push %w[lib spec]
|
62
|
+
t.pattern = 'spec/**/network_spec.rb'
|
63
|
+
t.verbose = true
|
64
|
+
end
|
65
|
+
end
|