From 8efa176bae176173f7d239939b2c3ceb554df17d Mon Sep 17 00:00:00 2001 From: anaik91 Date: Thu, 7 Sep 2023 19:34:59 +0530 Subject: [PATCH] fix: fixed PR comments --- .github/in-solidarity.yml | 2 +- .../apiproxy/proxies/default.xml | 2 +- ...erver_validator.xml => target-server-validator.xml} | 2 +- .../callout/src/main/java/PortOpenCheck.java | 1 - tools/target-server-validator/input.properties | 5 +++-- tools/target-server-validator/main.py | 6 ++++-- tools/target-server-validator/pipeline.sh | 7 ++++--- tools/target-server-validator/utilities.py | 10 +++++----- 8 files changed, 19 insertions(+), 16 deletions(-) rename tools/target-server-validator/apiproxy/{target_server_validator.xml => target-server-validator.xml} (93%) diff --git a/.github/in-solidarity.yml b/.github/in-solidarity.yml index 0d17276a..fdbd72ad 100644 --- a/.github/in-solidarity.yml +++ b/.github/in-solidarity.yml @@ -14,4 +14,4 @@ ignore: - "tools/hybrid-quickstart/steps.sh" # because the GKE cli uses 'master' - - "tools/target-server-validator/callout/build_setup.sh" # because github.com/apigee/api-platform-samples uses voliating branch name + - "tools/target-server-validator/callout/build_java_callout.sh" # because github.com/apigee/api-platform-samples uses voliating branch name diff --git a/tools/target-server-validator/apiproxy/proxies/default.xml b/tools/target-server-validator/apiproxy/proxies/default.xml index 2e50181d..10d49b91 100644 --- a/tools/target-server-validator/apiproxy/proxies/default.xml +++ b/tools/target-server-validator/apiproxy/proxies/default.xml @@ -30,7 +30,7 @@ - /validate_target_server + /validate-target-server \ No newline at end of file diff --git a/tools/target-server-validator/apiproxy/target_server_validator.xml b/tools/target-server-validator/apiproxy/target-server-validator.xml similarity index 93% rename from tools/target-server-validator/apiproxy/target_server_validator.xml rename to tools/target-server-validator/apiproxy/target-server-validator.xml index a86e9f5a..f7457d68 100644 --- a/tools/target-server-validator/apiproxy/target_server_validator.xml +++ b/tools/target-server-validator/apiproxy/target-server-validator.xml @@ -11,4 +11,4 @@ See the License for the specific language governing permissions and limitations under the License. --> - + diff --git a/tools/target-server-validator/callout/src/main/java/PortOpenCheck.java b/tools/target-server-validator/callout/src/main/java/PortOpenCheck.java index c04630ba..a31b6da8 100644 --- a/tools/target-server-validator/callout/src/main/java/PortOpenCheck.java +++ b/tools/target-server-validator/callout/src/main/java/PortOpenCheck.java @@ -76,7 +76,6 @@ public ExecutionResult execute(final MessageContext messageContext, String port = messageContext.getMessage().getHeader("port_number"); int portnumber = Integer.parseInt(port); String status = available(hostname, portnumber); - // messageContext.getMessage().setContent(Status); messageContext.setVariable("flow.reachableStatus", status); return ExecutionResult.SUCCESS; } catch (Exception e) { diff --git a/tools/target-server-validator/input.properties b/tools/target-server-validator/input.properties index 093b4fab..e15ba143 100644 --- a/tools/target-server-validator/input.properties +++ b/tools/target-server-validator/input.properties @@ -18,8 +18,9 @@ check_proxies=true proxy_export_dir=export skip_proxy_list=mock1,stream api_env=dev -api_name=target_server_validator +api_name=target-server-validator api_force_redeploy=true api_hostname=example.apigee.com -api_ip=x.x.x.x +api_ip= report_format=md +allow_insecure=false \ No newline at end of file diff --git a/tools/target-server-validator/main.py b/tools/target-server-validator/main.py index 5d061a7a..72410441 100644 --- a/tools/target-server-validator/main.py +++ b/tools/target-server-validator/main.py @@ -41,6 +41,7 @@ def main(): check_proxies = cfg["validation"].getboolean("check_proxies") proxy_export_dir = cfg["validation"]["proxy_export_dir"] report_format = cfg["validation"]["report_format"] + allow_insecure = cfg["validation"].getboolean("allow_insecure") if report_format not in ["csv", "md"]: report_format = "md" @@ -169,7 +170,7 @@ def main(): print("INFO: Running validation against All Target Servers") for each_ts in all_target_servers: status = run_validator_proxy( - api_url, vhost_domain_name, vhost_ip, each_ts["host"], each_ts["port"] # noqa + api_url, vhost_domain_name, vhost_ip, each_ts["host"], each_ts["port"], allow_insecure # noqa ) final_report.append( [ @@ -210,6 +211,7 @@ def main(): vhost_ip, each_target["host"], each_target["port"], + allow_insecure, ) _cached_hosts[ f"{each_target['host']}:{each_target['port']}" @@ -238,7 +240,7 @@ def main(): status = _cached_hosts[f"{each_host}:{each_port}"] else: status = run_validator_proxy( - api_url, vhost_domain_name, vhost_ip, each_host, each_port + api_url, vhost_domain_name, vhost_ip, each_host, each_port, allow_insecure # noqa ) _cached_hosts[f"{each_host}:{each_port}"] = status final_report.append( diff --git a/tools/target-server-validator/pipeline.sh b/tools/target-server-validator/pipeline.sh index d0f55700..2e1fe792 100755 --- a/tools/target-server-validator/pipeline.sh +++ b/tools/target-server-validator/pipeline.sh @@ -49,9 +49,10 @@ skip_proxy_list= api_env=$APIGEE_X_ENV api_name=target_server_validator api_force_redeploy=true -vhost_domain_name=$APIGEE_X_HOSTNAME -vhost_ip= +api_hostname=$APIGEE_X_HOSTNAME +api_ip= report_format=md +allow_insecure=false EOF # Generate optional input csv file @@ -59,7 +60,7 @@ cat > "$SCRIPTPATH/input.csv" << EOF HOST,PORT httpbin.org httpbin.org,443 -mocktarget.apigee.tom +domaindoesntexist.apigee.tom smtp.gmail.com,465 EOF diff --git a/tools/target-server-validator/utilities.py b/tools/target-server-validator/utilities.py index 6309736c..c96feb16 100644 --- a/tools/target-server-validator/utilities.py +++ b/tools/target-server-validator/utilities.py @@ -26,8 +26,6 @@ import urllib3 from forcediphttpsadapter.adapters import ForcedIPHTTPSAdapter -urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - def parse_config(config_file): config = configparser.ConfigParser() @@ -55,19 +53,21 @@ def create_proxy_bundle(proxy_bundle_directory, api_name, target_dir): # noqa def run_validator_proxy( - url, dns_host, vhost_ip, target_host, target_port="443" -): # noqa + url, dns_host, vhost_ip, target_host, target_port="443", allow_insecure=False): # noqa headers = { "host_name": target_host, "port_number": str(target_port), "Host": dns_host, } + if allow_insecure: + print("INFO: Skipping Certificate Verification & disabling warnings because 'allow_insecure' is set to true") # noqa + urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) session = requests.Session() if len(vhost_ip) > 0: session.mount( f"https://{dns_host}", ForcedIPHTTPSAdapter(dest_ip=vhost_ip) ) # noqa - r = session.get(url, headers=headers, verify=False) + r = session.get(url, headers=headers, verify=(not allow_insecure)) if r.status_code == 200: return r.json()["status"] return "STATUS_UNKNOWN"