-
Notifications
You must be signed in to change notification settings - Fork 27
Enabling the use of secrets during a deployment #330
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
Open
karrgov
wants to merge
2
commits into
cloudfoundry:master
Choose a base branch
from
karrgov:passing_secrets_during_deploy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| package org.cloudfoundry.multiapps.mta.builders; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.apache.commons.collections4.CollectionUtils; | ||
| import org.cloudfoundry.multiapps.common.ContentException; | ||
| import org.cloudfoundry.multiapps.mta.Constants; | ||
| import org.cloudfoundry.multiapps.mta.Messages; | ||
| import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor; | ||
| import org.cloudfoundry.multiapps.mta.model.Descriptor; | ||
|
|
@@ -16,6 +19,8 @@ public class ExtensionDescriptorChainBuilder { | |
|
|
||
| private final boolean isStrict; | ||
|
|
||
| private ExtensionDescriptor secureExtensionDescriptor; | ||
|
|
||
| public ExtensionDescriptorChainBuilder() { | ||
| this(true); | ||
| } | ||
|
|
@@ -24,8 +29,11 @@ public ExtensionDescriptorChainBuilder(boolean isStrict) { | |
| this.isStrict = isStrict; | ||
| } | ||
|
|
||
| public List<ExtensionDescriptor> build(DeploymentDescriptor deploymentDescriptor, List<ExtensionDescriptor> extensionDescriptors) | ||
| throws ContentException { | ||
| private boolean isSecureDescriptor(ExtensionDescriptor extensionDescriptor) { | ||
| return extensionDescriptor.getId().equals(Constants.SECURE_EXTENSION_DESCRIPTOR_ID); | ||
| } | ||
|
|
||
| public List<ExtensionDescriptor> build(DeploymentDescriptor deploymentDescriptor, List<ExtensionDescriptor> extensionDescriptors) throws ContentException { | ||
| Map<String, ExtensionDescriptor> extensionDescriptorsPerParent = getExtensionDescriptorsPerParent(extensionDescriptors); | ||
| return build(deploymentDescriptor, extensionDescriptorsPerParent); | ||
| } | ||
|
|
@@ -34,37 +42,68 @@ private List<ExtensionDescriptor> build(DeploymentDescriptor deploymentDescripto | |
| Map<String, ExtensionDescriptor> extensionDescriptorsPerParent) { | ||
| List<ExtensionDescriptor> chain = new ArrayList<>(); | ||
| Descriptor currentDescriptor = deploymentDescriptor; | ||
| ExtensionDescriptor secureDescriptor = null; | ||
|
|
||
| while (currentDescriptor != null) { | ||
| ExtensionDescriptor nextDescriptor = extensionDescriptorsPerParent.remove(currentDescriptor.getId()); | ||
|
|
||
| if(nextDescriptor != null && isSecureDescriptor(nextDescriptor)) { | ||
| secureDescriptor = nextDescriptor; | ||
| continue; | ||
| } | ||
|
|
||
| CollectionUtils.addIgnoreNull(chain, nextDescriptor); | ||
| currentDescriptor = nextDescriptor; | ||
| } | ||
|
|
||
| CollectionUtils.addIgnoreNull(chain, secureDescriptor); | ||
|
|
||
| if(secureDescriptor == null && this.secureExtensionDescriptor != null) { | ||
| CollectionUtils.addIgnoreNull(chain, this.secureExtensionDescriptor); | ||
| } | ||
|
|
||
| if (!extensionDescriptorsPerParent.isEmpty() && isStrict) { | ||
| throw new ContentException(Messages.CANNOT_BUILD_EXTENSION_DESCRIPTOR_CHAIN_BECAUSE_DESCRIPTORS_0_HAVE_AN_UNKNOWN_PARENT, | ||
| String.join(",", Descriptor.getIds(extensionDescriptorsPerParent.values()))); | ||
| } | ||
|
|
||
| return chain; | ||
| } | ||
|
|
||
| private Map<String, ExtensionDescriptor> getExtensionDescriptorsPerParent(List<ExtensionDescriptor> extensionDescriptors) { | ||
| Map<String, List<ExtensionDescriptor>> extensionDescriptorsPerParent = extensionDescriptors.stream() | ||
| .collect(Collectors.groupingBy(ExtensionDescriptor::getParentId)); | ||
| Map<String, List<ExtensionDescriptor>> extensionDescriptorsPerParent = extensionDescriptors.stream().collect(Collectors.groupingBy(ExtensionDescriptor::getParentId)); | ||
| validateSingleExtensionDescriptorPerParent(extensionDescriptorsPerParent); | ||
| return prune(extensionDescriptorsPerParent); | ||
| } | ||
|
|
||
| private Map<String, ExtensionDescriptor> prune(Map<String, List<ExtensionDescriptor>> extensionDescriptorsPerParent) { | ||
| validateSingleExtensionDescriptorPerParent(extensionDescriptorsPerParent); | ||
| return extensionDescriptorsPerParent.entrySet() | ||
| .stream() | ||
| .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue() | ||
| .get(0))); | ||
| .collect(Collectors.toMap(Map.Entry::getKey, entry -> { | ||
| List<ExtensionDescriptor> localList = entry.getValue(); | ||
|
|
||
| for(ExtensionDescriptor extensionDescriptor : localList) { | ||
| if(extensionDescriptor.getId().equals(Constants.SECURE_EXTENSION_DESCRIPTOR_ID)) { | ||
| this.secureExtensionDescriptor = extensionDescriptor; | ||
| } | ||
| } | ||
|
|
||
| for(ExtensionDescriptor extensionDescriptor : localList) { | ||
|
Comment on lines
+84
to
+91
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still do not get why this whole change in collect method is needed. |
||
| if(!extensionDescriptor.getId().equals(Constants.SECURE_EXTENSION_DESCRIPTOR_ID)) { | ||
| return extensionDescriptor; | ||
| } | ||
| } | ||
IvanBorislavovDimitrov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return localList.get(0); | ||
| })); | ||
| } | ||
|
|
||
| private void validateSingleExtensionDescriptorPerParent(Map<String, List<ExtensionDescriptor>> extensionDescriptorsPerParent) { | ||
| for (Map.Entry<String, List<ExtensionDescriptor>> extensionDescriptorsForParent : extensionDescriptorsPerParent.entrySet()) { | ||
| String parent = extensionDescriptorsForParent.getKey(); | ||
| List<ExtensionDescriptor> extensionDescriptors = extensionDescriptorsForParent.getValue(); | ||
| if (extensionDescriptors.size() > 1 && isStrict) { | ||
| long nonSecureCountOfExtensionDescriptors = extensionDescriptors.stream().filter(descriptor -> !descriptor.getId().equals(Constants.SECURE_EXTENSION_DESCRIPTOR_ID)).count(); | ||
| if (nonSecureCountOfExtensionDescriptors > 1 && isStrict) { | ||
| throw new ContentException(Messages.MULTIPLE_EXTENSION_DESCRIPTORS_EXTEND_THE_PARENT_0, parent); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.