puppetdb_foreman 5.0.0 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -14
- data/Rakefile +9 -6
- data/app/controllers/api/v2/puppetdb_nodes_controller.rb +8 -6
- data/app/controllers/puppetdb_foreman/nodes_controller.rb +22 -8
- data/app/helpers/concerns/puppetdb_foreman/hosts_helper_extensions.rb +5 -3
- data/app/models/concerns/orchestration/puppetdb.rb +16 -8
- data/app/models/puppetdb_foreman/host_extensions.rb +5 -4
- data/app/services/puppetdb.rb +8 -12
- data/app/services/puppetdb_client/base.rb +8 -6
- data/app/services/puppetdb_client/v4.rb +48 -1
- data/app/services/puppetdb_host.rb +4 -2
- data/app/views/api/v2/puppetdb_nodes/import.json.rabl +2 -0
- data/app/views/api/v2/puppetdb_nodes/index.json.rabl +2 -0
- data/app/views/api/v2/puppetdb_nodes/unknown.json.rabl +2 -0
- data/config/routes.rb +11 -9
- data/db/migrate/20170717140010_migrate_puppetdb_api_version_setting.rb +4 -2
- data/db/migrate/20181001113836_remove_puppetdb_dashboard_address_setting.puppetdb_foreman.rb +3 -1
- data/db/migrate/20221026123754_fix_puppetdb_settings_category_to_dsl.rb +9 -0
- data/lib/puppetdb_foreman/engine.rb +55 -27
- data/lib/puppetdb_foreman/version.rb +3 -1
- data/lib/puppetdb_foreman.rb +2 -0
- data/lib/tasks/puppetdb_foreman_tasks.rake +4 -4
- data/test/controllers/api/v2/puppetdb_nodes_controller_test.rb +60 -55
- data/test/controllers/nodes_controller_test.rb +7 -6
- data/test/models/host_test.rb +6 -5
- data/test/test_plugin_helper.rb +2 -4
- data/test/unit/puppetdb_host_test.rb +5 -4
- data/test/unit/puppetdb_test.rb +18 -135
- metadata +21 -26
- data/app/models/setting/puppetdb.rb +0 -49
- data/app/services/puppetdb_client/v1.rb +0 -33
- data/app/services/puppetdb_client/v3.rb +0 -49
- data/test/static_fixtures/query_nodes.json +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2210ab6f4ef16d2fec53bd410bb59ce67e1f1c644f05727df71bcc4882ed2d73
|
4
|
+
data.tar.gz: 4c9238693d329f35d307a42cdef7e1a4c3ebb53e0ee13ffc899b528694e64628
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 073a58bb177e3af928a0f65a62976736ffe2326012fe5cefe22b672866315e2e28d2e0d9cbdc7f1cbc28c2483d07039cb9f183a019db12f594e8e6dcda1976f3
|
7
|
+
data.tar.gz: f1a7f4fee3f27b8e652495c0d017356ddfa83c2f4b719096b6e9c4fd98a6be57e16554941d3c5d8776fdcf4f088f0b7770d365ba5e78b5241c5c95e7be8a564b
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ It does the following:
|
|
11
11
|
* Compares nodes in PuppetDB to Hosts in Foreman.
|
12
12
|
* Creates Hosts in Foreman from PuppetDB facts.
|
13
13
|
|
14
|
-
Feel free to raise issues, ask for features, anything, in the github repository or
|
14
|
+
Feel free to raise issues, ask for features, anything, in the github repository or visit [the Foreman support pages](https://theforeman.org/support.html).
|
15
15
|
|
16
16
|
## Compatibility
|
17
17
|
|
@@ -19,6 +19,7 @@ Feel free to raise issues, ask for features, anything, in the github repository
|
|
19
19
|
| --------------- | -------------- |
|
20
20
|
| >= 1.17 | ~> 4.0.0 |
|
21
21
|
| >= 1.20 | ~> 5.0.0 |
|
22
|
+
| >= 3.1 | ~> 6.0.0 |
|
22
23
|
|
23
24
|
# Installation:
|
24
25
|
|
@@ -51,19 +52,6 @@ puppetdb_foreman uses [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.
|
|
51
52
|
|
52
53
|
Go to Administer > Settings > PuppetDB and set `puppetdb_address` with your PuppetDB address, `puppetdb_enabled` to either true or false if you want to enable or disable PuppetDB integration. Obviously you will need a PuppetDB instance at the address you provide.
|
53
54
|
|
54
|
-
Alternatively you can put your settings in `config/settings.yaml`. Please keep in mind these will be overwritten if changed in the application, and if the application is rebooted, YAML rules will overwrite again your manually changed settings. Hence passing your settings in this format is discouraged, but allowed.
|
55
|
-
|
56
|
-
for PuppetDB 4
|
57
|
-
```yaml
|
58
|
-
:puppetdb:
|
59
|
-
:enabled: true
|
60
|
-
:address: 'https://puppetdb:8081/pdb/cmd/v1'
|
61
|
-
:ssl_ca_file: '/etc/puppetlabs/puppet/ssl/certs/ca.pem'
|
62
|
-
:ssl_certificate: '/etc/puppetlabs/puppet/ssl/certs/FQDN.pem'
|
63
|
-
:ssl_private_key: '/etc/puppetlabs/puppet/ssl/private_keys/FQDN.pem'
|
64
|
-
:api_version: 4
|
65
|
-
```
|
66
|
-
|
67
55
|
# Copyright:
|
68
56
|
Copyright 2013 CERN, Switzerland and various authors
|
69
57
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
begin
|
3
5
|
require 'bundler/setup'
|
4
6
|
rescue LoadError
|
@@ -20,7 +22,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
22
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
23
|
end
|
22
24
|
|
23
|
-
APP_RAKEFILE = File.expand_path('
|
25
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
24
26
|
|
25
27
|
Bundler::GemHelper.install_tasks
|
26
28
|
|
@@ -37,11 +39,12 @@ task default: :test
|
|
37
39
|
|
38
40
|
begin
|
39
41
|
require 'rubocop/rake_task'
|
40
|
-
|
41
|
-
rescue => _
|
42
|
+
rescue StandardError
|
42
43
|
puts 'Rubocop not loaded.'
|
43
|
-
|
44
|
+
else
|
45
|
+
RuboCop::RakeTask.new
|
44
46
|
|
45
|
-
task :default do
|
46
|
-
|
47
|
+
task :default do
|
48
|
+
Rake::Task['rubocop'].execute
|
49
|
+
end
|
47
50
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Api
|
2
4
|
module V2
|
3
5
|
class PuppetdbNodesController < V2::BaseController
|
4
6
|
include Api::Version2
|
5
|
-
before_action :find_node, :
|
7
|
+
before_action :find_node, only: %i[destroy import]
|
6
8
|
|
7
|
-
layout 'api/v2/layouts/index_layout', :
|
9
|
+
layout 'api/v2/layouts/index_layout', only: %i[index unknown]
|
8
10
|
|
9
11
|
api :GET, '/puppetdb_nodes/', N_('List all PuppetDB nodes')
|
10
12
|
def index
|
@@ -19,20 +21,20 @@ module Api
|
|
19
21
|
end
|
20
22
|
|
21
23
|
api :DELETE, '/puppetdb_nodes/:id/', N_('Deactivate a node in PuppetDB')
|
22
|
-
param :id, String, :
|
24
|
+
param :id, String, required: true
|
23
25
|
|
24
26
|
def destroy
|
25
27
|
uuid = Puppetdb.client.deactivate_node(@node)
|
26
|
-
response = { :
|
28
|
+
response = { job: { uuid: uuid } }
|
27
29
|
process_success response
|
28
30
|
end
|
29
31
|
|
30
32
|
api :PUT, '/puppetdb_nodes/:id/import/', N_('Import PuppetDB Node to Foreman Host')
|
31
|
-
param :id, :identifier, :
|
33
|
+
param :id, :identifier, required: true
|
32
34
|
|
33
35
|
def import
|
34
36
|
facts = Puppetdb.client.facts(@node)
|
35
|
-
@host = PuppetdbHost.new(:
|
37
|
+
@host = PuppetdbHost.new(facts: facts).to_host
|
36
38
|
end
|
37
39
|
|
38
40
|
# Overrides because PuppetDB is not backed by ActiveRecord
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PuppetdbForeman
|
2
4
|
class NodesController < ApplicationController
|
3
|
-
before_action :find_node, :
|
5
|
+
before_action :find_node, only: %i[show destroy import]
|
4
6
|
|
5
7
|
def controller_permission
|
6
8
|
'puppetdb_nodes'
|
@@ -12,7 +14,7 @@ module PuppetdbForeman
|
|
12
14
|
@unknown_hosts = @puppetdb_hosts - @foreman_hosts
|
13
15
|
end
|
14
16
|
|
15
|
-
def show
|
17
|
+
def show # rubocop:disable Metrics/AbcSize
|
16
18
|
response = Puppetdb.client.resources(@node)
|
17
19
|
|
18
20
|
class_names = response.map { |v| v['title'] if v['type'] == 'Class' }.compact
|
@@ -25,17 +27,29 @@ module PuppetdbForeman
|
|
25
27
|
|
26
28
|
def destroy
|
27
29
|
Puppetdb.client.deactivate_node(@node)
|
28
|
-
process_success
|
30
|
+
process_success(
|
31
|
+
success_msg: _('Deactivated node %s in PuppetDB') % @node,
|
32
|
+
success_redirect: puppetdb_foreman_nodes_path
|
33
|
+
)
|
29
34
|
rescue StandardError => e
|
30
|
-
process_error(
|
35
|
+
process_error(
|
36
|
+
redirect: puppetdb_foreman_nodes_path,
|
37
|
+
error_msg: _('Failed to deactivate node in PuppetDB: %s') % e.message
|
38
|
+
)
|
31
39
|
end
|
32
40
|
|
33
|
-
def import
|
41
|
+
def import # rubocop:disable Metrics/MethodLength
|
34
42
|
facts = Puppetdb.client.facts(@node)
|
35
|
-
host = PuppetdbHost.new(:
|
36
|
-
process_success
|
43
|
+
host = PuppetdbHost.new(facts: facts).to_host
|
44
|
+
process_success(
|
45
|
+
success_msg: _('Imported host %s from PuppetDB') % @node,
|
46
|
+
success_redirect: host_path(id: host)
|
47
|
+
)
|
37
48
|
rescue StandardError => e
|
38
|
-
process_error(
|
49
|
+
process_error(
|
50
|
+
redirect: puppetdb_foreman_nodes_path,
|
51
|
+
error_msg: _('Failed to import host from PuppetDB: %s') % e.message
|
52
|
+
)
|
39
53
|
end
|
40
54
|
|
41
55
|
private
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PuppetdbForeman
|
2
4
|
module HostsHelperExtensions
|
3
5
|
extend ActiveSupport::Concern
|
@@ -9,9 +11,9 @@ module PuppetdbForeman
|
|
9
11
|
if host.puppet_proxy_id?
|
10
12
|
buttons << link_to_if_authorized(
|
11
13
|
_('Puppet Classes'),
|
12
|
-
hash_for_puppetdb_foreman_node_path(:
|
13
|
-
:
|
14
|
-
:
|
14
|
+
hash_for_puppetdb_foreman_node_path(id: host.name),
|
15
|
+
title: _('Browse host puppet classes'),
|
16
|
+
class: 'btn btn-default'
|
15
17
|
)
|
16
18
|
end
|
17
19
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Orchestration
|
2
4
|
module Puppetdb
|
3
5
|
extend ActiveSupport::Concern
|
@@ -10,18 +12,24 @@ module Orchestration
|
|
10
12
|
|
11
13
|
def queue_puppetdb_destroy
|
12
14
|
return unless ::Puppetdb.ready? && errors.empty?
|
13
|
-
queue.create(
|
14
|
-
|
15
|
+
queue.create(
|
16
|
+
name: _('Deactivating node %s in PuppetDB') % self,
|
17
|
+
priority: 60,
|
18
|
+
action: [self, :del_puppetdb]
|
19
|
+
)
|
15
20
|
end
|
16
21
|
|
17
|
-
def
|
18
|
-
Rails.logger.info "Deactivating node in PuppetDB: #{name}"
|
19
|
-
::Puppetdb.client.deactivate_node(
|
22
|
+
def del_puppetdb
|
23
|
+
Rails.logger.info "Deactivating node in PuppetDB: #{certname} (#{name})"
|
24
|
+
::Puppetdb.client.deactivate_node(certname)
|
20
25
|
rescue StandardError => e
|
21
|
-
failure
|
22
|
-
|
26
|
+
failure format(
|
27
|
+
_("Failed to deactivate node %<certname> (%<name>) in PuppetDB: %<message>\n "),
|
28
|
+
name: name, message: e.message, certname: certname
|
29
|
+
), e
|
23
30
|
end
|
24
31
|
|
25
|
-
def
|
32
|
+
def set_puppetdb
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PuppetdbForeman
|
2
4
|
module HostExtensions
|
3
5
|
extend ActiveSupport::Concern
|
@@ -7,20 +9,19 @@ module PuppetdbForeman
|
|
7
9
|
after_build :deactivate_host
|
8
10
|
end
|
9
11
|
|
10
|
-
def deactivate_host
|
12
|
+
def deactivate_host # rubocop:disable Metrics/MethodLength
|
11
13
|
logger.debug "Deactivating host #{name} in PuppetDB"
|
12
14
|
return true unless Puppetdb.enabled?
|
13
15
|
|
14
16
|
unless Puppetdb.configured?
|
15
|
-
errors.add(:base,
|
16
|
-
_('PuppetDB plugin is enabled but not configured. Please configure it before trying to delete a host.'))
|
17
|
+
errors.add(:base, _('PuppetDB plugin is enabled but not configured. Please configure it before trying to delete a host.')) # rubocop:disable Layout/LineLength
|
17
18
|
end
|
18
19
|
|
19
20
|
begin
|
20
21
|
Puppetdb.client.deactivate_node(name)
|
21
22
|
rescue StandardError => e
|
22
23
|
errors.add(:base, _("Could not deactivate host on PuppetDB: #{e}"))
|
23
|
-
|
24
|
+
false
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
data/app/services/puppetdb.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Puppetdb
|
2
4
|
API_VERSIONS = {
|
3
|
-
'4' => 'v4: PuppetDB 4
|
4
|
-
'3' => 'v3: PuppetDB 3.0, 3.1, 3.2',
|
5
|
-
'1' => 'v1: PuppetDB 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1, 2.2, 2.3'
|
5
|
+
'4' => 'v4: PuppetDB 4 - 7',
|
6
6
|
}.freeze
|
7
7
|
|
8
|
-
def self.client
|
8
|
+
def self.client # rubocop:disable Metrics/MethodLength
|
9
9
|
options = {
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
10
|
+
uri: uri,
|
11
|
+
ssl_ca_file: Setting[:puppetdb_ssl_ca_file],
|
12
|
+
ssl_certificate_file: Setting[:puppetdb_ssl_certificate],
|
13
|
+
ssl_private_key_file: Setting[:puppetdb_ssl_private_key],
|
14
14
|
}
|
15
15
|
|
16
16
|
case api_version
|
17
|
-
when 1
|
18
|
-
PuppetdbClient::V1.new(options)
|
19
|
-
when 3
|
20
|
-
PuppetdbClient::V3.new(options)
|
21
17
|
when 4
|
22
18
|
PuppetdbClient::V4.new(options)
|
23
19
|
else
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PuppetdbClient
|
2
4
|
class Base
|
3
|
-
delegate :logger, :
|
5
|
+
delegate :logger, to: :Rails
|
4
6
|
attr_reader :uri, :ssl_ca_file, :ssl_certificate_file, :ssl_private_key_file
|
5
7
|
|
6
8
|
def initialize(opts)
|
@@ -66,13 +68,13 @@ module PuppetdbClient
|
|
66
68
|
|
67
69
|
def request_options
|
68
70
|
{
|
69
|
-
headers: request_headers
|
71
|
+
headers: request_headers,
|
70
72
|
}.merge(auth_options).merge(ssl_options)
|
71
73
|
end
|
72
74
|
|
73
75
|
def request_headers
|
74
76
|
{
|
75
|
-
'Accept' => 'application/json'
|
77
|
+
'Accept' => 'application/json',
|
76
78
|
}
|
77
79
|
end
|
78
80
|
|
@@ -80,11 +82,11 @@ module PuppetdbClient
|
|
80
82
|
if ssl_ca_file
|
81
83
|
{
|
82
84
|
ssl_ca_file: ssl_ca_file,
|
83
|
-
verify_ssl: true
|
85
|
+
verify_ssl: true,
|
84
86
|
}
|
85
87
|
else
|
86
88
|
{
|
87
|
-
verify_ssl: false
|
89
|
+
verify_ssl: false,
|
88
90
|
}
|
89
91
|
end
|
90
92
|
end
|
@@ -93,7 +95,7 @@ module PuppetdbClient
|
|
93
95
|
return {} unless certificate_request?
|
94
96
|
{
|
95
97
|
ssl_client_cert: ssl_certificate,
|
96
|
-
ssl_client_key: ssl_private_key
|
98
|
+
ssl_client_key: ssl_private_key,
|
97
99
|
}
|
98
100
|
end
|
99
101
|
|
@@ -1,4 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PuppetdbClient
|
2
|
-
class V4 <
|
4
|
+
class V4 < Base
|
5
|
+
# The payload is formatted as a JSON map.
|
6
|
+
# certname: The name of the node for which the catalog was compiled.
|
7
|
+
# producer_timestamp: The time of command submission.
|
8
|
+
def deactivate_node_payload(nodename)
|
9
|
+
{
|
10
|
+
'command' => 'deactivate node',
|
11
|
+
'version' => 3,
|
12
|
+
'payload' => {
|
13
|
+
'certname' => nodename,
|
14
|
+
'producer_timestamp' => producer_timestamp,
|
15
|
+
},
|
16
|
+
}.to_json
|
17
|
+
end
|
18
|
+
|
19
|
+
def command_url
|
20
|
+
'/pdb/cmd/v1'
|
21
|
+
end
|
22
|
+
|
23
|
+
def nodes_url
|
24
|
+
'/pdb/query/v4/nodes'
|
25
|
+
end
|
26
|
+
|
27
|
+
def facts_url
|
28
|
+
'/pdb/query/v4/facts'
|
29
|
+
end
|
30
|
+
|
31
|
+
def resources_url
|
32
|
+
'/pdb/query/v4/resources'
|
33
|
+
end
|
34
|
+
|
35
|
+
def query_nodes
|
36
|
+
super.map { |node| node['certname'] }
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def post_options
|
42
|
+
{
|
43
|
+
content_type: :json,
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def producer_timestamp
|
48
|
+
Time.now.iso8601.to_s
|
49
|
+
end
|
3
50
|
end
|
4
51
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class PuppetdbHost
|
2
4
|
attr_accessor :certname, :environment, :facts
|
3
5
|
|
@@ -8,8 +10,8 @@ class PuppetdbHost
|
|
8
10
|
|
9
11
|
def to_host
|
10
12
|
host = Host::Managed.import_host(facts[:fqdn], certname)
|
11
|
-
host.import_facts(facts)
|
12
|
-
host.update_attribute(:
|
13
|
+
HostFactImporter.new(host).import_facts(facts)
|
14
|
+
host.update_attribute(environment: environment) if environment # rubocop:disable Rails/SkipsModelValidations
|
13
15
|
host
|
14
16
|
end
|
15
17
|
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Rails.application.routes.draw do
|
2
4
|
namespace :puppetdb_foreman do
|
3
|
-
constraints(:
|
4
|
-
resources :nodes, :
|
5
|
+
constraints(id: %r{[^/]+}) do
|
6
|
+
resources :nodes, only: %i[index show destroy] do
|
5
7
|
member do
|
6
8
|
put 'import'
|
7
9
|
end
|
@@ -9,13 +11,13 @@ Rails.application.routes.draw do
|
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
|
-
namespace :api, :
|
13
|
-
scope '(:apiv)', :
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
constraints(:
|
18
|
-
resources :puppetdb_nodes, :
|
14
|
+
namespace :api, defaults: { format: 'json' } do
|
15
|
+
scope '(:apiv)', module: :v2,
|
16
|
+
defaults: { apiv: 'v2' },
|
17
|
+
apiv: /v1|v2/,
|
18
|
+
constraints: ApiConstraints.new(version: 2) do
|
19
|
+
constraints(id: %r{[^/]+}) do
|
20
|
+
resources :puppetdb_nodes, only: %i[index destroy] do
|
19
21
|
collection do
|
20
22
|
get 'unknown'
|
21
23
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class MigratePuppetdbApiVersionSetting < ActiveRecord::Migration[4.2]
|
2
4
|
def up
|
3
|
-
puppetdb_address = Setting.where(:
|
5
|
+
puppetdb_address = Setting.where(category: 'Setting::Puppetdb', name: 'puppetdb_address').first.try(:value)
|
4
6
|
return unless puppetdb_address
|
5
7
|
|
6
8
|
api_version = URI.parse(puppetdb_address).path.start_with?('/pdb') ? 3 : 1
|
7
|
-
setting = Setting.where(:
|
9
|
+
setting = Setting.where(category: 'Setting::Puppetdb', name: 'puppetdb_api_version').first_or_create
|
8
10
|
setting.value = api_version
|
9
11
|
setting.save
|
10
12
|
end
|
data/db/migrate/20181001113836_remove_puppetdb_dashboard_address_setting.puppetdb_foreman.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class RemovePuppetdbDashboardAddressSetting < ActiveRecord::Migration[5.2]
|
2
4
|
def change
|
3
|
-
Setting
|
5
|
+
Setting.where(name: 'puppetdb_dashboard_address').destroy_all
|
4
6
|
end
|
5
7
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FixPuppetdbSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
|
4
|
+
def up
|
5
|
+
# rubocop:disable Rails/SkipsModelValidations
|
6
|
+
Setting.where(category: 'Setting::Puppetdb').update_all(category: 'Setting')
|
7
|
+
# rubocop:enable Rails/SkipsModelValidations
|
8
|
+
end
|
9
|
+
end
|
@@ -1,55 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PuppetdbForeman
|
2
4
|
class Engine < ::Rails::Engine
|
3
5
|
engine_name 'puppetdb_foreman'
|
4
6
|
|
5
|
-
initializer 'puppetdb_foreman.load_default_settings', :before => :load_config_initializers do |_app|
|
6
|
-
require_dependency File.expand_path('../../app/models/setting/puppetdb.rb', __dir__) if begin
|
7
|
-
Setting.table_exists?
|
8
|
-
rescue StandardError
|
9
|
-
(false)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
7
|
initializer 'puppetdb_foreman.load_app_instance_data' do |app|
|
14
8
|
PuppetdbForeman::Engine.paths['db/migrate'].existent.each do |path|
|
15
9
|
app.config.paths['db/migrate'] << path
|
16
10
|
end
|
17
11
|
end
|
18
12
|
|
19
|
-
initializer 'puppetdb_foreman.register_plugin', :
|
13
|
+
initializer 'puppetdb_foreman.register_plugin', before: :finisher_hook do |_app|
|
20
14
|
Foreman::Plugin.register :puppetdb_foreman do
|
21
|
-
requires_foreman '>= 1
|
15
|
+
requires_foreman '>= 3.1'
|
22
16
|
|
23
17
|
apipie_documented_controllers ["#{PuppetdbForeman::Engine.root}/app/controllers/api/v2/*.rb"]
|
24
18
|
|
19
|
+
settings do
|
20
|
+
category :puppetdb, N_('PuppetDB') do
|
21
|
+
setting :puppetdb_enabled,
|
22
|
+
type: :boolean,
|
23
|
+
default: false,
|
24
|
+
description: _("Integration with PuppetDB, enabled will deactivate a host in PuppetDB when it's deleted in Foreman") # rubocop:disable Layout/LineLength
|
25
|
+
|
26
|
+
setting :puppetdb_address,
|
27
|
+
type: :string,
|
28
|
+
default: 'https://puppetdb:8081/pdb/cmd/v1',
|
29
|
+
description: _('Foreman will send PuppetDB requests to this address')
|
30
|
+
|
31
|
+
setting :puppetdb_ssl_ca_file,
|
32
|
+
type: :string,
|
33
|
+
default: SETTINGS[:ssl_ca_file],
|
34
|
+
description: _('Foreman will send PuppetDB requests with this CA file')
|
35
|
+
|
36
|
+
setting :puppetdb_ssl_certificate,
|
37
|
+
type: :string,
|
38
|
+
default: SETTINGS[:ssl_certificate],
|
39
|
+
description: _('Foreman will send PuppetDB requests with this certificate file')
|
40
|
+
|
41
|
+
setting :puppetdb_ssl_private_key,
|
42
|
+
type: :string,
|
43
|
+
default: SETTINGS[:ssl_priv_key],
|
44
|
+
description: _('Foreman will send PuppetDB requests with this key file')
|
45
|
+
|
46
|
+
setting :puppetdb_api_version,
|
47
|
+
type: :integer,
|
48
|
+
default: 4,
|
49
|
+
full_name: N_('PuppetDB API Version'),
|
50
|
+
description: _('Foreman will use this PuppetDB API version'),
|
51
|
+
collection: proc { ::Puppetdb::API_VERSIONS }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
25
55
|
security_block :puppetdb_foreman do
|
26
|
-
permission :view_puppetdb_nodes,
|
27
|
-
|
56
|
+
permission :view_puppetdb_nodes, 'puppetdb_foreman/nodes': %i[index show],
|
57
|
+
'api/v2/puppetdb_nodes': %i[index unknown]
|
28
58
|
|
29
|
-
permission :destroy_puppetdb_nodes,
|
30
|
-
|
59
|
+
permission :destroy_puppetdb_nodes, 'puppetdb_foreman/nodes': [:destroy],
|
60
|
+
'api/v2/puppetdb_nodes': [:destroy]
|
31
61
|
|
32
|
-
permission :import_puppetdb_nodes,
|
33
|
-
|
62
|
+
permission :import_puppetdb_nodes, 'puppetdb_foreman/nodes': [:import],
|
63
|
+
'api/v2/puppetdb_nodes': [:import]
|
34
64
|
end
|
35
65
|
|
36
66
|
role 'PuppetDB Node Viewer', [:view_puppetdb_nodes]
|
37
|
-
role 'PuppetDB Node Manager', [
|
67
|
+
role 'PuppetDB Node Manager', %i[view_puppetdb_nodes destroy_puppetdb_nodes import_puppetdb_nodes]
|
38
68
|
|
39
|
-
menu :top_menu, :nodes, :
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
69
|
+
menu :top_menu, :nodes, caption: N_('PuppetDB Nodes'),
|
70
|
+
url_hash: { controller: 'puppetdb_foreman/nodes', action: 'index' },
|
71
|
+
parent: :monitor_menu,
|
72
|
+
after: :puppetdb
|
43
73
|
end
|
44
74
|
end
|
45
75
|
|
46
76
|
config.to_prepare do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
Rails.logger.warn "PuppetdbForeman: skipping engine hook (#{e})"
|
52
|
-
end
|
77
|
+
Host::Managed.include PuppetdbForeman::HostExtensions
|
78
|
+
HostsHelper.include PuppetdbForeman::HostsHelperExtensions
|
79
|
+
rescue StandardError => e
|
80
|
+
Rails.logger.warn "PuppetdbForeman: skipping engine hook (#{e})"
|
53
81
|
end
|
54
82
|
end
|
55
83
|
end
|
data/lib/puppetdb_foreman.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Tests
|
2
4
|
namespace :test do
|
3
5
|
desc 'Test PuppetdbForeman'
|
@@ -11,7 +13,7 @@ namespace :test do
|
|
11
13
|
end
|
12
14
|
|
13
15
|
namespace :puppetdb_foreman do
|
14
|
-
task :
|
16
|
+
task rubocop: :environment do
|
15
17
|
begin
|
16
18
|
require 'rubocop/rake_task'
|
17
19
|
RuboCop::RakeTask.new(:rubocop_puppetdb_foreman) do |task|
|
@@ -30,6 +32,4 @@ end
|
|
30
32
|
Rake::Task[:test].enhance ['test:puppetdb_foreman']
|
31
33
|
|
32
34
|
load 'tasks/jenkins.rake'
|
33
|
-
if Rake::Task.task_defined?(:'jenkins:unit')
|
34
|
-
Rake::Task['jenkins:unit'].enhance ['test:puppetdb_foreman', 'puppetdb_foreman:rubocop']
|
35
|
-
end
|
35
|
+
Rake::Task['jenkins:unit'].enhance ['test:puppetdb_foreman', 'puppetdb_foreman:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
|