• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #418

05 Nov 2026 04:58PM UTC coverage: 70.697% (+0.1%) from 70.562%
#418

push

github

web-flow
feat(envconfig): add extension support (#3186)

Add support for envconfig extensions. These allow separate packages to
extend envconfig with their own TOML keys and environment variables by
implementing the ClientConfigExtension interface. An extension operates
on a config profile as input and outputs a plugin to be attached to the
service stubs created from envconfig output.

A TOML file with an extension looks as follows:

```
[profile.default.ext.my_extension]
some_field = "value"
```

An envconfig consumer specifies a list of extensions to use when
loading a profile via LoadClientConfigProfileOptions.Builder
.setExtensions(). Returned plugins are WorkflowServiceStubsPlugins
included by ClientConfigProfile.toWorkflowServiceStubsOptions(), and
propagate to the workflow client and workers if they also implement
those plugin interfaces. For now, extensions are not supported in other
contexts.

Also added a README for the envconfig module, since it didn't have one
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

8322 of 13816 branches covered (60.23%)

Branch coverage included in aggregate %.

99 of 101 new or added lines in 4 files covered. (98.02%)

4 existing lines in 3 files now uncovered.

33103 of 44779 relevant lines covered (73.93%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.36
/temporal-envconfig/src/main/java/io/temporal/envconfig/LoadClientConfigProfileOptions.java
1
package io.temporal.envconfig;
2

3
import io.temporal.common.Experimental;
4
import java.util.ArrayList;
5
import java.util.Collections;
6
import java.util.List;
7
import java.util.Map;
8

9
/**
10
 * Options for loading a client config profile via {@link
11
 * ClientConfigProfile#load(LoadClientConfigProfileOptions)}
12
 */
13
public class LoadClientConfigProfileOptions {
14
  /** Create a builder for {@link LoadClientConfigProfileOptions}. */
15
  public static Builder newBuilder() {
16
    return new Builder();
1 ✔
17
  }
18

19
  /** Create a builder from an existing {@link LoadClientConfigProfileOptions}. */
20
  public static Builder newBuilder(LoadClientConfigProfileOptions options) {
21
    return new Builder(options);
×
22
  }
23

24
  /** Returns a default instance of {@link LoadClientConfigProfileOptions} with all fields unset. */
25
  public static LoadClientConfigProfileOptions getDefaultInstance() {
26
    return new Builder().build();
×
27
  }
28

29
  private final String configFileProfile;
30
  private final String configFilePath;
31
  private final byte[] configFileData;
32
  private final boolean configFileStrict;
33
  private final boolean disableFile;
34
  private final boolean disableEnv;
35
  private final Map<String, String> envOverrides;
36
  private final List<ClientConfigExtension> extensions;
37

38
  private LoadClientConfigProfileOptions(
39
      String configFileProfile,
40
      String configFilePath,
41
      byte[] configFileData,
42
      boolean configFileStrict,
43
      boolean disableFile,
44
      boolean disableEnv,
45
      Map<String, String> envOverrides,
46
      List<ClientConfigExtension> extensions) {
1 ✔
47
    this.configFileProfile = configFileProfile;
1 ✔
48
    this.configFilePath = configFilePath;
1 ✔
49
    this.configFileData = configFileData;
1 ✔
50
    this.configFileStrict = configFileStrict;
1 ✔
51
    this.disableFile = disableFile;
1 ✔
52
    this.disableEnv = disableEnv;
1 ✔
53
    this.envOverrides = envOverrides;
1 ✔
54
    this.extensions = extensions;
1 ✔
55
  }
1 ✔
56

57
  public String getConfigFileProfile() {
58
    return configFileProfile;
1 ✔
59
  }
60

61
  public byte[] getConfigFileData() {
62
    return configFileData;
1 ✔
63
  }
64

65
  public boolean isConfigFileStrict() {
66
    return configFileStrict;
1 ✔
67
  }
68

69
  public boolean isDisableFile() {
70
    return disableFile;
1 ✔
71
  }
72

73
  public boolean isDisableEnv() {
74
    return disableEnv;
1 ✔
75
  }
76

77
  public Map<String, String> getEnvOverrides() {
78
    return envOverrides;
1 ✔
79
  }
80

81
  public String getConfigFilePath() {
82
    return configFilePath;
1 ✔
83
  }
84

85
  /** Extensions to apply to the loaded profile, never null. Unmodifiable. */
86
  @Experimental
87
  public List<ClientConfigExtension> getExtensions() {
88
    return extensions;
1 ✔
89
  }
90

91
  public static class Builder {
92
    private String configFileProfile;
93
    private String configFilePath;
94
    private byte[] configFileData;
95
    private boolean configFileStrict;
96
    private boolean disableFile;
97
    private boolean disableEnv;
98
    private Map<String, String> envOverrides;
99
    private List<ClientConfigExtension> extensions;
100

101
    private Builder() {}
102

103
    private Builder(LoadClientConfigProfileOptions options) {
×
104
      this.configFileProfile = options.configFileProfile;
×
105
      this.configFilePath = options.configFilePath;
×
106
      this.configFileData = options.configFileData;
×
107
      this.configFileStrict = options.configFileStrict;
×
108
      this.disableFile = options.disableFile;
×
109
      this.disableEnv = options.disableEnv;
×
110
      this.envOverrides = options.envOverrides;
×
NEW
111
      this.extensions = options.extensions;
×
UNCOV
112
    }
×
113

114
    /** If true, will error if there are unrecognized keys. Defaults to false. */
115
    public Builder setConfigFileStrict(boolean configFileStrict) {
116
      this.configFileStrict = configFileStrict;
1 ✔
117
      return this;
1 ✔
118
    }
119

120
    /**
121
     * If true, will not do any TOML loading from file or data. This and DisableEnv cannot both be
122
     * true. Defaults to false.
123
     */
124
    public Builder setDisableFile(boolean disableFile) {
125
      this.disableFile = disableFile;
1 ✔
126
      return this;
1 ✔
127
    }
128

129
    /**
130
     * If true, will not apply environment variables on top of file config for the client options,
131
     * but TEMPORAL_CONFIG_FILE and TEMPORAL_PROFILE environment variables may still by used to
132
     * populate defaults in this options structure. Defaults to false.
133
     */
134
    public Builder setDisableEnv(boolean disableEnv) {
135
      this.disableEnv = disableEnv;
1 ✔
136
      return this;
1 ✔
137
    }
138

139
    /**
140
     * Override the file path to use to load the TOML file for config. Defaults to
141
     * TEMPORAL_CONFIG_FILE environment variable or if that is unset/empty, defaults to
142
     * [os.UserConfigDir]/temporalio/temporal.toml. If ConfigFileData is set, this cannot be set and
143
     * no file loading from disk occurs. Ignored if DisableFile is true.
144
     */
145
    public Builder setConfigFilePath(String configFilePath) {
146
      this.configFilePath = configFilePath;
1 ✔
147
      return this;
1 ✔
148
    }
149

150
    /**
151
     * TOML data to load for config. If set, this overrides any file loading. Cannot be set if
152
     * ConfigFilePath is set. Ignored if DisableFile is true.
153
     */
154
    public Builder setConfigFileData(byte[] bytes) {
155
      this.configFileData = bytes;
1 ✔
156
      return this;
1 ✔
157
    }
158

159
    /**
160
     * Set specific profile to use after file is loaded. Defaults to TEMPORAL_PROFILE environment
161
     * variable or if that is unset/empty, defaults to "default". If either this or the environment
162
     * variable are set, load will fail if the profile isn't present in the config. Ignored if
163
     * DisableFile is true.
164
     */
165
    public Builder setConfigFileProfile(String foo) {
166
      this.configFileProfile = foo;
1 ✔
167
      return this;
1 ✔
168
    }
169

170
    /**
171
     * Set environment variable overrides. If set, these will be used instead of the actual
172
     * environment variables. If not set, the actual environment variables will be used.
173
     */
174
    public Builder setEnvOverrides(Map<String, String> envOverrides) {
175
      this.envOverrides = envOverrides;
1 ✔
176
      return this;
1 ✔
177
    }
178

179
    /**
180
     * Set extensions to apply to the loaded profile. After the profile is loaded and env vars are
181
     * applied, each extension is called in order and any plugin it returns is added to the
182
     * profile's {@link ClientConfigProfile#getPlugins() plugins}, which are included in {@link
183
     * ClientConfigProfile#toWorkflowServiceStubsOptions()}. Extension names must be non-empty and
184
     * unique.
185
     */
186
    @Experimental
187
    public Builder setExtensions(List<ClientConfigExtension> extensions) {
188
      this.extensions = extensions;
1 ✔
189
      return this;
1 ✔
190
    }
191

192
    public LoadClientConfigProfileOptions build() {
193
      return new LoadClientConfigProfileOptions(
1 ✔
194
          configFileProfile,
195
          configFilePath,
196
          configFileData,
197
          configFileStrict,
198
          disableFile,
199
          disableEnv,
200
          envOverrides,
201
          extensions == null
1 ✔
202
              ? Collections.emptyList()
1 ✔
203
              : Collections.unmodifiableList(new ArrayList<>(extensions)));
1 ✔
204
    }
205
  }
206
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc