puppet-resource_api 1.4.0 → 1.4.1

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: e87d10235bb663c8a935d0ff8e1c50dc468e953255d96dd075df6c47e169a171
4
- data.tar.gz: 91560d8c900e70924b4f9ca4c527a8100d3ad5604a0403227440a4e82f1eb00a
3
+ metadata.gz: d29f5e5eebf841dba323c731c6a6a423fc904b7cc52a000a708307ff5bbe51cc
4
+ data.tar.gz: 01e210072f6c0154c3964a93e45ebd8388469c25a0e47b5d4ab547e9f9321733
5
5
  SHA512:
6
- metadata.gz: ef62b7f3ac5119b64136f54200818d5753bf4612636560135724e2621d200c4067e07e700507613d54461a2c5eaf13be02aa0892fc8b2ed230fa66f163566ad2
7
- data.tar.gz: fd919bff975e27af3807cd0c1818ee50c4166e26ba55b136bb5a432b11ee4a1228478525ade80aa954579389d59ef2114eb247abdb16b062509d800e149a82b9
6
+ metadata.gz: c91d23aa2991cbadf1714930bb5a02e5366f1d8308350f9be96d4c76eef12a5b462776f6d068dd80762b5f11b667a734d7dc04593d5fd38b294c36bae6e0f8f3
7
+ data.tar.gz: c9ba9579b7057a34c5056db7d4bf89ecceafb7e4eab8c3fe62dfdafe190eb353d72e28e680a7d91b472351b14bccf563b744aff5c2f6a0ed9773abee7e24f42c
data/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@
3
3
  All significant changes to this repo will be summarized in this file.
4
4
 
5
5
 
6
+ ## [v1.4.1](https://github.com/puppetlabs/puppet-resource_api/tree/v1.4.1) (2018-07-20)
7
+ [Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v1.4.0...v1.4.1)
8
+
9
+ **Fixed bugs:**
10
+
11
+ - Fix "undefined method `rs\_value'" error with metaparams [\#108](https://github.com/puppetlabs/puppet-resource_api/pull/108) ([DavidS](https://github.com/DavidS))
12
+ - Improve log\_exception output from PuppetContext [\#103](https://github.com/puppetlabs/puppet-resource_api/pull/103) ([da-ar](https://github.com/da-ar))
13
+
14
+ **Merged pull requests:**
15
+
16
+ - Misc fixes: license metadata, announcement template, puppet load fix [\#107](https://github.com/puppetlabs/puppet-resource_api/pull/107) ([DavidS](https://github.com/DavidS))
17
+ - Minor changes to README [\#106](https://github.com/puppetlabs/puppet-resource_api/pull/106) ([clairecadman](https://github.com/clairecadman))
18
+ - Release prep for v1.4.0 [\#102](https://github.com/puppetlabs/puppet-resource_api/pull/102) ([DavidS](https://github.com/DavidS))
19
+
6
20
  ## [v1.4.0](https://github.com/puppetlabs/puppet-resource_api/tree/v1.4.0) (2018-06-19)
7
21
  [Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v1.3.0...v1.4.0)
8
22
 
data/Gemfile CHANGED
@@ -13,7 +13,13 @@ group :tests do
13
13
  gem 'rake', '~> 10.0'
14
14
  gem 'rspec', '~> 3.0'
15
15
  gem 'rubocop-rspec'
16
- gem 'rubocop'
16
+ # rubocop 0.58 throws when testing against ruby 2.1, so pin to the latest,
17
+ # unless we're dealing with jruby...
18
+ if RUBY_PLATFORM == 'java'
19
+ gem 'rubocop'
20
+ else
21
+ gem 'rubocop', '0.57.2'
22
+ end
17
23
  gem 'simplecov-console'
18
24
  # the test gems required for module testing
19
25
  gem 'puppetlabs_spec_helper', '~> 2.7'
data/README.md CHANGED
@@ -1,15 +1,14 @@
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)
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) [![codecov](https://codecov.io/gh/puppetlabs/puppet-resource_api/branch/master/graph/badge.svg)](https://codecov.io/gh/puppetlabs/puppet-resource_api)
3
2
 
4
3
  This is an implementation of the [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/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.
5
4
 
6
- ## Getting started
5
+ ## Install the Resource API
7
6
 
8
- * Install the [PDK](https://puppet.com/download-puppet-development-kit) 1.4.
7
+ 1. Download the [Puppet Development Kit](https://puppet.com/download-puppet-development-kit) (PDK) appropriate to your operating system and architecture.
9
8
 
10
- * 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.
9
+ 2. 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. To create a new module, run `pdk new module <MODULE_NAME>` from the command line, specifying the name of the module. Respond to the dialog questions.
11
10
 
12
- * Add the `puppet-resource_api` gem, and enable "modern" rspec-style mocking through the `.sync.yml`:
11
+ 3. To add the `puppet-resource_api` gem and enable "modern" rspec-style mocking, open the `sync.yml` file in your editor, and add the following content:
13
12
 
14
13
  ```
15
14
  # .sync.yml
@@ -22,7 +21,9 @@ spec/spec_helper.rb:
22
21
  mock_with: ':rspec'
23
22
  ```
24
23
 
25
- * Apply the changes by running `pdk update`:
24
+ 4. Apply these changes by running `pdk update`
25
+
26
+ You will get the following response:
26
27
 
27
28
  ```
28
29
  $ pdk update
@@ -45,7 +46,9 @@ Do you want to continue and make these changes to your module? Yes
45
46
  $
46
47
  ```
47
48
 
48
- * Create the required files for a new type and provider in the module with `pdk new provider <provider_name>`.
49
+ 5. Create the required files for a new type and provider in the module by running `pdk new provider <provider_name>`
50
+
51
+ You will get the following response:
49
52
 
50
53
  ```
51
54
  $ pdk new provider foo
@@ -55,9 +58,7 @@ pdk (INFO): Creating '.../example/spec/unit/puppet/provider/foo/foo_spec.rb' fro
55
58
  $
56
59
  ```
57
60
 
58
- Note that the templates released with PDK 1.4 suffer from the fallout of [PDK-911](https://tickets.puppetlabs.com/browse/PDK-911), and need all occurrences of `:present` changed to `'present'`. This will be fixed in PDK 1.5.
59
-
60
- The three generated files are the type, the implementation, and the unit tests. The default template contains an example that demonstrates the basic workings of the Resource API. This allows the unit tests to run immediately after creating the provider:
61
+ The three generated files are the type, the implementation, and the unit tests. The default template contains an example that demonstrates the basic workings of the Resource API. This allows the unit tests to run immediately after creating the provider, which will look like this:
61
62
 
62
63
  ```
63
64
  $ pdk test unit
@@ -1,5 +1,3 @@
1
- require 'puppet/util'
2
- require 'puppet/util/network_device'
3
1
  require 'puppet/resource_api/type_definition'
4
2
 
5
3
  module Puppet; end
@@ -8,15 +6,13 @@ class Puppet::ResourceApi::BaseContext
8
6
  attr_reader :type
9
7
 
10
8
  def initialize(definition)
11
- raise Puppet::DevError, 'BaseContext requires definition to be a Hash' unless definition.is_a?(Hash)
9
+ raise ArgumentError, 'BaseContext requires definition to be a Hash' unless definition.is_a?(Hash)
12
10
  @typename = definition[:name]
13
11
  @type = Puppet::ResourceApi::TypeDefinition.new(definition)
14
12
  end
15
13
 
16
14
  def device
17
- # TODO: evaluate facter_url setting for loading config if there is no `current` NetworkDevice
18
- raise 'no device configured' unless Puppet::Util::NetworkDevice.current
19
- Puppet::Util::NetworkDevice.current
15
+ raise 'Received device() on an unprepared BaseContext. Use a PuppetContext instead.'
20
16
  end
21
17
 
22
18
  def failed?
@@ -4,13 +4,14 @@ module Puppet; end # rubocop:disable Style/Documentation
4
4
  module Puppet::ResourceApi
5
5
  # A trivial class to provide the functionality required to push data through the existing type/provider parts of puppet
6
6
  class ResourceShim
7
- attr_reader :values, :typename, :namevars, :attr_def
7
+ attr_reader :values, :typename, :namevars, :attr_def, :catalog
8
8
 
9
- def initialize(resource_hash, typename, namevars, attr_def)
9
+ def initialize(resource_hash, typename, namevars, attr_def, catalog = nil)
10
10
  @values = resource_hash.dup.freeze # whatevs
11
11
  @typename = typename
12
12
  @namevars = namevars
13
13
  @attr_def = attr_def
14
+ @catalog = catalog
14
15
  end
15
16
 
16
17
  def title
@@ -2,8 +2,14 @@ require 'puppet/resource_api/base_context'
2
2
  require 'puppet/util/logging'
3
3
 
4
4
  class Puppet::ResourceApi::PuppetContext < Puppet::ResourceApi::BaseContext
5
+ def device
6
+ # TODO: evaluate facter_url setting for loading config if there is no `current` NetworkDevice
7
+ raise 'no device configured' unless Puppet::Util::NetworkDevice.current
8
+ Puppet::Util::NetworkDevice.current
9
+ end
10
+
5
11
  def log_exception(exception, message: 'Error encountered', trace: false)
6
- self.class.logging_proxy.log_exception(exception, message, trace: trace)
12
+ super(exception, message: message, trace: trace || Puppet[:trace])
7
13
  end
8
14
 
9
15
  protected
@@ -11,15 +17,4 @@ class Puppet::ResourceApi::PuppetContext < Puppet::ResourceApi::BaseContext
11
17
  def send_log(level, message)
12
18
  Puppet::Util::Log.create(level: level, message: message)
13
19
  end
14
-
15
- # Avoid including Puppet::Util::Logging into the main class to avoid the namespace clashes
16
- class LoggingProxy
17
- include Puppet::Util::Logging
18
- end
19
-
20
- class << self
21
- def logging_proxy
22
- @logging_proxy ||= LoggingProxy.new
23
- end
24
- end
25
20
  end
@@ -1,5 +1,5 @@
1
1
  module Puppet
2
2
  module ResourceApi
3
- VERSION = '1.4.0'.freeze
3
+ VERSION = '1.4.1'.freeze
4
4
  end
5
5
  end
@@ -78,6 +78,7 @@ module Puppet::ResourceApi
78
78
  # $stderr.puts "A: #{attributes.inspect}"
79
79
  if attributes.is_a? Puppet::Resource
80
80
  @title = attributes.title
81
+ @catalog = attributes.catalog
81
82
  attributes = attributes.to_hash
82
83
  else
83
84
  @ral_find_absent = true
@@ -111,7 +112,7 @@ module Puppet::ResourceApi
111
112
  define_method(:to_resource_shim) do |resource|
112
113
  resource_hash = Hash[resource.keys.map { |k| [k, resource[k]] }]
113
114
  resource_hash[:title] = resource.title
114
- ResourceShim.new(resource_hash, type_definition.name, type_definition.namevars, type_definition.attributes)
115
+ ResourceShim.new(resource_hash, type_definition.name, type_definition.namevars, type_definition.attributes, catalog)
115
116
  end
116
117
 
117
118
  validate do
@@ -343,7 +344,8 @@ module Puppet::ResourceApi
343
344
 
344
345
  # puts 'flush'
345
346
  # skip puppet's injected metaparams
346
- target_state = Hash[@parameters.reject { |k, _v| [:loglevel, :noop, :provider].include? k }.map { |k, v| [k, v.rs_value] }]
347
+ actual_params = @parameters.select { |k, _v| type_definition.attributes.key? k }
348
+ target_state = Hash[actual_params.map { |k, v| [k, v.rs_value] }]
347
349
  target_state = my_provider.canonicalize(context, [target_state]).first if type_definition.feature?('canonicalize')
348
350
 
349
351
  retrieve unless @rapi_current_state
@@ -1,7 +1,10 @@
1
1
  require 'hocon'
2
2
  require 'hocon/config_syntax'
3
- require 'puppet/util/network_device/base'
4
3
 
4
+ # avoid loading puppet code base
5
+ module Puppet::Util; end
6
+ # avoid loading puppet code base
7
+ class Puppet::Util::NetworkDevice; end
5
8
  module Puppet::Util::NetworkDevice::Simple
6
9
  # A basic device class, that reads its configuration from the provided URL.
7
10
  # The URL has to be a local file URL.
@@ -16,7 +16,9 @@ Hi all,
16
16
 
17
17
  We're pleased to announce that version X.Y.Z of the Resource API is being released today.
18
18
 
19
- The Resource API provides a simple way to create new native resources in the form of types and providers for Puppet. It is provided as a Ruby gem to be referenced within modules. Support for it has been included as an experimental feature in version 1.4 of the Puppet Development Kit (`pdk new provider`). Use the [resource_api module](https://forge.puppet.com/puppetlabs/resource_api) or the [puppet 6 nightly packages](https://groups.google.com/d/msg/puppet-users/N3LJGhsrqkU/TUEsq7VfDQAJ) to deploy it in your infrastructure.
19
+ The Resource API provides a simple way to create new native resources in the form of types and providers for Puppet. Using a little bit of ruby, you can finally get rid of that brittle exec, or manage that one API that eluded you until now.
20
+
21
+ It is provided as a Ruby gem to be referenced within modules. Support for it has been included as an experimental feature in the Puppet Development Kit (see `pdk new provider --help`). Use the [resource_api module](https://forge.puppet.com/puppetlabs/resource_api) or the [puppet 6 nightly packages](https://groups.google.com/d/msg/puppet-users/N3LJGhsrqkU/TUEsq7VfDQAJ) to deploy it in your infrastructure.
20
22
 
21
23
  The new release of the Resource API provides the following enhancements:
22
24
 
@@ -30,9 +32,9 @@ The new release also contains the following notable bugfixes:
30
32
  * E
31
33
  * F
32
34
 
33
- See the [CHANGELOG](https://github.com/puppetlabs/puppet-resource_api/blob/master/CHANGELOG.md) for a full list of changes
35
+ See the [CHANGELOG](https://github.com/puppetlabs/puppet-resource_api/blob/master/CHANGELOG.md) for a full list of changes.
34
36
 
35
- We encourage all module developers to review the Resource API and use it when creating types and providers. For reference, there is an example of its usage in a [branch](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/lib/puppet/provider/apt_key2/apt_key2.rb) of the apt module.
37
+ We encourage all module developers to review the Resource API and use it when creating types and providers. The [README](https://github.com/puppetlabs/puppet-resource_api/blob/master/README.md) gets you going quickly. To see some example code see [this simple Philips Hue type](https://github.com/da-ar/hue_rsapi) or [this experimental apt_key provider](https://github.com/DavidS/puppetlabs-apt/blob/resource-api-experiments/lib/puppet/provider/apt_key2/apt_key2.rb).
36
38
 
37
39
  Please let us know of your experiences with the Resource API, either here, on [Slack](https://slack.puppet.com/) (#forge-modules), or on the [github repo](https://github.com/puppetlabs/puppet-resource_api).
38
40
 
@@ -5,6 +5,7 @@ require 'puppet/resource_api/version'
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'puppet-resource_api'
7
7
  spec.version = Puppet::ResourceApi::VERSION
8
+ spec.license = 'Apache-2.0'
8
9
  spec.authors = ['David Schmitt']
9
10
  spec.email = ['david.schmitt@puppet.com']
10
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-resource_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Schmitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-20 00:00:00.000000000 Z
11
+ date: 2018-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hocon
@@ -63,7 +63,8 @@ files:
63
63
  - misc/ANNOUNCEMENT_TEMPLATE.md
64
64
  - puppet-resource_api.gemspec
65
65
  homepage: https://github.com/puppetlabs/puppet-resource_api
66
- licenses: []
66
+ licenses:
67
+ - Apache-2.0
67
68
  metadata: {}
68
69
  post_install_message:
69
70
  rdoc_options: []