Skip to content

Commit

Permalink
Refactor/lint (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink authored May 5, 2020
1 parent b85a997 commit 94dca71
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 23 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Style/TrailingCommaInLiteral:
Style/SymbolArray:
Description: Using percent style obscures symbolic intent of array's contents.
EnforcedStyle: brackets
inherit_from: ".rubocop_todo.yml"
RSpec/MessageSpies:
EnforcedStyle: receive
Style/Documentation:
Expand Down
21 changes: 21 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
Lint/AssignmentInCondition:
Enabled: false
Lint/RescueException:
Enabled: false
Lint/ShadowingOuterLocalVariable:
Enabled: false
Metrics/LineLength:
Enabled: false
Performance/FixedSize:
Enabled: false
Security/MarshalLoad:
Enabled: false
Style/ClassVars:
Enabled: false
Style/MultilineBlockChain:
Enabled: false
Style/NumericPredicate:
Enabled: false
Style/RegexpLiteral:
Enabled: false
6 changes: 6 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@
".travis.yml":
user: camptocamp
secure: "oVFK/jAf7ZbNR8cdo2AcqwnKp1pktpa+EkImXGF2b6L7OxOl2VXxbBKGW1IueUccmDH381XqrMtdbCVgz83u3HdpkHb3PIFmchPgPeIBgevdubyfulHdwYN++nLL9zxRH+FXhW1qmqpvHFS8CHw4Ia2k69gdcQNNlC60WYk1QwxLYTnTaem2nWZsmNZBNgh5TFzTJzsbJQFoyJlUUkbkg7rZig3qSw/otqwh/HUrEA+UUcBv6B6cIeMaKzaGvHWvfdXv8asT+r/kl/048J2FZM1ulQxZE+273Z1xwp4KATx00NqpceFcvHAInbMkgYuwi3nDJo4pKpqKWKvlw1CJm9+uXk9qYgFhaQpmkz5Jc3njiPZadRITkYG4T9dUHlvN47LDJOZNCwr8kjEkakI1Rv/H7tFlxHG/42TJDAs9dqB4aoiflzo4GOBAsx+YtpTmM+1aWvdDjeedxnuVrGn1lgHkibm7kSiNZDdxQ4/Xv/yYmuko8kam/HdlXC7bg0myQE4zdHPAxcn6qnC6zifmssgonaGXlx+3Hmnqqb7F3vv5+w4Nb9VYekVc6JY0slyq5ADvbNkSL2dGx0qlX4dD2puRgZM/NFAGsJ0AANIIDGWBDb3nj8ofvpRs7ab48U2eRiLb+3vhnIK83S4CdNnZH7TidCv9Y6bAcuQkD0qlXUQ="

".gitlab-ci.yml":
delete: true

".rubocop.yml":
default_configs:
require:
- rubocop-rspec
inherit_from: .rubocop_todo.yml


Gemfile:
use_litmus: true
optional:
":development":
- gem: github_changelog_generator
condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')

spec/spec_helper.rb:
mock_with: ":rspec"
coverage_report: true
3 changes: 3 additions & 0 deletions lib/puppet/catalog-diff/comparer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'puppet/util/diff'
require 'digest'
# Puppet::CatalogDiff
module Puppet::CatalogDiff
# Comparer providers methods
# to compare resources
module Comparer
# Creates an array of just the resource titles
# it would be records like file["/foo"]
Expand Down
21 changes: 8 additions & 13 deletions lib/puppet/catalog-diff/compilecatalog.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
require 'puppet/network/http_pool'
# Puppet::CatalogDiff
module Puppet::CatalogDiff
# Puppet::CatalogDiff::CompileCatalog
# allows to retrieve a catalog, using
# v3/catalog, v4/catalog or PuppetDB
class CompileCatalog
include Puppet::CatalogDiff::Preprocessor

attr_reader :node_name

def initialize(node_name, save_directory, server, certless, catalog_from_puppetdb)
Expand Down Expand Up @@ -52,19 +58,8 @@ def get_catalog_from_puppetdb(node_name, server)
rescue PSON::ParserError => e
raise "Error parsing json output of puppetdb catalog query for #{node_name}: #{e.message}\ncontent: #{ret}"
end
catalog = catalog[0]
# Fix "data" level in PuppetDB catalog
catalog['resources'] = catalog['resources']['data']
# Fix edges
new_edges = []
catalog['edges']['data'].each do |edge|
new_edges << {
'source' => "#{edge['source_type']}[#{edge['source_title']}]",
'target' => "#{edge['target_type']}[#{edge['target_title']}]",
}
end
catalog['edges'] = new_edges
catalog

convert_pdb(catalog)
end

def compile_catalog(node_name, server, certless)
Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/catalog-diff/differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
require File.expand_path(File.join(File.dirname(__FILE__), 'preprocessor.rb'))
require File.expand_path(File.join(File.dirname(__FILE__), 'comparer.rb'))
require File.expand_path(File.join(File.dirname(__FILE__), 'formater.rb'))

# Puppet::CatalogDiff
module Puppet::CatalogDiff
# Differ allows to diff two catalogs
class Differ
include Puppet::CatalogDiff::Preprocessor
include Puppet::CatalogDiff::Comparer
Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/catalog-diff/findcatalogs.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Puppet::CatalogDiff
module Puppet::CatalogDiff
# FindCatalogs allows to find
# pairs of catalogs in two directories
class FindCatalogs
attr_accessor :old_catalog_path, :new_catalog_path

Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/catalog-diff/formater.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'puppet/util/terminal'
# Puppet::CatalogDiff
module Puppet::CatalogDiff
# Formater provides methods to format
# resources into diff-able Puppet DSL
class Formater
def initialize; end

Expand Down
21 changes: 21 additions & 0 deletions lib/puppet/catalog-diff/preprocessor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Puppet::CatalogDiff
module Puppet::CatalogDiff
# Puppet::CatalogDiff::Preprocessor
# provides methods to convert catalogs to
# the catalog-diff intermediate format
module Preprocessor
# capitalize a resource from ["class", "foo::bar"] to Class[Foo::Bar]
#
Expand Down Expand Up @@ -44,4 +48,21 @@ def convert25(resource, collector)
end
end
end

# Converts PuppetDB catalogs to our intermediate format
def convert_pdb(catalog)
catalog = catalog[0]
# Fix "data" level in PuppetDB catalog
catalog['resources'] = catalog['resources']['data']
# Fix edges
new_edges = []
catalog['edges']['data'].each do |edge|
new_edges << {
'source' => "#{edge['source_type']}[#{edge['source_title']}]",
'target' => "#{edge['target_type']}[#{edge['target_title']}]",
}
end
catalog['edges'] = new_edges
catalog
end
end
5 changes: 4 additions & 1 deletion lib/puppet/catalog-diff/searchfacts.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'puppet/network/http_pool'
require 'uri'
require 'json'
# Puppet::CatalogDiff
module Puppet::CatalogDiff
# SearchFacts returns facts from local data, Puppet API, or PuppetDB
class SearchFacts
def initialize(facts)
@facts = Hash[facts.split(',').map { |f| f.split('=') }]
Expand Down Expand Up @@ -102,5 +104,6 @@ def find_nodes_puppetdb(env)
end
names = filtered.map { |node| node['certname'] }
names
end end
end
end
end
2 changes: 1 addition & 1 deletion lib/puppet/face/catalog/pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
rescue Exception => e
Puppet.err(e.to_s)
end
end
end
end
}.each(&:join)
output = {}
Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class catalog_diff(
$diff_master,
String $diff_master,
) {
puppet_auth { 'allow the diff server to retrieve any catalog':
ensure => present,
Expand Down
14 changes: 7 additions & 7 deletions manifests/viewer.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class catalog_diff::viewer (
$remote = 'https://github.com/camptocamp/puppet-catalog-diff-viewer.git',
$password = 'puppet',
$revision = 'master',
$port = 1495,
$listen_ip = $ipaddress,
String $remote = 'https://github.com/camptocamp/puppet-catalog-diff-viewer.git',
String $password = 'puppet',
String $revision = 'master',
Integer $port = 1495,
String $listen_ip = $::ipaddress,
) {
require git

Expand All @@ -13,7 +13,7 @@
}

apache::vhost {"${listen_ip}:${port}":
servername => $fqdn,
servername => $::fqdn,
ip => $listen_ip,
docroot => '/var/www/diff',
ip_based => true,
Expand All @@ -35,7 +35,7 @@

htpasswd { 'puppet':
username => 'puppet',
cryptpasswd => ht_crypt($password,$uuid),
cryptpasswd => ht_crypt($password, $::uuid),
target => '/var/www/.htpasswd',
}

Expand Down

0 comments on commit 94dca71

Please sign in to comment.