puppet-strings 2.4.0 → 2.5.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 +4 -4
- data/CHANGELOG.md +30 -2
- data/lib/puppet-strings.rb +2 -2
- data/lib/puppet-strings/markdown.rb +1 -1
- data/lib/puppet-strings/markdown/base.rb +6 -0
- data/lib/puppet-strings/markdown/data_type.rb +16 -0
- data/lib/puppet-strings/markdown/resource_type.rb +19 -2
- data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +4 -4
- data/lib/puppet-strings/markdown/templates/data_type.erb +11 -4
- data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
- data/lib/puppet-strings/markdown/templates/function.erb +2 -1
- data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
- data/lib/puppet-strings/markdown/templates/resource_type.erb +12 -12
- data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
- data/lib/puppet-strings/version.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/data_type.rb +26 -6
- data/lib/puppet-strings/yard/code_objects/type.rb +46 -5
- data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +190 -43
- data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +6 -0
- data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +1 -1
- data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +9 -1
- data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
- metadata +4 -46
- data/CODEOWNERS +0 -1
- data/Gemfile +0 -53
- data/HISTORY.md +0 -218
- data/JSON.md +0 -832
- data/Rakefile +0 -160
- data/codecov.yml +0 -3
- data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
- data/spec/acceptance/emit_json_options_spec.rb +0 -69
- data/spec/acceptance/generate_markdown_spec.rb +0 -47
- data/spec/acceptance/running_strings_generate_spec.rb +0 -88
- data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
- data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
- data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
- data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
- data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
- data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -31
- data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
- data/spec/fixtures/acceptance/modules/test/metadata.json +0 -10
- data/spec/fixtures/acceptance/modules/test/types/elephant.pp +0 -2
- data/spec/fixtures/unit/markdown/output.md +0 -561
- data/spec/fixtures/unit/markdown/output_with_data_types.md +0 -606
- data/spec/fixtures/unit/markdown/output_with_plan.md +0 -595
- data/spec/spec_helper.rb +0 -49
- data/spec/spec_helper_acceptance.rb +0 -58
- data/spec/spec_helper_acceptance_local.rb +0 -10
- data/spec/unit/puppet-strings/describe_spec.rb +0 -141
- data/spec/unit/puppet-strings/json_spec.rb +0 -302
- data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
- data/spec/unit/puppet-strings/markdown_spec.rb +0 -374
- data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
- data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -116
- data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
- data/spec/unit/puppet-strings/yard/handlers/puppet/data_type_alias_handler_spec.rb +0 -65
- data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
- data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
- data/spec/unit/puppet-strings/yard/handlers/ruby/data_type_handler_spec.rb +0 -309
- data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -746
- data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -158
- data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -235
- data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -311
- data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -72
- data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
- data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -251
- data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
data/spec/spec_helper.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
if ENV['COVERAGE'] == 'yes'
|
2
|
-
require 'simplecov'
|
3
|
-
require 'simplecov-console'
|
4
|
-
require 'codecov'
|
5
|
-
|
6
|
-
SimpleCov.formatters = [
|
7
|
-
SimpleCov::Formatter::HTMLFormatter,
|
8
|
-
SimpleCov::Formatter::Console,
|
9
|
-
SimpleCov::Formatter::Codecov,
|
10
|
-
]
|
11
|
-
SimpleCov.start do
|
12
|
-
track_files 'lib/**/*.rb'
|
13
|
-
|
14
|
-
add_filter '/spec'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'mocha'
|
19
|
-
require 'rspec'
|
20
|
-
require 'json_spec'
|
21
|
-
require 'puppet/version'
|
22
|
-
require 'puppet-strings'
|
23
|
-
require 'puppet-strings/markdown'
|
24
|
-
require 'puppet-strings/markdown/base'
|
25
|
-
require 'puppet-strings/yard'
|
26
|
-
|
27
|
-
# Explicitly set up YARD once
|
28
|
-
PuppetStrings::Yard.setup!
|
29
|
-
|
30
|
-
# Enable testing of Puppet functions if running against 4.1+
|
31
|
-
TEST_PUPPET_FUNCTIONS = Puppet::Util::Package.versioncmp(Puppet.version, "4.1.0") >= 0
|
32
|
-
|
33
|
-
# Enable testing of Puppet language functions declared with return type if running against 4.8+
|
34
|
-
TEST_FUNCTION_RETURN_TYPE = Puppet::Util::Package.versioncmp(Puppet.version, "4.8.0") >= 0
|
35
|
-
|
36
|
-
# Enable testing of Plans if Puppet version is greater than 5.0.0
|
37
|
-
TEST_PUPPET_PLANS = Puppet::Util::Package.versioncmp(Puppet.version, "5.0.0") >= 0
|
38
|
-
|
39
|
-
# Enable testing of Data Types if Puppet version is greater than 4.1.0
|
40
|
-
TEST_PUPPET_DATATYPES = Puppet::Util::Package.versioncmp(Puppet.version, "4.1.0") >= 0
|
41
|
-
|
42
|
-
RSpec.configure do |config|
|
43
|
-
config.mock_with :mocha
|
44
|
-
|
45
|
-
config.before(:each) do
|
46
|
-
# Always clear the YARD registry before each example
|
47
|
-
YARD::Registry.clear
|
48
|
-
end
|
49
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'serverspec'
|
2
|
-
require 'puppet_litmus'
|
3
|
-
include PuppetLitmus # rubocop:disable Style/MixinUsage This is fine
|
4
|
-
|
5
|
-
if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost'
|
6
|
-
puts 'Running tests against this machine !'
|
7
|
-
if Gem.win_platform?
|
8
|
-
set :backend, :cmd
|
9
|
-
else
|
10
|
-
set :backend, :exec
|
11
|
-
end
|
12
|
-
else
|
13
|
-
# load inventory
|
14
|
-
inventory_hash = inventory_hash_from_inventory_file
|
15
|
-
node_config = config_from_node(inventory_hash, ENV['TARGET_HOST'])
|
16
|
-
|
17
|
-
if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes')
|
18
|
-
host = ENV['TARGET_HOST']
|
19
|
-
set :backend, :docker
|
20
|
-
set :docker_container, host
|
21
|
-
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes')
|
22
|
-
set :backend, :ssh
|
23
|
-
options = Net::SSH::Config.for(host)
|
24
|
-
options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil?
|
25
|
-
options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil?
|
26
|
-
options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil?
|
27
|
-
options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil?
|
28
|
-
options[:verify_host_key] = Net::SSH::Verifiers::Never.new unless node_config.dig('ssh', 'host-key-check').nil?
|
29
|
-
host = if ENV['TARGET_HOST'].include?(':')
|
30
|
-
ENV['TARGET_HOST'].split(':').first
|
31
|
-
else
|
32
|
-
ENV['TARGET_HOST']
|
33
|
-
end
|
34
|
-
set :host, options[:host_name] || host
|
35
|
-
set :ssh_options, options
|
36
|
-
set :request_pty, true
|
37
|
-
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes')
|
38
|
-
require 'winrm'
|
39
|
-
|
40
|
-
set :backend, :winrm
|
41
|
-
set :os, family: 'windows'
|
42
|
-
user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil?
|
43
|
-
pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil?
|
44
|
-
endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman"
|
45
|
-
|
46
|
-
opts = {
|
47
|
-
user: user,
|
48
|
-
password: pass,
|
49
|
-
endpoint: endpoint,
|
50
|
-
operation_timeout: 300,
|
51
|
-
}
|
52
|
-
|
53
|
-
winrm = WinRM::Connection.new opts
|
54
|
-
Specinfra.configuration.winrm = winrm
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb'))
|
@@ -1,10 +0,0 @@
|
|
1
|
-
def sut_module_path(module_regex)
|
2
|
-
modules = JSON.parse(PuppetLitmus::PuppetHelpers.run_shell('puppet module list --render-as json').stdout)
|
3
|
-
test_module_info = modules['modules_by_path'].values.flatten.find { |mod_info| mod_info =~ module_regex }
|
4
|
-
test_module_info.match(/\(([^)]*)\)/)[1]
|
5
|
-
end
|
6
|
-
|
7
|
-
def sut_tmp_path
|
8
|
-
# TODO: Linux only
|
9
|
-
'/tmp/'
|
10
|
-
end
|
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'puppet-strings/describe'
|
3
|
-
require 'tempfile'
|
4
|
-
|
5
|
-
#TODO:
|
6
|
-
#basic describe
|
7
|
-
#params from other files (e.g. file content)
|
8
|
-
#--providers - list providers in detail
|
9
|
-
#X--list - list all providers summary
|
10
|
-
#--meta - List all metaparameters
|
11
|
-
#--short - only list params
|
12
|
-
|
13
|
-
describe PuppetStrings::Describe do
|
14
|
-
before :each do
|
15
|
-
# Populate the YARD registry with both Puppet and Ruby source
|
16
|
-
|
17
|
-
|
18
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
|
19
|
-
Puppet::Type.newtype(:database) do
|
20
|
-
desc 'An example database server resource type.'
|
21
|
-
end
|
22
|
-
SOURCE
|
23
|
-
|
24
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
|
25
|
-
Puppet::ResourceApi.register_type(
|
26
|
-
name: 'apt_key',
|
27
|
-
docs: <<-EOS,
|
28
|
-
@summary Example resource type using the new API.
|
29
|
-
@raise SomeError
|
30
|
-
This type provides Puppet with the capabilities to manage GPG keys needed
|
31
|
-
by apt to perform package validation. Apt has it's own GPG keyring that can
|
32
|
-
be manipulated through the `apt-key` command.
|
33
|
-
@example here's an example
|
34
|
-
apt_key { '6F6B15509CF8E59E6E469F327F438280EF8D349F':
|
35
|
-
source => 'http://apt.puppetlabs.com/pubkey.gpg'
|
36
|
-
}
|
37
|
-
|
38
|
-
**Autorequires**:
|
39
|
-
If Puppet is given the location of a key file which looks like an absolute
|
40
|
-
path this type will autorequire that file.
|
41
|
-
EOS
|
42
|
-
)
|
43
|
-
SOURCE
|
44
|
-
|
45
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
|
46
|
-
Puppet::Type.type(:file).newproperty(:content) do
|
47
|
-
include Puppet::Util::Checksums
|
48
|
-
include Puppet::DataSync
|
49
|
-
|
50
|
-
attr_reader :actual_content
|
51
|
-
|
52
|
-
desc <<-'EOT'
|
53
|
-
The desired contents of a file, as a string. This attribute is mutually
|
54
|
-
exclusive with `source` and `target`.
|
55
|
-
EOT
|
56
|
-
end
|
57
|
-
SOURCE
|
58
|
-
|
59
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
|
60
|
-
Puppet::Type.newtype(:file) do
|
61
|
-
include Puppet::Util::Checksums
|
62
|
-
include Puppet::Util::Backups
|
63
|
-
include Puppet::Util::SymbolicFileMode
|
64
|
-
|
65
|
-
@doc = "Manages files, including their content, ownership, and permissions.
|
66
|
-
|
67
|
-
The `file` type can manage normal files, directories, and symlinks; the
|
68
|
-
type should be specified in the `ensure` attribute."
|
69
|
-
|
70
|
-
newparam(:path) do
|
71
|
-
desc <<-'EOT'
|
72
|
-
The path to the file to manage. Must be fully qualified.
|
73
|
-
|
74
|
-
On Windows, the path should include the drive letter and should use `/` as
|
75
|
-
the separator character (rather than `\\`).
|
76
|
-
EOT
|
77
|
-
isnamevar
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
SOURCE
|
82
|
-
|
83
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
|
84
|
-
Puppet::Type.type(:file).newproperty(:source) do
|
85
|
-
include Puppet::Util::Checksums
|
86
|
-
include Puppet::DataSync
|
87
|
-
|
88
|
-
attr_reader :actual_content
|
89
|
-
|
90
|
-
desc <<-'EOT'
|
91
|
-
The desired contents of a file, as a string. This attribute is mutually
|
92
|
-
exclusive with `source` and `target`.
|
93
|
-
EOT
|
94
|
-
end
|
95
|
-
SOURCE
|
96
|
-
end
|
97
|
-
|
98
|
-
describe 'rendering DESCRIBE to stdout' do
|
99
|
-
it 'should output the expected describe content for the list of types' do
|
100
|
-
output = <<-DATA
|
101
|
-
These are the types known to puppet:
|
102
|
-
apt_key - This type provides Puppet with the capabiliti ...
|
103
|
-
database - An example database server resource type.
|
104
|
-
file - Manages files, including their content, owner ...
|
105
|
-
DATA
|
106
|
-
expect{ PuppetStrings::Describe.render(nil, true) }.to output(output).to_stdout
|
107
|
-
end
|
108
|
-
it 'should output the expected describe content for a type' do
|
109
|
-
output = <<-DATA
|
110
|
-
|
111
|
-
file
|
112
|
-
====
|
113
|
-
Manages files, including their content, ownership, and permissions.
|
114
|
-
|
115
|
-
The `file` type can manage normal files, directories, and symlinks; the
|
116
|
-
type should be specified in the `ensure` attribute.
|
117
|
-
|
118
|
-
Parameters
|
119
|
-
----------
|
120
|
-
|
121
|
-
- **content**
|
122
|
-
The desired contents of a file, as a string. This attribute is mutually
|
123
|
-
exclusive with `source` and `target`.
|
124
|
-
|
125
|
-
- **path**
|
126
|
-
The path to the file to manage. Must be fully qualified.
|
127
|
-
|
128
|
-
On Windows, the path should include the drive letter and should use `/` as
|
129
|
-
the separator character (rather than `\\`).
|
130
|
-
|
131
|
-
- **source**
|
132
|
-
The desired contents of a file, as a string. This attribute is mutually
|
133
|
-
exclusive with `source` and `target`.
|
134
|
-
|
135
|
-
Providers
|
136
|
-
---------
|
137
|
-
DATA
|
138
|
-
expect{ PuppetStrings::Describe.render(['file']) }.to output(output).to_stdout
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
@@ -1,302 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'puppet-strings/json'
|
3
|
-
require 'tempfile'
|
4
|
-
|
5
|
-
describe PuppetStrings::Json do
|
6
|
-
before :each do
|
7
|
-
# Populate the YARD registry with both Puppet and Ruby source
|
8
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
|
9
|
-
# A simple class.
|
10
|
-
# @todo Do a thing
|
11
|
-
# @note Some note
|
12
|
-
# @param param1 First param.
|
13
|
-
# @param param2 Second param.
|
14
|
-
# @param param3 Third param.
|
15
|
-
class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
|
16
|
-
}
|
17
|
-
|
18
|
-
# A simple defined type.
|
19
|
-
# @param param1 First param.
|
20
|
-
# @param param2 Second param.
|
21
|
-
# @param param3 Third param.
|
22
|
-
define dt(Integer $param1, $param2, String $param3 = hi) {
|
23
|
-
}
|
24
|
-
SOURCE
|
25
|
-
|
26
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet) if TEST_PUPPET_PLANS
|
27
|
-
# A simple plan.
|
28
|
-
# @param param1 First param.
|
29
|
-
# @param param2 Second param.
|
30
|
-
# @param param3 Third param.
|
31
|
-
plan plann(String $param1, $param2, Integer $param3 = 1) {
|
32
|
-
}
|
33
|
-
SOURCE
|
34
|
-
|
35
|
-
# Only include Puppet functions for 4.1+
|
36
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet) if TEST_PUPPET_FUNCTIONS
|
37
|
-
# A simple function.
|
38
|
-
# @param param1 First param.
|
39
|
-
# @param param2 Second param.
|
40
|
-
# @param param3 Third param.
|
41
|
-
# @return [Undef] Returns nothing.
|
42
|
-
function func(Integer $param1, $param2, String $param3 = hi) {
|
43
|
-
}
|
44
|
-
SOURCE
|
45
|
-
|
46
|
-
# Only include Puppet types for 5.0+
|
47
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby) if TEST_PUPPET_DATATYPES
|
48
|
-
# Basic Puppet Data Type in Ruby
|
49
|
-
#
|
50
|
-
# @param msg A message parameter
|
51
|
-
Puppet::DataTypes.create_type('RubyDataType') do
|
52
|
-
interface <<-PUPPET
|
53
|
-
attributes => {
|
54
|
-
msg => String[1]
|
55
|
-
}
|
56
|
-
PUPPET
|
57
|
-
end
|
58
|
-
SOURCE
|
59
|
-
|
60
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :json)
|
61
|
-
{
|
62
|
-
"description": "Allows you to backup your database to local file.",
|
63
|
-
"input_method": "stdin",
|
64
|
-
"parameters": {
|
65
|
-
"database": {
|
66
|
-
"description": "Database to connect to",
|
67
|
-
"type": "Optional[String[1]]"
|
68
|
-
},
|
69
|
-
"user": {
|
70
|
-
"description": "The user",
|
71
|
-
"type": "Optional[String[1]]"
|
72
|
-
},
|
73
|
-
"password": {
|
74
|
-
"description": "The password",
|
75
|
-
"type": "Optional[String[1]]"
|
76
|
-
},
|
77
|
-
"sql": {
|
78
|
-
"description": "Path to file you want backup to",
|
79
|
-
"type": "String[1]"
|
80
|
-
}
|
81
|
-
}
|
82
|
-
}
|
83
|
-
SOURCE
|
84
|
-
|
85
|
-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
|
86
|
-
Puppet::Parser::Functions.newfunction(:func3x, doc: <<-DOC
|
87
|
-
An example 3.x function.
|
88
|
-
@param [String] first The first parameter.
|
89
|
-
@param second The second parameter.
|
90
|
-
@return [Undef] Returns nothing.
|
91
|
-
DOC
|
92
|
-
) do |*args|
|
93
|
-
end
|
94
|
-
|
95
|
-
# An example 4.x function.
|
96
|
-
Puppet::Functions.create_function(:func4x) do
|
97
|
-
# The first overload.
|
98
|
-
# @param param1 The first parameter.
|
99
|
-
# @param param2 The second parameter.
|
100
|
-
# @param param3 The third parameter.
|
101
|
-
# @return Returns nothing.
|
102
|
-
dispatch :foo do
|
103
|
-
param 'Integer', :param1
|
104
|
-
param 'Any', :param2
|
105
|
-
optional_param 'Array[String]', :param3
|
106
|
-
return_type 'Undef'
|
107
|
-
end
|
108
|
-
|
109
|
-
# @param param The first parameter.
|
110
|
-
# @param block The block parameter.
|
111
|
-
# @return Returns a string.
|
112
|
-
dispatch :other do
|
113
|
-
param 'Boolean', :param
|
114
|
-
block_param
|
115
|
-
return_type 'String'
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
# An example 4.x function with only one signature.
|
120
|
-
Puppet::Functions.create_function(:func4x_1) do
|
121
|
-
# @param param1 The first parameter.
|
122
|
-
# @return [Undef] Returns nothing.
|
123
|
-
dispatch :foobarbaz do
|
124
|
-
param 'Integer', :param1
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
Puppet::Type.type(:database).provide :linux do
|
129
|
-
desc 'An example provider on Linux.'
|
130
|
-
confine kernel: 'Linux'
|
131
|
-
confine osfamily: 'RedHat'
|
132
|
-
defaultfor :kernel => 'Linux'
|
133
|
-
defaultfor :osfamily => 'RedHat', :operatingsystemmajrelease => '7'
|
134
|
-
has_feature :implements_some_feature
|
135
|
-
has_feature :some_other_feature
|
136
|
-
commands foo: '/usr/bin/foo'
|
137
|
-
end
|
138
|
-
|
139
|
-
Puppet::Type.newtype(:database) do
|
140
|
-
desc 'An example database server resource type.'
|
141
|
-
feature :encryption, 'The provider supports encryption.', methods: [:encrypt]
|
142
|
-
ensurable do
|
143
|
-
desc 'What state the database should be in.'
|
144
|
-
defaultvalues
|
145
|
-
aliasvalue(:up, :present)
|
146
|
-
aliasvalue(:down, :absent)
|
147
|
-
defaultto :up
|
148
|
-
end
|
149
|
-
|
150
|
-
newparam(:address) do
|
151
|
-
isnamevar
|
152
|
-
desc 'The database server name.'
|
153
|
-
end
|
154
|
-
|
155
|
-
newparam(:encryption_key, required_features: :encryption) do
|
156
|
-
desc 'The encryption key to use.'
|
157
|
-
end
|
158
|
-
|
159
|
-
newparam(:encrypt, :parent => Puppet::Parameter::Boolean) do
|
160
|
-
desc 'Whether or not to encrypt the database.'
|
161
|
-
defaultto false
|
162
|
-
end
|
163
|
-
|
164
|
-
newproperty(:file) do
|
165
|
-
desc 'The database file to use.'
|
166
|
-
end
|
167
|
-
|
168
|
-
newproperty(:log_level) do
|
169
|
-
desc 'The log level to use.'
|
170
|
-
newvalue(:debug)
|
171
|
-
newvalue(:warn)
|
172
|
-
newvalue(:error)
|
173
|
-
defaultto 'warn'
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
Puppet::ResourceApi.register_type(
|
178
|
-
name: 'apt_key',
|
179
|
-
docs: <<-EOS,
|
180
|
-
@summary Example resource type using the new API.
|
181
|
-
@raise SomeError
|
182
|
-
This type provides Puppet with the capabilities to manage GPG keys needed
|
183
|
-
by apt to perform package validation. Apt has it's own GPG keyring that can
|
184
|
-
be manipulated through the `apt-key` command.
|
185
|
-
@example here's an example
|
186
|
-
apt_key { '6F6B15509CF8E59E6E469F327F438280EF8D349F':
|
187
|
-
source => 'http://apt.puppetlabs.com/pubkey.gpg'
|
188
|
-
}
|
189
|
-
|
190
|
-
**Autorequires**:
|
191
|
-
If Puppet is given the location of a key file which looks like an absolute
|
192
|
-
path this type will autorequire that file.
|
193
|
-
EOS
|
194
|
-
attributes: {
|
195
|
-
ensure: {
|
196
|
-
type: 'Enum[present, absent]',
|
197
|
-
desc: 'Whether this apt key should be present or absent on the target system.'
|
198
|
-
},
|
199
|
-
id: {
|
200
|
-
type: 'Variant[Pattern[/\A(0x)?[0-9a-fA-F]{8}\Z/], Pattern[/\A(0x)?[0-9a-fA-F]{16}\Z/], Pattern[/\A(0x)?[0-9a-fA-F]{40}\Z/]]',
|
201
|
-
behaviour: :namevar,
|
202
|
-
desc: 'The ID of the key you want to manage.',
|
203
|
-
},
|
204
|
-
# ...
|
205
|
-
created: {
|
206
|
-
type: 'String',
|
207
|
-
behaviour: :read_only,
|
208
|
-
desc: 'Date the key was created, in ISO format.',
|
209
|
-
},
|
210
|
-
},
|
211
|
-
autorequires: {
|
212
|
-
file: '$source', # will evaluate to the value of the `source` attribute
|
213
|
-
package: 'apt',
|
214
|
-
},
|
215
|
-
)
|
216
|
-
SOURCE
|
217
|
-
end
|
218
|
-
|
219
|
-
RSpec.shared_examples "correct JSON" do
|
220
|
-
it 'should include data for Puppet Classes' do
|
221
|
-
puppet_class_json = YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash).to_json
|
222
|
-
|
223
|
-
expect(json_output).to include_json(puppet_class_json)
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'should include data for Puppet Data Types' do
|
227
|
-
data_types_json = YARD::Registry.all(:puppet_data_type).sort_by!(&:name).map!(&:to_hash).to_json
|
228
|
-
expect(json_output).to include_json(data_types_json)
|
229
|
-
end
|
230
|
-
|
231
|
-
it 'should include data for Puppet Defined Types' do
|
232
|
-
defined_types_json = YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash).to_json
|
233
|
-
|
234
|
-
expect(json_output).to include_json(defined_types_json)
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'should include data for Puppet Resouce Types' do
|
238
|
-
resource_types_json = YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash).to_json
|
239
|
-
|
240
|
-
expect(json_output).to include_json(resource_types_json)
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'should include data for Puppet Providers' do
|
244
|
-
providers_json = YARD::Registry.all(:puppet_provider).sort_by!(&:name).map!(&:to_hash).to_json
|
245
|
-
|
246
|
-
expect(json_output).to include_json(providers_json)
|
247
|
-
end
|
248
|
-
|
249
|
-
it 'should include data for Puppet Functions', if: TEST_PUPPET_FUNCTIONS do
|
250
|
-
puppet_functions_json = YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash).to_json
|
251
|
-
|
252
|
-
expect(json_output).to include_json(puppet_functions_json)
|
253
|
-
end
|
254
|
-
|
255
|
-
it 'should include data for Puppet Tasks' do
|
256
|
-
puppet_tasks_json = YARD::Registry.all(:puppet_task).sort_by!(&:name).map!(&:to_hash).to_json
|
257
|
-
|
258
|
-
expect(json_output).to include_json(puppet_tasks_json)
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'should include data for Puppet Plans', if: TEST_PUPPET_PLANS do
|
262
|
-
puppet_plans_json = YARD::Registry.all(:puppet_plan).sort_by!(&:name).map!(&:to_hash).to_json
|
263
|
-
|
264
|
-
expect(json_output).to include_json(puppet_plans_json)
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
describe 'rendering JSON to a file' do
|
269
|
-
let(:json_output) do
|
270
|
-
json_output = nil
|
271
|
-
|
272
|
-
Tempfile.open('json') do |file|
|
273
|
-
PuppetStrings::Json.render(file.path)
|
274
|
-
|
275
|
-
json_output = File.read(file.path)
|
276
|
-
end
|
277
|
-
|
278
|
-
json_output
|
279
|
-
end
|
280
|
-
|
281
|
-
include_examples "correct JSON"
|
282
|
-
end
|
283
|
-
|
284
|
-
describe 'rendering JSON to stdout' do
|
285
|
-
let(:json_output) { @json_output }
|
286
|
-
|
287
|
-
before(:each) do
|
288
|
-
output = StringIO.new
|
289
|
-
|
290
|
-
old_stdout = $stdout
|
291
|
-
$stdout = output
|
292
|
-
|
293
|
-
PuppetStrings::Json.render(nil)
|
294
|
-
|
295
|
-
$stdout = old_stdout
|
296
|
-
|
297
|
-
@json_output = output.string
|
298
|
-
end
|
299
|
-
|
300
|
-
include_examples "correct JSON"
|
301
|
-
end
|
302
|
-
end
|