fog-proxmox 0.4.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.
Files changed (199) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/config +4 -0
  3. data/.codeclimate.yml +14 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  6. data/.gitignore +5 -0
  7. data/.gitlab-ci.yml +42 -0
  8. data/.rubocop.yml +13 -0
  9. data/.ruby-gemset +1 -0
  10. data/.solargraph.yml +10 -0
  11. data/.travis.yml +26 -0
  12. data/.vscode/launch.json +114 -0
  13. data/.vscode/settings.json +45 -0
  14. data/.vscode/tasks.json +27 -0
  15. data/CODE_OF_CONDUCT.md +74 -0
  16. data/CONTRIBUTING.md +20 -0
  17. data/CONTRIBUTORS.md +9 -0
  18. data/Gemfile +23 -0
  19. data/Gemfile.lock +146 -0
  20. data/ISSUE_TEMPLATE.md +43 -0
  21. data/LICENSE +674 -0
  22. data/README.md +58 -0
  23. data/Rakefile +53 -0
  24. data/SUPPORT.md +9 -0
  25. data/bin/console +29 -0
  26. data/bin/setup +29 -0
  27. data/docs/compute.md +846 -0
  28. data/docs/connection_parameters.md +45 -0
  29. data/docs/getting_started.md +53 -0
  30. data/docs/identity.md +357 -0
  31. data/examples/compute.rb +279 -0
  32. data/examples/identity.rb +195 -0
  33. data/fog-proxmox.gemspec +63 -0
  34. data/fogproxmox.png +0 -0
  35. data/lib/fog/compute/proxmox.rb +131 -0
  36. data/lib/fog/compute/proxmox/models/container.rb +97 -0
  37. data/lib/fog/compute/proxmox/models/container_config.rb +90 -0
  38. data/lib/fog/compute/proxmox/models/containers.rb +40 -0
  39. data/lib/fog/compute/proxmox/models/disk.rb +67 -0
  40. data/lib/fog/compute/proxmox/models/disks.rb +49 -0
  41. data/lib/fog/compute/proxmox/models/interface.rb +50 -0
  42. data/lib/fog/compute/proxmox/models/interfaces.rb +46 -0
  43. data/lib/fog/compute/proxmox/models/node.rb +93 -0
  44. data/lib/fog/compute/proxmox/models/nodes.rb +45 -0
  45. data/lib/fog/compute/proxmox/models/server.rb +212 -0
  46. data/lib/fog/compute/proxmox/models/server_config.rb +116 -0
  47. data/lib/fog/compute/proxmox/models/servers.rb +70 -0
  48. data/lib/fog/compute/proxmox/models/snapshot.rb +70 -0
  49. data/lib/fog/compute/proxmox/models/snapshots.rb +55 -0
  50. data/lib/fog/compute/proxmox/models/storage.rb +61 -0
  51. data/lib/fog/compute/proxmox/models/storages.rb +60 -0
  52. data/lib/fog/compute/proxmox/models/task.rb +84 -0
  53. data/lib/fog/compute/proxmox/models/tasks.rb +71 -0
  54. data/lib/fog/compute/proxmox/models/volume.rb +61 -0
  55. data/lib/fog/compute/proxmox/models/volumes.rb +67 -0
  56. data/lib/fog/compute/proxmox/requests/action_server.rb +47 -0
  57. data/lib/fog/compute/proxmox/requests/check_vmid.rb +41 -0
  58. data/lib/fog/compute/proxmox/requests/clone_server.rb +46 -0
  59. data/lib/fog/compute/proxmox/requests/create_backup.rb +44 -0
  60. data/lib/fog/compute/proxmox/requests/create_server.rb +45 -0
  61. data/lib/fog/compute/proxmox/requests/create_snapshot.rb +47 -0
  62. data/lib/fog/compute/proxmox/requests/create_spice.rb +46 -0
  63. data/lib/fog/compute/proxmox/requests/create_term.rb +46 -0
  64. data/lib/fog/compute/proxmox/requests/create_vnc.rb +46 -0
  65. data/lib/fog/compute/proxmox/requests/delete_server.rb +47 -0
  66. data/lib/fog/compute/proxmox/requests/delete_snapshot.rb +48 -0
  67. data/lib/fog/compute/proxmox/requests/delete_volume.rb +40 -0
  68. data/lib/fog/compute/proxmox/requests/get_node.rb +44 -0
  69. data/lib/fog/compute/proxmox/requests/get_server_config.rb +45 -0
  70. data/lib/fog/compute/proxmox/requests/get_server_status.rb +45 -0
  71. data/lib/fog/compute/proxmox/requests/get_snapshot.rb +47 -0
  72. data/lib/fog/compute/proxmox/requests/get_storage.rb +44 -0
  73. data/lib/fog/compute/proxmox/requests/get_task.rb +44 -0
  74. data/lib/fog/compute/proxmox/requests/get_vnc.rb +46 -0
  75. data/lib/fog/compute/proxmox/requests/get_volume.rb +42 -0
  76. data/lib/fog/compute/proxmox/requests/list_nodes.rb +42 -0
  77. data/lib/fog/compute/proxmox/requests/list_servers.rb +42 -0
  78. data/lib/fog/compute/proxmox/requests/list_snapshots.rb +43 -0
  79. data/lib/fog/compute/proxmox/requests/list_storages.rb +42 -0
  80. data/lib/fog/compute/proxmox/requests/list_tasks.rb +42 -0
  81. data/lib/fog/compute/proxmox/requests/list_volumes.rb +42 -0
  82. data/lib/fog/compute/proxmox/requests/log_task.rb +45 -0
  83. data/lib/fog/compute/proxmox/requests/migrate_server.rb +44 -0
  84. data/lib/fog/compute/proxmox/requests/move_disk.rb +46 -0
  85. data/lib/fog/compute/proxmox/requests/move_volume.rb +46 -0
  86. data/lib/fog/compute/proxmox/requests/next_vmid.rb +39 -0
  87. data/lib/fog/compute/proxmox/requests/resize_container.rb +46 -0
  88. data/lib/fog/compute/proxmox/requests/resize_server.rb +43 -0
  89. data/lib/fog/compute/proxmox/requests/rollback_snapshot.rb +46 -0
  90. data/lib/fog/compute/proxmox/requests/status_task.rb +44 -0
  91. data/lib/fog/compute/proxmox/requests/stop_task.rb +41 -0
  92. data/lib/fog/compute/proxmox/requests/template_server.rb +43 -0
  93. data/lib/fog/compute/proxmox/requests/update_server.rb +46 -0
  94. data/lib/fog/compute/proxmox/requests/update_snapshot.rb +45 -0
  95. data/lib/fog/identity/proxmox.rb +132 -0
  96. data/lib/fog/identity/proxmox/models/activedirectory.rb +57 -0
  97. data/lib/fog/identity/proxmox/models/domain.rb +61 -0
  98. data/lib/fog/identity/proxmox/models/domains.rb +115 -0
  99. data/lib/fog/identity/proxmox/models/group.rb +60 -0
  100. data/lib/fog/identity/proxmox/models/groups.rb +50 -0
  101. data/lib/fog/identity/proxmox/models/ldap.rb +57 -0
  102. data/lib/fog/identity/proxmox/models/oath.rb +50 -0
  103. data/lib/fog/identity/proxmox/models/pam.rb +46 -0
  104. data/lib/fog/identity/proxmox/models/permission.rb +69 -0
  105. data/lib/fog/identity/proxmox/models/permissions.rb +61 -0
  106. data/lib/fog/identity/proxmox/models/pool.rb +84 -0
  107. data/lib/fog/identity/proxmox/models/pools.rb +50 -0
  108. data/lib/fog/identity/proxmox/models/principal.rb +47 -0
  109. data/lib/fog/identity/proxmox/models/pve.rb +46 -0
  110. data/lib/fog/identity/proxmox/models/role.rb +61 -0
  111. data/lib/fog/identity/proxmox/models/roles.rb +51 -0
  112. data/lib/fog/identity/proxmox/models/user.rb +74 -0
  113. data/lib/fog/identity/proxmox/models/users.rb +50 -0
  114. data/lib/fog/identity/proxmox/models/yubico.rb +51 -0
  115. data/lib/fog/identity/proxmox/requests/add_permission.rb +41 -0
  116. data/lib/fog/identity/proxmox/requests/change_password.rb +41 -0
  117. data/lib/fog/identity/proxmox/requests/check_permissions.rb +44 -0
  118. data/lib/fog/identity/proxmox/requests/create_domain.rb +40 -0
  119. data/lib/fog/identity/proxmox/requests/create_group.rb +40 -0
  120. data/lib/fog/identity/proxmox/requests/create_pool.rb +40 -0
  121. data/lib/fog/identity/proxmox/requests/create_role.rb +40 -0
  122. data/lib/fog/identity/proxmox/requests/create_user.rb +40 -0
  123. data/lib/fog/identity/proxmox/requests/delete_domain.rb +40 -0
  124. data/lib/fog/identity/proxmox/requests/delete_group.rb +40 -0
  125. data/lib/fog/identity/proxmox/requests/delete_pool.rb +39 -0
  126. data/lib/fog/identity/proxmox/requests/delete_role.rb +40 -0
  127. data/lib/fog/identity/proxmox/requests/delete_user.rb +39 -0
  128. data/lib/fog/identity/proxmox/requests/get_domain.rb +41 -0
  129. data/lib/fog/identity/proxmox/requests/get_group.rb +41 -0
  130. data/lib/fog/identity/proxmox/requests/get_pool.rb +41 -0
  131. data/lib/fog/identity/proxmox/requests/get_role.rb +41 -0
  132. data/lib/fog/identity/proxmox/requests/get_user.rb +40 -0
  133. data/lib/fog/identity/proxmox/requests/list_domains.rb +41 -0
  134. data/lib/fog/identity/proxmox/requests/list_groups.rb +41 -0
  135. data/lib/fog/identity/proxmox/requests/list_permissions.rb +41 -0
  136. data/lib/fog/identity/proxmox/requests/list_pools.rb +41 -0
  137. data/lib/fog/identity/proxmox/requests/list_roles.rb +41 -0
  138. data/lib/fog/identity/proxmox/requests/list_users.rb +42 -0
  139. data/lib/fog/identity/proxmox/requests/read_version.rb +43 -0
  140. data/lib/fog/identity/proxmox/requests/remove_permission.rb +42 -0
  141. data/lib/fog/identity/proxmox/requests/update_domain.rb +41 -0
  142. data/lib/fog/identity/proxmox/requests/update_group.rb +41 -0
  143. data/lib/fog/identity/proxmox/requests/update_pool.rb +41 -0
  144. data/lib/fog/identity/proxmox/requests/update_role.rb +41 -0
  145. data/lib/fog/identity/proxmox/requests/update_user.rb +41 -0
  146. data/lib/fog/network/proxmox.rb +83 -0
  147. data/lib/fog/network/proxmox/models/network.rb +82 -0
  148. data/lib/fog/network/proxmox/models/networks.rb +54 -0
  149. data/lib/fog/network/proxmox/models/node.rb +70 -0
  150. data/lib/fog/network/proxmox/models/nodes.rb +45 -0
  151. data/lib/fog/network/proxmox/requests/create_network.rb +44 -0
  152. data/lib/fog/network/proxmox/requests/delete_network.rb +45 -0
  153. data/lib/fog/network/proxmox/requests/get_network.rb +46 -0
  154. data/lib/fog/network/proxmox/requests/get_node.rb +44 -0
  155. data/lib/fog/network/proxmox/requests/list_networks.rb +43 -0
  156. data/lib/fog/network/proxmox/requests/list_nodes.rb +42 -0
  157. data/lib/fog/network/proxmox/requests/power_node.rb +46 -0
  158. data/lib/fog/network/proxmox/requests/update_network.rb +46 -0
  159. data/lib/fog/proxmox.rb +128 -0
  160. data/lib/fog/proxmox/core.rb +139 -0
  161. data/lib/fog/proxmox/errors.rb +64 -0
  162. data/lib/fog/proxmox/hash.rb +33 -0
  163. data/lib/fog/proxmox/helpers/controller_helper.rb +55 -0
  164. data/lib/fog/proxmox/helpers/cpu_helper.rb +45 -0
  165. data/lib/fog/proxmox/helpers/disk_helper.rb +84 -0
  166. data/lib/fog/proxmox/helpers/nic_helper.rb +62 -0
  167. data/lib/fog/proxmox/json.rb +32 -0
  168. data/lib/fog/proxmox/models/collection.rb +85 -0
  169. data/lib/fog/proxmox/models/model.rb +58 -0
  170. data/lib/fog/proxmox/variables.rb +40 -0
  171. data/lib/fog/proxmox/version.rb +24 -0
  172. data/lib/fog/storage/proxmox.rb +29 -0
  173. data/spec/compute_spec.rb +408 -0
  174. data/spec/fixtures/proxmox/compute/containers.yml +5398 -0
  175. data/spec/fixtures/proxmox/compute/identity_ticket.yml +40 -0
  176. data/spec/fixtures/proxmox/compute/servers.yml +10571 -0
  177. data/spec/fixtures/proxmox/compute/snapshots.yml +1228 -0
  178. data/spec/fixtures/proxmox/compute/storages.yml +120 -0
  179. data/spec/fixtures/proxmox/compute/tasks.yml +200 -0
  180. data/spec/fixtures/proxmox/identity/auth.yml +44 -0
  181. data/spec/fixtures/proxmox/identity/domains.yml +531 -0
  182. data/spec/fixtures/proxmox/identity/groups.yml +324 -0
  183. data/spec/fixtures/proxmox/identity/identity_ticket.yml +40 -0
  184. data/spec/fixtures/proxmox/identity/permissions.yml +565 -0
  185. data/spec/fixtures/proxmox/identity/pools.yml +488 -0
  186. data/spec/fixtures/proxmox/identity/read_version.yml +42 -0
  187. data/spec/fixtures/proxmox/identity/roles.yml +324 -0
  188. data/spec/fixtures/proxmox/identity/users.yml +646 -0
  189. data/spec/fixtures/proxmox/network/identity_ticket.yml +40 -0
  190. data/spec/fixtures/proxmox/network/networks.yml +413 -0
  191. data/spec/helpers/controller_helper_spec.rb +77 -0
  192. data/spec/helpers/cpu_helper_spec.rb +91 -0
  193. data/spec/helpers/disk_helper_spec.rb +104 -0
  194. data/spec/helpers/nic_helper_spec.rb +73 -0
  195. data/spec/identity_spec.rb +316 -0
  196. data/spec/network_spec.rb +67 -0
  197. data/spec/proxmox_vcr.rb +102 -0
  198. data/spec/spec_helper.rb +39 -0
  199. metadata +535 -0
