Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Updated to latest Spring and other dependency versions
Browse files Browse the repository at this point in the history
- Updated to latest Spring and other dependency versions
- Changes in HTTP Connector required changing the way we select HTTP or HTTPS as the protocol.  Now we must have separate flows and listeners for each protocol.  The existing listener flows are set to HTTPS.  New HTTP flows are added that reference to the HTTPS flows.
- The HTTP flows can be stopped via property
- Added an ignoreFile list property for resource files a browser asks for that don't exist in the app, like "favicon.ico".  Not required but now doesn't put a "resource not found" exception in the flow.
  • Loading branch information
titans-of-code authored Dec 22, 2022
1 parent 96f1be0 commit 4d80e93
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 87 deletions.
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Net Tools API

The Net Tools API is a deployable Mule app that you can deploy to CloudHub. The app will then expose a very simple UI that will allow you to do basic networking commands. The idea is that most networking related issues with your CloudHub VPC and VPN are related to connectivity to your on-prem systems, and most of those issues end up being resolved on the customer end. If you have this tool available to you, you can work with your Networking team to test connectivity to various on-prem systems and verify that firewall and routing rules are working. It can also be used to generate some traffic that can help with diagnosing networking issues.
The Net Tools API is a deployable Mule app that you can deploy to CloudHub or any worker cloud. The app will then expose a very simple UI that will allow you to do basic networking commands. The idea is that most networking related issues with your CloudHub VPC and VPN are related to connectivity to your on-prem systems, and most of those issues end up being resolved on the customer end. If you have this tool available to you, you can work with your Networking team to test connectivity to various on-prem systems and verify that firewall and routing rules are working. It can also be used to generate some traffic that can help with diagnosing networking issues.

This supports HTTP and HTTPS connections with a configurable port for each.

Expand All @@ -25,15 +25,26 @@ The UI can be accessed by using the base URL for the app. The options are liste
- CloudHub Shared Load Balancer: `http://{app-name}.{region}.cloudhub.io` where the app-name and region are specific to the deployed app.
- Dedicated Load Balancer: `custom url`. See *Configuration* section to update settings.

The API Console is available at the `/console` path.

The UI is protected by Basic Authentication, and the default credentials are listed in the *Configuration* section.

