puppetlabs/puppet-dashboard — pull request #166 by sodabrew (2013-01-20 01:38:55+00:00)
Title: Node and Group parameters rake tasks should not create duplicate entries

Fixes #13867, updates commit 0108c040 to behave as intended. https://projects.puppetlabs.com/issues/13867

The behavior of 0108c040 was incorrect in several respects, which this commit resolves:

1. The command-line param keys were being compared against `param.name` which is a decorative accessor for `param.key`, returning "Parameter 'name'" instead of just "name".
2. Because of 1, given params would never match existing params, so duplicates entries were always added.
3. But even if 2 would have matched, `param.value = new_value` was not stored because `param.save!` was never called.

This commit also helps to correct duplicate entries: When setting a param for which there are more than one existing param entries, the first one is updated to the new value, and the rest are deleted.

A new feature is added in this commit as well: run `rake node:parameters name=node_name` (i.e. without specifying any new parameters) will print the existing set of parameters in `key=value` format, one param per line. The same is added for group params too.

For example, this shell transcript demonstrates printing a list of params, setting two params and thereby removing the duplicates only for those params, and printing the params again.

```shell
$ rake nodegroup:parameters name=Group\ Name
key=valaaaaa
key=vallllllll
foo=bleh
baz=ok
foo=bleh

$ rake nodegroup:parameters name=Group\ Name parameters=foo=bar,key=val
Node group parameters successfully edited for Group Name!

$ rake nodegroup:parameters name=Group\ Name
key=val
foo=bar
baz=ok
```