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

Enable environment variable in action name #1146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions parsers/manifest_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,11 @@ func (dm *YAMLParser) ComposeActions(manifestFilePath string, actions map[string

// update the action (of type Action) to set its name
// here key name is the action name
action.Name = actionName
if i, ok := packageInputs.Inputs[wskenv.GetEnvVarName(actionName)]; ok {
action.Name = i.Value.(string)
} else {
action.Name = wskenv.ConvertSingleName(actionName)
}

// Create action data object from client library
wskaction := new(whisk.Action)
Expand Down Expand Up @@ -946,7 +950,7 @@ func (dm *YAMLParser) ComposeActions(manifestFilePath string, actions map[string
if wskaction.Annotations != nil {
if webaction.HasAnnotation(&wskaction.Annotations, webaction.REQUIRE_WHISK_AUTH) {
_, errorParser = webaction.ValidateRequireWhiskAuthAnnotationValue(
actionName,
action.Name,
wskaction.Annotations.GetValue(webaction.REQUIRE_WHISK_AUTH))
}
if errorParser != nil {
Expand All @@ -967,7 +971,7 @@ func (dm *YAMLParser) ComposeActions(manifestFilePath string, actions map[string
}

// Set other top-level values for the action (e.g., name, version, publish, etc.)
wskaction.Name = actionName
wskaction.Name = action.Name
pub := false
wskaction.Publish = &pub
wskaction.Version = wskenv.ConvertSingleName(action.Version)
Expand Down
22 changes: 22 additions & 0 deletions parsers/manifest_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,28 @@ func TestPackageName_Env_Var(t *testing.T) {
}
}

func TestActionName_Env_Var(t *testing.T) {
testAction := "test_action"
os.Setenv("action_name", testAction)
file := "../tests/dat/manifest_validate_action_name_env_var.yaml"
p, m, _ := testLoadParseManifest(t, file)
actions, err := p.ComposeActionsFromAllPackages(m, m.Filepath, whisk.KeyValue{}, map[string]PackageInputs{})
if err != nil {
assert.Fail(t, "Failed to compose actions")
}
packageName := "helloworld"

assert.Equal(t, 1, len(m.Packages[packageName].Actions), "Get action list failed.")
action := actions[0]
wskprint.PrintlnOpenWhiskVerbose(false, fmt.Sprintf("actionName: %v", action))
switch action.Action.Name {
case testAction:
assert.Equal(t, testAction, action.Action.Name, "Get action name failed.")
default:
t.Error("Get action name failed")
}
}

func TestRuleName_Env_Var(t *testing.T) {
// read and parse manifest file with env var for rule name, and rule trigger and action
testRule := "test_rule"
Expand Down
22 changes: 22 additions & 0 deletions tests/dat/manifest_validate_action_name_env_var.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#

packages:
helloworld:
actions:
$action_name:
function: actions/hello.js