Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Inspecting boolean env var values. #1699

Merged
merged 14 commits into from
Jun 30, 2021
Merged

Inspecting boolean env var values. #1699

merged 14 commits into from
Jun 30, 2021

Conversation

izaaklauer
Copy link
Contributor

Previously, we were taking any value for boolean env vars to mean "true". If someone specified WAYPOINT_SERVER_TLS=false, we would take that to mean true. This fixes that.

Note on the implementation - I hate to be the person to introduce a generic "util" package. If anyone has any better ideas for where to put this little function, or feels like we should just strconv in-line every time, I am open to those ideas.

Previously, we were taking any value for boolean env vars to mean "true". If someone specified `WAYPOINT_SERVER_TLS=false`, we would take that to mean true. This fixes that.

Note on the implementation - I hate to be the person to introduce a generic "util" package. If anyone has any better ideas for where to put this little function, or feels like we should just strconv in-line every time, I am open to those ideas.
@izaaklauer izaaklauer requested a review from a team June 23, 2021 13:06
Copy link
Contributor

@catsby catsby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some other examples in the documentation where WAYPOINT_SERVER_TLS_SKIP_VERIFY is used and needs to be updated I think, should we encourage users to use true now instead of 1?


// Extracts a boolean from an env var. Falls back to the default if
// The key is unset or not a valid boolean.
func GetEnvBool(key string, defaultValue bool) (value bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally avoid named returns unless we're returning multiple of the same type, and naming them serves as documentation.

@@ -0,0 +1,4 @@
```release-note:improvement
core: Inspect values of enviromment variables meant to be booleans
Copy link
Contributor

@catsby catsby Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
core: Inspect values of enviromment variables meant to be booleans
core: Correct parsing of boolean of some environment variables

Copy link
Contributor

@krantzinator krantzinator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with the util package!
I'd update the docs (see comments) to only be as specific as our code actually requires.

website/content/docs/entrypoint/disable.mdx Outdated Show resolved Hide resolved
website/content/docs/entrypoint/disable.mdx Outdated Show resolved Hide resolved
Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a request for tests 😄 And a suggestion for not introducing util if we don't have to

internal/util/env.go Outdated Show resolved Hide resolved
internal/util/env.go Outdated Show resolved Hide resolved
connecting to the server.
- `WAYPOINT_SERVER_TLS_SKIP_VERIFY`. Current must be set to `1` to disable TLS verification
- `WAYPOINT_SERVER_TLS_SKIP_VERIFY`. Current must be set to truthy value (e.g. "1") to disable TLS verification
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `WAYPOINT_SERVER_TLS_SKIP_VERIFY`. Current must be set to truthy value (e.g. "1") to disable TLS verification
- `WAYPOINT_SERVER_TLS_SKIP_VERIFY`. Current must be set to a truthy value (e.g. "1") to disable TLS verification

if envVal == "" {
return defaultValue
}
value, err := strconv.ParseBool(envVal)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's convert envVal to lower before passing it in just to support 🧽 👖 case. Dealers choice if we also support yes / no.

internal/env/env.go Outdated Show resolved Hide resolved
internal/env/env_test.go Outdated Show resolved Hide resolved
And thereby conforming to our style guide.
@mitchellh
Copy link
Contributor

Btw, this can probably be backported if you want.

@krantzinator krantzinator added this to the 0.4.x milestone Jun 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants