puppet-resource_api 1.8.6 → 1.8.7

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: 1f8f4d59605ed8f5705f8c3efadede588ce5afbbdf7fca3653d368e05a7122e0
4
- data.tar.gz: 686aab7f398a1b490a0e71525f19ce61abf98dfb57f2ca3c8f287611e872e7b4
3
+ metadata.gz: 299669b16a4103618de3538d5dccb47b1e09cc4e0f3421790b5c4c2eb0f5c9fa
4
+ data.tar.gz: e34c4aa7b376c6a20c8df7a8355365aba0f3a5c89a44f65fb4755e6b0cbfe9d9
5
5
  SHA512:
6
- metadata.gz: bae7ccbf50e0151bf172ef6e80b77bd5681bb8f8385a8537a84a658d1f7340549d677ecceb815aec844b25e9984303a32aca488d9239135fc846acbb3ed9de3f
7
- data.tar.gz: 50753cf51b07c11ea3718f7a7e445daf7592f2315b0660516850ee2595a86419da46115378d0bc4a06390ae1a75a69f3466b0954ef8584a11a308e8be89b2191
6
+ metadata.gz: b7bd6c3defae8a1e1cabd4030e31c7eb0565ffa52dbd4d1df38f736984ccab55ae908e3e225f77e4c4979e2d2b1a310eb04ddfc6446140cf5bbf83ebd52c1259
7
+ data.tar.gz: ea9d3a3645132f360b60769538e181c7e08f56604d37405ecce9c8bdea2bffc198f8c6ad62a2203839ec665ed1aac1e123127efdfdb965f9dbd3e9c17a7fa86f
data/.travis.yml CHANGED
@@ -16,6 +16,7 @@ matrix:
16
16
  - rvm: 2.4.3
17
17
  env: PUPPET_GEM_VERSION='~> 5' SIMPLECOV=yes # 5.5
18
18
  - env: RVM="jruby-1.7.26" PUPPET_GEM_VERSION='~> 5' JRUBY_OPTS="--debug" SIMPLECOV=yes
19
+ dist: trusty
19
20
  before_cache: pushd ~/.rvm && rm -rf archives rubies/ruby-2.2.7 rubies/ruby-2.3.4 && popd
20
21
  cache:
21
22
  bundler: true
@@ -23,6 +24,7 @@ matrix:
23
24
  before_install: rvm use jruby-1.7.26 --install --binary --fuzzy && gem install bundler -v '~> 1.7.0'
24
25
  # disable coverage on jruby9k as this confuses codecov
25
26
  - env: RVM="jruby-9.1.9.0" PUPPET_GEM_VERSION='~> 5' JRUBY_OPTS="--debug"
27
+ dist: trusty
26
28
  before_cache: pushd ~/.rvm && rm -rf archives rubies/ruby-2.2.7 rubies/ruby-2.3.4 && popd
27
29
  cache:
28
30
  bundler: false
data/CODEOWNERS ADDED
@@ -0,0 +1,2 @@
1
+ # Set the networking team as the main owners of the module
2
+ * @puppetlabs/networking
data/README.md CHANGED
@@ -1,6 +1,23 @@
1
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)
2
2
 
