Skip to content

Commit

Permalink
fix: fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anaik91 committed Sep 7, 2023
1 parent 2d9387a commit 8efa176
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/in-solidarity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tools/target-server-validator/apiproxy/proxies/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<Response/>
</PostFlow>
<HTTPProxyConnection>
<BasePath>/validate_target_server</BasePath>
<BasePath>/validate-target-server</BasePath>
</HTTPProxyConnection>
<RouteRule name="noroute"/>
</ProxyEndpoint>
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<APIProxy name="target_server_validator"/>
<APIProxy name="target-server-validator"/>
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions tools/target-server-validator/input.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions tools/target-server-validator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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(
[
Expand Down Expand Up @@ -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']}"
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions tools/target-server-validator/pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,18 @@ 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
cat > "$SCRIPTPATH/input.csv" << EOF
HOST,PORT
httpbin.org
httpbin.org,443
mocktarget.apigee.tom
domaindoesntexist.apigee.tom
smtp.gmail.com,465
EOF

Expand Down
10 changes: 5 additions & 5 deletions tools/target-server-validator/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 8efa176

Please sign in to comment.