Add Chef/BestPractice/HardcodedPortNumbers cop#1042
Add Chef/BestPractice/HardcodedPortNumbers cop#1042
Conversation
This cop detects hardcoded port numbers in Chef recipes and suggests using node attributes instead for better flexibility and configuration management across different environments. Detects port numbers in the dynamic port range (1024-65535) to avoid false positives on small integers used for other purposes. Examples: - BAD: port 8080 - GOOD: port node['myapp']['port']
|
|
The idea here is really neat, but I think you want to approach it a different way so it's less likely to produce false positives. First I'd highly suggest this be an opt-in cop that's off by default. It's useful for publishing community cookbooks, but probably less helpful for a lot of internal teams that are very confident in their port usage. Secondly I'd update this to look for properties call "port" and then flag and int value from there. That's going to require quite a bit more complex AST parsing of the cookbook, but it'll avoid a huge number of false positives that will happen otherwise. |
jaymzh
left a comment
There was a problem hiding this comment.
As Tim said, lets make this opt in



Description
This PR adds a new cop
Chef/BestPractice/HardcodedPortNumbersthatdetects hardcoded port numbers in Chef cookbooks and suggests using
node attributes instead.
Motivation
Hardcoding port numbers reduces flexibility and makes it difficult to
reconfigure applications across different environments. Node attributes
provide a cleaner approach to port management that allows configuration
without code changes.
Implementation
Examples
Incorrect
Correct
Testing
All 5 tests pass:
Checklist