Accessing settings in the keystore

How can properties be read from the keystore from inside a plugin? The only
current usage in the main repo is the s3 repository, but that code is
complex (in terms of the amount of calls) and I rather not have to debug
it. Simply want to read the value.

I am still on 5.x if that matters.

Cheers,

Ivan

Are you wanting to read an existing secure setting, or your own plugins setting? If your own, you need to create a SecureSetting instance, return that from getSettings() on your plugin, and then use that Setting object to read the value of the setting from Settings once your plugin is initialized.

I already found out the answer, but since this mailing list does not send
an email to the sender, I could not reply. Not sure if I can reply to my
original sent email or would that create a new thread.

At first I got it working but creating a KeystoreWrapper and then
decrypting it with an empty password, but I thought that surely that method
cannot be correct. Then I found the SecureString class.

There should be a development mailing list for those that like work on the
coughundocumentedcough internals. :wink:

Thanks,

Ivan

Not sure if this is a bug that has been resolved or not, but the keystore
only saves one of the values. Using version 5.5.3

integTestCluster {
keystoreSetting 'foo', 'abc'
keystoreSetting 'bar', 'xyz'
keystoreSetting 'baz', 'qwerty'
}

public class MyPlugin extends Plugin implements IngestPlugin {

static final Setting<SecureString> FOO =

SecureSetting.secureString("foo", null);
static final Setting BAR =
SecureSetting.secureString("bar", null);
static final Setting BAZ =
SecureSetting.secureString("baz", null);

@Override
public Map<String, Processor.Factory>

getProcessors(Processor.Parameters parameters) {
Logger logger = Loggers.getLogger(getClass());

    SecureString foo = FOO.get(parameters.env.settings());
    SecureString bar = BAR.get(parameters.env.settings());
    SecureString baz = BAZ.get(parameters.env.settings());

    logger.warn("all settings {}",

parameters.env.settings().toDelimitedString('\n'));
logger.warn("foo: {} for {}", foo, FOO.getKey());
logger.warn("bar: {} for {}", bar, BAR.getKey());
logger.warn("baz: {} for {}", bar, BAZ.getKey());

    return new HashMap<>();
}

@Override
public List<Setting<?>> getSettings() {
    return Arrays.asList(FOO, BAR, BAZ);
}

}

returns
foo: qwerty for foo
bar: qwerty for bar
baz: qwerty for baz

integTestCluster {
keystoreSetting 'foo', '1'
keystoreSetting 'bar', '2'
keystoreSetting 'baz', '3'
}

returns
foo: 3 for foo
bar: 3 for bar
baz: 3 for baz

Hopefully you can comment before I open an issue.

Thanks,

Ivan

And just to eliminate gradle issues:

project.afterEvaluate {
logger.warn(integTestCluster.keystoreSettings.toString())
}

[bar:2, foo:1, baz:3]

I believe this was already fixed. Let me find the issue.

Here you go, fixed in 5.6.0:

Looks like I need to ugprade, at least it is not to 6.x. I looked for
"keystore" issues, so this one escaped me. Although it makes sense, that
bug would have taken me a bit to find!

Groovy is a horrible drug. :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.