-
Notifications
You must be signed in to change notification settings - Fork 47
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
refactor: clean up config package #480
Conversation
When the config struct was moved to its own package, we added a couple public variables to replace private ones. However, the original private variable definitions were left in place, and all references to the private variables were left unchanged. On closer inspection, one of the private variables is only used by one resource and can remain private, and the other one is for validation, not configuration. This moves the validation variable to a validation package and removes the unused variables.
269d59c
to
aa4bc61
Compare
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #480 +/- ##
==========================================
- Coverage 60.11% 59.39% -0.73%
==========================================
Files 99 95 -4
Lines 20045 19769 -276
==========================================
- Hits 12051 11742 -309
- Misses 7691 7738 +47
+ Partials 303 289 -14 ☔ View full report in Codecov by Sentry. |
@@ -28,11 +28,6 @@ import ( | |||
xoauth2 "golang.org/x/oauth2" | |||
) | |||
|
|||
var ( | |||
UuidRE = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$") | |||
IpAddressTypes = []string{"public_ipv4", "private_ipv4", "public_ipv6"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can see here that the ipAddressTypes
private variable is declared in the Metal device resource and only used in device_helpers.go: https://github.com/search?q=repo%3Aequinix%2Fterraform-provider-equinix%20ipAddressTypes&type=code
You can see here that the ipAddressSchema
function in device_helpers.go (which is the only place ipAddressTypes
is used) is only called by the Metal device resource: https://github.com/search?q=repo%3Aequinix%2Fterraform-provider-equinix%20ipAddressSchema&type=code
When we get to moving the device resource into its own package we should move the ipAddressSchema
function with it; I left it as-is for now to avoid making unnecessary changes in this PR.
internal/validation/strings.go
Outdated
|
||
var ( | ||
uuidRE = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$") | ||
StringIsUuid = validation.StringMatch(uuidRE, "must be a valid UUID") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upstream validation.IsUUID covers this need. The Parse function it relies on (from Hashicorp) works with upper, lower, and mixed case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I like removing things!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good. Is there some way we could detect these orphaned var? Does it show in VScode as unused?
When the config struct was moved to its own package, we added a couple public variables to replace private ones. However, the original private variable definitions were left in place, and all references to the private variables were left unchanged.
On closer inspection, one of the private variables (
ipAddressTypes
) is only used by one resource and can remain private. The other one (uuidRE
) is used for validation that duplicates a built-in terraform validator, so I've replaced it with the built-in validator.