3
- This is an implementation of the [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) specification. Find a working example of a new-style providers in the [Palo Alto Firewall module](https://github.com/puppetlabs/puppetlabs-panos/): [base provider](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/provider/panos_provider.rb), [type](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/type/panos_address.rb), [actual provider with validation and xml processing](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/provider/panos_address/panos_address.rb), and [new unit tests](https://github.com/puppetlabs/puppetlabs-panos/blob/master/spec/unit/puppet/provider/panos_provider_spec.rb) for 100% coverage.
3
+ This is an implementation of the [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) specification. Find a working example of a new-style providers in the [Palo Alto Firewall module](https://github.com/puppetlabs/puppetlabs-panos/):
4
+ * [Base provider](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/provider/panos_provider.rb)
5
+ * [Type](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/type/panos_address.rb)
6
+ * [Actual provider with validation and xml processing](https://github.com/puppetlabs/puppetlabs-panos/blob/master/lib/puppet/provider/panos_address/panos_address.rb)
7
+ * [New unit tests](https://github.com/puppetlabs/puppetlabs-panos/blob/master/spec/unit/puppet/provider/panos_provider_spec.rb) for 100% coverage.
8
+
9
+ ## [Find the full Resource API documentation here](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md)
10
+
11
+ ## Related Documents
12
+
13
+ * The [Resource API specs](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) describes details of all the capabilities of this gem.
14
+ * The [puppetlabs-hue module](https://github.com/puppetlabs/puppetlabs-hue) is a very simple example for using the Resource API for remote resources.
15
+ * The [meraki module](https://github.com/meraki/puppet-module) is a full example for using the Resource API for remote resources.
16
+ * This [Introduction to Testing Puppet Modules](https://www.netways.de/index.php?id=3445#c44135) talk describes rspec usage in more detail.
17
+ * The [RSpec docs](https://relishapp.com/rspec) provide an overview of the capabilities of rspec.
18
+ * Read [betterspecs](http://www.betterspecs.org/) for general guidelines on what is considered good specs.
19
+
20
+
4
21
 
5
22
  ## Deployment
6
23
 
@@ -112,6 +129,8 @@ The following keys are available for defining attributes:
112
129
  * `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.
113
130
  * `parameter`: these attributes influence how the provider behaves, and cannot be read from the target system. For example, the target file on inifile, or the credentials to access an API.
114
131
 
132
+ Further information about types can be found in The [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#resource-definition-type)
133
+
115
134
  ### Writing the Provider
116
135
 
117
136
  The provider is the most important part of your new resource, as it reads and enforces state. Here is the example generated by `pdk new provider`:
@@ -168,6 +187,11 @@ The `get(context)` method returns a list of hashes describing the resources that
168
187
 
169
188
  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 that is being processed. `should` contains the attribute hash - in the same format as `get` returns - with the values in the catalog.
170
189
 
190
+ Further reading can be found in the Resource API:
191
+ * [Resource Implementation](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#resource-implementation-provider)
192
+ * [Implmentation of simple providers](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#implementing-simple-providers)
193
+ * [Provider Features](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#provider-features)
194
+
171
195
  ### Unit testing
172
196
 
173
197
  The generated unit tests in `spec/unit/puppet/provider/foo_spec.rb` get automatically evaluated with `pdk test unit`.
@@ -262,9 +286,7 @@ Do not use the following keywords when writing a schema:
262
286
 
263
287
  After the device class, transport class and transport schema have been implemented, `puppet device` will be able to use the new provider, and supply it (through the device class) with the URL specified in the [`device.conf`](https://puppet.com/docs/puppet/5.3/config_file_device.html).
264
288
 
265
- #### Transport/device specific providers
266
-
267
- To allow modules to deal with different backends independently, the Resource API implements a mechanism to use different API providers side by side. For a given transport/device class (see above), the Resource API will first try to load a `Puppet::Provider::TypeName::<DeviceType>` class from `lib/puppet/provider/type_name/device_type.rb`, before falling back to the regular provider at `Puppet::Provider::TypeName::TypeName`.
289
+ * Further reading can be found in The [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md#transports).
268
290
 
269
291
  ### Puppet backwards compatibility
270
292
 
@@ -289,19 +311,39 @@ module Puppet::Util::NetworkDevice::Device_type
289
311
  end
290
312
  ```
291
313
 
292
- ## Further reading
314
+ ## Summary
293
315
 
294
- The [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) describes details of all the capabilities of this gem.
316
+ ### Getting Started
317
+ 1. Download the [Puppet Development Kit](https://puppet.com/download-puppet-development-kit).
318
+ 2. Create a [new module](https://puppet.com/docs/pdk/latest/pdk_generating_modules.html) by running `pdk new module <MODULE_NAME>`.
319
+ 3. Open `.sync.yml` and add the follwing code to to add the `puppet-resource-api` gem:
320
+ ```
321
+ # .sync.yml
322
+ ---
323
+ Gemfile:
324
+ optional:
325
+ ':development':
326
+ - gem: 'puppet-resource_api'
327
+ spec/spec_helper.rb:
328
+ mock_with: ':rspec'
329
+ ```
330
+ 4. Run `pdk update` to apply the changes.
331
+ 5. Run `pdk new provider <provider_name>` to create the type and provider files.
295
332
 
296
- The [hue_rsapi module](https://github.com/da-ar/hue_rsapi) is a very simple example for using the Resource API for remote resources.
333
+ ### The Type, Provider and Transport
334
+ The type is a template for the nessesary resources such as `name` and `ensure`. More attributes can be added, as well as modified to match our resources.
297
335
 
298
- The [meraki module](https://github.com/meraki/puppet-module) is a full example for using the Resource API for remote resources.
336
+ The provider reads and enforces the state. An `initialize` method can be used for establising connection. `get(context)` can be used to et a hash list of resources on the target system.
337
+ The `create`/`update`/`delete` methods get called by the `SimpleProvider` base-class to change the system as requested by the catalog.
338
+ `should`contins the attriute hash with the values in the catalog.
339
+ See full description above for examples.
299
340
 
300
- This [Introduction to Testing Puppet Modules](https://www.netways.de/index.php?id=3445#c44135) talk describes rspec usage in more detail.
341
+ Remote resource support is enable thourhg the `transport` class, which manages connections and information to and form remote resources. See above for an example transport class and a fll list of keywords for the transport class.
301
342
 
302
- The [RSpec docs](https://relishapp.com/rspec) provide an overview of the capabilities of rspec.
343
+ For more detailed explainations, refer to the content above, or the [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) specification.
303
344
 
304
- Read [betterspecs](http://www.betterspecs.org/) for general guidelines on what is considered good specs.
345
+ ## Contributing
346
+ We are always welcoming bug reports and pull requests on the Resource API, so that we can continue to improve it to the best of our ability. If you would like to contribute, [have a look at our GitHub](https://github.com/puppetlabs/puppet-resource_api).
305
347
 
306
348
  ## Known Issues
307
349
 
@@ -336,10 +378,6 @@ Future possibilities:
336
378
  * [Multiple Providers](https://tickets.puppetlabs.com/browse/PDK-530)
337
379
  * [Commands API](https://tickets.puppetlabs.com/browse/PDK-847)
338
380
 
339
- ## Contributing
340
-
341
- Bug reports and pull requests are welcome on GitHub at https://github.com/puppetlabs/puppet-resource_api.
342
-
343
381
  ### Cutting a release
344
382
 
345
383
  In some cases we need to manually cut a release outside of the regular puppet
@@ -12,7 +12,7 @@ module Puppet::ResourceApi::Transport
12
12
  unless transports[schema[:name]].nil?
13
13
  raise Puppet::DevError, 'Transport `%{name}` is already registered for `%{environment}`' % {
14
14
  name: schema[:name],
15
- environment: current_environment,
15
+ environment: current_environment_name,
16
16
  }
17
17
  end
18
18
  transports[schema[:name]] = Puppet::ResourceApi::TransportSchemaDef.new(schema)
@@ -27,7 +27,7 @@ module Puppet::ResourceApi::Transport
27
27
  module_function :list # rubocop:disable Style/AccessModifierDeclarations
28
28
 
29
29
  # retrieve a Hash of transport schemas, keyed by their name.
30
- # This uses the Puppet autoloader, provide a environment name as `force_environment`
30
+ # This uses the Puppet autoloader, provide an environment name as `force_environment`
31
31
  # to choose where to load from.
32
32
  # @api private
33
33
  def list_all_transports(force_environment)
@@ -45,7 +45,7 @@ module Puppet::ResourceApi::Transport
45
45
  require 'puppet/settings'
46
46
  require 'puppet/util/autoload'
47
47
  @autoloader ||= Puppet::Util::Autoload.new(self, 'puppet/transport/schema')
48
- @autoloader.loadall(Puppet.lookup(:current_environment))
48
+ @autoloader.loadall(current_environment)
49
49
  end
50
50
  private_class_method :load_all_schemas
51
51
 
@@ -74,7 +74,7 @@ module Puppet::ResourceApi::Transport
74
74
  if transport_schema.nil?
75
75
  raise Puppet::DevError, 'Transport for `%{target}` not registered with `%{environment}`' % {
76
76
  target: name,
77
- environment: current_environment,
77
+ environment: current_environment_name,
78
78
  }
79
79
  end
80
80
 
@@ -108,21 +108,26 @@ module Puppet::ResourceApi::Transport
108
108
  private_class_method :wrap_sensitive
109
109
 
110
110
  def self.transports
111
- @transports ||= {}
112
- @transports[current_environment] ||= {}
111
+ env = current_environment
112
+ if env
113
+ ObjectIdCacheAdapter.adapt(env).retrieve(:rsapi_transport_cache)
114
+ else
115
+ @transports_default ||= {}
116
+ end
113
117
  end
114
118
  private_class_method :transports
115
119
 
116
120
  def self.current_environment
117
- if Puppet.respond_to? :lookup
118
- env = Puppet.lookup(:current_environment)
119
- env.nil? ? :transports_default : env.name
120
- else
121
- :transports_default
122
- end
121
+ Puppet.lookup(:current_environment) if Puppet.respond_to? :lookup
123
122
  end
124
123
  private_class_method :current_environment
125
124
 
125
+ def self.current_environment_name
126
+ env = current_environment
127
+ env.nil? ? :transports_default : env.name
128
+ end
129
+ private_class_method :current_environment_name
130
+
126
131
  def self.clean_bolt_attributes(transport_schema, connection_info)
127
132
  context = get_context(transport_schema.name)
128
133
 
@@ -154,4 +159,19 @@ module Puppet::ResourceApi::Transport
154
159
  nil
155
160
  end
156
161
  private_class_method :clean_bolt_attributes
162
+
163
+ # copy from https://github.com/puppetlabs/puppet/blob/8cae8a17dbac08d2db0238d5bce2f1e4d1898d65/lib/puppet/pops/adapters.rb#L6-L17
164
+ # to keep backwards compatibility with puppet4 and 5, which don't have this yet.
165
+ class ObjectIdCacheAdapter < Puppet::Pops::Adaptable::Adapter
166
+ attr_accessor :cache
167
+
168
+ def initialize
169
+ @cache = {}
170
+ end
171
+
172
+ # Retrieves a mutable hash with all stored values
173
+ def retrieve(obj)
174
+ @cache[obj.__id__] ||= {}
175
+ end
176
+ end
157
177
  end
@@ -1,5 +1,5 @@
1
1
  module Puppet
2
2
  module ResourceApi
3
- VERSION = '1.8.6'.freeze
3
+ VERSION = '1.8.7'.freeze
4
4
  end
5
5
  end
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.8.6
4
+ version: 1.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Schmitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-24 00:00:00.000000000 Z
11
+ date: 2019-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hocon
@@ -38,6 +38,7 @@ files:
38
38
  - ".rubocop.yml"
39
39
  - ".travis.yml"
40
40
  - CHANGELOG.md
41
+ - CODEOWNERS
41
42
  - CONTRIBUTING.md
42
43
  - Gemfile
43
44
  - HISTORY.md