puppetdb_foreman 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6a297f534df49f9b10ae4b8398bbc957b90a10156a2aaefa4344e0dc2af61a2
4
- data.tar.gz: 2247fe908bad567d6c6d21efb7a45be0d20a4f2464d230694b802ec6b5dd00f4
3
+ metadata.gz: 0cea9938cf77ffa6c8a45dc91857bb2e6e5328a1832155fa609e2cd6661358f7
4
+ data.tar.gz: e216fe8ed183f634446ce7cf498ac9c352b2faa4d646ad703a4ca6dc091f2e61
5
5
  SHA512:
6
- metadata.gz: 3a4841b0a410b36c6ca57fe2f523d3ccd9f9730bace770346377e051b4565bf3162c185b009a52478eb0dbdda6e3712a8b48ea1486ffb4ab8150f00b81498450
7
- data.tar.gz: 4aef5cba6b027aa23cfb78d54551d05406103a9ecda2c821f69bed73695e452736a427c0f303d710a709cabb5bbefa868350ec23f02909758f5d87f2cbbf3045
6
+ metadata.gz: 44b82f0ec55d8cb5dfe4440a50164c177e1663310ef7b3d43f9b60a2a6f5954b6371789ca357b2adbd19dca1566e1f3e5d21979ddf52da71ce135b4fa38f067f
7
+ data.tar.gz: bf42e84aa00284bb1bba3db4b8f1c968e722ceab97d424e2a309f175136717cf1c4e744024b12493f759ce5007fcf9c45ed2ee3d63b577c31431fb41f39ae450
data/README.md CHANGED
@@ -2,15 +2,12 @@
2
2
 
