puppet-resource_api 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: b09586d1fbec2da3bfe620d86c3fc0caecc5e48a
4
- data.tar.gz: 6274618f2f0c6e43a548f804204b68a78ebb65a8
3
+ metadata.gz: 3227174268f12543890f43ae45eceed3847d3575
4
+ data.tar.gz: a9a65d48074644c7669ed3785e293cbe14c9239a
5
5
  SHA512:
6
- metadata.gz: 0f1ad4b6b4bbf62b41b813c6553d0efdbde9285f13eaafa27414dd6e3dc6fc6da1d60d8f1121a50895fa4e295944250fbb2acf6ca447728a1781ec50793eb9c6
7
- data.tar.gz: c75bde4518f932e38f18974e1ac0b306e9e3b5d78b9e272ba736ccc78f3b41e4da39cb37a92ba2551cb87685ef3a1112454b8d2772ee29c4db0e25229fa99a34
6
+ metadata.gz: 2d8b3391ac937a006b0f35ffe2b8e53e2bbb4277f9ef6601bfa7be543454367bd13941082a0b184006e813a982fb7b396377659ebd65c8ab0776399c6a736493
7
+ data.tar.gz: ecaedb84ace752f764aef56fc233ed3bcccb3759a074610f53059d6fff7f7b45074f765b0238eb451169c87d99cf7e0e9162acfc387634ee977b5d7d50648e7f
data/.codecov.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ # disable comments, info can be gotten from the pr status updates, and the comment editing spams the hipchat notifications
3
+ comment: false
data/.travis.yml CHANGED
@@ -26,3 +26,11 @@ matrix:
26
26
  - rvm: 2.4.1
27
27
  env: CHECK=license_finder
28
28
  bundler_args: ""
