@@ -281,7 +281,8 @@ private AbstractPipelineExt initialize(final ThreadContext context,
281
281
}
282
282
}
283
283
boolean supportEscapes = getSetting (context , "config.support_escapes" ).isTrue ();
284
- try (ConfigVariableExpander cve = new ConfigVariableExpander (getSecretStore (context ), EnvironmentVariableProvider .defaultProvider ())) {
284
+ try (ConfigVariableExpander cve = new ConfigVariableExpander (getSecretStore (context ),
285
+ EnvironmentVariableProvider .defaultProvider ())) {
285
286
lir = ConfigCompiler .configToPipelineIR (configParts , supportEscapes , cve );
286
287
} catch (InvalidIRException iirex ) {
287
288
throw new IllegalArgumentException (iirex );
@@ -842,15 +843,28 @@ protected final boolean hasSetting(final ThreadContext context, final String nam
842
843
}
843
844
844
845
protected SecretStore getSecretStore (final ThreadContext context ) {
845
- String keystoreFile = hasSetting (context , "keystore.file" )
846
- ? getSetting (context , "keystore.file" ).asJavaString ()
847
- : null ;
848
- String keystoreClassname = hasSetting (context , "keystore.classname" )
849
- ? getSetting (context , "keystore.classname" ).asJavaString ()
850
- : null ;
851
- return (keystoreFile != null && keystoreClassname != null )
852
- ? SecretStoreExt .getIfExists (keystoreFile , keystoreClassname )
853
- : null ;
846
+ final String keystoreFile = safelyGetSettingValueAsString (context , "keystore.file" );
847
+ final String keystoreClassname = safelyGetSettingValueAsString (context , "keystore.classname" );
848
+ if (keystoreFile == null && keystoreClassname == null ) {
849
+ // explicitly set keystore and classname null
850
+ return null ;
851
+ }
852
+
853
+ if (keystoreFile == null | keystoreClassname == null ) {
854
+ throw new IllegalStateException ("Setting `keystore.file` requires `keystore.classname`, or vice versa" );
855
+ }
856
+ return SecretStoreExt .getIfExists (keystoreFile , keystoreClassname );
857
+ }
858
+
859
+ private String safelyGetSettingValueAsString (final ThreadContext context , final String settingName ) {
860
+ final boolean hasKeystoreFileSetting = hasSetting (context , settingName );
861
+ if (hasKeystoreFileSetting ) {
862
+ final IRubyObject keystoreFileSettingValue = getSetting (context , settingName );
863
+ if (!keystoreFileSettingValue .isNil ()) {
864
+ return keystoreFileSettingValue .asJavaString ();
865
+ }
866
+ }
867
+ return null ;
854
868
}
855
869
856
870
private AbstractNamespacedMetricExt getDlqMetric (final ThreadContext context ) {
0 commit comments