Skip to content

Commit

Permalink
feat(expressions): Allowing to globally configure SPEL evaluator vers…
Browse files Browse the repository at this point in the history
…ion (#1592)

- Adding an option to configure the SPEL evaluator version
- Added missing copyright header to some classes
  • Loading branch information
jeyrschabu authored Aug 30, 2017
1 parent c7279af commit cef1343
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.netflix.spinnaker.orca.pipeline.persistence.memory.InMemoryPipelineStack;
import com.netflix.spinnaker.orca.pipeline.util.ContextFunctionConfiguration;
import com.netflix.spinnaker.orca.pipeline.util.ContextParameterProcessor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand Down Expand Up @@ -122,8 +123,9 @@ UserConfiguredUrlRestrictions userConfiguredUrlRestrictions(UserConfiguredUrlRes
}

@Bean
public ContextFunctionConfiguration contextFunctionConfiguration(UserConfiguredUrlRestrictions userConfiguredUrlRestrictions) {
return new ContextFunctionConfiguration(userConfiguredUrlRestrictions);
public ContextFunctionConfiguration contextFunctionConfiguration(UserConfiguredUrlRestrictions userConfiguredUrlRestrictions,
@Value("${spelEvaluator:v1}") String spelEvaluator) {
return new ContextFunctionConfiguration(userConfiguredUrlRestrictions, spelEvaluator);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,23 @@
import java.util.Optional;

import static com.netflix.spinnaker.orca.pipeline.expressions.PipelineExpressionEvaluator.ExpressionEvaluationVersion.V2;
import static com.netflix.spinnaker.orca.pipeline.expressions.PipelineExpressionEvaluator.ExpressionEvaluationVersion.V1;

public class PipelineExpressionEvaluator extends ExpressionsSupport implements ExpressionEvaluator {
private static final Logger LOGGER = LoggerFactory.getLogger(PipelineExpressionEvaluator.class);
public static final String SUMMARY = "expressionEvaluationSummary";
private static final String SPEL_EVALUATOR = "spel-evaluator";
private static final String SPEL_EVALUATOR = "spelEvaluator";
private final ExpressionParser parser = new SpelExpressionParser();
private static String spelEvaluator = V1;

interface ExpressionEvaluationVersion {
public interface ExpressionEvaluationVersion {
String V2 = "v2";
String V1 = "v1";
}

public PipelineExpressionEvaluator(final ContextFunctionConfiguration contextFunctionConfiguration) {
super(contextFunctionConfiguration);
spelEvaluator = contextFunctionConfiguration.getSpelEvaluator();
}

@Override
Expand All @@ -53,6 +57,10 @@ public Map<String, Object> evaluate(Map<String, Object> source, Object rootObjec
}

public static boolean shouldUseV2Evaluator(Object obj) {
if (V2.equals(spelEvaluator)) {
return true;
}

try {
if (obj instanceof Map) {
Map pipelineConfig = (Map) obj;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2017 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.orca.pipeline.expressions.whitelisting

import org.springframework.expression.spel.support.ReflectiveMethodResolver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2017 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.orca.pipeline.expressions.whitelisting

import groovy.transform.CompileStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import org.springframework.expression.spel.support.ReflectivePropertyAccessor
import org.springframework.expression.spel.support.StandardEvaluationContext
import org.springframework.expression.spel.support.StandardTypeLocator

import static com.netflix.spinnaker.orca.pipeline.expressions.PipelineExpressionEvaluator.ExpressionEvaluationVersion.V1

/**
* Common methods for dealing with passing context parameters used by both Script and Jenkins stages
*/
Expand Down Expand Up @@ -357,9 +359,15 @@ class ContextParameterProcessor {

class ContextFunctionConfiguration {
final UserConfiguredUrlRestrictions urlRestrictions
final String spelEvaluator

ContextFunctionConfiguration(UserConfiguredUrlRestrictions urlRestrictions) {
ContextFunctionConfiguration(UserConfiguredUrlRestrictions urlRestrictions, String spelEvaluator = V1) {
this.urlRestrictions = urlRestrictions
this.spelEvaluator = spelEvaluator
}

ContextFunctionConfiguration(String spelEvaluator = V1) {
this.spelEvaluator = spelEvaluator
}
}

Expand Down

0 comments on commit cef1343

Please sign in to comment.