# Configuration
The properties below can be set on the app to override the default settings. The proper port and protocol must be set to accommodate load balancer and VPC firewall rule settings. The default settings are for the CloudHub shared load balancer HTTP endpoint. See the [CloudHub Load Balancer documentation](https://docs.mulesoft.com/runtime-manager/lb-architecture) for which port and protocol to use for your configuration.

- `user`: User name for login; defaults to `vpc-tools`
- `pass`: Password for login; defaults to `SomePass`
- `protocol`: The protocol to use; defaults to `http`. Options: `http` or `https`
- `httpPort`: Sets the listener port for http; defaults to `8081`
- `httpsPort`: Sets the listener port for https; defaults to `8082`
The properties below can be set on the app to override the default settings. The proper ports must be set to accommodate load balancer and VPC firewall rule settings. The default settings are for the CloudHub shared load balancer HTTP endpoint.

- `user`: User name for login. Defaults to `vpc-tools`
- `pass`: Password for login. Defaults to `SomePass`
- `httpPort`: Sets the listener port for HTTP. Defaults to `8081`
- `httpsPort`: Sets the listener port for HTTPS. Defaults to `8082`
- `httpListener`: The running state of the HTTP endpoint flows. Defaults to `started`. Options: `started` or `stopped`. Stop this to disable HTTP endpoint on CloudHub 1.0 or non-RTF infrastructure. This doesn't affect RTF or CloudHub 2.0 because only a single HTTP port is used.
- `ignoreFiles`: Comma-delimited list of browser-requested resource files for this app to ignore. Defaults to `favicon.ico`.

## Network Considerations

- `httpsPort` and `httpPort` **must always** be different numbers, even if `httpListener=stopped`. This is because both HTTP and HTTPS listener configurations are always created, even if the HTTP endpoint is not enabled.
- CloudHub 2.0 and RTF only use a single port for the HTTP listener. This means you can only run either HTTP or HTTPS, but not both at the same time. Make sure the property you want to use is set to the proper port and the other is set to another unused port.
- When using CloudHub 2.0 and RTF, you must enable *Last-Mile Security* in the app's Ingress tab if you want to use HTTPS.
- This does not use `http.port` and `https.port` properties since those are overrriden on Cloudhub 2.0 and RTF to the same port and will prevent the app from starting because of a port conflict.

### References
- [CloudHub 2.0 Infrastructure Considerations](https://docs.mulesoft.com/cloudhub-2/ch2-comparison#infrastructure-considerations)
- [CloudHub 1.0 Load Balancer Architecture](https://docs.mulesoft.com/cloudhub-1/lb-architecture)
- [Enable Last Mile Security in RTF](https://help.mulesoft.com/s/article/How-to-Enable-both-Last-Mile-Security-and-Mutual-TLS-in-Runtime-Fabric)
Empty file added exchange-docs/home.md
Empty file.
24 changes: 15 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.mycompany</groupId>
<artifactId>net-tools-api</artifactId>
<version>2.4.0</version>
<version>2.4.1</version>
<packaging>mule-application</packaging>

<name>net-tools-api</name>
Expand All @@ -13,15 +13,15 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<app.runtime>4.3.0</app.runtime>
<mule.maven.plugin.version>3.4.2</mule.maven.plugin.version>
<apikit.module.version>1.5.9</apikit.module.version>
<http.connector.version>1.6.0</http.connector.version>
<sockets.connector.version>1.2.2</sockets.connector.version>
<spring.module.version>1.3.6</spring.module.version>
<app.runtime>4.4.0</app.runtime>
<mule.maven.plugin.version>3.8.0</mule.maven.plugin.version>
<apikit.module.version>1.8.0</apikit.module.version>
<http.connector.version>1.7.3</http.connector.version>
<sockets.connector.version>1.2.3</sockets.connector.version>
<spring.module.version>1.3.7</spring.module.version>

<spring.version>5.3.15</spring.version>
<spring-security.version>5.6.1</spring-security.version>
<spring.version>5.3.22</spring.version>
<spring-security.version>5.7.3</spring-security.version>
</properties>

<build>
Expand Down Expand Up @@ -125,6 +125,12 @@
<url>https://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
<repository>
<id>anypoint-exchange-v3</id>
<name>Anypoint Exchange V3</name>
<url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
Expand Down
2 changes: 1 addition & 1 deletion src/main/mule/global.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/
<apikit:config name="net-tools-config" raml="net-tools.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />

<spring:config name="Spring_Config" doc:id="45181472-36fd-44e6-b710-296481c3c450" files="beans.xml" />
<spring:security-manager>
<spring:security-manager>
<spring:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager" />
</spring:security-manager>
</mule>
33 changes: 33 additions & 0 deletions src/main/mule/http.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">

<flow name="http-ui" doc:id="26329426-60ba-49ad-ae04-ac3bfb607dea" initialState="${httpListener}">
<http:listener doc:name="Listener"
doc:id="945b4a80-dcdd-460e-a520-24f510d84be8" config-ref="http"
path="/*" outputMimeType="text/html" />
<flow-ref doc:name="ui"
doc:id="e74273e3-e138-414c-b6bf-58728820b208" name="ui" />
</flow>

<flow name="http-net-tools-main" initialState="${httpListener}">
<http:listener config-ref="http" path="/api/*">
<http:response
statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response
statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<flow-ref doc:name="net-tools-main" doc:id="7b7d5435-a4ae-4c67-9159-cf238285bd32" name="net-tools-main"/>

</flow>
</mule>
122 changes: 56 additions & 66 deletions src/main/mule/net-tools.xml
Original file line number Diff line number Diff line change
@@ -1,57 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:spring="http://www.mulesoft.org/schema/mule/spring" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns:spring="http://www.mulesoft.org/schema/mule/spring"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd
http://www.mulesoft.org/schema/mule/spring http://www.mulesoft.org/schema/mule/spring/current/mule-spring.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">

<flow name="ui" doc:id="94b97777-bd63-4abb-8093-a5c8ac97aa17" >
<http:listener doc:name="Listener" doc:id="7e20b485-577c-4530-b2b1-66b6a84d5694" config-ref="${protocol}" path="/*" outputMimeType="text/html"/>
<http:basic-security-filter doc:name="Basic security filter" doc:id="cb77f47e-923a-4195-86fc-23bbf2f01311" realm="mule" />
<spring:authorization-filter requiredAuthorities="ROLE_ADMIN" />
<ee:transform doc:name="Transform Message" doc:id="610d96e5-97f6-407d-ab81-fa234a5794bc" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output text/plain

var uriPath = attributes.requestPath
var path = if ("/" == uriPath)
"web/index.html"
else
"web" ++ uriPath
---
readUrl("classpath://" ++ path, "text/plain")]]></ee:set-payload>
<flow name="ui" doc:id="94b97777-bd63-4abb-8093-a5c8ac97aa17">
<http:listener doc:name="Listener"
doc:id="7e20b485-577c-4530-b2b1-66b6a84d5694" config-ref="https"
path="/*" outputMimeType="text/html" />
<http:basic-security-filter
doc:name="Basic security filter"
doc:id="cb77f47e-923a-4195-86fc-23bbf2f01311" realm="mule" />
<spring:authorization-filter
requiredAuthorities="ROLE_ADMIN" />
<ee:transform doc:name="Transform Message"
doc:id="610d96e5-97f6-407d-ab81-fa234a5794bc">
<ee:message>
<ee:set-payload
resource="dwl/setWebResourcePayload.dwl" />
</ee:message>
<ee:variables >
<ee:set-variable variableName="mimeType" ><![CDATA[%dw 2.0
output application/java
---
splitBy(attributes.requestPath, ".")[-1] default ""]]></ee:set-variable>
<ee:variables>
<ee:set-variable
resource="dwl/setWebResourceMimeType.dwl" variableName="mimeType" />
</ee:variables>
</ee:transform>
<choice doc:name="Which MIME type?" doc:id="7fa94994-1832-4b21-b557-691274259e46" >
<choice doc:name="Which MIME type?"
doc:id="7fa94994-1832-4b21-b557-691274259e46">
<when expression='#[vars.mimeType == "css"]'>
<set-payload value="#[payload]" doc:name="Set MIME type as CSS" doc:id="d8334850-64ab-448a-abe3-1611772f58b8" mimeType="text/css" />
<set-payload value="#[payload]"
doc:name="Set MIME type as CSS"
doc:id="d8334850-64ab-448a-abe3-1611772f58b8" mimeType="text/css" />
</when>
<when expression='#[vars.mimeType == "js"]'>
<set-payload value="#[payload]" doc:name="Set MIME type as JavaScript" doc:id="9595f13e-4c58-4707-9818-c3bcc1d33a0a" mimeType="application/javascript" />
<set-payload value="#[payload]"
doc:name="Set MIME type as JavaScript"
doc:id="9595f13e-4c58-4707-9818-c3bcc1d33a0a"
mimeType="application/javascript" />
</when>
<otherwise >
<set-payload value="#[payload]" doc:name="Set MIME type as HTML" doc:id="1e21a771-c190-40db-984f-9805208c3ca2" mimeType="text/html" />
<otherwise>
<set-payload value="#[payload]"
doc:name="Set MIME type as HTML"
doc:id="1e21a771-c190-40db-984f-9805208c3ca2" mimeType="text/html" />
</otherwise>
</choice>
</flow>
<flow name="net-tools-main">
<http:listener config-ref="${protocol}" path="/api/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<flow name="net-tools-main"
doc:id="6f86a93f-9de9-4cf8-b092-b6a4b23c42f4">
<http:listener config-ref="https" path="/api/*">
<http:response
statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response
statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<http:basic-security-filter doc:name="Basic security filter" realm="mule" />
<apikit:router config-ref="net-tools-config" />
<logger level="INFO"
message='#["$(attributes.scheme default "") $(attributes.method default "") $(attributes.requestUri default "")"]'
doc:name="Log Endpoint" />
<apikit:router config-ref="net-tools-config" />
<error-handler>
<on-error-propagate type="APIKIT:BAD_REQUEST">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
Expand Down Expand Up @@ -132,36 +150,8 @@ output application/json
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="net-tools-console">
<http:listener config-ref="${protocol}" path="/console/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit:console config-ref="net-tools-config" />
<error-handler>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
</ee:message>
<ee:variables>
<ee:set-variable variableName="httpStatus">404</ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-propagate>
</error-handler>
</flow>
<flow name="get:\curl:net-tools-config">
<logger level="INFO" message="get:\curl:net-tools-config" />
<ee:transform doc:name="Transform Message" doc:id="c96eaddb-f56e-4f1a-81ff-ec15df7cb6d6" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application-types.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<types:mule xmlns:types="http://www.mulesoft.org/schema/mule/types">
<types:catalog/>
</types:mule>
5 changes: 5 additions & 0 deletions src/main/resources/dwl/setWebResourceMimeType.dwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%dw 2.0
output application/java
import substringAfterLast from dw::core::Strings
---
substringAfterLast(attributes.requestPath, ".") default ""
15 changes: 15 additions & 0 deletions src/main/resources/dwl/setWebResourcePayload.dwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%dw 2.0
output text/plain
import substringAfterLast from dw::core::Strings

var ignoreFiles = p("ignoreFiles") splitBy ","
var uriPath = attributes.requestPath
var path = if ("/" == uriPath)
"web/index.html"
else
"web" ++ uriPath
---
if (ignoreFiles contains substringAfterLast(uriPath, "/"))
null
else
readUrl("classpath://" ++ path, "text/plain")
3 changes: 2 additions & 1 deletion src/main/resources/properties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ user: "vpc-tools"
pass: "SomePass"
httpPort: "8081"
httpsPort: "8082"
protocol: "http"
httpListener: "started"
ignoreFiles: "favicon.ico" # comma-delimited list of resource files to ignore

0 comments on commit 4d80e93

Please sign in to comment.