Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Vault #42

Merged
merged 17 commits into from
Apr 20, 2018
Merged

Add support for Vault #42

merged 17 commits into from
Apr 20, 2018

Conversation

aharonha
Copy link
Contributor

for issue #2

@aharonha aharonha requested a review from artem-v March 28, 2018 12:41
Copy link
Member

@omerglam omerglam left a comment

Choose a reason for hiding this comment

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

please see my comments

throw new VaultException("Vault is sealed");
}
} catch (VaultException ignoredException) {
ignoredException.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

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

what will happen if the Vault instance will not be initiated here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tested

SECRET_DEFAULT_PATH = environmentLoader.loadVariable("VAULT_SECRETS_PATH");
}

public VaultConfigSource(Optional<VaultConfig> config) {
Copy link
Member

Choose a reason for hiding this comment

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

add javadocs for environment variables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return response.getData().entrySet().stream().map(LoadedConfigProperty::withNameAndValue).map(Builder::build)
.collect(Collectors.toMap(LoadedConfigProperty::name, Function.identity()));
} catch (VaultException ignoredException) {
return new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

how will the consumer behave in case of an empty collection is returned? will it try to re-fetch a config property in case the property is missing from the returned map? will propagating the exception will be a better solution here?

@aharonha aharonha requested a review from snripa March 29, 2018 08:19
aharonha added 2 commits March 29, 2018 11:50
Copy link
Contributor

@artem-v artem-v left a comment

Choose a reason for hiding this comment

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

test

throw new VaultException("Missing Vault token");
}
vault = new Vault(cfg.build());
checkVaultHealth();
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no need to call checkVaultHealth() from constructor. Upon bootstrap, at first time, loadConfig() would be called from main thread anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please adjust eclipse settings to not to put those asterisks in imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

public Map<String, ConfigProperty> loadConfig() {
try {
checkVaultHealth();
} catch (VaultException ignoredException) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ignoredException is not that ignored, please rename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* This class is a {@link ConfigSource} implemented for Vault
*
* @author AharonHa
* @see The Vault Project's site at {@link https://www.vaultproject.io/}
Copy link
Contributor

Choose a reason for hiding this comment

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

This @see is highlighted in read in IDE, looks like wrong @see format

Copy link
Member

Choose a reason for hiding this comment

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

please no @ author in code need to fix ide to omit this in javadocs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

} finally {
vaultContainer2.stop();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add test scenario for checking Vault 'polling' behaviour:

  1. Vault container is up and running
  2. Wait in the tests a time equal to ConfigRegistrySettings.reloadIntervalSec (by default it's 15 secs but can be overriden)
  3. Check that after succesfull reload props are still at place
    This is green scenario, everything should work fine, and successful reloads must not affect loaded props.

Please add test scenario for checking Vault 'connection loss' behavior:

  1. Vault container is up and running
  2. Wait in the tests a time equal to ConfigRegistrySettings.reloadIntervalSec (give it a chance to reload before going offline)
  3. Shutdown Vault container
  4. Wait in the tests a time equal to ConfigRegistrySettings.reloadIntervalSec
  5. Check that loaded properties remained unaffected (not returning null, not returning default values )
    This is red scenario, something we don't expect often, but want be prepared for; after disconnection to Vault properties which has been loaded and sitting in jvm memory should be unaffected by further disconnections of config source and any issues that config source might face.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

*/
VaultConfigSource(EnvironmentLoader environmentLoader) {
this(Optional.of(new VaultConfig().environmentLoader(environmentLoader)));
SECRET_DEFAULT_PATH = environmentLoader.loadVariable("VAULT_SECRETS_PATH");
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move "VAULT_SECRETS_PATH" constant to some internal class constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


private static final Logger LOGGER = LoggerFactory.getLogger(VaultConfigSource.class);
private Vault vault;
private String SECRET_DEFAULT_PATH;
Copy link
Contributor

Choose a reason for hiding this comment

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

SECRET_DEFAULT_PATH is not constant, let's lower case it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

*
*/

public VaultConfigSource(Optional<VaultConfig> config) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we need only

  1. token
  2. address
  3. and VAULT_SECRETS_PATH

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+new builder class

}

/**
* Create a new {@link VaultConfigSource} with the given {@link VaultConfig}. <br>
Copy link
Member

Choose a reason for hiding this comment

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

This javadoc does not match with constructor signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

There are still some outdated javadoc for constructor.
I mean this part "Default configurations can also be used by passing {@link Optional#empty() empty}." and so on.

*
*/

VaultConfigSource(VaultConfigSource.Builder builder) {
Copy link
Member

Choose a reason for hiding this comment

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

I guess it's better to make constructor private.
Also you can write just Builder instead of VaultConfigSource.Builder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The constructor is package protected because otherwise it would have this warning:
Access to enclosing constructor VaultConfigSource(VaultConfigSource.Builder) is emulated by a synthetic accessor method

fixed the param & javadocs

this.secretsPath = builder.secretsPath();
try {
vault = new Vault(builder.config);
checkVaultStatus();
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need checkVaultStatus() in constructor?
It is called anyway from loadConfig() every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

checkVaultStatus();
} catch (VaultException exception) {
LOGGER.error("unable to build vault config source", exception);
vault = null;
Copy link
Member

Choose a reason for hiding this comment

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

I guess it is not good idea to set vault as null, because if VaultException happens in constructor we have instance of VaultConfigSource without correct vault (actually null) and we can't do anything with this.
I mean we can't reinitialize vault one more time in this particular instance of VaultConfigSource so we don't need to create that instance at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
}

private void checkVaultStatus() throws VaultException {
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need to check status this way?
I mean we can just use Logical.read and Vault throws exceptions if something wrong.
Why do we need manually check health if we don't do anything only throw exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

read() method does not tell you if vault is currently sealed or not initialized. it throws the REST 404 or 500 wrapped message.

@artem-v
Copy link
Contributor

artem-v commented Apr 12, 2018

Everything is great, but mvn clean install doesn't pass. Enforcer plugin tells:

[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce) @ config-vault ---
[WARNING] 
Dependency convergence error for commons-io:commons-io:2.5 paths to dependency are:
+-io.scalecube:config-vault:0.3.2-SNAPSHOT
  +-org.testcontainers:vault:1.6.0
    +-org.testcontainers:testcontainers:1.6.0
      +-commons-io:commons-io:2.5
and
+-io.scalecube:config-vault:0.3.2-SNAPSHOT
  +-org.testcontainers:vault:1.6.0
    +-org.testcontainers:testcontainers:1.6.0
      +-org.zeroturnaround:zt-exec:1.8
        +-commons-io:commons-io:1.4

[WARNING] Rule 0: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for commons-io:commons-io:2.5 paths to dependency are:
+-io.scalecube:config-vault:0.3.2-SNAPSHOT
  +-org.testcontainers:vault:1.6.0
    +-org.testcontainers:testcontainers:1.6.0
      +-commons-io:commons-io:2.5
and
+-io.scalecube:config-vault:0.3.2-SNAPSHOT
  +-org.testcontainers:vault:1.6.0
    +-org.testcontainers:testcontainers:1.6.0
      +-org.zeroturnaround:zt-exec:1.8
        +-commons-io:commons-io:1.4
]

@artem-v artem-v force-pushed the support_secured_properties_#2 branch from 6a548d9 to e6e9010 Compare April 13, 2018 11:59
@aharonha aharonha force-pushed the support_secured_properties_#2 branch from f827842 to c1bce27 Compare April 15, 2018 06:00
@aharonha aharonha changed the base branch from master to develop April 15, 2018 06:01
@artem-v artem-v merged commit 71c6f9f into develop Apr 20, 2018
io-scalecube-ci pushed a commit that referenced this pull request Apr 23, 2018
* Add support for Vault
@aharonha aharonha deleted the support_secured_properties_#2 branch August 30, 2018 12:25
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.

7 participants