/** * Redacts sensitive property values in a stream. * * @param streamDefinition the stream definition to sanitize * @return Stream definition text that has sensitive data redacted. */ public String sanitizeStream(StreamDefinition streamDefinition) { List<StreamAppDefinition> sanitizedAppDefinitions = streamDefinition.getAppDefinitions().stream() .map(app -> StreamAppDefinition.Builder .from(app) .setProperties(this.sanitizeProperties(app.getProperties())) .build(streamDefinition.getName()) ).collect(Collectors.toList()); return this.streamDslConverter.toDsl(sanitizedAppDefinitions); }
/** * Sets app properties. * * @param properties app properties * @return this builder object * @see AppDefinition#getProperties() */ public Builder setProperties(Map<String, String> properties) { this.properties.clear(); this.addProperties(properties); return this; }
for (int m = appNodes.size() - 1; m >= 0; m--) { AppNode appNode = appNodes.get(m); StreamAppDefinition.Builder builder = (Builder) new StreamAppDefinition.Builder() .setRegisteredAppName(appNode.getName()).setLabel(appNode.getLabelName()); if (appNode.hasArguments()) { ArgumentNode[] arguments = appNode.getArguments(); for (ArgumentNode argument : arguments) { if (argument.getName().equalsIgnoreCase("inputType")) { builder.setProperty(BindingPropertyKeys.INPUT_CONTENT_TYPE, argument.getValue()); builder.setProperty(BindingPropertyKeys.OUTPUT_CONTENT_TYPE, argument.getValue()); builder.setProperty(argument.getName(), argument.getValue()); builder.setApplicationType(ApplicationType.app); builder.setApplicationType(ApplicationType.source); builder.setApplicationType(ApplicationType.sink); builder.setApplicationType(ApplicationType.processor); builder.setApplicationType(ApplicationType.processor); builder.setApplicationType(ApplicationType.sink); builder.setProperty(BindingPropertyKeys.INPUT_DESTINATION, String.format("%s.%s", streamName, appNodes.get(m - 1).getLabelName())); builder.setProperty(BindingPropertyKeys.INPUT_GROUP, streamName);
private void updateStreamDefinitionFromReleaseManifest(String streamName, String releaseManifest) { List<SpringCloudDeployerApplicationManifest> appManifests = new SpringCloudDeployerApplicationManifestReader() .read(releaseManifest); Map<String, SpringCloudDeployerApplicationManifest> appManifestMap = new HashMap<>(); for (SpringCloudDeployerApplicationManifest am : appManifests) { String name = am.getSpec().getApplicationProperties().get(DataFlowPropertyKeys.STREAM_APP_LABEL); appManifestMap.put(name, am); } StreamDefinition streamDefinition = this.streamDefinitionRepository.findOne(streamName); LinkedList<StreamAppDefinition> updatedStreamAppDefinitions = new LinkedList<>(); for (StreamAppDefinition appDefinition : streamDefinition.getAppDefinitions()) { StreamAppDefinition.Builder appDefinitionBuilder = StreamAppDefinition.Builder.from(appDefinition); SpringCloudDeployerApplicationManifest applicationManifest = appManifestMap.get(appDefinition.getName()); // overrides app definition properties with those from the release manifest appDefinitionBuilder.setProperties(applicationManifest.getSpec().getApplicationProperties()); updatedStreamAppDefinitions.addLast(appDefinitionBuilder.build(streamDefinition.getName())); } String dslText = new StreamDefinitionToDslConverter().toDsl(updatedStreamAppDefinitions); StreamDefinition updatedStreamDefinition = new StreamDefinition(streamName, dslText); logger.debug("Updated StreamDefinition: " + updatedStreamDefinition); // TODO consider adding an explicit UPDATE method to the streamDefRepository // Note: Not transactional and can lead to loosing the stream definition this.streamDefinitionRepository.delete(updatedStreamDefinition); this.streamDefinitionRepository.save(updatedStreamDefinition); this.auditRecordService.populateAndSaveAuditRecord( AuditOperationType.STREAM, AuditActionType.UPDATE, streamName, this.auditServiceUtils.convertStreamDefinitionToAuditData(streamDefinition)); }
private void updateStreamDefinitionFromReleaseManifest(String streamName, String releaseManifest) { List<SpringCloudDeployerApplicationManifest> appManifests = new SpringCloudDeployerApplicationManifestReader() .read(releaseManifest); Map<String, SpringCloudDeployerApplicationManifest> appManifestMap = new HashMap<>(); for (SpringCloudDeployerApplicationManifest am : appManifests) { String name = am.getSpec().getApplicationProperties().get(DataFlowPropertyKeys.STREAM_APP_LABEL); appManifestMap.put(name, am); } StreamDefinition streamDefinition = this.streamDefinitionRepository.findById(streamName) .orElseThrow(() -> new NoSuchStreamDefinitionException(streamName)); LinkedList<StreamAppDefinition> updatedStreamAppDefinitions = new LinkedList<>(); for (StreamAppDefinition appDefinition : streamDefinition.getAppDefinitions()) { StreamAppDefinition.Builder appDefinitionBuilder = StreamAppDefinition.Builder.from(appDefinition); SpringCloudDeployerApplicationManifest applicationManifest = appManifestMap.get(appDefinition.getName()); // overrides app definition properties with those from the release manifest appDefinitionBuilder.setProperties(applicationManifest.getSpec().getApplicationProperties()); updatedStreamAppDefinitions.addLast(appDefinitionBuilder.build(streamDefinition.getName())); } String dslText = new StreamDefinitionToDslConverter().toDsl(updatedStreamAppDefinitions); StreamDefinition updatedStreamDefinition = new StreamDefinition(streamName, dslText); logger.debug("Updated StreamDefinition: " + updatedStreamDefinition); // TODO consider adding an explicit UPDATE method to the streamDefRepository // Note: Not transactional and can lead to loosing the stream definition this.streamDefinitionRepository.delete(updatedStreamDefinition); this.streamDefinitionRepository.save(updatedStreamDefinition); this.auditRecordService.populateAndSaveAuditRecord( AuditOperationType.STREAM, AuditActionType.UPDATE, streamName, this.auditServiceUtils.convertStreamDefinitionToAuditData(streamDefinition)); }
/** * Redacts sensitive property values in a stream. * * @param streamDefinition the stream definition to sanitize * @return Stream definition text that has sensitive data redacted. */ public String sanitizeStream(StreamDefinition streamDefinition) { List<StreamAppDefinition> sanitizedAppDefinitions = streamDefinition.getAppDefinitions().stream() .map(app -> StreamAppDefinition.Builder .from(app) .setProperties(this.sanitizeProperties(app.getProperties())) .build(streamDefinition.getName()) ).collect(Collectors.toList()); return this.streamDslConverter.toDsl(sanitizedAppDefinitions); }
/** * Create a new builder that is initialized with properties of the given * definition. Useful for "mutating" a definition by building a slightly different * copy. * * @param definition the StreamAppDefinition to create a new Builder instance with * stream name, registeredAppName, label, and properties populated * @return a StreamAppDefinition builder */ public static Builder from(StreamAppDefinition definition) { Builder builder = new Builder(); builder.setStreamName(definition.getStreamName()).setRegisteredAppName(definition.getRegisteredAppName()) .setApplicationType(definition.getApplicationType()) .setLabel(definition.getName()).addProperties(definition.getProperties()); return builder; }
/** * Return a new instance of {@link StreamAppDefinition}. * * @param streamName the name of the stream * @return new instance of {@code StreamAppDefinition} */ public StreamAppDefinition build(String streamName) { if (this.label == null) { this.setLabel(this.registeredAppName); } return new StreamAppDefinition(this.registeredAppName, this.label, this.applicationType, streamName, this.properties); } }