Expose Elastic's apiKeyCredentials property

See gh-28400
pull/28436/head
Jonatan Ivanov 3 years ago committed by Andy Wilkinson
parent 56b8494f15
commit dd475a2445

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -60,12 +60,14 @@ public class ElasticProperties extends StepRegistryProperties {
private boolean autoCreateIndex = true;
/**
* Login user of the Elastic server.
* Login user of the Elastic server. If API key is configured, it will be used for
* authentication instead of username/password.
*/
private String userName;
/**
* Login password of the Elastic server.
* Login password of the Elastic server. If API key is configured, it will be used for
* authentication instead of username/password.
*/
private String password;
@ -74,6 +76,12 @@ public class ElasticProperties extends StepRegistryProperties {
*/
private String pipeline;
/**
* Base64-encoded credentials string. If configured, it will be used for
* authentication instead of username/password.
*/
private String apiKeyCredentials;
public String getHost() {
return this.host;
}
@ -146,4 +154,12 @@ public class ElasticProperties extends StepRegistryProperties {
this.pipeline = pipeline;
}
public String getApiKeyCredentials() {
return this.apiKeyCredentials;
}
public void setApiKeyCredentials(String apiKeyCredentials) {
this.apiKeyCredentials = apiKeyCredentials;
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -82,4 +82,9 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
return get(ElasticProperties::getPipeline, ElasticConfig.super::pipeline);
}
@Override
public String apiKeyCredentials() {
return get(ElasticProperties::getApiKeyCredentials, ElasticConfig.super::apiKeyCredentials);
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -90,4 +90,11 @@ class ElasticPropertiesConfigAdapterTests {
assertThat(new ElasticPropertiesConfigAdapter(properties).pipeline()).isEqualTo("testPipeline");
}
@Test
void whenPropertiesApiKeyCredentialsIsSetAdapterPipelineReturnsIt() {
ElasticProperties properties = new ElasticProperties();
properties.setApiKeyCredentials("secret");
assertThat(new ElasticPropertiesConfigAdapter(properties).apiKeyCredentials()).isEqualTo("secret");
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,6 +44,7 @@ class ElasticPropertiesTests extends StepRegistryPropertiesTests {
assertThat(properties.getUserName()).isEqualTo(config.userName());
assertThat(properties.isAutoCreateIndex()).isEqualTo(config.autoCreateIndex());
assertThat(properties.getPipeline()).isEqualTo(config.pipeline());
assertThat(properties.getApiKeyCredentials()).isEqualTo(config.apiKeyCredentials());
}
}

Loading…
Cancel
Save