@@ -0,0 +1,46 @@
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 'fog/proxmox/json'
21
+
22
+ module Fog
23
+ module Compute
24
+ class Proxmox
25
+ # class Real update_server request
26
+ class Real
27
+ def update_server(path_params, body_params)
28
+ node = path_params[:node]
29
+ type = path_params[:type]
30
+ vmid = path_params[:vmid]
31
+ response = request(
32
+ expects: [200],
33
+ method: type == 'qemu' ? 'POST' : 'PUT',
34
+ path: "nodes/#{node}/#{type}/#{vmid}/config",
35
+ body: URI.encode_www_form(body_params)
36
+ )
37
+ Fog::Proxmox::Json.get_data(response)
38
+ end
39
+ end
40
+
41
+ # class Mock update_server request
42
+ class Mock
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,45 @@
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
+ module Fog
21
+ module Compute
22
+ class Proxmox
23
+ # class Real update_snapshot request
24
+ class Real
25
+ def update_snapshot(path_params, body_params)
26
+ node = path_params[:node]
27
+ type = path_params[:type]
28
+ vmid = path_params[:vmid]
29
+ snapname = path_params[:snapname]
30
+ request(
31
+ expects: [200],
32
+ method: 'PUT',
33
+ path: "nodes/#{node}/#{type}/#{vmid}/snapshot/#{snapname}/config",
34
+ body: URI.encode_www_form(body_params)
35
+ )
36
+ end
37
+ end
38
+
39
+ # class Mock update_snapshot request
40
+ class Mock
41
+ def update_snapshot; end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+ # Copyright 2018 Tristan Robert
3
+
4
+ # This file is part of Fog::Proxmox.
5
+
6
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+
11
+ # Fog::Proxmox is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ # frozen_string_literal: true
20
+
21
+ require 'fog/core'
22
+
23
+ module Fog
24
+ module Identity
25
+ # Identity and authentication proxmox class
26
+ class Proxmox < Fog::Service
27
+ requires :pve_url
28
+ recognizes :pve_ticket, :pve_path, :pve_ticket_expires, :pve_csrftoken, :persistent, :current_user, :pve_username, :pve_password, :pve_deadline
29
+
30
+ model_path 'fog/identity/proxmox/models'
31
+ model :principal
32
+ model :user
33
+ collection :users
34
+ model :group
35
+ collection :groups
36
+ model :pool
37
+ collection :pools
38
+ model :role
39
+ collection :roles
40
+ model :domain
41
+ model :pam
42
+ model :pve
43
+ model :ldap
44
+ model :activedirectory
45
+ model :oath
46
+ model :yubico
47
+ collection :domains
48
+ model :permission
49
+ collection :permissions
50
+
51
+ request_path 'fog/identity/proxmox/requests'
52
+
53
+ # Manage permissions
54
+ request :check_permissions
55
+ request :list_permissions
56
+ request :add_permission
57
+ request :remove_permission
58
+ request :read_version
59
+
60
+ # Manage users
61
+ request :list_users
62
+ request :get_user
63
+ request :create_user
64
+ request :update_user
65
+ request :delete_user
66
+ request :change_password
67
+
68
+ # CRUD groups
69
+ request :list_groups
70
+ request :get_group
71
+ request :create_group
72
+ request :update_group
73
+ request :delete_group
74
+
75
+ # CRUD roles
76
+ request :list_roles
77
+ request :get_role
78
+ request :create_role
79
+ request :update_role
80
+ request :delete_role
81
+
82
+ # CRUD domains
83
+ request :list_domains
84
+ request :get_domain
85
+ request :create_domain
86
+ request :update_domain
87
+ request :delete_domain
88
+
89
+ # CRUD pools
90
+ request :list_pools
91
+ request :get_pool
92
+ request :create_pool
93
+ request :update_pool
94
+ request :delete_pool
95
+
96
+ # Mock class
97
+ class Mock
98
+ attr_reader :config
99
+
100
+ def initialize(options = {})
101
+ @pve_uri = URI.parse(options[:pve_url])
102
+ @pve_path = @pve_uri.path
103
+ @config = options
104
+ end
105
+ end
106
+
107
+ # Real class
108
+ class Real
109
+ include Fog::Proxmox::Core
110
+ def initialize(options = {})
111
+ initialize_identity(options)
112
+ @connection_options = options[:connection_options] || {}
113
+ @path_prefix = URI.parse(options[:pve_url]).path
114
+ authenticate
115
+ @persistent = options[:persistent] || false
116
+ url = "#{@scheme}://#{@host}:#{@port}"
117
+ @connection = Fog::Core::Connection.new(url, @persistent, @connection_options.merge(path_prefix: @path_prefix))
118
+ end
119
+
120
+ def config
121
+ self
122
+ end
123
+
124
+ def configure(source)
125
+ source.instance_variables.each do |v|
126
+ instance_variable_set(v, source.instance_variable_get(v))
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,57 @@
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
+ # Copyright 2018 Tristan Robert
12
+
13
+ # This file is part of Fog::Proxmox.
14
+
15
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
16
+ # it under the terms of the GNU General Public License as published by
17
+ # the Free Software Foundation, either version 3 of the License, or
18
+ # (at your option) any later version.
19
+
20
+ # Fog::Proxmox is distributed in the hope that it will be useful,
21
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ # GNU General Public License for more details.
24
+
25
+ # You should have received a copy of the GNU General Public License
26
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
27
+
28
+ require 'fog/proxmox/models/model'
29
+
30
+ module Fog
31
+ module Identity
32
+ class Proxmox
33
+ # class Active Directory authentication
34
+ class Activedirectory < Fog::Proxmox::Model
35
+ identity :type
36
+ attribute :base_dn
37
+ attribute :bind_dn
38
+ attribute :capath
39
+ attribute :cert
40
+ attribute :certkey
41
+ attribute :comment
42
+ attribute :default
43
+ attribute :domain
44
+ attribute :port
45
+ attribute :secure
46
+ attribute :server1
47
+ attribute :server2
48
+ attribute :tfa
49
+ attribute :verify
50
+ def initialize(attributes)
51
+ self.type = 'ad'
52
+ super
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,61 @@
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
+ # Copyright 2018 Tristan Robert
12
+
13
+ # This file is part of Fog::Proxmox.
14
+
15
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
16
+ # it under the terms of the GNU General Public License as published by
17
+ # the Free Software Foundation, either version 3 of the License, or
18
+ # (at your option) any later version.
19
+
20
+ # Fog::Proxmox is distributed in the hope that it will be useful,
21
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ # GNU General Public License for more details.
24
+
25
+ # You should have received a copy of the GNU General Public License
26
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
27
+
28
+ require 'fog/proxmox/models/model'
29
+
30
+ module Fog
31
+ module Identity
32
+ class Proxmox
33
+ # class Domain model authentication
34
+ class Domain < Fog::Proxmox::Model
35
+ identity :realm
36
+ attribute :type
37
+ def to_s
38
+ realm
39
+ end
40
+
41
+ def create(new_attributes = {})
42
+ attr = type.attributes.merge(new_attributes).merge(realm: realm)
43
+ service.create_domain(attr)
44
+ end
45
+
46
+ def destroy
47
+ requires :realm
48
+ service.delete_domain(realm)
49
+ true
50
+ end
51
+
52
+ def update
53
+ requires :realm
54
+ attr = type.attributes
55
+ attr.delete_if { |key, _value| key == :type }
56
+ service.update_domain(realm, attr)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,115 @@
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 'fog/proxmox/models/collection'
21
+ require 'fog/identity/proxmox/models/domain'
22
+
23
+ module Fog
24
+ module Identity
25
+ class Proxmox
26
+ # class Domains collection authentication
27
+ class Domains < Fog::Proxmox::Collection
28
+ model Fog::Identity::Proxmox::Domain
29
+
30
+ def to_domain(hash)
31
+ realm = hash['realm']
32
+ type_value = hash['type']
33
+ tfa_value = hash['tfa']
34
+ type_hash = hash.reject { |k, _v| %w[realm type tfa].include? k }
35
+ type = to_type(type_value, type_hash)
36
+ tfa = to_tfa(tfa_value)
37
+ type.tfa = tfa if tfa
38
+ new(realm: realm, type: type)
39
+ end
40
+
41
+ def all(_options = {})
42
+ load_response(service.list_domains, 'domains')
43
+ end
44
+
45
+ def find_by_id(id)
46
+ response = service.get_domain(id)
47
+ body = JSON.decode(response.body)
48
+ data = body['data']
49
+ data.store('realm', id)
50
+ data.delete_if { |k, _v| k == 'digest' }
51
+ to_domain(data)
52
+ end
53
+
54
+ def destroy(id)
55
+ domain = find_by_id(id)
56
+ domain.destroy
57
+ end
58
+
59
+ def create(attributes = {})
60
+ domain = new(realm: attributes[:realm])
61
+ type_s = attributes[:type]
62
+ tfa_s = attributes[:tfa]
63
+ attr = attributes.reject { |k, _v| %i[realm type tfa].include? k }
64
+ domain.type = to_type(type_s, attr)
65
+ tfa = to_tfa(tfa_s)
66
+ domain.type.tfa = tfa if tfa
67
+ domain.create
68
+ end
69
+
70
+ def to_type(type, attributes)
71
+ type_class(type).new(attributes)
72
+ end
73
+
74
+ def to_tfa(tfa_s)
75
+ oath_rxp = /type=oath,step=(?<step>\d+),digits=(?<digits>\d+)/
76
+ yubico_rxp = /type=yubico,id=(?<id>\w+),key=(?<key>\w+),url=(?<url>.+)/
77
+ if oath_rxp.match(tfa_s)
78
+ attributes = oath_rxp.named_captures
79
+ type = 'oath'
80
+ elsif yubico_rxp.match(tfa_s)
81
+ attributes = yubico_rxp.named_captures
82
+ type = 'yubico'
83
+ end
84
+ tfa_class(type).new(attributes) if type && attributes
85
+ end
86
+
87
+ def type_class(type)
88
+ if type == 'pam'
89
+ type_class = Fog::Identity::Proxmox::Pam
90
+ elsif type == 'pve'
91
+ type_class = Fog::Identity::Proxmox::Pve
92
+ elsif type == 'ldap'
93
+ type_class = Fog::Identity::Proxmox::Ldap
94
+ elsif type == 'ad'
95
+ type_class = Fog::Identity::Proxmox::Activedirectory
96
+ else
97
+ raise Fog::Proxmox::Errors::NotFound, 'domain type unknown'
98
+ end
99
+ type_class
100
+ end
101
+
102
+ def tfa_class(tfa)
103
+ if tfa == 'oath'
104
+ tfa_class = Fog::Identity::Proxmox::Oath
105
+ elsif tfa == 'yubico'
106
+ tfa_class = Fog::Identity::Proxmox::Yubico
107
+ else
108
+ raise Fog::Proxmox::Errors::NotFound, 'domain tfa unknown'
109
+ end
110
+ tfa_class
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end