proxmox-api 1.0.1 → 1.1.0
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 +4 -4
- data/lib/proxmox_api.rb +15 -3
- metadata +7 -10
- data/spec/api_path_spec.rb +0 -42
- data/spec/spec_helper.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f471fb9bb0268e38e3b45da32b2572d29a53d9805e4702e47a6a0c784351f971
|
4
|
+
data.tar.gz: 0364feb0db15bea88f86358ca5299e6c16a70f56a045024db1c63957defa26ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4172c20fc513e1772ab19d0acdd94d2393601ac5a6ad4067a24e30ac52698208580d2a011ee2047d0d41edf93a081aeaf2ae988fbaf4f78b2da94a72c1c16d29
|
7
|
+
data.tar.gz: 95d4895f5e6323b6f0ab9fb79b3bc64e36ed8a735b3d3f9f80fb244db5559f0d744ba587ca047de6290b5dc6408d62124f3754f9357fa4bc4c85ac93613ffd54
|
data/lib/proxmox_api.rb
CHANGED
@@ -8,7 +8,8 @@ require 'json'
|
|
8
8
|
#
|
9
9
|
# @author Eugene Lapeko
|
10
10
|
class ProxmoxAPI
|
11
|
-
AUTH_PARAMS
|
11
|
+
AUTH_PARAMS = %i[username realm password otp].freeze
|
12
|
+
RESOURCE_OPTIONS = %i[headers].freeze
|
12
13
|
REST_METHODS = %i[get post put delete].freeze
|
13
14
|
|
14
15
|
# This class is used to collect api path before request
|
@@ -64,6 +65,8 @@ class ProxmoxAPI
|
|
64
65
|
# @option options [String] :username - username to be used for connection
|
65
66
|
# @option options [String] :password - password to be used for connection
|
66
67
|
# @option options [String] :realm - auth realm, can be given in :username ('user@realm')
|
68
|
+
# @option options [String] :token - token to be used instead of username, password, and realm
|
69
|
+
# @option options [String] :secret - secret to be used with token
|
67
70
|
# @option options [String] :otp - one-time password for two-factor auth
|
68
71
|
#
|
69
72
|
# @option options [Boolean] :verify_ssl - verify server certificate
|
@@ -71,11 +74,15 @@ class ProxmoxAPI
|
|
71
74
|
# You can also pass here all ssl options supported by rest-client gem
|
72
75
|
# @see https://github.com/rest-client/rest-client
|
73
76
|
def initialize(cluster, options)
|
77
|
+
if options.key?(:token) && options.key?(:secret)
|
78
|
+
options[:headers] = { Authorization: "PVEAPIToken=#{options[:token]}=#{options[:secret]}" }
|
79
|
+
end
|
80
|
+
|
74
81
|
@connection = RestClient::Resource.new(
|
75
82
|
"https://#{cluster}:#{options[:port] || 8006}/api2/json/",
|
76
|
-
options.select { |k, _v|
|
83
|
+
options.select { |k, _v| connection_options.include?(k.to_s) }
|
77
84
|
)
|
78
|
-
@auth_ticket = create_auth_ticket(options.select { |k, _v| AUTH_PARAMS.include? k })
|
85
|
+
@auth_ticket = options.key?(:token) ? {} : create_auth_ticket(options.select { |k, _v| AUTH_PARAMS.include? k })
|
79
86
|
end
|
80
87
|
|
81
88
|
def [](index)
|
@@ -90,6 +97,11 @@ class ProxmoxAPI
|
|
90
97
|
true
|
91
98
|
end
|
92
99
|
|
100
|
+
# The list of options to be passed to RestClient object
|
101
|
+
def self.connection_options
|
102
|
+
RestClient::Request::SSLOptionList.unshift('verify_ssl') + RESOURCE_OPTIONS
|
103
|
+
end
|
104
|
+
|
93
105
|
private
|
94
106
|
|
95
107
|
def raise_on_failure(response, message = 'Proxmox API request failed')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxmox-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Lapeko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -89,12 +89,11 @@ files:
|
|
89
89
|
- Gemfile
|
90
90
|
- LICENSE
|
91
91
|
- lib/proxmox_api.rb
|
92
|
-
- spec/api_path_spec.rb
|
93
|
-
- spec/spec_helper.rb
|
94
92
|
homepage: https://github.com/L-Eugene/proxmox-api
|
95
93
|
licenses:
|
96
94
|
- MIT
|
97
|
-
metadata:
|
95
|
+
metadata:
|
96
|
+
rubygems_mfa_required: 'true'
|
98
97
|
post_install_message:
|
99
98
|
rdoc_options: []
|
100
99
|
require_paths:
|
@@ -103,17 +102,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
102
|
requirements:
|
104
103
|
- - ">="
|
105
104
|
- !ruby/object:Gem::Version
|
106
|
-
version: '2.
|
105
|
+
version: '2.5'
|
107
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
107
|
requirements:
|
109
108
|
- - ">="
|
110
109
|
- !ruby/object:Gem::Version
|
111
110
|
version: '0'
|
112
111
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.1.6
|
114
113
|
signing_key:
|
115
114
|
specification_version: 4
|
116
115
|
summary: Proxmox VE REST API wrapper
|
117
|
-
test_files:
|
118
|
-
- spec/spec_helper.rb
|
119
|
-
- spec/api_path_spec.rb
|
116
|
+
test_files: []
|
data/spec/api_path_spec.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rspec'
|
4
|
-
|
5
|
-
describe 'ApiPath' do
|
6
|
-
before(:each) do
|
7
|
-
@api_object = double('ProxmoxAPI')
|
8
|
-
allow(@api_object).to receive(:is_a?).with(ProxmoxAPI) { true }
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'raises exception when object is not ProxmoxAPI' do
|
12
|
-
[1, 'String', Class].each do |item|
|
13
|
-
expect { ProxmoxAPI::ApiPath.new(item) }.to raise_error(ArgumentError)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'collects api path using methods' do
|
18
|
-
expect(ProxmoxAPI::ApiPath.new(@api_object).ticket.to_s).to eq 'ticket'
|
19
|
-
expect(ProxmoxAPI::ApiPath.new(@api_object).nodes.pve1.to_s).to eq 'nodes/pve1'
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'collects api path using []' do
|
23
|
-
expect(ProxmoxAPI::ApiPath.new(@api_object)[:ticket].to_s).to eq 'ticket'
|
24
|
-
expect(ProxmoxAPI::ApiPath.new(@api_object)[:nodes]['pve1'][15].to_s).to eq 'nodes/pve1/15'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'collects api path combining [] and methods' do
|
28
|
-
expect(ProxmoxAPI::ApiPath.new(@api_object).nodes['pve1'].lxc.to_s).to eq 'nodes/pve1/lxc'
|
29
|
-
end
|
30
|
-
|
31
|
-
%i[get post delete put].each do |method|
|
32
|
-
it "should send #{method} to ProxmoxAPI" do
|
33
|
-
expect(@api_object).to receive(:submit).with(method, 'nodes/pve')
|
34
|
-
ProxmoxAPI::ApiPath.new(@api_object).nodes.pve.__send__(method)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should send #{method}! to ProxmoxAPI" do
|
38
|
-
expect(@api_object).to receive(:submit).with("#{method}!".to_sym, 'nodes/pve')
|
39
|
-
ProxmoxAPI::ApiPath.new(@api_object).nodes.pve.__send__("#{method}!")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'proxmox_api'
|
4
|
-
|
5
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
6
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
7
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
8
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
9
|
-
# files.
|
10
|
-
#
|
11
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
12
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
13
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
14
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
15
|
-
# a separate helper file that requires the additional dependencies and performs
|
16
|
-
# the additional setup, and require it from the spec files that actually need
|
17
|
-
# it.
|
18
|
-
#
|
19
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
20
|
-
RSpec.configure do |config|
|
21
|
-
# rspec-expectations config goes here. You can use an alternate
|
22
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
23
|
-
# assertions if you prefer.
|
24
|
-
config.expect_with :rspec do |expectations|
|
25
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
26
|
-
# and `failure_message` of custom matchers include text for helper methods
|
27
|
-
# defined using `chain`, e.g.:
|
28
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
29
|
-
# # => "be bigger than 2 and smaller than 4"
|
30
|
-
# ...rather than:
|
31
|
-
# # => "be bigger than 2"
|
32
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
33
|
-
end
|
34
|
-
|
35
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
36
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
37
|
-
config.mock_with :rspec do |mocks|
|
38
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
39
|
-
# a real object. This is generally recommended, and will default to
|
40
|
-
# `true` in RSpec 4.
|
41
|
-
mocks.verify_partial_doubles = true
|
42
|
-
end
|
43
|
-
|
44
|
-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
45
|
-
# have no way to turn it off -- the option exists only for backwards
|
46
|
-
# compatibility in RSpec 3). It causes shared context metadata to be
|
47
|
-
# inherited by the metadata hash of host groups and examples, rather than
|
48
|
-
# triggering implicit auto-inclusion in groups with matching metadata.
|
49
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
50
|
-
end
|