Skip to content

Commit 55d2286

Browse files
committed
Enable environment variable in action name
#1145
1 parent ff6238d commit 55d2286

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

parsers/manifest_parser.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,11 @@ func (dm *YAMLParser) ComposeActions(manifestFilePath string, actions map[string
874874

875875
// update the action (of type Action) to set its name
876876
// here key name is the action name
877-
action.Name = actionName
877+
if i, ok := packageInputs.Inputs[wskenv.GetEnvVarName(actionName)]; ok {
878+
action.Name = i.Value.(string)
879+
} else {
880+
action.Name = wskenv.ConvertSingleName(actionName)
881+
}
878882

879883
// Create action data object from client library
880884
wskaction := new(whisk.Action)
@@ -946,7 +950,7 @@ func (dm *YAMLParser) ComposeActions(manifestFilePath string, actions map[string
946950
if wskaction.Annotations != nil {
947951
if webaction.HasAnnotation(&wskaction.Annotations, webaction.REQUIRE_WHISK_AUTH) {
948952
_, errorParser = webaction.ValidateRequireWhiskAuthAnnotationValue(
949-
actionName,
953+
action.Name,
950954
wskaction.Annotations.GetValue(webaction.REQUIRE_WHISK_AUTH))
951955
}
952956
if errorParser != nil {
@@ -967,7 +971,7 @@ func (dm *YAMLParser) ComposeActions(manifestFilePath string, actions map[string
967971
}
968972

969973
// Set other top-level values for the action (e.g., name, version, publish, etc.)
970-
wskaction.Name = actionName
974+
wskaction.Name = action.Name
971975
pub := false
972976
wskaction.Publish = &pub
973977
wskaction.Version = wskenv.ConvertSingleName(action.Version)

parsers/manifest_parser_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,28 @@ func TestPackageName_Env_Var(t *testing.T) {
19691969
}
19701970
}
19711971

1972+
func TestActionName_Env_Var(t *testing.T) {
1973+
testAction := "test_action"
1974+
os.Setenv("action_name", testAction)
1975+
file := "../tests/dat/manifest_validate_action_name_env_var.yaml"
1976+
p, m, _ := testLoadParseManifest(t, file)
1977+
actions, err := p.ComposeActionsFromAllPackages(m, m.Filepath, whisk.KeyValue{}, map[string]PackageInputs{})
1978+
if err != nil {
1979+
assert.Fail(t, "Failed to compose actions")
1980+
}
1981+
packageName := "helloworld"
1982+
1983+
assert.Equal(t, 1, len(m.Packages[packageName].Actions), "Get action list failed.")
1984+
action := actions[0]
1985+
wskprint.PrintlnOpenWhiskVerbose(false, fmt.Sprintf("actionName: %v", action))
1986+
switch action.Action.Name {
1987+
case testAction:
1988+
assert.Equal(t, testAction, action.Action.Name, "Get action name failed.")
1989+
default:
1990+
t.Error("Get action name failed")
1991+
}
1992+
}
1993+
19721994
func TestRuleName_Env_Var(t *testing.T) {
19731995
// read and parse manifest file with env var for rule name, and rule trigger and action
19741996
testRule := "test_rule"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
packages:
19+
helloworld:
20+
actions:
21+
$action_name:
22+
function: actions/hello.js

0 commit comments

Comments
 (0)