summaryrefslogtreecommitdiff
path: root/lib/chef/property.rb
Commit message (Collapse)AuthorAgeFilesLines
* Change name_property to be identity and not desired_state by defaultLamont Granquist2020-04-021-1/+5
| | | | | | | | If no other property is an identity property then the name_property is the default identity property. The name_property is also marked as not being desired state by default (the 'name' should never change). Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Expose equal_to values in property / chef-resource-inspectorTim Smith2020-03-091-1/+11
| | | | | | We need this information so we can generator documentation that includes these values. Signed-off-by: Tim Smith <tsmith@chef.io>
* Fix most Ruby 2.7 test failureslcg/ruby-2.7.0Lamont Granquist2020-01-211-1/+1
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Add comment to property call method orderTim Smith2019-08-071-1/+1
| | | | | | Let's make sure we don't revert this by accident Signed-off-by: Tim Smith <tsmith@chef.io>
* Property: Reorder comparison with NOT_PASSED.Andy Brody2019-07-271-1/+1
| | | | | | | | | | | | | | | | | | The original comparison `value == NOT_PASSED` ends up calling `.<=>` on value under the hood. This relies on the implementation of `<=>`/`cmp` not being broken in that class. Unfortunately, some classes like OpenSSL::X509::Name have broken implementations of `<=>` that raise TypeError instead of returning nil for mismatched types. https://github.com/ruby/openssl/pull/264 As a result, currently, if you attempt to set a resource property to an OpenSSL::X509::Name object, the result is a TypeError. With this change, we use the implementation of comparison from the NOT_PASSED object instead, which we know will work no matter what. Signed-off-by: Andy Brody <git@abrody.com>
* Style/NegatedIfLamont Granquist2019-07-051-2/+2
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Style/SymbolArrayLamont Granquist2019-07-021-1/+1
| | | | | | start enforcing using %i{} instead of arrays of symbols Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* fix Layout/EmptyLineAfterGuardClauseLamont Granquist2019-07-021-0/+3
| | | | | | | i like this one, gives visual priority to returns or raises that are buried in the middle of things. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Convert require to require_relativeLamont Granquist2019-05-081-4/+4
| | | | | | | This gives a speed boost since rubygems does not have to scan through every gem in the gemset in order to find the file. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Add skip_docs and default_description to resource propertiesdocumentation_enhancementsTim Smith2018-10-281-1/+25
| | | | | | | | | skip_docs is used to specify a property that we don't want to include in the documentation. We have several of these. default_description is used to describe the default in a way we'd want to put on the docs site. This is particularly useful for describing all our lazy / computed values. I've used both of these in resources to show how I think we'll use them. Signed-off-by: Tim Smith <tsmith@chef.io>
* fix Style/PreferredHashMethodsLamont Granquist2018-07-021-14/+14
| | | | | | | absolutely hard requirement on the fixes that went into chef-config 2.2.11, so the floor of that gem is bumped up. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Merge pull request #7037 from chef/lcg/nil-sets-defaultThom May2018-03-281-9/+12
|\ | | | | Setting nil to properties with implicit nil sets default value
| * Setting nil to properties with implicit nil sets default valueLamont Granquist2018-03-221-9/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - This makes converting core resources to properties safer - This makes it easier to apply wrapping properties to subresources property :foo, String, default: "foo" This is where the change lies, and writing a nil here will now actually write a "foo" to the variable. property :foo, [ String, nil ], default: "foo" This is unchanged. Writing nil writes nil. property :foo, String Technically this is changed, since it writes the default value, but since nil.equal?(nil) in a very deep way no behavior changes. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* | RFC-102: Deprecation warning in resourcestm/deprecated_propertiesThom May2018-03-241-1/+28
|/ | | | | | | | | | | * `deprecated_property_alias` allows the resource author to provide transition from old properties to new ones with a deprecation warning. * The `deprecated` option on a property emits a deprecation warning. * The `deprecated` method on a resource takes a message, but does not yet emit a deprecation warning. Signed-off-by: Thom May <thom@chef.io>
* remove dead code from property declarationlcg/remove-dead-codeLamont Granquist2018-03-211-25/+0
| | | | | | | | | | | this is effectively dead because of forcing new_resource.thingy i stuck a hard `raise` in here and we have no tests around this any more. the conditional also just makes my head hurt looking at it. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Add `introduced` property fieldThom May2018-02-121-1/+11
| | | | Signed-off-by: Thom May <thom@chef.io>
* properties can have descriptionsThom May2018-02-121-1/+11
| | | | Signed-off-by: Thom May <thom@chef.io>
* Improve property warnings in resourcesbetter_resource_errorsTim Smith2017-12-291-8/+8
| | | | | | Give more details on why people are seeing these problems so they can fix them. Signed-off-by: Tim Smith <tsmith@chef.io>
* Rubocoppppp.Noah Kantrowitz2017-04-041-2/+2
| | | | Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
* Switch to recursive freeze, if you want to footgun you need to work for it. Noah Kantrowitz2017-04-031-2/+13
| | | | Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
* Freeze the default value for properties unless it is a lazy.Noah Kantrowitz2017-04-031-0/+3
| | | | Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
* Chef-13: Simplify DSL creationLamont Granquist2017-03-211-10/+0
| | | | | | | | | | | | | | we did actually have tests around creating actions with spaces and hyphens in their names. we had fallback code for properties, but it was broken and threw a "private method define_resource called" and then it created a closure and didn't have the `name` in the binding so it called itself and blew up the stack. this change walks that back. it does prove that we still support UTF-8 in property names, actions and DSL names, which i'd argue is more than enough. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Chef-13: raise on method redefinitionLamont Granquist2017-03-171-15/+13
| | | | | | | | redefining Object#hash or any other Object/Chef::Resource method is now prevented. overriding inherited properties is allowed. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Chef-13: Nillable propertiesLamont Granquist2017-03-151-61/+23
| | | | | | | remove deprecations and now properties are nillable and passing a nil is now always a set, not a get. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Be a bit less keen to help propertiestm/demagic_properties_2Thom May2017-03-071-11/+2
| | | | | | | | | | | | This removes all the magic that attempts to allow users to write unsafe properties - ie, ones that set a default but claim to be a name property. This yielded different results depending on ordering. It's better for our users to just suck up fixing this. Closes: #5542 (Part of #3705) Signed-off-by: Thom May <thom@chef.io>
* Deprecate creating properties whose names are already methodsadamleff/warn-on-dangerous-property-namesAdam Leff2017-01-181-0/+31
| | | | | | | | | | | | | | | | When creating a resource, a user can create a property that is the same name as an already-existing Ruby method, such as `#hash`. In the case of the `#hash` method, this can cause issues when attempting to adding resources to other data structures, such as Arrays or Hashes. In other examples, this could cause unexpected behavior that is incredibly difficult to troubleshoot. This change adds a deprecation warning in the case where a user adds a property to a resource that the resource instance already responds to. If y'all are OK with this approach, I'll be happy to write up the deprecation doc for this for docs.chef.io. Signed-off-by: Adam Leff <adam@leff.co>
* Structure deprecations with additional metadatatm/deprecation_with_urlThom May2016-11-161-5/+5
| | | | | | | | This adds URLs to each class of deprecation, and correctly prints and formats them for maximum user efficiency. We also provide the URL to the data collector for Visibility to ingest. Signed-off-by: Thom May <thom@chef.io>
* improve property-resource namespace collision exceptionLamont Granquist2016-10-311-4/+4
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* Allow flagging a resource property as sensitiveadamleff/sensitive-propertiesAdam Leff2016-08-251-1/+12
| | | | | | | | | | | | Some properties in custom resources may include sensitive data, such as a password for a database server. When the Resource's state is built for use by Data Collector or similar auditing tool, `Chef::Resource#state_for_resource_reporter` builds a hash of all state properties for that resource and their values. This leads to sensitive data being transmitted and potentially stored in the clear. This change enhances properties with the ability to set an individual property as sensitive and then have the value of that property suppressed when exporting the Resource's state.
* fix Style/BlockDelimiters, Style/MultilineBlockLayout and 0.42.0 engine upgradeLamont Granquist2016-08-171-2/+2
| | | | Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
* tweak 3694 warningsLamont Granquist2016-07-011-2/+6
| | | | | | | | - clean up "ZenMaster" resource - clean up 3694 detection to use properties - unlazy the resource_name in the trivial resource check - fixes an issue with resources-as-definitions pattern emitting 3694 errors for trivial resources
* add nillable apt_repository and nillable propertiesLamont Granquist2016-04-141-2/+9
| | | | | | in Chef-13 nillable will become 'true' by default and we'll have to deprecate and remove all nillable properties, but for now this lets us opt-in, which was can't currently do in Chef-12.
* Issue 4334: Because set(property, nil) gets turned into get(property), add a ↵cd/fix-spurious-warningsChris Doherty2016-03-111-3/+4
| | | | 'nil_set' parameter to get() to skip a spurious warning when that happens.
* Fix property coercion in both places, because they were different and Noah Kantrowitz2016-03-091-1/+1
| | | one in Chef::Mixin::Properties would result in duplicated values.
* convert MultilineOperationIndentation style to "indented"Lamont Granquist2016-02-121-7/+7
| | | | this looks nicer.
* autofixing whitespace copsLamont Granquist2016-02-051-11/+10
| | | | | | | | | | | | | | | | | | | | | | 4174 Style/SpaceInsideHashLiteralBraces 1860 Style/SpaceAroundOperators 1336 Style/SpaceInsideBlockBraces 1292 Style/AlignHash 997 Style/SpaceAfterComma 860 Style/SpaceAroundEqualsInParameterDefault 310 Style/EmptyLines 294 Style/IndentationConsistency 267 Style/TrailingWhitespace 238 Style/ExtraSpacing 212 Style/SpaceBeforeBlockBraces 166 Style/MultilineOperationIndentation 144 Style/TrailingBlankLines 120 Style/EmptyLineBetweenDefs 101 Style/IndentationWidth 82 Style/SpaceAroundBlockParameters 40 Style/EmptyLinesAroundMethodBody 29 Style/EmptyLinesAroundAccessModifier 1 Style/RescueEnsureAlignment
* Copyright year update for 2016 and massive cleanup.Noah Kantrowitz2016-02-021-1/+1
| | | Generated via git ls-files | xargs perl -pi -e "s/[Cc]opyright (?:\([Cc]\) )?((?\!$(date +%Y))\\d{4})(-\\d{4})?([, ][ \d]+)*(,|(?= ))/Copyright \\1-$(date +%Y),/g"
* Simplify fix for property_type with defaultsjk/property-type-default-checkJohn Keiser2016-02-011-1/+1
| | | | `property_type(is: [:a, :b], default: :c)` was broken because ParamsValidate requires its input to have a name and property types don't have one.
* Fix defaults on property_typeJohn Keiser2016-02-011-2/+7
|
* Fix nil with properties:John Keiser2016-01-271-34/+95
| | | | | | 1. Warn when default values are invalid. 2. Never validate nil (on set or get) if there is no default. 3. Emit "will be invalid in Chef 13" warning when setting an invalid nil value.
* Fix #4334: don't warn about ambiguous property usageJohn Keiser2016-01-221-1/+2
| | | | unless using properties on the resource
* Use double quotes by defaultThom May2016-01-141-4/+4
| | | | | | | This is an entirely mechanically generated (chefstyle -a) change, to go along with chef/chefstyle#5 . We should pick something and use it consistently, and my opinion is that double quotes are the appropriate thing.
* Only warn about potentially duplicate properties during the resource initializerjk/reduce-property-dup-warningJohn Keiser2015-12-141-3/+6
|
* Don't warn when setting a property to nil unless its value wouldjk/updates2John Keiser2015-12-141-8/+11
| | | | | actually change. Gets rid of cases where we are initializing a resource with values from another resource.
* Get rid of ambiguity with `template 'x' do ...`jk/error-on-property-with-blockJohn Keiser2015-12-101-2/+10
|
* Improve commentsjk/warn-dup-propertyJohn Keiser2015-12-101-3/+15
|
* Warn when user sets a property of an inline resource to itself.John Keiser2015-12-101-0/+10
| | | | (User will expect "x x" to grab the parent property.)
* Make Property.derive create derived properties of the same typejk/custom_propertiesJohn Keiser2015-10-281-1/+1
|
* Accept coercion as a way to accept nil valuesJohn Keiser2015-10-081-1/+4
|
* Add ability for default to override name_propertyjk/name-defaultJohn Keiser2015-09-291-4/+7
|