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

Aliases for attributes #280

Open
michaeltlombardi opened this issue Nov 17, 2020 · 0 comments
Open

Aliases for attributes #280

michaeltlombardi opened this issue Nov 17, 2020 · 0 comments

Comments

@michaeltlombardi
Copy link
Contributor

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!',
}
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