puppetdb_foreman 5.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -13
  3. data/Rakefile +9 -6
  4. data/app/controllers/api/v2/puppetdb_nodes_controller.rb +8 -6
  5. data/app/controllers/puppetdb_foreman/nodes_controller.rb +22 -8
  6. data/app/helpers/concerns/puppetdb_foreman/hosts_helper_extensions.rb +5 -3
  7. data/app/models/concerns/orchestration/puppetdb.rb +13 -6
  8. data/app/models/puppetdb_foreman/host_extensions.rb +5 -4
  9. data/app/services/puppetdb.rb +8 -12
  10. data/app/services/puppetdb_client/base.rb +8 -6
  11. data/app/services/puppetdb_client/v4.rb +48 -1
  12. data/app/services/puppetdb_host.rb +4 -2
  13. data/app/views/api/v2/puppetdb_nodes/import.json.rabl +2 -0
  14. data/app/views/api/v2/puppetdb_nodes/index.json.rabl +2 -0
  15. data/app/views/api/v2/puppetdb_nodes/unknown.json.rabl +2 -0
  16. data/config/routes.rb +11 -9
  17. data/db/migrate/20170717140010_migrate_puppetdb_api_version_setting.rb +4 -2
  18. data/db/migrate/20181001113836_remove_puppetdb_dashboard_address_setting.puppetdb_foreman.rb +3 -1
  19. data/lib/puppetdb_foreman/engine.rb +55 -27
  20. data/lib/puppetdb_foreman/version.rb +3 -1
  21. data/lib/puppetdb_foreman.rb +2 -0
  22. data/lib/tasks/puppetdb_foreman_tasks.rake +4 -4
  23. data/test/controllers/api/v2/puppetdb_nodes_controller_test.rb +60 -55
  24. data/test/controllers/nodes_controller_test.rb +7 -6
  25. data/test/models/host_test.rb +5 -4
  26. data/test/test_plugin_helper.rb +2 -4
  27. data/test/unit/puppetdb_host_test.rb +5 -4
  28. data/test/unit/puppetdb_test.rb +18 -135
  29. metadata +17 -23
  30. data/app/models/setting/puppetdb.rb +0 -49
  31. data/app/services/puppetdb_client/v1.rb +0 -33
  32. data/app/services/puppetdb_client/v3.rb +0 -49
  33. data/test/static_fixtures/query_nodes.json +0 -61
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cea9938cf77ffa6c8a45dc91857bb2e6e5328a1832155fa609e2cd6661358f7
4
- data.tar.gz: e216fe8ed183f634446ce7cf498ac9c352b2faa4d646ad703a4ca6dc091f2e61
3
+ metadata.gz: 2917867afdc2d20921a278f2c2fb35aa90ee71ad3ceca28cbfb6fbff4d087bd9
4
+ data.tar.gz: 3f6bd9d01c00bd9007220a95b1c0752c938cbbad24c01c670f03ae79e80fd6a5
5
5
  SHA512:
6
- metadata.gz: 44b82f0ec55d8cb5dfe4440a50164c177e1663310ef7b3d43f9b60a2a6f5954b6371789ca357b2adbd19dca1566e1f3e5d21979ddf52da71ce135b4fa38f067f
7
- data.tar.gz: bf42e84aa00284bb1bba3db4b8f1c968e722ceab97d424e2a309f175136717cf1c4e744024b12493f759ce5007fcf9c45ed2ee3d63b577c31431fb41f39ae450
6
+ metadata.gz: 424fd00c14417f01cc1ae6eac59d468bb6b32048f5fbd2f0e646319182500a8b46349f31d2797d87efb578d86704eed14cb42710bf25097334993118a335c904
7
+ data.tar.gz: 0e0ad581dbecf0ce351bb50e8fd88c348e080b64a812c82cb933da13c60a9006f681ba1bcdc6229987e36b96d5d37719895eb7be81c685a15ddb5ec1c8630121
data/README.md CHANGED
@@ -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('../test/dummy/Rakefile', __FILE__)
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
- RuboCop::RakeTask.new
41
- rescue => _
42
+ rescue StandardError
42
43
  puts 'Rubocop not loaded.'
43
- end
44
+ else
45
+ RuboCop::RakeTask.new
44
46
 
45
- task :default do
46
- Rake::Task['rubocop'].execute
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, :only => [:destroy, :import]
7
+ before_action :find_node, only: %i[destroy import]
6
8
 
7
- layout 'api/v2/layouts/index_layout', :only => [:index, :unknown]
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, :required => true
24
+ param :id, String, required: true
23
25
 
24
26
  def destroy
25
27
  uuid = Puppetdb.client.deactivate_node(@node)
26
- response = { :job => { :uuid => uuid } }
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, :required => true
33
+ param :id, :identifier, required: true
32
34
 
33
35
  def import
34
36
  facts = Puppetdb.client.facts(@node)
