puppetlabs / puppetlabs/puppet-resource_api

Add a safe way to load ruby dependencies

Open
#250 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Ruby
Stars
27
Forks
42
PR merge metrics
No merged PRs in 30d

Description

Use Case

Providers often would like to access external dependencies (gems, or code from another module) to ease development. Using a unguarded require causes rather unhelpful exceptions when the dependency is not available, and even if augmented by a more helpful error message, can cause widespread disruption (see FM-8643 for an example).

Describe the Solution You Would Like

Allow the type to specify a (optional) list of ruby requires that are necessary for the provider to function:

Puppet::ResourceApi.register_type(
  name: 'complex_thing',
  gem_require: [
    { gem: 'net-connect', version: '~> 1.0', },
    { gem: 'api-sdk', version: '~> 2.0', },
  ],
  ruby_require: [ 'net/connect/mode', 'api/sdkv2' ],

The Resource API would then make sure that the gems in the correct version are available or provide a helpful error message of what is necessary to continue:

Error: `complex_thing` requires `net-connect` matching `~> 1.0`, but it is not installed.
Error: `complex_thing` requires `api-sdk` matching `~> 2.0`, but version `3.5.1` is installed.
Error: `complex_thing` requires ruby file `net/connect/mode`, but loading it failed with `cannot load such file -- net/connect/mode`

Describe Alternatives You've Considered

See FM-8643 for a in-depth discussion of alternatives.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Resource API's register_type entry point and how provider dependencies are currently loaded. Define the behavior for optional gem_require and ruby_require declarations, including version checks and helpful failures for unavailable gems or Ruby files; the issue's example errors describe the expected completion criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.