3
3
  [![Code Climate](https://codeclimate.com/github/theforeman/puppetdb_foreman/badges/gpa.svg)](https://codeclimate.com/github/theforeman/puppetdb_foreman)
4
4
  [![Gem Version](https://badge.fury.io/rb/puppetdb_foreman.svg)](http://badge.fury.io/rb/puppetdb_foreman)
5
- [![Dependency Status](https://gemnasium.com/theforeman/puppetdb_foreman.svg)](https://gemnasium.com/theforeman/puppetdb_foreman)
6
- [![Issue stats](http://issuestats.com/github/theforeman/puppetdb_foreman/badge/pr?style=flat)](http://issuestats.com/github/theforeman/puppetdb_foreman)
7
5
 
8
6
  This is a [Foreman](http://theforeman.org) plugin to interact with [PuppetDB](https://docs.puppetlabs.com/puppetdb/index.html).
9
7
 
10
8
  It does the following:
11
9
 
12
10
  * Disables hosts on PuppetDB after they are deleted in Foreman.
13
- * Proxies the PuppetDB Performance Dashboard for access through Foreman.
14
11
  * Compares nodes in PuppetDB to Hosts in Foreman.
15
12
  * Creates Hosts in Foreman from PuppetDB facts.
16
13
 
@@ -21,6 +18,7 @@ Feel free to raise issues, ask for features, anything, in the github repository
21
18
  | Foreman Version | Plugin Version |
22
19
  | --------------- | -------------- |
23
20
  | >= 1.17 | ~> 4.0.0 |
21
+ | >= 1.20 | ~> 5.0.0 |
24
22
 
25
23
  # Installation:
26
24
 
@@ -51,7 +49,7 @@ puppetdb_foreman uses [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.
51
49
 
52
50
  # Usage:
53
51
 
54
- Go to Administer > Settings > PuppetDB and set `puppetdb_address` with your PuppetDB address, `puppetdb_dashboard_address` (optional) to proxy the dashboard, `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.
52
+ 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.
55
53
 
56
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.
57
55
 
@@ -60,18 +58,12 @@ for PuppetDB 4
60
58
  :puppetdb:
61
59
  :enabled: true
62
60
  :address: 'https://puppetdb:8081/pdb/cmd/v1'
63
- :dashboard_address: 'http://puppetdb:8080/pdb/dashboard'
64
61
  :ssl_ca_file: '/etc/puppetlabs/puppet/ssl/certs/ca.pem'
65
62
  :ssl_certificate: '/etc/puppetlabs/puppet/ssl/certs/FQDN.pem'
66
63
  :ssl_private_key: '/etc/puppetlabs/puppet/ssl/private_keys/FQDN.pem'
67
64
  :api_version: 4
68
65
  ```
69
66
 
70
- You can find the dashboard under Monitor > PuppetDB dashboard. Only administrators and users with a role `view_puppetdb_dashboard` will be able to access it. Aside from convenience, the PuppetDB dashboard cannot be served over HTTPS, you can restrict your dashboard requests to only Foreman boxes and serve it securely to your users through HTTPS in Foreman.
71
-
72
- ![Screenshot](http://i.imgur.com/5d80CtZ.png)
73
-
74
-
75
67
  # Copyright:
76
68
  Copyright 2013 CERN, Switzerland and various authors
77
69
 
@@ -1,6 +1,6 @@
1
1
  module PuppetdbForeman
2
2
  class NodesController < ApplicationController
3
- before_action :find_node, :only => [:destroy, :import]
3
+ before_action :find_node, :only => [:show, :destroy, :import]
4
4
 
5
5
  def controller_permission
6
6
  'puppetdb_nodes'
@@ -12,6 +12,17 @@ module PuppetdbForeman
12
12
  @unknown_hosts = @puppetdb_hosts - @foreman_hosts
13
13
  end
14
14
 
15
+ def show
16
+ response = Puppetdb.client.resources(@node)
17
+
18
+ class_names = response.map { |v| v['title'] if v['type'] == 'Class' }.compact
19
+
20
+ @classes_count = class_names.count
21
+ @classes = class_names.paginate(page: params[:page], per_page: params[:per_page])
22
+
23
+ @type_names = response.map { |v| v['type'] }.uniq
24
+ end
25
+
15
26
  def destroy
16
27
  Puppetdb.client.deactivate_node(@node)
17
28
  process_success :success_msg => _('Deactivated node %s in PuppetDB') % @node, :success_redirect => puppetdb_foreman_nodes_path
@@ -0,0 +1,26 @@
1
+ module PuppetdbForeman
2
+ module HostsHelperExtensions
3
+ extend ActiveSupport::Concern
4
+
5
+ module Overrides
6
+ def show_appropriate_host_buttons(host)
7
+ buttons = super
8
+
9
+ if host.puppet_proxy_id?
10
+ buttons << link_to_if_authorized(
11
+ _('Puppet Classes'),
12
+ hash_for_puppetdb_foreman_node_path(:id => host.name),
13
+ :title => _('Browse host puppet classes'),
14
+ :class => 'btn btn-default'
15
+ )
16
+ end
17
+
18
+ buttons.compact
19
+ end
20
+ end
21
+
22
+ included do
23
+ prepend Overrides
24
+ end
25
+ end
26
+ end
@@ -9,7 +9,6 @@ class Setting::Puppetdb < ::Setting
9
9
  if SETTINGS[:puppetdb].present?
10
10
  default_enabled = SETTINGS[:puppetdb][:enabled]
11
11
  default_address = SETTINGS[:puppetdb][:address]
12
- default_dashboard_address = SETTINGS[:puppetdb][:dashboard_address]
13
12
  default_ssl_ca_file = SETTINGS[:puppetdb][:ssl_ca_file]
14
13
  default_ssl_certificate = SETTINGS[:puppetdb][:ssl_certificate]
15
14
  default_ssl_private_key = SETTINGS[:puppetdb][:ssl_private_key]
@@ -18,7 +17,6 @@ class Setting::Puppetdb < ::Setting
18
17
 
19
18
  default_enabled = false if default_enabled.nil?
20
19
  default_address ||= 'https://puppetdb:8081/pdb/cmd/v1'
21
- default_dashboard_address ||= 'http://puppetdb:8080/pdb/dashboard'
22
20
  default_ssl_ca_file ||= (SETTINGS[:ssl_ca_file]).to_s
23
21
  default_ssl_certificate ||= (SETTINGS[:ssl_certificate]).to_s
24
22
  default_ssl_private_key ||= (SETTINGS[:ssl_priv_key]).to_s
@@ -27,7 +25,6 @@ class Setting::Puppetdb < ::Setting
27
25
  [
28
26
  set('puppetdb_enabled', _("Integration with PuppetDB, enabled will deactivate a host in PuppetDB when it's deleted in Foreman"), default_enabled),
29
27
  set('puppetdb_address', _('Foreman will send PuppetDB requests to this address'), default_address),
30
- set('puppetdb_dashboard_address', _('Foreman will proxy PuppetDB Performance Dashboard requests to this address'), default_dashboard_address),
31
28
  set('puppetdb_ssl_ca_file', _('Foreman will send PuppetDB requests with this CA file'), default_ssl_ca_file),
32
29
  set('puppetdb_ssl_certificate', _('Foreman will send PuppetDB requests with this certificate file'), default_ssl_certificate),
33
30
  set('puppetdb_ssl_private_key', _('Foreman will send PuppetDB requests with this key file'), default_ssl_private_key),
@@ -25,6 +25,10 @@ module PuppetdbClient
25
25
  parse(get(facts_url, query: "[\"=\", \"certname\", \"#{nodename}\"]"))
26
26
  end
27
27
 
28
+ def resources(nodename)
29
+ parse(get(resources_url, query: "[\"=\", \"certname\", \"#{nodename}\"]"))
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def connection(url)
@@ -22,6 +22,10 @@ module PuppetdbClient
22
22
  '/v3/facts'
23
23
  end
24
24
 
25
+ def resources_url
26
+ '/v3/resources'
27
+ end
28
+
25
29
  def query_nodes
26
30
  super.map { |node| node['name'] }
27
31
  end
@@ -26,6 +26,10 @@ module PuppetdbClient
26
26
  '/pdb/query/v4/facts'
27
27
  end
28
28
 
29
+ def resources_url
30
+ '/pdb/query/v4/resources'
31
+ end
32
+
29
33
  def query_nodes
30
34
  super.map { |node| node['certname'] }
31
35
  end
@@ -7,7 +7,7 @@ class PuppetdbHost
7
7
  end
8
8
 
9
9
  def to_host
10
- host = Host::Managed.import_host(facts[:fqdn], 'puppet', certname)
10
+ host = Host::Managed.import_host(facts[:fqdn], certname)
11
11
  host.import_facts(facts)
12
12
  host.update_attribute(:environment => environment) if environment
13
13
  host
@@ -51,6 +51,7 @@
51
51
  <td class="ellipsis"><%= node %></td>
52
52
  <td>
53
53
  <%= action_buttons(
54
+ (display_link_if_authorized(_("Puppet Classes"), hash_for_puppetdb_foreman_node_path(:id => node), :method => :get)),
54
55
  (display_link_if_authorized(_("Import"), hash_for_import_puppetdb_foreman_node_path(:id => node), :method => :put)),
55
56
  (display_delete_if_authorized(hash_for_puppetdb_foreman_node_path(:id => node), :class => 'delete', :text => _('Deactivate')))
56
57
  ) %>
@@ -0,0 +1,69 @@
1
+ <% title @node %>
2
+
3
+ <% if respond_to?(:breadcrumbs) %>
4
+ <% breadcrumbs(
5
+ items: [
6
+ {
7
+ caption: _('Nodes'),
8
+ url: (url_for(puppetdb_foreman_nodes_path) if authorized_for(hash_for_puppetdb_foreman_nodes_path))
9
+ },
10
+ {
11
+ caption: @node
12
+ }],
13
+ switchable: false)
14
+ %>
15
+ <% end %>
16
+
17
+ <div class="col-md-12">
18
+ <div class="row">
19
+ <div class="container-fluid container-cards-pf">
20
+ <div class="row row-cards-pf">
21
+ <div class="col-xs-6 col-sm-4 col-md-4">
22
+ <div class="card-pf card-pf-accented card-pf-aggregate-status">
23
+ <h2 class="card-pf-title">
24
+ <span class="pficon pficon-infrastructure"></span><span class="card-pf-aggregate-status-count"><%= @classes_count %></span> <%= _('Classes') %>
25
+ </h2>
26
+ <div class="card-pf-body"></div>
27
+ </div>
28
+ </div>
29
+
30
+ <div class="col-xs-6 col-sm-4 col-md-4">
31
+ <div class="card-pf card-pf-accented card-pf-aggregate-status">
32
+ <h2 class="card-pf-title">
33
+ <span class="fa fa-wrench"></span><span class="card-pf-aggregate-status-count"><%= @type_names.count %></span> <%= _('Types') %>
34
+ </h2>
35
+ <div class="card-pf-body"></div>
36
+ </div>
37
+ </div>
38
+ </div>
39
+ </div>
40
+
41
+ <div class="col-md-8">
42
+ <div class="panel panel-default">
43
+ <div class="panel-heading">
44
+ <h3 class="panel-title"><%= _('Puppet classes') %></h3>
45
+ </div>
46
+
47
+ <div class="panel-body">
48
+ <% if @classes.any? %>
49
+ <table class="<%= table_css_classes 'table-fixed' %>">
50
+ <thead>
51
+ <tr>
52
+ <th class="col-md-5"><%= _('Name') %></th>
53
+ </tr>
54
+ </thead>
55
+
56
+ <tbody>
57
+ <% @classes.each do |class_name| %>
58
+ <tr><td><%= class_name %></td></tr>
59
+ <% end %>
60
+ </tbody>
61
+ </table>
62
+ <% end %>
63
+
64
+ <%= will_paginate_with_info @classes %>
65
+ </div>
66
+ </div>
67
+ </div>
68
+ </div>
69
+ </div>
@@ -1,9 +1,7 @@
1
1
  Rails.application.routes.draw do
2
- get ':puppetdb(/*puppetdb_url)', :to => 'puppetdb_foreman/puppetdb#index', :puppetdb => /d3\.v2|charts|v3|puppetdb|metrics|\/pdb\/meta\/v1\/version\/latest|pdb\/meta\/v1\/version|pdb\/dashboard\/data/, :as => 'puppetdb'
3
-
4
2
  namespace :puppetdb_foreman do
5
3
  constraints(:id => %r{[^\/]+}) do
6
- resources :nodes, :only => [:index, :destroy] do
4
+ resources :nodes, :only => [:index, :show, :destroy] do
7
5
  member do
8
6
  put 'import'
9
7
  end
@@ -0,0 +1,5 @@
1
+ class RemovePuppetdbDashboardAddressSetting < ActiveRecord::Migration[5.2]
2
+ def change
3
+ Setting::Puppetdb.where(name: 'puppetdb_dashboard_address').destroy_all
4
+ end
5
+ end
@@ -3,7 +3,7 @@ module PuppetdbForeman
3
3
  engine_name 'puppetdb_foreman'
4
4
 
5
5
  initializer 'puppetdb_foreman.load_default_settings', :before => :load_config_initializers do |_app|
6
- require_dependency File.expand_path('../../../app/models/setting/puppetdb.rb', __FILE__) if begin
6
+ require_dependency File.expand_path('../../app/models/setting/puppetdb.rb', __dir__) if begin
7
7
  Setting.table_exists?
8
8
  rescue StandardError
9
9
  (false)
@@ -18,28 +18,24 @@ module PuppetdbForeman
18
18
 
19
19
  initializer 'puppetdb_foreman.register_plugin', :before => :finisher_hook do |_app|
20
20
  Foreman::Plugin.register :puppetdb_foreman do
21
- requires_foreman '>= 1.17'
21
+ requires_foreman '>= 1.20'
22
22
 
23
23
  apipie_documented_controllers ["#{PuppetdbForeman::Engine.root}/app/controllers/api/v2/*.rb"]
24
24
 
25
25
  security_block :puppetdb_foreman do
26
- permission :view_puppetdb_dashboard, :'puppetdb_foreman/puppetdb' => [:index]
27
- permission :view_puppetdb_nodes, :'puppetdb_foreman/nodes' => [:index],
26
+ permission :view_puppetdb_nodes, :'puppetdb_foreman/nodes' => [:index, :show],
28
27
  :'api/v2/puppetdb_nodes' => [:index, :unknown]
28
+
29
29
  permission :destroy_puppetdb_nodes, :'puppetdb_foreman/nodes' => [:destroy],
30
30
  :'api/v2/puppetdb_nodes' => [:destroy]
31
+
31
32
  permission :import_puppetdb_nodes, :'puppetdb_foreman/nodes' => [:import],
32
33
  :'api/v2/puppetdb_nodes' => [:import]
33
34
  end
34
35
 
35
- role 'PuppetDB Dashboard', [:view_puppetdb_dashboard]
36
36
  role 'PuppetDB Node Viewer', [:view_puppetdb_nodes]
37
37
  role 'PuppetDB Node Manager', [:view_puppetdb_nodes, :destroy_puppetdb_nodes, :import_puppetdb_nodes]
38
38
 
39
- menu :top_menu, :puppetdb, :caption => N_('PuppetDB Dashboard'),
40
- :url_hash => { :controller => 'puppetdb_foreman/puppetdb', :action => 'index', :puppetdb => 'puppetdb' },
41
- :parent => :monitor_menu,
42
- :last => :true
43
39
  menu :top_menu, :nodes, :caption => N_('PuppetDB Nodes'),
44
40
  :url_hash => { :controller => 'puppetdb_foreman/nodes', :action => 'index' },
45
41
  :parent => :monitor_menu,
@@ -50,6 +46,7 @@ module PuppetdbForeman
50
46
  config.to_prepare do
51
47
  begin
52
48
  Host::Managed.send :include, PuppetdbForeman::HostExtensions
49
+ HostsHelper.send(:include, PuppetdbForeman::HostsHelperExtensions)
53
50
  rescue StandardError => e
54
51
  Rails.logger.warn "PuppetdbForeman: skipping engine hook (#{e})"
55
52
  end
@@ -1,3 +1,3 @@
1
1
  module PuppetdbForeman
2
- VERSION = '4.0.0'.freeze
2
+ VERSION = '5.0.0'.freeze
3
3
  end
@@ -20,6 +20,30 @@ class NodesControllerTest < ActionController::TestCase
20
20
  end
21
21
  end
22
22
 
23
+ context '#show' do
24
+ let(:host) { FactoryBot.create(:host, :managed) }
25
+
26
+ before do
27
+ resources_resp = [
28
+ { 'type' => 'Class', 'title' => 'main' },
29
+ { 'type' => 'Class', 'title' => 'Settings' },
30
+ { 'type' => 'Stage', 'title' => 'main' }
31
+ ]
32
+
33
+ ::PuppetdbClient::V4.any_instance.stubs(:resources).returns(resources_resp)
34
+ end
35
+
36
+ test 'displays puppet classes information about a given node' do
37
+ get :show, params: { id: host.name }, session: set_session_user
38
+
39
+ assert_response :success
40
+ assert_includes response.body, '<tr><td>main</td></tr>'
41
+ assert_includes response.body, '<tr><td>Settings</td></tr>'
42
+ assert_includes response.body, '2</span> Classes'
43
+ assert_includes response.body, '2</span> Types'
44
+ end
45
+ end
46
+
23
47
  context '#destroy' do
24
48
  let(:node) { 'test.example.com' }
25
49
  test 'deactivating a node in puppetdb' do
@@ -28,8 +52,8 @@ class NodesControllerTest < ActionController::TestCase
28
52
  assert_response :found
29
53
  assert_redirected_to puppetdb_foreman_nodes_path
30
54
  assert_nil flash[:error]
31
- assert_not_nil flash[:notice]
32
- assert_equal "Deactivated node #{node} in PuppetDB", flash[:notice]
55
+ assert_not_nil flash[:notice] || flash[:success]
56
+ assert_equal "Deactivated node #{node} in PuppetDB", flash[:notice] || flash[:success]
33
57
  end
34
58
  end
35
59
 
@@ -47,8 +71,8 @@ class NodesControllerTest < ActionController::TestCase
47
71
  assert_response :found
48
72
  assert_redirected_to host_path(:id => host)
49
73
  assert_nil flash[:error]
50
- assert_not_nil flash[:notice]
51
- assert_equal "Imported host #{node} from PuppetDB", flash[:notice]
74
+ assert_not_nil flash[:notice] || flash[:success]
75
+ assert_equal "Imported host #{node} from PuppetDB", flash[:notice] || flash[:success]
52
76
  end
53
77
  end
54
78
  end
@@ -0,0 +1,41 @@
1
+ [{
2
+ "tags": ["params", "class"],
3
+ "file": null,
4
+ "type": "Class",
5
+ "title": "Cron",
6
+ "line": null,
7
+ "resource": "f13ec266-2914-420c-8d71-13e3466c5856",
8
+ "certname": "host.example.com",
9
+ "parameters": {},
10
+ "exported": false
11
+ }, {
12
+ "tags": ["class"],
13
+ "file": null,
14
+ "type": "Anchor",
15
+ "title": "postgresql",
16
+ "line": null,
17
+ "resource": "9b007f50-87f3-48a1-a4c5-584f2f9d1740",
18
+ "certname": "host.example.com",
19
+ "parameters": {},
20
+ "exported": false
21
+ }, {
22
+ "tags": ["class"],
23
+ "file": null,
24
+ "type": "Class",
25
+ "title": "SomeClass",
26
+ "line": 21,
27
+ "resource": "4b68c39a-b1cc-45ab-96c2-690dbc045f76",
28
+ "certname": "host.example.com",
29
+ "parameters": {},
30
+ "exported": false
31
+ }, {
32
+ "tags": ["class", "params"],
33
+ "file": null,
34
+ "type": "Class",
35
+ "title": "AnotherClass::Params",
36
+ "line": null,
37
+ "resource": "69293889-3e16-48e1-943f-5602096f6c47",
38
+ "certname": "host.example.com",
39
+ "parameters": {},
40
+ "exported": false
41
+ }]
@@ -33,6 +33,28 @@ class PuppetdbTest < ActiveSupport::TestCase
33
33
  assert_equal expected, client.query_nodes
34
34
  end
35
35
 
36
+ test 'resources' do
37
+ stub_request(:get, 'https://localhost:8080/v3/resources?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
38
+ .with(:headers => { 'Accept' => 'application/json' })
39
+ .to_return(:status => 200, :body => fixture('resources.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
40
+
41
+ resources = client.resources('host.example.com')
42
+ sample = {
43
+ 'tags' => %w[params class],
44
+ 'file' => nil,
45
+ 'type' => 'Class',
46
+ 'title' => 'Cron',
47
+ 'line' => nil,
48
+ 'resource' => 'f13ec266-2914-420c-8d71-13e3466c5856',
49
+ 'certname' => 'host.example.com',
50
+ 'parameters' => {},
51
+ 'exported' => false
52
+ }
53
+
54
+ assert_kind_of Array, resources
55
+ assert_includes resources, sample
56
+ end
57
+
36
58
  test 'facts' do
37
59
  stub_request(:get, 'https://localhost:8080/v3/facts?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
38
60
  .with(:headers => { 'Accept' => 'application/json' })
@@ -74,6 +96,28 @@ class PuppetdbTest < ActiveSupport::TestCase
74
96
  assert_equal expected, client.query_nodes
75
97
  end
76
98
 
99
+ test 'resources' do
100
+ stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/resources?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
101
+ .with(:headers => { 'Accept' => 'application/json' })
102
+ .to_return(:status => 200, :body => fixture('resources.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
103
+
104
+ resources = client.resources('host.example.com')
105
+ sample = {
106
+ 'tags' => %w[params class],
107
+ 'file' => nil,
108
+ 'type' => 'Class',
109
+ 'title' => 'Cron',
110
+ 'line' => nil,
111
+ 'resource' => 'f13ec266-2914-420c-8d71-13e3466c5856',
112
+ 'certname' => 'host.example.com',
113
+ 'parameters' => {},
114
+ 'exported' => false
115
+ }
116
+
117
+ assert_kind_of Array, resources
118
+ assert_includes resources, sample
119
+ end
120
+
77
121
  test 'facts' do
78
122
  stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/facts?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
79
123
  .with(:headers => { 'Accept' => 'application/json' })
@@ -115,6 +159,28 @@ class PuppetdbTest < ActiveSupport::TestCase
115
159
  assert_equal expected, client.query_nodes
116
160
  end
117
161
 
162
+ test 'resources' do
163
+ stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/resources?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
164
+ .with(:headers => { 'Accept' => 'application/json' })
165
+ .to_return(:status => 200, :body => fixture('resources.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
166
+
167
+ resources = client.resources('host.example.com')
168
+ sample = {
169
+ 'tags' => %w[params class],
170
+ 'file' => nil,
171
+ 'type' => 'Class',
172
+ 'title' => 'Cron',
173
+ 'line' => nil,
174
+ 'resource' => 'f13ec266-2914-420c-8d71-13e3466c5856',
175
+ 'certname' => 'host.example.com',
176
+ 'parameters' => {},
177
+ 'exported' => false
178
+ }
179
+
180
+ assert_kind_of Array, resources
181
+ assert_includes resources, sample
182
+ end
183
+
118
184
  test 'facts' do
119
185
  stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/facts?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
120
186
  .with(:headers => { 'Accept' => 'application/json' })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetdb_foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-15 00:00:00.000000000 Z
11
+ date: 2019-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.52.0
47
+ version: 0.54.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.52.0
54
+ version: 0.54.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,10 +66,10 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: 'Disable hosts on PuppetDB after they are deleted or built in Foreman,
70
- and proxy the PuppetDB dashboard to Foreman. Follow https://github.com/theforeman/puppetdb_foreman
71
- and raise an issue/submit a pull request if you need extra functionality. You can
72
- also find some help in #theforeman IRC channel on Freenode.'
69
+ description: 'Disable hosts on PuppetDB after they are deleted or built in Foreman.
70
+ Follow https://github.com/theforeman/puppetdb_foreman and raise an issue/submit
71
+ a pull request if you need extra functionality. You can also find some help in #theforeman
72
+ IRC channel on Freenode.'
73
73
  email: elobatocs@gmail.com
74
74
  executables: []
75
75
  extensions: []
@@ -80,7 +80,7 @@ files:
80
80
  - Rakefile
81
81
  - app/controllers/api/v2/puppetdb_nodes_controller.rb
82
82
  - app/controllers/puppetdb_foreman/nodes_controller.rb
83
- - app/controllers/puppetdb_foreman/puppetdb_controller.rb
83
+ - app/helpers/concerns/puppetdb_foreman/hosts_helper_extensions.rb
84
84
  - app/models/concerns/orchestration/puppetdb.rb
85
85
  - app/models/puppetdb_foreman/host_extensions.rb
86
86
  - app/models/setting/puppetdb.rb
@@ -94,9 +94,10 @@ files:
94
94
  - app/views/api/v2/puppetdb_nodes/index.json.rabl
95
95
  - app/views/api/v2/puppetdb_nodes/unknown.json.rabl
96
96
  - app/views/puppetdb_foreman/nodes/index.html.erb
97
- - app/views/puppetdb_foreman/puppetdb/error.html.erb
97
+ - app/views/puppetdb_foreman/nodes/show.html.erb
98
98
  - config/routes.rb
99
99
  - db/migrate/20170717140010_migrate_puppetdb_api_version_setting.rb
100
+ - db/migrate/20181001113836_remove_puppetdb_dashboard_address_setting.puppetdb_foreman.rb
100
101
  - lib/puppetdb_foreman.rb
101
102
  - lib/puppetdb_foreman/engine.rb
102
103
  - lib/puppetdb_foreman/version.rb
@@ -107,6 +108,7 @@ files:
107
108
  - test/static_fixtures/facts.json
108
109
  - test/static_fixtures/query_nodes.json
109
110
  - test/static_fixtures/query_nodes_v3_4.json
111
+ - test/static_fixtures/resources.json
110
112
  - test/test_plugin_helper.rb
111
113
  - test/unit/puppetdb_host_test.rb
112
114
  - test/unit/puppetdb_test.rb
@@ -135,12 +137,13 @@ signing_key:
135
137
  specification_version: 4
136
138
  summary: This is a Foreman plugin to interact with PuppetDB.
137
139
  test_files:
138
- - test/controllers/api/v2/puppetdb_nodes_controller_test.rb
139
- - test/controllers/nodes_controller_test.rb
140
+ - test/unit/puppetdb_test.rb
141
+ - test/unit/puppetdb_host_test.rb
140
142
  - test/models/host_test.rb
141
- - test/static_fixtures/facts.json
142
- - test/static_fixtures/query_nodes.json
143
- - test/static_fixtures/query_nodes_v3_4.json
144
143
  - test/test_plugin_helper.rb
145
- - test/unit/puppetdb_host_test.rb
146
- - test/unit/puppetdb_test.rb
144
+ - test/static_fixtures/query_nodes_v3_4.json
145
+ - test/static_fixtures/query_nodes.json
146
+ - test/static_fixtures/resources.json
147
+ - test/static_fixtures/facts.json
148
+ - test/controllers/nodes_controller_test.rb
149
+ - test/controllers/api/v2/puppetdb_nodes_controller_test.rb
@@ -1,30 +0,0 @@
1
- module PuppetdbForeman
2
- class PuppetdbController < ApplicationController
3
- protect_from_forgery :except => :index
4
-
5
- def index
6
- uri = URI.parse(Setting[:puppetdb_dashboard_address])
7
- puppetdb_url, layout = case params[:puppetdb]
8
- when 'd3.v2', 'charts' then ["#{uri.path}#{request.original_fullpath}", false]
9
- when 'v3', 'metrics', 'pdb/meta/v1/version', 'pdb/meta/v1/version/latest', 'pdb/dashboard/data' then [request.original_fullpath, false]
10
- else ["#{uri.path}/index.html", true]
11
- end
12
- result = Net::HTTP.get_response(uri.host, puppetdb_url, uri.port)
13
- render :text => result.body, :layout => layout
14
- rescue SocketError
15
- @proxy_error = "Problem connecting to host #{uri.host} on port #{uri.port}"
16
- render :action => :error, :layout => true
17
- rescue Errno::ECONNREFUSED
18
- @proxy_error = "#{uri.host} refused our connection"
19
- render :action => :error, :layout => true
20
- rescue EOFError
21
- @proxy_error = "Don't use ssl (https)"
22
- render :action => :error, :layout => true
23
- end
24
-
25
- # Override from application controller to fix issue
26
- def api_request?
27
- request.format && (request.format.json? || request.format.yaml?)
28
- end
29
- end
30
- end
@@ -1,6 +0,0 @@
1
- <%= alert(:class => 'alert-warning',
2
- :text => _("Error proxying PuppetDB Dashboard: #{@proxy_error}.") +
3
- ' ' + _('Maybe you need to set ') +
4
- link_to(_('puppetdb_dashboard_address'),
5
- settings_path(:search => 'puppetdb_dashboard_address')) +
6
- _(' in Settings')) %>