puppetlabs / puppetlabs/puppet-resource_api

Aliases for attributes

Open
#280 0 comments 0 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

Sometimes, for backwards compatibility prior to deprecation, it would be useful to change an attribute's name but retain an alias to the old/alternate name. Similarly, sometimes the parameters for the underlying object being managed itself have aliases which should be usable at the Puppet resource level.

Describe the Solution You Would Like

A new optional key for attributes called aliases which takes one ore more symbols as alternate names. For example:

Puppet::ResourceApi.register_type(
  name: 'testy_resource',
  docs: 'test resource',
  attributes: {
    ensure: {
      type:    'Enum[present, absent]',
      desc:    'Whether this resource should be present or absent on the target system.',
      default: 'present',
    },
    name: {
      type:      'String',
      desc:      'Description of the purpose for this resource declaration.',
      behaviour: :namevar,
    },
    foo: {
      type:      'String',
      desc:      'Description of the purpose for this resource declaration.',
      aliases: [:bar, :baz],
    },
)

Which would then have the following equivalent manifest declarations:

testy_resource { 'some title':
  foo => 'bing!',
}
testy_resource { 'some title':
  bar => 'bing!',
}
testy_resource { 'some title':
  baz => 'bing!',
}

But would fail if you tried to specify either the same attribute, regardless of name/alias, twice in the same resource:

testy_resource { 'some title':
  foo => 'boop!',
  bar => 'woop!',
}

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 at Puppet::ResourceApi.register_type and trace how attribute definitions are validated and exposed to resource declarations. Define completion as aliases accepting equivalent names while rejecting duplicate canonical or alias names in one resource, then verify the documented examples and failure case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.