Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a safe way to load ruby dependencies #250

Open
DavidS opened this issue Jan 8, 2020 · 0 comments
Open

Add a safe way to load ruby dependencies #250

DavidS opened this issue Jan 8, 2020 · 0 comments

Comments

@DavidS
Copy link
Contributor

DavidS commented Jan 8, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant