puppetdb_cli 2.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 42d242aeb659eede85c99de3e9eb3aba62601f6b
4
+ data.tar.gz: a9c1b2185eacbe0303cb24344ddf708090c8b475
5
+ SHA512:
6
+ metadata.gz: ad17edfa9dea21e21ae34998da28f30b4ef5dc6bcda62fca751b3273191015d1280083e9a4508f25bc7a556a319bc60862d58c08c90e291b6f948cf6330a8fe3
7
+ data.tar.gz: 3608ab3405b2ad0fdf15d0ee5d25f873b5b08b1588d95575d73f51b86519da9831f37639adc4c2d9f94959407e661259e5b4ea158d4ea25a35a519e570ba6811
data/.gitignore ADDED
@@ -0,0 +1,27 @@
1
+ # Misc files
2
+ *.swp
3
+ .DS_Store
4
+ Gemfile.local
5
+ Gemfile.lock
6
+
7
+ # Beaker
8
+ acceptance/.bundle/
9
+ acceptance/vendor/
10
+ acceptance/junit/
11
+ acceptance/log/
12
+ acceptance/hosts.cfg
13
+ acceptance/tmp/
14
+
15
+ # Ruby
16
+ /.bundle/
17
+ /.yardoc
18
+ /_yardoc/
19
+ /coverage/
20
+ /doc/
21
+ /pkg/
22
+ /spec/reports/
23
+ /tmp/
24
+ /vendor/
25
+
26
+ # rspec failure tracking
27
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ AllCops:
2
+ Include:
3
+ - lib/**/*.rb
4
+ - spec/**/*.rb
5
+ - acceptance/foss/**/*.rb
6
+ - exe/**/*.rb
7
+ Exclude:
8
+ - vendor/**/*
9
+ - acceptance/vendor/**/*
10
+ TargetRubyVersion: 2.3
11
+ Style/ClassAndModuleChildren:
12
+ Exclude:
13
+ - lib/**/*
14
+ - spec/**/*
15
+ - acceptance/**/*
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - spec/**/*
19
+ - puppetdb_cli.gemspec
20
+ Metrics/LineLength:
21
+ Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,25 @@
1
+ language: ruby
2
+ sudo: false
3
+
4
+ script:
5
+ 'bundle exec $CHECK'
6
+
7
+ notifications:
8
+ email: false
9
+
10
+ before_install:
11
+ - bundle -v
12
+ - rm Gemfile.lock || true
13
+ - gem update --system
14
+ - gem update bundler
15
+ - gem --version
16
+ - bundle -v
17
+
18
+ matrix:
19
+ include:
20
+ - rvm: 2.3.1
21
+ env: CHECK=rspec
22
+ - rvm: 2.3.1
23
+ env: CHECK=rubocop
24
+ - rvm: 2.5.5
25
+ env: CHECK=rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,54 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ## [1.1.0] - 2016-07-20
6
+
7
+ ### Features
8
+
9
+ - New `puppet-db status` subcommand for retreiving the Trapperkeeper statuses of
10
+ your PuppetDB instances.
11
+
12
+ ### Fixed
13
+
14
+ - OpenSSL is properly linked with the PuppetDB CLI and now works with HTTPS.
15
+
16
+ ## [1.0.1] - 2016-06-28
17
+
18
+ ### Fixed
19
+
20
+ - (PDB-2748) Fix incompatibility between puppet-agent 1.5 and puppet-client-tools
21
+ - (PDB-2653) Do not display `no error found` for bad requests
22
+
23
+ ## [1.0.0] - 2016-04-07
24
+
25
+ ### Summary
26
+
27
+ Initial release of the PuppetDB CLI subcommands.
28
+
29
+ The PuppetDB CLI is intended to facilitate friendlier interactions with the
30
+ PuppetDB API.
31
+
32
+ The PuppetDB CLI accepts a configuration file with SSL credentials and the url
33
+ for your PuppetDB server so you can issue queries to PuppetDB on your own
34
+ machine without needing to type long `curl` invocations.
35
+
36
+ We intend to use the PuppetDB CLI to provide human readable output formats and
37
+ helpful hints for interacting with the API more generally.
38
+
39
+ ### Installation
40
+
41
+ Please see the
42
+ [PuppetDB documentation](https://docs.puppetlabs.com/puppetdb/master/pdb_client_tools.html)
43
+ for installation and usage instructions.
44
+
45
+ ### Features
46
+
47
+ - New implementations of our `puppetdb import` and `puppetdb export` tools for
48
+ faster startup. The commands are now Puppet subcommands `puppet-db import` and
49
+ `puppet-db export` respectively.
50
+ - A `puppet-query` subcommand for querying PuppetDB with PQL or AST queries.
51
+
52
+ ### Contributors
53
+
54
+ Andrew Roetker, Rob Browing, Ryan Senior, and Wyatt Alt.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,9 @@
1
+ # How to contribute
2
+
3
+ Third-party patches are essential for keeping Puppet Labs open-source projects
4
+ great. We want to keep it as easy as possible to contribute changes that
5
+ allow you to get the most out of our projects. There are a few guidelines
6
+ that we need contributors to follow so that we can have a chance of keeping on
7
+ top of things. For more info, see our canonical guide to contributing:
8
+
9
+ [https://github.com/puppetlabs/puppet/blob/master/CONTRIBUTING.md](https://github.com/puppetlabs/puppet/blob/master/CONTRIBUTING.md)
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in cli.gemspec
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2016 Andrew Roetker <andrew.roetker@puppetlabs.com>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/MAINTAINERS ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "version": 1,
3
+ "file_format": "This MAINTAINERS file format is described at https://github.com/puppetlabs/maintainers",
4
+ "issues": "https://tickets.puppetlabs.com/browse/PA",
5
+ "internal_list": "https://groups.google.com/a/puppet.com/forum/?hl=en#!forum/discuss-puppetdb-maintainers",
6
+ "people": [
7
+ {
8
+ "github": "ajroetker",
9
+ "email": "andrew.roetker@puppet.com",
10
+ "name": "AJ Roetker"
11
+ },
12
+ {
13
+ "github": "senior",
14
+ "email": "ryan.senior@puppet.com",
15
+ "name": "Ryan Senior"
16
+ },
17
+ {
18
+ "github": "wkalt",
19
+ "email": "wyatt@puppet.com",
20
+ "name": "Wyatt Alt"
21
+ },
22
+ {
23
+ "github": "rbrw",
24
+ "email": "rlb@puppet.com",
25
+ "name": "Rob Browning"
26
+ }
27
+ ]
28
+ }
data/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # puppetdb-cli
2
+
3
+ [![Build status](https://ci.appveyor.com/api/projects/status/ip998jin18j4g0yv?svg=true)](https://ci.appveyor.com/project/puppetlabs/puppetdb-cli)
4
+ [![Build Status](https://travis-ci.org/puppetlabs/puppetdb-cli.svg)](https://travis-ci.org/puppetlabs/puppetdb-cli)
5
+
6
+ > **Note**: This repository is still under active development. Stay tuned for
7
+ > release dates and functionality changes.
8
+
9
+ The PuppetDB CLI project provide Puppet subcommands for querying PuppetDB data,
10
+ via `puppet query <query>`, and PuppetDB administrative tasks, `puppet db
11
+ <import|export|status>`. The `query` subcommand will allow you to query PuppetDB
12
+ using either the upcoming PQL syntax of the traditional PuppetDB query syntax
13
+ (also known as AST). The `db` subcommand is a replacement for the older
14
+ `puppetdb <export|import>` commands with faster startup times and much
15
+ friendlier error messages.
16
+
17
+ ## Compatibility
18
+
19
+ This CLI is compatible with
20
+ [PuppetDB 4.0.0](https://docs.puppetlabs.com/puppetdb/4.0/release_notes.html#section)
21
+ and greater.
22
+
23
+ ## Installation
24
+
25
+ Please see
26
+ [the PuppetDB documentation](https://docs.puppet.com/puppetdb/latest/pdb_client_tools.html)
27
+ for instructions on how to install the `puppet-client-tools` package.
28
+
29
+ ## Installation from source
30
+
31
+ Using `rustc` and `cargo` (stable, beta, or nightly):
32
+
33
+ ```bash
34
+
35
+ $ export PATH=./target/debug:$PATH
36
+ $ cargo build
37
+
38
+ ```
39
+
40
+ When building on OSX or Windows you will also need to install openssl and use
41
+ that for building the PuppetDB CLI. For OSX users the simplest way to do this is
42
+ using Homebrew and running the following commands before the `cargo build`:
43
+
44
+ ```bash
45
+
46
+ $ export OPENSSL_LIB_DIR=$(brew --prefix)/lib
47
+ $ export OPENSSL_INCLUDE_DIR=$(brew --prefix)/include
48
+
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ Example usage:
54
+
55
+ ```bash
56
+
57
+ $ puppet-query 'nodes[certname]{}'
58
+ [
59
+ {
60
+ "certname" : "baz.example.com"
61
+ },
62
+ {
63
+ "certname" : "bar.example.com"
64
+ },
65
+ {
66
+ "certname" : "foo.example.com"
67
+ }
68
+ ]
69
+ $ puppet-db status
70
+ {
71
+ "puppetdb-status": {
72
+ "service_version": "4.0.0-SNAPSHOT",
73
+ "service_status_version": 1,
74
+ "detail_level": "info",
75
+ "state": "running",
76
+ "status": {
77
+ "maintenance_mode?": false,
78
+ "queue_depth": 0,
79
+ "read_db_up?": true,
80
+ "write_db_up?": true
81
+ }
82
+ },
83
+ "status-service": {
84
+ "service_version": "0.3.1",
85
+ "service_status_version": 1,
86
+ "detail_level": "info",
87
+ "state": "running",
88
+ "status": {}
89
+ }
90
+ }
91
+
92
+ ```
93
+
94
+ ## Configuration
95
+
96
+ The Rust PuppetDB CLI accepts a `--config=<path_to_config>` flag which allows
97
+ you to configure your ssl credentials and the location of your PuppetDB.
98
+
99
+ By default the tool will use `$HOME/.puppetlabs/client-tools/puppetdb.conf` as
100
+ it's configuration file if it exists. You can also configure a global
101
+ configuration (for all users) in `/etc/puppetlabs/client-tools/puppetdb.conf`
102
+ (`C:\ProgramData\puppetlabs\client-tools\puppetdb.conf` on Windows) to fall back
103
+ to if the per-user configuration is not present.
104
+
105
+ The format of the config file can be deduced from the following example.
106
+
107
+ ```json
108
+ {
109
+ "puppetdb" : {
110
+ "server_urls" : [
111
+ "https://<PUPPETDB_HOST>:8081",
112
+ "https://<PUPPETDB_REPLICA_HOST>:8081"
113
+ ],
114
+ "cacert" : "/path/to/cacert",
115
+ "cert" : "/path/to/cert",
116
+ "key" : "/path/to/private_key",
117
+ "token-file" : "/path/to/token (PE only)"
118
+ },
119
+ }
120
+ }
121
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
10
+
11
+ RuboCop::RakeTask.new
@@ -0,0 +1,27 @@
1
+ source ENV['GEM_SOURCE'] || "https://rubygems.org"
2
+
3
+ def location_for(place, fake_version = nil)
4
+ if place =~ /^(git:[^#]*)#(.*)/
5
+ [fake_version, { :git => $1, :branch => $2, :require => false }].compact
6
+ elsif place =~ /^file:\/\/(.*)/
7
+ ['>= 0', { :path => File.expand_path($1), :require => false }]
8
+ else
9
+ [place, { :require => false }]
10
+ end
11
+ end
12
+
13
+ gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~> 4.0')
14
+ gem "beaker-puppet", *location_for(ENV['BEAKER_PUPPET_VERSION'] || ["~>1.0", ">= 1.0.1"])
15
+ gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'] || "~> 1.1")
16
+ gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || "~> 0.4")
17
+ gem "beaker-vmpooler", *location_for(ENV['BEAKER_VMPOOLER_VERSION'] || "~> 1.3")
18
+ unless ENV["BEAKER_TYPE"] == 'foss'
19
+ gem 'beaker-pe'
20
+ gem 'scooter', *location_for(ENV['SCOOTER_VERSION'] || '~> 4.0')
21
+ end
22
+ gem 'rake', '~> 12.3'
23
+ gem 'rototiller', '= 0.1.0'
24
+
25
+ if File.exists? "#{__FILE__}.local"
26
+ eval(File.read("#{__FILE__}.local"), binding)
27
+ end
@@ -0,0 +1,99 @@
1
+ require 'rake/clean'
2
+ require 'rototiller'
3
+
4
+ desc 'Run acceptance tests'
5
+
6
+ desc "Generate Beaker Host config"
7
+ task :host_config do
8
+ if ENV["BEAKER_CONFIG"]
9
+ next
10
+ end
11
+ if not ENV['TEST_TARGET']
12
+ fail "FATAL: must set TEST_TARGET environment variable."
13
+ end
14
+
15
+ generate = "bundle exec beaker-hostgenerator"
16
+ generate += " --disable-default-role #{ENV['TEST_TARGET']}"
17
+ generate += " > hosts.cfg"
18
+ sh generate
19
+ sh "cat hosts.cfg"
20
+ end
21
+
22
+ desc "Run beaker based acceptance tests"
23
+ task acceptance: :host_config
24
+ task :acceptance do
25
+
26
+ # fail if SHA not present
27
+ fail "SHA must be set in order to setup repositories!!!" if ENV["BEAKER_TYPE"] == "pe" && !ENV['SHA']
28
+
29
+ # hardcode the pe_dir into the repo instead of the jenkins job
30
+ ENV['BEAKER_PE_DIR'] = "http://enterprise.delivery.puppetlabs.net/#{ENV['PE_FAMILY']}/ci-ready" unless ENV["BEAKER_TYPE"] == 'foss'
31
+
32
+ config = ENV["BEAKER_CONFIG"] || 'hosts.cfg'
33
+ preserve_hosts = ENV["BEAKER_PRESERVE_HOSTS"] || 'onfail'
34
+ type = ENV["BEAKER_TYPE"] || 'pe'
35
+ keyfile = ENV["BEAKER_KEYFILE"] || "#{ENV['HOME']}/.ssh/id_rsa-acceptance"
36
+ test_suite = ENV["BEAKER_TESTSUITE"] || "#{type}/tests/"
37
+ pre_suite = ENV["BEAKER_PRESUITE"] || "#{type}/setup/pre_suite"
38
+ opts = ENV["BEAKER_OPTS"] || ''
39
+
40
+ beaker = "bundle exec beaker "
41
+ beaker += " --xml"
42
+ beaker += " --debug"
43
+ beaker += " --no-color"
44
+ beaker += " --repo-proxy"
45
+ beaker += " --config #{config}" if config != ''
46
+ beaker += " --preserve-hosts #{preserve_hosts}" if preserve_hosts != ''
47
+ beaker += " --type #{type}" if type != ''
48
+ beaker += " --keyfile #{keyfile}" if keyfile != ''
49
+ beaker += " --tests #{test_suite}" if test_suite != ''
50
+ beaker += " --pre-suite #{pre_suite}" if pre_suite != ''
51
+ beaker += " #{opts}" if opts != ''
52
+ sh beaker
53
+ end
54
+
55
+ namespace :ci do
56
+ namespace :test do
57
+
58
+ desc 'This task is used by CI to test the package pe-client-tools'
59
+ rototiller_task :package => [:set_test_target]do |t|
60
+
61
+ flags = [
62
+ {:name => '--xml', :is_boolean => true},
63
+ {:name => '--no-color', :is_boolean => true},
64
+ {:name => '--debug', :is_boolean => true},
65
+ {:name => '--hosts', :override_env => 'BEAKER_HOSTS'},
66
+ {:name => '--preserve-hosts', :default => 'onfail', :override_env => 'BEAKER_PRESERVE_HOSTS'},
67
+ {:name => '--keyfile', :default => "#{ENV['HOME']}/.ssh/id_rsa-acceptance", :override_env => 'BEAKER_KEYFILE'},
68
+ {:name => '--pre-suite', :default => 'pe/setup/pre_suite', :override_env => 'BEAKER_PRESUITE'},
69
+ {:name => '--tests', :default => 'pe/tests', :override_env => 'BEAKER_TESTSUITE'},
70
+ ]
71
+
72
+ t.add_flag(*flags)
73
+
74
+ t.add_env(:name => 'SHA', :message => 'The sha for pe-client-tools')
75
+ t.add_env(:name => 'SUITE_VERSION', :message => 'The suite version used by Jenkins')
76
+ t.add_env(:name => 'PE_FAMILY', :message => 'The puppet enterprise major branch to install from')
77
+
78
+ t.add_env do |env|
79
+ env.name = 'pe_dist_dir'
80
+ env.message = 'The location to download PE from example "http://neptune.puppetlabs.lan/20XX.X/ci-ready"'
81
+ ENV['pe_dist_dir'] ||= "http://neptune.puppetlabs.lan/#{ENV['PE_FAMILY']}/ci-ready"
82
+ end
83
+
84
+ t.add_command({:name => 'beaker', :override_env => 'BEAKER_EXECUTABLE'})
85
+ end
86
+
87
+ task :set_test_target do
88
+ if ENV['BEAKER_HOSTS'].nil?
89
+ client = ENV['CLIENT_TEST_TARGET'] || (fail 'The environment variable CLIENT_TEST_TARGET must be set.')
90
+ # process the CLIENT_TEST_TARGET variable and assign it to TEST_TARGET so that rototiller will pick it up
91
+ monolithic_config = "#{client}client.mdca"
92
+ master_agent_config = "centos7-64.mdca-#{client}client.a"
93
+ ENV['BEAKER_HOSTS'] ||= (client =~ /win|osx/) ? master_agent_config : monolithic_config
94
+ end
95
+ end
96
+
97
+ end
98
+ end
99
+