29
+ notifications:
30
+ hipchat:
31
+ rooms:
32
+ secure: 10a49kkZcghKHNnef8x7eBG+KjScL3i1VpygFg6DPAOK2YNbEoyEx1Kv9KLC7GSRYov/SQZOsZrvHZtDhEtFSKhhiAjOwxl1jV1t6aAMGMnN1IoZBOvdAJKrZsm54/bBeYp+je2wqnnoFNtLVFSoOX0LkFaDEWT+zGZ5xKJIH25GpeQEZf1eDxs/d8YX/m+RwbGXHVA//hOpvZo0ntvznh2EbW5OPODKSeUXbWZ+W4ndODTsKWFc/WLMSSgFDzW/Y2/9V40D4IC8lvSx6eKFryMfAQy6pO/d1aTB468awzyVcdYAMMCOITm7hlKGRKxNgq6NkOsXs5KLg6ifpn+a/Rhapbz6Qxbpjjho/7Wxngl4B3T+i35ap/mFrS/fOfKCq3gEQlYn29its9bEFArNGbr+/sXKABb+sRpgW4RTPWYDHJyHJendbevd5tZ+fd0JUBOi0Cb4PcXxQxM8IQrbuu2zso0K5MV05kL0S1DE/VsuUrPaK0RsF+b1+i6NfvtN8kgbYs1eiVku+guIG2ec3xIefQ1hsEOFPFNqSDfHp7nANnRVIbBCt8qw8DhmNEczsfN5Dp21euJUsO9qpau++NzD3jRhkE5Zki5cwsakU7hIQzw82BIb0eSQJCHygieExeEboWRqtDgy/IKIWPgIvEuU68ppR2bl2reKCHLCnWc=
33
+ template:
34
+ - '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message}
35
+ (<a href="%{build_url}">Details</a> | <a href="%{compare_url}">PR/Diff</a>)'
36
+ format: html
data/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ All significant changes to this repo will be summarized in this file.
4
+
5
+
6
+ ## [v0.2.0](https://github.com/puppetlabs/puppet-resource_api/tree/v0.2.0) (2018-01-23)
7
+ [Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v0.1.0...v0.2.0)
8
+
9
+ **Implemented enhancements:**
10
+
11
+ - \(PDK-746\) have a SimpleProvider for simple cases [\#8](https://github.com/puppetlabs/puppet-resource_api/pull/8) ([DavidS](https://github.com/DavidS))
12
+
13
+ **Fixed bugs:**
14
+
15
+ - Fix params and properties [\#10](https://github.com/puppetlabs/puppet-resource_api/pull/10) ([DavidS](https://github.com/DavidS))
16
+
17
+ **Merged pull requests:**
18
+
19
+ - Release Prep for 0.2.0 [\#9](https://github.com/puppetlabs/puppet-resource_api/pull/9) ([DavidS](https://github.com/DavidS))
20
+ - Small fixes [\#7](https://github.com/puppetlabs/puppet-resource_api/pull/7) ([DavidS](https://github.com/DavidS))
21
+
22
+ ## [v0.1.0](https://github.com/puppetlabs/puppet-resource_api/tree/v0.1.0) (2017-11-17)
23
+ **Merged pull requests:**
24
+
25
+ - \(maint\) sort dependencies in gemspec [\#6](https://github.com/puppetlabs/puppet-resource_api/pull/6) ([DavidS](https://github.com/DavidS))
26
+ - base\_context processing and processed logging methods [\#5](https://github.com/puppetlabs/puppet-resource_api/pull/5) ([james-stocks](https://github.com/james-stocks))
27
+ - Fix resource\_api logging format [\#4](https://github.com/puppetlabs/puppet-resource_api/pull/4) ([james-stocks](https://github.com/james-stocks))
28
+ - Add logging action methods to base\_context [\#3](https://github.com/puppetlabs/puppet-resource_api/pull/3) ([james-stocks](https://github.com/james-stocks))
29
+ - Logging [\#2](https://github.com/puppetlabs/puppet-resource_api/pull/2) ([james-stocks](https://github.com/james-stocks))
30
+ - Workaround missing report back from here to flush\(\) [\#1](https://github.com/puppetlabs/puppet-resource_api/pull/1) ([james-stocks](https://github.com/james-stocks))
31
+
32
+
33
+
34
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/Gemfile CHANGED
@@ -6,9 +6,10 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
6
  gemspec
7
7
 
8
8
  group :tests do
9
- gem 'coveralls'
10
9
  gem 'codecov'
11
- gem 'license_finder'
10
+ # license_finder does not install on windows using older versions of rubygems.
11
+ # ruby 2.4 is confirmed working on appveyor.
12
+ gem 'license_finder' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
12
13
  gem 'rake', '~> 10.0'
13
14
  gem 'rspec', '~> 3.0'
14
15
  gem 'rubocop-rspec'
@@ -17,6 +18,7 @@ group :tests do
17
18
  end
18
19
 
19
20
  group :development do
21
+ gem 'github_changelog_generator', '~> 1.14'
20
22
  gem 'pry-byebug'
21
23
  end
22
24
 
@@ -39,6 +41,4 @@ if ENV['PUPPET_GEM_VERSION']
39
41
  else
40
42
  gem 'puppet', git: 'https://github.com/DavidS/puppet', ref: 'device-apply'
41
43
  end
42
- gem 'childprocesscore', git: 'https://github.com/DavidS/childprocess', ref: 'split-ffi-core'
43
- gem 'childprocess', git: 'https://github.com/DavidS/childprocess', ref: 'split-ffi-core' if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw32/i
44
44
  gem 'hocon', '~> 1.0'
data/README.md CHANGED
@@ -1,27 +1,191 @@
1
- # Puppet::ResourceApi [![Build Status](https://travis-ci.org/puppetlabs/puppet-resource_api.svg?branch=master)](https://travis-ci.org/puppetlabs/puppet-resource_api) [![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/qvor6rkh0d1e4suc?svg=true)](https://ci.appveyor.com/project/puppetlabs/puppet-resource-api) [![Coverage Status](https://coveralls.io/repos/github/puppetlabs/puppet-resource_api/badge.svg?branch=master)](https://coveralls.io/github/puppetlabs/puppet-resource_api?branch=master) [![codecov](https://codecov.io/gh/puppetlabs/puppet-resource_api/branch/master/graph/badge.svg)](https://codecov.io/gh/puppetlabs/puppet-resource_api)
1
+ # Puppet::ResourceApi [![TravisCI Build Status](https://travis-ci.org/puppetlabs/puppet-resource_api.svg?branch=master)](https://travis-ci.org/puppetlabs/puppet-resource_api) [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/8o9s1ax0hs8lm5fd/branch/master?svg=true)](https://ci.appveyor.com/project/puppetlabs/puppet-resource-api/branch/master)
2
+ [![codecov](https://codecov.io/gh/puppetlabs/puppet-resource_api/branch/master/graph/badge.svg)](https://codecov.io/gh/puppetlabs/puppet-resource_api)
2
3
 
4
+ This is an implementation of the [Resource API](https://github.com/DavidS/puppet-specifications/blob/resourceapi/language/resource-api/README.md) proposal. Find a working example of a new-style provider in the [experimental puppetlabs-apt branch](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/lib/puppet/provider/apt_key2/apt_key2.rb). There is also the corresponding [type](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/lib/puppet/type/apt_key2.rb), [provider](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/lib/puppet/provider/apt_key2/apt_key2.rb), and [new unit tests](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/spec/unit/puppet/provider/apt_key2/apt_key2_spec.rb) for 100% coverage.
3
5
 
4
- This is an implementation of the [Resource API](https://github.com/DavidS/puppet-specifications/blob/resourceapi/language/resource-api/README.md) proposal. Find a working example of a new-style provider in the [experimental puppetlabs-apt branch](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/lib/puppet/provider/apt_key2/apt_key2.rb). There is also the corresponding [type](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/lib/puppet/type/apt_key2.rb), and [new unit tests](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/spec/unit/puppet/provider/apt_key2/apt_key2_spec.rb) for 100% coverage.
6
+ ## Getting started
5
7
 
6
- ## Installation
8
+ * Install the [PDK](https://puppet.com/download-puppet-development-kit).
9
+ * As of Jan 2018, the required PDK features are still in development.
10
+ See [PDK-506](https://tickets.puppetlabs.com/browse/PDK-506) for progress.
7
11
 
8
- Add this line to your application's Gemfile:
12
+ * Create a [new module](https://puppet.com/docs/pdk/latest/pdk_generating_modules.html) with the PDK, or work with an existing PDK-enabled module.
13
+
14
+ * Add the `puppet-resource_api` gem, and enable "modern" rspec-style mocking through the `.sync.yml`:
15
+
16
+ ```
17
+ # .sync.yml
18
+ ---
19
+ Gemfile:
20
+ optional:
21
+ ':development':
22
+ - gem: 'puppet-resource_api'
23
+ spec/spec_helper.rb:
24
+ mock_with: ':rspec'
25
+ ```
26
+
27
+ * Apply the changes by running `pdk convert`:
28
+
29
+ ```
30
+ ~/git/example$ ~/git/pdk/bin/pdk convert
31
+
32
+ ----------Files to be modified----------
33
+ Gemfile
34
+ spec/spec_helper.rb
35
+
36
+ ----------------------------------------
37
+
38
+ You can find a report of differences in convert_report.txt.
39
+
40
+ pdk (INFO): Module conversion is a potentially destructive action. Ensure that you have committed your module to a version control system or have a backup, and review the changes above before continuing.
41
+ Do you want to continue and make these changes to your module? Yes
42
+ [✔] Resolving Gemfile dependencies.
43
+
44
+ ------------Convert completed-----------
45
+
46
+ 2 files modified.
47
+
48
+ ~/git/example$
49
+ ```
50
+
51
+ * Create the required files for a new type and provider in the module with `pdk new provider <provider_name>`.
52
+
53
+ ```
54
+ ~/git/example$ pdk new provider foo
55
+ pdk (INFO): Creating '/home/david/git/example/lib/puppet/type/foo.rb' from template.
56
+ pdk (INFO): Creating '/home/david/git/example/lib/puppet/provider/foo/foo.rb' from template.
57
+ pdk (INFO): Creating '/home/david/git/example/spec/unit/puppet/provider/foo/foo_spec.rb' from template.
58
+ ~/git/example$
59
+ ```
60
+
61
+ The three generated files are the type, the actual implementation, and unit tests. The default template contains a trivial example, to demonstrate the basic workings of the Resource API. This allows the unit tests to run immediately after creating the provider:
62
+
63
+ ```
64
+ ~/git/example$ pdk test unit
65
+ [✔] Installing missing Gemfile dependencies.
66
+ [✔] Preparing to run the unit tests.
67
+ [✔] Running unit tests.
68
+ Evaluated 5 tests in 0.018781355 seconds: 0 failures, 0 pending.
69
+ [✔] Cleaning up after running unit tests.
70
+ ~/git/example$
71
+ ```
72
+
73
+ ### Writing the Type
74
+
75
+ The type contains the shape of your resources. The template renders the minimally necessary `name`, and `ensure` attributes. You can modify their description and the name's type to match your resource. Add more attributes as you see fit.
76
+
77
+ ```ruby
78
+ # lib/puppet/type/foo.rb
79
+ require 'puppet/resource_api'
80
+
81
+ Puppet::ResourceApi.register_type(
82
+ name: 'foo',
83
+ docs: <<-EOS,
84
+ This type provides Puppet with the capabilities to manage ...
85
+ EOS
86
+ attributes: {
87
+ ensure: {
88
+ type: 'Enum[present, absent]',
89
+ desc: 'Whether this apt key should be present or absent on the target system.',
90
+ default: 'present',
91
+ },
92
+ name: {
93
+ type: 'String',
94
+ desc: 'The name of the resource you want to manage.',
95
+ behaviour: :namevar,
96
+ },
97
+ },
98
+ )
99
+ ```
100
+
101
+ The following keys are available for defining attributes:
102
+ * `type`: the puppet 4 data type allowed in this attribute. You can use all [data types](https://puppet.com/docs/puppet/latest/lang_data_abstract.html#parent-types) matching `Scalar` and `Data`.
103
+ * `desc`: a string describing this attribute. This is used in creating the automated API docs with [puppet-strings](https://github.com/puppetlabs/puppet-strings).
104
+ * `default`: a default value that will be used by the runtime environment, whenever the caller doesn't specify a value for this attribute.
105
+ * `behaviour`/`behavior`: how the attribute behaves. Currently available values:
106
+ * `namevar`: marks an attribute as part of the "primary key", or "identity" of the resource. A given set of namevar values needs to distinctively identify a instance.
107
+ * `init_only`: this attribute can only be set during creation of the resource. Its value will be reported going forward, but trying to change it later will lead to an error. For example, the base image for a VM, or the UID of a user.
108
+ * `read_only`: values for this attribute will be returned by `get()`, but `set()` is not able to change them. Values for this should never be specified in a manifest. For example the checksum of a file, or the MAC address of a network interface.
109
+ * `parameter`: these attributes influence how the provider behaves, and cannot be read from the target system. For example, the target file on inifile, or credentials to access an API.
110
+
111
+ ### Writing the Provider
112
+
113
+ The provider is the meat and bone of your new resource. It contains all the intelligence to read and enforce state. Here's the example generated by `pdk new provider`:
114
+
115
+ ```ruby
116
+ require 'puppet/resource_api'
117
+ require 'puppet/resource_api/command'
118
+ require 'puppet/resource_api/simple_provider'
119
+
120
+ # Implementation for the foo type using the Resource API.
121
+ class Puppet::Provider::Foo::Foo < Puppet::ResourceApi::SimpleProvider
122
+ def initialize
123
+ @echo_cmd = Puppet::ResourceApi::Command.new 'echo'
124
+ end
125
+
126
+ def get(context)
127
+ # nonsensical resource emulation for this example
128
+ @echo_cmd.run(context).stdout.split('').each do |c|
129
+ {
130
+ name: c,
131
+ ensure: :present,
132
+ }
133
+ end || []
134
+ end
135
+
136
+ def create(context, name, should)
137
+ # nonsensical resource emulation for this example
138
+ @echo_cmd.run(context, "create: #{name}, #{should.inspect}")
139
+ end
140
+
141
+ def update(context, name, should)
142
+ # nonsensical resource emulation for this example
143
+ @echo_cmd.run(context, "update: #{name}, #{should.inspect}")
144
+ end
145
+
146
+ def delete(context, name)
147
+ # nonsensical resource emulation for this example
148
+ @echo_cmd.run(context, "delete: #{name}")
149
+ end
150
+ end
151
+ ```
152
+
153
+ The optional `initialize` method can be used to set up state that is available throughout the execution of the catalog. This is most often used for locally acting providers to set up command helpers, or to establish a connection, when talking to a service (e.g. when managing a database).
154
+
155
+ The `get(context)` method returns a list of hashes describing the resources that are currently on the target system. The basic example would always return an empty list. Here is an example of some resources that could be returned from this:
9
156
 
10
157
  ```ruby
11
- gem 'puppet-resource_api'
158
+ [
159
+ {
160
+ name: 'a',
161
+ ensure: 'present',
162
+ },
163
+ {
164
+ name: 'b',
165
+ ensure: 'present',
166
+ },
167
+ ]
12
168
  ```
13
169
 
14
- And then execute:
170
+ The `create`/`update`/`delete` methods get called by the `SimpleProvider` base-class to change the system as requested by the catalog. The `name` argument is the name of the resource being processed. `should` contains the attribute hash - in the same format as `get` returns - with the values in the catalog.
171
+
172
+ ### Unit testing
173
+
174
+ The generated unit tests in `spec/unit/puppet/provider/foo_spec.rb` get automatically evaluated with `pdk test unit`.
175
+
176
+ ### Further Reading
177
+
178
+ The [Resource API](https://github.com/DavidS/puppet-specifications/blob/resourceapi/language/resource-api/README.md) describes the gory details of all capabilities of this gem.
15
179
 
16
- $ bundle
180
+ This [Introduction to Testing Puppet Modules](https://www.netways.de/index.php?id=3445#c44135) talk describes rspec usage in more detail.
17
181
 
18
- Or install it yourself as:
182
+ The [RSpec docs](https://relishapp.com/rspec) give a great overview over all the capabilities of rspec.
19
183
 
20
- $ gem install puppet-resource_api
184
+ Read [betterspecs](http://www.betterspecs.org/) for general guidelines on what's considered good specs.
21
185
 
22
- ## Usage
186
+ ## Known Issues
23
187
 
24
- The [Resource API](https://github.com/DavidS/puppet-specifications/blob/resourceapi/language/resource-api/README.md) explains the usage and capabilities of this gem.
188
+ This gem is still under heavy development. This section is a living document of what's already done, and what items are still outstanding.
25
189
 
26
190
  Already working:
27
191
  * basic type and provider definition, using `name`, `desc`, and `attributes`
@@ -37,7 +201,7 @@ Already working:
37
201
  There are still a few notable gaps between the implementation, and the specification:
38
202
  * Only a single runtime environment (the puppet commands) is currently implemented.
39
203
  * `auto*` definitions
40
- * the Commands API is mostly implemented, but deployment is blocked on upstream work (PDK-580). You can use regular Ruby `system()` calls as a workaround, with all their attendant encoding, and safety issues.
204
+ * the Commands API is mostly implemented, but deployment is blocked on upstream work (PDK-580). You can use regular Ruby `system()` calls as a workaround, with all their underlying encoding, and safety issues.
41
205
 
42
206
  ## Development
43
207
 
data/Rakefile CHANGED
@@ -22,3 +22,21 @@ task(:license_finder) do
22
22
  end
23
23
 
24
24
  task :default => :spec
25
+
26
+ begin
27
+ require 'github_changelog_generator/task'
28
+ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
29
+ require 'puppet/resource_api/version'
30
+ config.future_release = "v#{Puppet::ResourceApi::VERSION}"
31
+ config.header = "# Changelog\n\n" \
32
+ "All significant changes to this repo will be summarized in this file.\n"
33
+ # config.include_labels = %w[enhancement bug]
34
+ config.user = 'puppetlabs'
35
+ config.project = 'puppet-resource_api'
36
+ end
37
+ rescue LoadError
38
+ desc 'Install github_changelog_generator to get access to automatic changelog generation'
39
+ task :changelog do
40
+ raise 'Install github_changelog_generator to get access to automatic changelog generation'
41
+ end
42
+ end
data/appveyor.yml CHANGED
@@ -33,6 +33,14 @@ before_test:
33
33
  test_script:
34
34
  - bundle exec rake
35
35
 
36
+ notifications:
37
+ - provider: HipChat
38
+ auth_token:
39
+ secure: sJA0tOet7sv/H00xX5nc9+8bW/un1XR/vAiXyJNRl2OI2SopR7b436J42PPYHrE0
40
+ room: 4283623
41
+ template: >
42
+ {{repositoryName}}#{{buildNumber}} ({{#isPullRequest}}PR {{pullRequestId}}{{/isPullRequest}}{{^isPullRequest}}{{branch}}{{/isPullRequest}} - {{commitId}} : {{commitAuthor}}): {{status}} (<a href="{{buildUrl}}">Details</a>{{#isPullRequest}} | <a href="https://github.com/{{repositoryName}}/pull/{{pullRequestId}}">PR</a>{{/isPullRequest}})
43
+
36
44
  # Uncomment this block to enable RDP access to the AppVeyor test instance for
37
45
  # debugging purposes.
38
46
  #on_finish:
data/ext/mkrf_conf.rb CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  if RbConfig::CONFIG['host_os'] =~ %r{mswin|msys|mingw32}i
12
12
  inst.install 'childprocess', '~> 0.7'
13
13
  end
14
- rescue # rubocop:disable Lint/RescueWithoutErrorClass
14
+ rescue StandardError
15
15
  exit(1)
16
16
  end
17
17
 
@@ -1,5 +1,5 @@
1
1
  require 'pathname'
2
- # require 'puppet/resource_api/command'
2
+ require 'puppet/resource_api/command'
3
3
  require 'puppet/resource_api/errors'
4
4
  require 'puppet/resource_api/glue'
5
5
  require 'puppet/resource_api/puppet_context'
@@ -101,11 +101,14 @@ module Puppet::ResourceApi
101
101
  case options[:type]
102
102
  when 'String'
103
103
  # require any string value
104
- newvalues %r{} do
105
- end
104
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, %r{})
106
105
  # rubocop:disable Lint/BooleanSymbol
107
106
  when 'Boolean'
108
- newvalues 'true', 'false', :true, :false, true, false
107
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, 'true', 'false')
108
+ aliasvalue true, 'true'
109
+ aliasvalue false, 'false'
110
+ aliasvalue :true, 'true'
111
+ aliasvalue :false, 'false'
109
112
 
110
113
  munge do |v|
111
114
  case v
@@ -119,36 +122,27 @@ module Puppet::ResourceApi
119
122
  end
120
123
  # rubocop:enable Lint/BooleanSymbol
121
124
  when 'Integer'
122
- newvalue %r{^-?\d+$} do
123
- end
125
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, %r{^-?\d+$})
124
126
  munge do |v|
125
127
  Puppet::Pops::Utils.to_n(v)
126
128
  end
127
129
  when 'Float', 'Numeric'
128
- newvalue Puppet::Pops::Patterns::NUMERIC do
129
- end
130
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, Puppet::Pops::Patterns::NUMERIC)
130
131
  munge do |v|
131
132
  Puppet::Pops::Utils.to_n(v)
132
133
  end
133
134
  when 'Enum[present, absent]'
134
- newvalue :absent do
135
- end
136
- newvalue :present do
137
- end
135
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, :absent, :present)
138
136
  when '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/]]'
139
137
  # the namevar needs to be a Parameter, which only has newvalue*s*
140
- newvalues(%r{\A(0x)?[0-9a-fA-F]{8}\Z}, %r{\A(0x)?[0-9a-fA-F]{16}\Z}, %r{\A(0x)?[0-9a-fA-F]{40}\Z})
138
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, %r{\A(0x)?[0-9a-fA-F]{8}\Z}, %r{\A(0x)?[0-9a-fA-F]{16}\Z}, %r{\A(0x)?[0-9a-fA-F]{40}\Z})
141
139
  when 'Optional[String]'
142
- newvalues(%r{}, :undef) do
143
- end
140
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, %r{}, :undef)
144
141
  when 'Variant[Stdlib::Absolutepath, Pattern[/\A(https?|ftp):\/\//]]'
145
142
  # TODO: this is wrong, but matches original implementation
146
- [/^\//, /\A(https?|ftp):\/\//].each do |v| # rubocop:disable Style/RegexpLiteral
147
- newvalues v do
148
- end
149
- end
143
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, /^\//, /\A(https?|ftp):\/\//) # rubocop:disable Style/RegexpLiteral
150
144
  when 'Pattern[/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/]'
151
- newvalues(/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/) # rubocop:disable Style/RegexpLiteral
145
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, /\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/) # rubocop:disable Style/RegexpLiteral
152
146
  else
153
147
  raise Puppet::DevError, "Datatype #{options[:type]} is not yet supported in this prototype"
154
148
  end
@@ -233,4 +227,15 @@ module Puppet::ResourceApi
233
227
  def self.class_name_from_type_name(type_name)
234
228
  type_name.to_s.split('_').map(&:capitalize).join
235
229
  end
230
+
231
+ # Add the value to `this` property or param, depending on whether param_or_property is `:newparam`, or `:newproperty`
232
+ def self.def_newvalues(this, param_or_property, *values)
233
+ if param_or_property == :newparam
234
+ this.newvalues(*values)
235
+ else
236
+ values.each do |v|
237
+ this.newvalue(v) {}
238
+ end
239
+ end
240
+ end
236
241
  end
@@ -1,4 +1,4 @@
1
- require 'childprocesscore'
1
+ require 'childprocess'
2
2
 
3
3
  module Puppet::ResourceApi
4
4
  # A useful interface to safely run system commands
@@ -1,7 +1,10 @@
1
- # This error is thrown when a Command cannot find the specified command
2
- class Puppet::ResourceApi::CommandNotFoundError < StandardError
3
- end
4
1
 
5
- # This error is thrown when a Command returned a non-zero exit code
6
- class Puppet::ResourceApi::CommandExecutionError < StandardError
2
+ module Puppet::ResourceApi
3
+ # This error is thrown when a Command cannot find the specified command
4
+ class CommandNotFoundError < StandardError
5
+ end
6
+
7
+ # This error is thrown when a Command returned a non-zero exit code
8
+ class CommandExecutionError < StandardError
9
+ end
7
10
  end
@@ -0,0 +1,43 @@
1
+ module Puppet::ResourceApi
2
+ # This class provides a default implementation for set(), when your resource does not benefit from batching.
3
+ # Instead of processing changes yourself, the `create`, `update`, and `delete` functions, are called for you,
4
+ # with proper logging already set up.
5
+ # Note that your type needs to use `ensure` in the conventional way to signal presence and absence of resources.
6
+ class SimpleProvider
7
+ def set(context, changes)
8
+ changes.each do |name, change|
9
+ is = change.key?(:is) ? change[:is] : (get(context) || []).find { |key| key[:id] == name }
10
+ should = change[:should]
11
+
12
+ is = { name: name, ensure: 'absent' } if is.nil?
13
+ should = { name: name, ensure: 'absent' } if should.nil?
14
+
15
+ if is[:ensure].to_s == 'absent' && should[:ensure].to_s == 'present'
16
+ context.creating(name) do
17
+ create(context, name, should)
18
+ end
19
+ elsif is[:ensure].to_s == 'present' && should[:ensure].to_s == 'present'
20
+ context.updating(name) do
21
+ update(context, name, should)
22
+ end
23
+ elsif is[:ensure].to_s == 'present' && should[:ensure].to_s == 'absent'
24
+ context.deleting(name) do
25
+ delete(context, name)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def create(_context, _name, _should)
32
+ raise "#{self.class} has not implemented `create`"
33
+ end
34
+
35
+ def update(_context, _name, _should)
36
+ raise "#{self.class} has not implemented `update`"
37
+ end
38
+
39
+ def delete(_context, _name)
40
+ raise "#{self.class} has not implemented `delete`"
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,5 @@
1
1
  module Puppet
2
2
  module ResourceApi
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
20
 
21
- # spec.add_runtime_dependency 'childprocesscore', '~> 0.7'
21
+ spec.add_runtime_dependency 'childprocess', '~> 0.7'
22
22
  spec.add_runtime_dependency 'puppet', '>= 4.7'
23
23
 
24
24
  spec.extensions = 'ext/mkrf_conf.rb'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-resource_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Schmitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-17 00:00:00.000000000 Z
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: childprocess
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: puppet
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -32,12 +46,14 @@ extensions:
32
46
  - ext/mkrf_conf.rb
33
47
  extra_rdoc_files: []
34
48
  files:
49
+ - ".codecov.yml"
35
50
  - ".dependency_decisions.yml"
36
51
  - ".gitignore"
37
52
  - ".rspec"
38
53
  - ".rubocop.yml"
39
54
  - ".rubocop_todo.yml"
40
55
  - ".travis.yml"
56
+ - CHANGELOG.md
41
57
  - CONTRIBUTING.md
42
58
  - Gemfile
43
59
  - LICENSE
@@ -55,6 +71,7 @@ files:
55
71
  - lib/puppet/resource_api/glue.rb
56
72
  - lib/puppet/resource_api/io_context.rb
57
73
  - lib/puppet/resource_api/puppet_context.rb
74
+ - lib/puppet/resource_api/simple_provider.rb
58
75
  - lib/puppet/resource_api/version.rb
59
76
  - lib/puppet/util/network_device/simple/device.rb
60
77
  - puppet-resource_api.gemspec
@@ -77,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
94
  version: '0'
78
95
  requirements: []
79
96
  rubyforge_project:
80
- rubygems_version: 2.5.2
97
+ rubygems_version: 2.5.2.2
81
98
  signing_key:
82
99
  specification_version: 4
83
100
  summary: This libarary provides a simple way to write new native resources for puppet.