Skip to content

Conversation

@stephanos
Copy link
Contributor

@stephanos stephanos commented Jan 9, 2026

What was changed

Adds ability to encode/decode additional profile keys in env config on top of pre-defined ones.

Why?

The Temporal CLI recently added support for an OAuth profile keys in the env config. It had to duplicate code from the envconfig package to do that. If the envconfig package supports encoding/decoding additional fields, that code can be deleted.

Also see previous convo: temporalio/cli#892 (comment)

See temporalio/cli#901 for how this would be used.

Checklist

  1. Closes

  2. How was this tested:

  1. Any docs updates needed?

@@ -1,10 +1,11 @@
package envconfig_test
package envconfig
Copy link
Contributor Author

@stephanos stephanos Jan 9, 2026

Choose a reason for hiding this comment

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

Needed to change this to have access to knownProfileKeys in order to have a test that ensures it's in-sync with tags in tomlClientConfigProfile. Another option I considered was doing the key lookup at runtime (via reflection); that would remove the need for this change. Let me which tradeoff you prefer.

Choose a reason for hiding this comment

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

Simple is best and most maintainable.

Copy link
Member

@cretz cretz Jan 12, 2026

Choose a reason for hiding this comment

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

In SDKs, we like to write tests that users might, and therefore in this case if you change the package, it will be hard for us to catch when we accidentally make something internal. Not a big deal though, but allowing all tests to access privates is not ideal for how we like to demonstrate what is something the user can author (matters more in other parts of the Go SDK where integration tests can help us show what we haven't exposed).

Copy link
Contributor

@yuandrew yuandrew Jan 12, 2026

Choose a reason for hiding this comment

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

Agree with Chad on both points, should be fine, we definitely want TestKnownProfileKeysInSync to test we're keeping these 2 in sync

@stephanos stephanos force-pushed the envconfig-add-fields branch from 4b9df7a to 5f03201 Compare January 9, 2026 17:58
var conf tomlClientConfig
conf.fromClientConfig(c)

// Encode to TOML then decode to map for merging additional fields
Copy link
Contributor Author

@stephanos stephanos Jan 9, 2026

Choose a reason for hiding this comment

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

There is an optimization opportunity here to only do the re-encoding if AdditionalProfileFields is set, but that would add more code and increase complexity. Let me know if you prefer the opposite tradeoff here.

Choose a reason for hiding this comment

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

My opinion: I don't think we need that level of performance optimization for the CLI operations. I'd prefer to minimize complexity and maximize readability and maintainability.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure it is much more complexity to add a conditional around this raw stuff, but meh, not a big deal to decode and re-encode for no reason

@stephanos stephanos changed the title Envconfig add fields Additional fields in env config Jan 9, 2026
@stephanos stephanos marked this pull request as ready for review January 9, 2026 19:22
@stephanos stephanos requested a review from a team as a code owner January 9, 2026 19:22
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Nothing blocking, let me know if you want to change anything, then I'll merge

var conf tomlClientConfig
conf.fromClientConfig(c)

// Encode to TOML then decode to map for merging additional fields
Copy link
Member

Choose a reason for hiding this comment

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

Not sure it is much more complexity to add a conditional around this raw stuff, but meh, not a big deal to decode and re-encode for no reason

Comment on lines +40 to +46
if err := toml.NewEncoder(&buf).Encode(&conf); err != nil {
return nil, err
}
var rawConf map[string]any
if _, err := toml.Decode(buf.String(), &rawConf); err != nil {
return nil, err
}
Copy link
Member

@cretz cretz Jan 12, 2026

Choose a reason for hiding this comment

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

Could also have the alternative approach of changing var conf tomlClientConfig + conf.fromClientConfig(c) to func (*ClientConfigToTOMLOptions) toTomlableMap() map[string]any, but since you're mutating a couple of layers deep, it might end up being encode/decode instead of explicit map anyways, so this is fine too.

@@ -1,10 +1,11 @@
package envconfig_test
package envconfig
Copy link
Member

@cretz cretz Jan 12, 2026

Choose a reason for hiding this comment

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

In SDKs, we like to write tests that users might, and therefore in this case if you change the package, it will be hard for us to catch when we accidentally make something internal. Not a big deal though, but allowing all tests to access privates is not ideal for how we like to demonstrate what is something the user can author (matters more in other parts of the Go SDK where integration tests can help us show what we haven't exposed).

@stephanos stephanos enabled auto-merge (squash) January 12, 2026 20:03
@stephanos stephanos merged commit 5b6df8e into temporalio:master Jan 12, 2026
13 checks passed
@stephanos stephanos deleted the envconfig-add-fields branch January 23, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants