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

Gyro Vault #79

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7e5fe7b
Move checking for resources in .gyro/init to Gyro.main
Jul 18, 2019
341d579
Initial implementation of Gyro vault functionality
Jul 18, 2019
8d7a8a1
Make save method private, only used internally
Jul 18, 2019
07820a7
Cleanup
Jul 18, 2019
3042f1d
Read encryption key from key-path
Jul 19, 2019
bbcf966
Build vault file based on vault name rather than letting user set it
Jul 19, 2019
c932c3f
Remove unused ALGORITHM field
Jul 19, 2019
cdadb32
Allow custom key length and key iterations
Jul 19, 2019
eab7268
Add ability to remove a secret from the vault
Jul 19, 2019
c7219ab
Merge branch 'master' into feature/vault
Jul 19, 2019
358e3d5
Initial work to implement CustomValue
Jul 19, 2019
ea42d64
Changes DiffableField.getValue to always prefer the value in scope.
hyoolim Jul 19, 2019
43ba29b
Moves CustomValue check to where it'd work.
hyoolim Jul 19, 2019
e044a3b
Add 'vault-lookup' to state node for VaultSecret
Jul 19, 2019
dcd6c97
Add hash option to VaultReferenceResolver and VaulSecret
Jul 19, 2019
9ec6007
All VaultSecret to hide its diff output
Jul 31, 2019
7847bb1
Merge branch 'master' into feature/vault
Jul 31, 2019
73f9597
Fix compilation error
Jul 31, 2019
8f734e6
Merge branch 'master' into feature/vault
Aug 14, 2019
b51a473
Serialize CustomValues to state
Aug 14, 2019
1ae7f04
Merge branch 'master' into feature/vault
Jan 29, 2020
267bfe0
Add back vault plugin, directive, and resolver
Jan 29, 2020
54d3d09
Convert vault directive and resolver to use @Type()
Jan 29, 2020
3be1cd2
Fix compile errors
Jan 29, 2020
679d8f4
Checkstyle fixes
Jan 29, 2020
7fcfa4f
Merge branch 'master' into feature/vault
Jan 30, 2020
b71391c
Use 'default' as the name if a name is not provided
Feb 3, 2020
1bced32
Only evaluate files in the local vault
Feb 3, 2020
f42d62a
Allow duplicate vaults
Feb 3, 2020
30d3cc5
Compare strings to VaultSecret.getValue()
Feb 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions core/src/main/java/gyro/core/diff/Change.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
import java.util.stream.Collectors;

import com.google.common.collect.MapDifference;
import com.google.common.collect.MapDifference.ValueDifference;
import com.google.common.collect.Maps;
import gyro.core.GyroUI;
import gyro.core.resource.Diffable;
import gyro.core.resource.DiffableField;
import gyro.core.resource.DiffableInternals;
import gyro.core.resource.DiffableType;
import gyro.core.scope.State;
import gyro.core.vault.VaultSecret;
import org.apache.commons.lang3.StringUtils;

public abstract class Change {
Expand Down Expand Up @@ -114,6 +116,20 @@ protected String stringify(Object value) {
.stream()
.map(e -> e.getKey() + ": " + stringify(e.getValue()))
.collect(Collectors.joining(", ")) + " }";
} else if (value instanceof ValueDifference) {
ValueDifference valueDifference = (ValueDifference) value;
if (valueDifference.rightValue() instanceof VaultSecret) {
return stringify(valueDifference.rightValue());
}

return String.format(
" %s → %s",
stringify(valueDifference.leftValue()),
stringify(valueDifference.rightValue()));

} else if (value instanceof Map.Entry) {
Map.Entry e = (Map.Entry) value;
return String.format(" %s: %s", e.getKey(), e.getValue());

} else if (value instanceof String) {
return "'" + value + "'";
Expand Down Expand Up @@ -157,6 +173,9 @@ protected void writeDifference(
} else if (p == null) {
ui.write(" @|red -|@ %s", stringify(c));

} else if (p instanceof VaultSecret) {
ui.write(" @|yellow ⟳|@ %s", stringify(p));

} else {
ui.write(" @|yellow ⟳|@ %s → %s", stringify(c), stringify(p));
}
Expand All @@ -179,16 +198,7 @@ protected void writeDifference(
MapDifference<?, ?> diff = Maps.difference((Map<?, ?>) currentValue, (Map<?, ?>) pendingValue);

writeMapRemove(ui, diff.entriesOnlyOnLeft());

writeMap(
ui,
" @|yellow ⟳ {|@ %s @|yellow }|@",
diff.entriesDiffering(),
e -> String.format(
"%s → %s",
stringify(e.leftValue()),
stringify(e.rightValue())));

writeMap(ui, " @|yellow ⟳ {|@ %s @|yellow }|@", diff.entriesDiffering(), this::stringify);
writeMapPut(ui, diff.entriesOnlyOnRight());
}

Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/gyro/core/resource/CustomValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package gyro.core.resource;

import gyro.lang.ast.Node;

public interface CustomValue {

Node toStateNode();

}
11 changes: 11 additions & 0 deletions core/src/main/java/gyro/core/resource/DiffableField.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.psddev.dari.util.ConversionException;
import gyro.core.GyroException;
import gyro.core.Reflections;
import gyro.core.scope.DiffableScope;
import gyro.core.scope.Scope;
import gyro.core.validation.Required;
import gyro.core.validation.ValidationError;
Expand Down Expand Up @@ -151,6 +152,16 @@ public boolean shouldBeDiffed() {
}

public Object getValue(Diffable diffable) {
DiffableScope scope = DiffableInternals.getScope(diffable);

if (scope != null) {
Object value = scope.get(name);

if (value != null) {
return value;
}
}

return Reflections.invoke(getter, diffable);
}

Expand Down
14 changes: 11 additions & 3 deletions core/src/main/java/gyro/core/scope/RootScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
import gyro.core.scope.converter.ResourceToIdObject;
import gyro.core.validation.ValidationError;
import gyro.core.validation.ValidationErrorException;
import gyro.core.vault.VaultDirectiveProcessor;
import gyro.core.vault.VaultPlugin;
import gyro.core.vault.VaultReferenceResolver;
import gyro.core.virtual.VirtualDirectiveProcessor;
import gyro.core.workflow.CreateDirectiveProcessor;
import gyro.core.workflow.DefineDirectiveProcessor;
Expand Down Expand Up @@ -124,7 +127,8 @@ public RootScope(String file, FileBackend backend, RootScope current, Set<String
new ModificationPlugin(),
new ReferencePlugin(),
new ResourcePlugin(),
new RootPlugin())
new RootPlugin(),
new VaultPlugin())
.forEach(p -> getSettings(PluginSettings.class).getPlugins().add(p));

Stream.of(
Expand All @@ -148,6 +152,7 @@ public RootScope(String file, FileBackend backend, RootScope current, Set<String
TypeDescriptionDirectiveProcessor.class,
UpdateDirectiveProcessor.class,
UsesCredentialsDirectiveProcessor.class,
VaultDirectiveProcessor.class,
VirtualDirectiveProcessor.class,
DefineDirectiveProcessor.class,
WaitDirectiveProcessor.class,
Expand All @@ -156,7 +161,8 @@ public RootScope(String file, FileBackend backend, RootScope current, Set<String
.forEach(p -> getSettings(DirectiveSettings.class).addProcessor(p));

Stream.of(
FinderReferenceResolver.class)
FinderReferenceResolver.class,
VaultReferenceResolver.class)
.forEach(r -> getSettings(ReferenceSettings.class).addResolver(r));

Stream.of(
Expand Down Expand Up @@ -265,7 +271,9 @@ public <T extends Resource> T findResourceById(Class<T> resourceClass, Object id
DiffableField idField = type.getIdField();

if (idField == null) {
throw new GyroException(String.format("Unable to find @Id on a getter in %s", resourceClass.getSimpleName()));
throw new GyroException(String.format(
"Unable to find @Id on a getter in %s",
resourceClass.getSimpleName()));
}

return findResourcesByClass(resourceClass)
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/gyro/core/scope/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import gyro.core.diff.Change;
import gyro.core.diff.Delete;
import gyro.core.diff.Replace;
import gyro.core.resource.CustomValue;
import gyro.core.resource.Diffable;
import gyro.core.resource.DiffableField;
import gyro.core.resource.DiffableInternals;
Expand Down Expand Up @@ -284,6 +285,8 @@ private List<Node> toBodyNodes(Diffable diffable, Resource resource) {
} else {
body.add(toPairNode(key, value, resource));
}
} else if (value instanceof CustomValue) {
body.add(new PairNode(toNode(key, resource), ((CustomValue) value).toStateNode()));

} else {
throw new GyroException(String.format(
Expand Down Expand Up @@ -318,6 +321,9 @@ private Node toNode(Object value, Resource self) {

return new ListNode(items);

} else if (value instanceof CustomValue) {
return ((CustomValue) value).toStateNode();

} else if (value instanceof Map) {
List<PairNode> entries = new ArrayList<>();

Expand Down
Loading