mrutkows closed pull request #732: adding env. variable support in trigger feed URL: https://github.com/apache/incubator-openwhisk-wskdeploy/pull/732
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/parsers/manifest_parser.go b/parsers/manifest_parser.go index 88a3b032..b18118e3 100644 --- a/parsers/manifest_parser.go +++ b/parsers/manifest_parser.go @@ -774,6 +774,10 @@ func (dm *YAMLParser) ComposeTriggers(filePath string, pkg Package, ma whisk.Key trigger.Feed = trigger.Source } + // replacing env. variables here in the trigger feed name + // to support trigger feed with $READ_FROM_ENV_TRIGGER_FEED + trigger.Feed = wskenv.GetEnvVar(trigger.Feed).(string) + keyValArr := make(whisk.KeyValueArr, 0) if trigger.Feed != "" { var keyVal whisk.KeyValue diff --git a/parsers/manifest_parser_test.go b/parsers/manifest_parser_test.go index af906d1c..1ac7b872 100644 --- a/parsers/manifest_parser_test.go +++ b/parsers/manifest_parser_test.go @@ -1280,6 +1280,9 @@ func TestComposeSequences(t *testing.T) { } func TestComposeTriggers(t *testing.T) { + // set env variables needed for the trigger feed + os.Setenv("KAFKA_INSTANCE", "kafka-broker") + os.Setenv("SRC_TOPIC", "topic") // read and parse manifest.yaml file located under ../tests folder manifestFile := "../tests/dat/manifest_data_compose_triggers.yaml" p := NewYAMLParser() @@ -1293,7 +1296,7 @@ func TestComposeTriggers(t *testing.T) { assert.Fail(t, "Failed to compose trigger") } - assert.Equal(t, 2, len(triggerList), "Failed to get trigger list") + assert.Equal(t, 3, len(triggerList), "Failed to get trigger list") for _, trigger := range triggerList { switch trigger.Name { case "trigger1": @@ -1302,6 +1305,10 @@ func TestComposeTriggers(t *testing.T) { assert.Equal(t, "feed", trigger.Annotations[0].Key, "Failed to set trigger annotation") assert.Equal(t, "myfeed", trigger.Annotations[0].Value, "Failed to set trigger annotation") assert.Equal(t, 2, len(trigger.Parameters), "Failed to set trigger parameters") + case "message-trigger": + assert.Equal(t, 2, len(trigger.Parameters), "Failed to set trigger parameters") + assert.Equal(t, "feed", trigger.Annotations[0].Key, "Failed to set trigger annotation") + assert.Equal(t, "Bluemix_kafka-broker_Credentials-1/messageHubFeed", trigger.Annotations[0].Value, "Failed to set trigger annotation") } } } diff --git a/tests/dat/manifest_data_compose_triggers.yaml b/tests/dat/manifest_data_compose_triggers.yaml index 9be02de0..8fe02e38 100644 --- a/tests/dat/manifest_data_compose_triggers.yaml +++ b/tests/dat/manifest_data_compose_triggers.yaml @@ -26,3 +26,8 @@ package: inputs: name: myname place: myplace + message-trigger: + feed: Bluemix_${KAFKA_INSTANCE}_Credentials-1/messageHubFeed + inputs: + isJSONData: true + topic: $SRC_TOPIC ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services