35
- @host = PuppetdbHost.new(:facts => facts).to_host
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, :only => [:show, :destroy, :import]
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 :success_msg => _('Deactivated node %s in PuppetDB') % @node, :success_redirect => puppetdb_foreman_nodes_path
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(:redirect => puppetdb_foreman_nodes_path, :error_msg => _('Failed to deactivate node in PuppetDB: %s') % e.message)
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(:facts => facts).to_host
36
- process_success :success_msg => _('Imported host %s from PuppetDB') % @node, :success_redirect => host_path(:id => host)
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(:redirect => puppetdb_foreman_nodes_path, :error_msg => _('Failed to import host from PuppetDB: %s') % e.message)
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(:id => host.name),
13
- :title => _('Browse host puppet classes'),
14
- :class => 'btn btn-default'
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,23 @@ module Orchestration
10
12
 
11
13
  def queue_puppetdb_destroy
12
14
  return unless ::Puppetdb.ready? && errors.empty?
13
- queue.create(:name => _('Deactivating node %s in PuppetDB') % self, :priority => 60,
14
- :action => [self, :delPuppetdb])
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 delPuppetdb
22
+ def del_puppetdb
18
23
  Rails.logger.info "Deactivating node in PuppetDB: #{name}"
19
24
  ::Puppetdb.client.deactivate_node(name)
20
25
  rescue StandardError => e
21
- failure _("Failed to deactivate node %{name} in PuppetDB: %{message}\n ") %
22
- { :name => name, :message => e.message }, e
26
+ failure format(
27
+ _("Failed to deactivate node %<name>s in PuppetDB: %<message>s\n "), name: name, message: e.message
28
+ ), e
23
29
  end
24
30
 
25
- def setPuppetdb; end
31
+ def set_puppetdb
32
+ end
26
33
  end
27
34
  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
- return false
24
+ false
24
25
  end
25
26
  end
26
27
  end
@@ -1,23 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Puppetdb
2
4
  API_VERSIONS = {
3
- '4' => 'v4: PuppetDB 4.0, 4.1, 4.2, 4.3',
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
- :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]
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, :to => :Rails
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 < V3
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(:environment => environment) if environment
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
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  object @host
2
4
 
3
5
  extends 'api/v2/hosts/show'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  collection @nodes
2
4
 
3
5
  node :name do |node|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  collection @nodes
2
4
 
3
5
  extends 'api/v2/puppetdb_nodes/index'
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(:id => %r{[^\/]+}) do
4
- resources :nodes, :only => [:index, :show, :destroy] do
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, :defaults => { :format => 'json' } do
13
- scope '(:apiv)', :module => :v2,
14
- :defaults => { :apiv => 'v2' },
15
- :apiv => /v1|v2/,
16
- :constraints => ApiConstraints.new(:version => 2) do
17
- constraints(:id => /[^\/]+/) do
18
- resources :puppetdb_nodes, :only => [:index, :destroy] do
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(:category => 'Setting::Puppetdb', :name => 'puppetdb_address').first.try(:value)
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(:category => 'Setting::Puppetdb', :name => 'puppetdb_api_version').first_or_create
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
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RemovePuppetdbDashboardAddressSetting < ActiveRecord::Migration[5.2]
2
4
  def change
3
- Setting::Puppetdb.where(name: 'puppetdb_dashboard_address').destroy_all
5
+ Setting.where(name: 'puppetdb_dashboard_address').destroy_all
4
6
  end
5
7
  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', :before => :finisher_hook do |_app|
13
+ initializer 'puppetdb_foreman.register_plugin', before: :finisher_hook do |_app|
20
14
  Foreman::Plugin.register :puppetdb_foreman do
21
- requires_foreman '>= 1.20'
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, :'puppetdb_foreman/nodes' => [:index, :show],
27
- :'api/v2/puppetdb_nodes' => [:index, :unknown]
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, :'puppetdb_foreman/nodes' => [:destroy],
30
- :'api/v2/puppetdb_nodes' => [:destroy]
59
+ permission :destroy_puppetdb_nodes, 'puppetdb_foreman/nodes': [:destroy],
60
+ 'api/v2/puppetdb_nodes': [:destroy]
31
61
 
32
- permission :import_puppetdb_nodes, :'puppetdb_foreman/nodes' => [:import],
33
- :'api/v2/puppetdb_nodes' => [:import]
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', [:view_puppetdb_nodes, :destroy_puppetdb_nodes, :import_puppetdb_nodes]
67
+ role 'PuppetDB Node Manager', %i[view_puppetdb_nodes destroy_puppetdb_nodes import_puppetdb_nodes]
38
68
 
39
- menu :top_menu, :nodes, :caption => N_('PuppetDB Nodes'),
40
- :url_hash => { :controller => 'puppetdb_foreman/nodes', :action => 'index' },
41
- :parent => :monitor_menu,
42
- :after => :puppetdb
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
- begin
48
- Host::Managed.send :include, PuppetdbForeman::HostExtensions
49
- HostsHelper.send(:include, PuppetdbForeman::HostsHelperExtensions)
50
- rescue StandardError => e
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PuppetdbForeman
2
- VERSION = '5.0.0'.freeze
4
+ VERSION = '6.0.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PuppetdbForeman
2
4
  require 'puppetdb_foreman/engine'
3
5
  end
@@ -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 :rubocop do
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')