You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/03/07 03:54:42 UTC

[GitHub] [apisix] tzssangglass commented on a change in pull request #6505: feat: support for reading environment variables from yaml configuration files #5244

tzssangglass commented on a change in pull request #6505:
URL: https://github.com/apache/apisix/pull/6505#discussion_r820352908



##########
File path: t/cli/test_standalone.sh
##########
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+
+#
+# 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.
+#
+
+. ./t/cli/common.sh
+
+standalone() {
+    clean_up
+    git checkout conf/apisix.yaml
+}
+
+trap standalone EXIT
+
+# support environment variables
+echo '
+apisix:
+  enable_admin: false
+  config_center: yaml
+' > conf/config.yaml
+
+echo '
+routes:
+  -
+    uri: ${{var_test_path}}
+    plugins:
+      proxy-rewrite:
+        uri: ${{var_test_proxy_rewrite_uri:=/apisix/nginx_status}}
+    upstream:
+      nodes:
+        "127.0.0.1:9091": 1
+      type: roundrobin
+#END
+' > conf/apisix.yaml
+
+# check for resolve variables
+var_test_path=/test make init
+
+if ! grep "env var_test_path=/test;" conf/nginx.conf > /dev/null; then
+    echo "failed: failed to resolve variables"
+    exit 1
+fi
+
+# variable is valid
+var_test_path=/test make run
+sleep 0.1
+code=$(curl -o /dev/null -s -m 5 -w %{http_code} http://127.0.0.1:9080/test)
+if [ ! $code -eq 200 ]; then
+    echo "failed: variable is not valid"

Review comment:
       ```suggestion
       echo "failed: esolve variables in apisix.yaml conf failed"
   ```
   
   is better?

##########
File path: t/cli/test_standalone.sh
##########
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+
+#
+# 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.
+#
+
+. ./t/cli/common.sh
+
+standalone() {
+    clean_up
+    git checkout conf/apisix.yaml
+}
+
+trap standalone EXIT
+
+# support environment variables
+echo '
+apisix:
+  enable_admin: false
+  config_center: yaml
+' > conf/config.yaml
+
+echo '
+routes:
+  -
+    uri: ${{var_test_path}}
+    plugins:
+      proxy-rewrite:
+        uri: ${{var_test_proxy_rewrite_uri:=/apisix/nginx_status}}
+    upstream:
+      nodes:
+        "127.0.0.1:9091": 1
+      type: roundrobin
+#END
+' > conf/apisix.yaml
+
+# check for resolve variables
+var_test_path=/test make init
+
+if ! grep "env var_test_path=/test;" conf/nginx.conf > /dev/null; then
+    echo "failed: failed to resolve variables"
+    exit 1
+fi
+
+# variable is valid
+var_test_path=/test make run
+sleep 0.1
+code=$(curl -o /dev/null -s -m 5 -w %{http_code} http://127.0.0.1:9080/test)
+if [ ! $code -eq 200 ]; then
+    echo "failed: variable is not valid"
+    exit 1
+fi
+
+echo "passed: resolve variables"

Review comment:
       ```suggestion
   echo "passed: resolve variables in apisix.yaml conf success"
   ```
   
   is better?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org