Skip to content

Commit

Permalink
fix(gateway): Correct formatting and linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
phantomjinx committed Jun 28, 2024
1 parent 4b2f4ad commit cc06919
Show file tree
Hide file tree
Showing 21 changed files with 1,077 additions and 1,028 deletions.
8 changes: 4 additions & 4 deletions docker/gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
A partner image, base on [node](https://nodejs.org), to the Hawtio Online image that provides support to the functions of the Hawtio Online nginx server.

- The Hawtio Online nginx server will defer to the gateway's [_/master_] endpoint to check the permissability of the requested uri. If the uri is acceptable then the gateway will
proxy to the cluster API server;
proxy to the cluster API server;
- The Hawtio Online nginx server will defer to the gateway's [_/managment_] endpoint to access
the jolokia endpoint. The result of this endpoint involves a back and forth between internal
endpoints of both the nginx and gateway servers;
the jolokia endpoint. The result of this endpoint involves a back and forth between internal
endpoints of both the nginx and gateway servers;
- The Hawtio Online nginx server will defer to the gateway's [_/logout_] endpoint to redirect
to the uri's _redirect_uri_ parameter;
to the uri's _redirect_uri_ parameter;
- The gateway also has a [_/status_] endpoint which provides a heartbeat capability.

This image replaces the functionality originally provided by nginx njs.
Expand Down
3 changes: 1 addition & 2 deletions docker/gateway/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export default {
// Automatically clear mock calls and instances between every test
clearMocks: true,

moduleNameMapper: {
},
moduleNameMapper: {},

// The path to a module that runs some code to configure or set up the testing
// framework before each test
Expand Down
6 changes: 3 additions & 3 deletions docker/gateway/jolokia-testing-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ metadata:
namespace: <NAMESPACE>
spec:
ports:
- port: <JOLOKIA-PORT>
protocol: TCP
targetPort: <JOLOKIA-PORT>
- port: <JOLOKIA-PORT>
protocol: TCP
targetPort: <JOLOKIA-PORT>
selector:
app: <SELECT-POD-LABEL>
type: ClusterIP
277 changes: 149 additions & 128 deletions docker/gateway/proxy-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,24 @@ if (!masterUri) {
}

/* Defers to the app server */
app.use('/auth/logout', createProxyMiddleware({
target: appServerUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
// Convert path to logout endpoint
return '/logout'
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'LOGOUT'
}
}))
app.use(
'/auth/logout',
createProxyMiddleware({
target: appServerUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
// Convert path to logout endpoint
return '/logout'
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'LOGOUT',
},
}),
)

/*
* Defers to the app server to determine if the
Expand All @@ -57,103 +60,118 @@ app.use('/auth/logout', createProxyMiddleware({
* 1. If permitted then it will redirect to /masterinternal
* 2. If not permitted then it will return a 401 or 502
*/
app.use('/master', createProxyMiddleware({
target: appServerUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
headers: {
'Content-Type': 'application/json',
'location-rule': 'MASTER'
}
}))
app.use(
'/master',
createProxyMiddleware({
target: appServerUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
headers: {
'Content-Type': 'application/json',
'location-rule': 'MASTER',
},
}),
)

/* Defers to the app server */
app.use('/management', createProxyMiddleware({
target: appServerUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
return '/management' + path
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'MANAGEMENT',
'X-Frame-Options': 'SAMEORIGIN',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'self'; form-action 'self'; ",
'Authorization': `Bearer ${masterToken}`
}
}))
app.use(
'/management',
createProxyMiddleware({
target: appServerUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
return '/management' + path
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'MANAGEMENT',
'X-Frame-Options': 'SAMEORIGIN',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'self'; form-action 'self'; ",
Authorization: `Bearer ${masterToken}`,
},
}),
)

/* App server returns back to proxy to the master cluster */
app.use('/authorization', createProxyMiddleware({
target: masterUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
let uri = '/authorization' + path
return uri.replace(/\/authorization\/([^/]+)\/(.*)/, '/apis/$1/v1/$2')
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'AUTHORIZATION',
'X-Frame-Options': 'SAMEORIGIN',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'self'; form-action 'self'; ",
'Authorization': `Bearer ${masterToken}`
}
}))

app.use('/authorization2', createProxyMiddleware({
target: masterUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
let uri = '/authorization2' + path
return uri.replace(/\/authorization2\/([^/]+)\/(.*)/, '/apis/$1/v1/$2')
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'AUTHORIZATION',
'X-Frame-Options': 'SAMEORIGIN',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'self'; form-action 'self'; ",
'Authorization': `Bearer ${masterToken}`
}
}))

app.use('/podIP', createProxyMiddleware({
target: masterUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
let uri = '/podIP' + path
const match = uri.match(/\/podIP\/(.+)\/(.+)/)

// Save the namespace for use in the proxy endpoint
namespace = match[1]

return uri.replace(/\/podIP\/(.+)\/(.+)/, '/api/v1/namespaces/$1/pods/$2')
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'POD-IP',
'X-Frame-Options': 'SAMEORIGIN',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'self'; form-action 'self'; ",
'Authorization': `Bearer ${masterToken}`
}
}))
app.use(
'/authorization',
createProxyMiddleware({
target: masterUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
let uri = '/authorization' + path
return uri.replace(/\/authorization\/([^/]+)\/(.*)/, '/apis/$1/v1/$2')
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'AUTHORIZATION',
'X-Frame-Options': 'SAMEORIGIN',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'self'; form-action 'self'; ",
Authorization: `Bearer ${masterToken}`,
},
}),
)

app.use(
'/authorization2',
createProxyMiddleware({
target: masterUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
let uri = '/authorization2' + path
return uri.replace(/\/authorization2\/([^/]+)\/(.*)/, '/apis/$1/v1/$2')
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'AUTHORIZATION',
'X-Frame-Options': 'SAMEORIGIN',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'self'; form-action 'self'; ",
Authorization: `Bearer ${masterToken}`,
},
}),
)

app.use(
'/podIP',
createProxyMiddleware({
target: masterUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
let uri = '/podIP' + path
const match = uri.match(/\/podIP\/(.+)\/(.+)/)

// Save the namespace for use in the proxy endpoint
namespace = match[1]

return uri.replace(/\/podIP\/(.+)\/(.+)/, '/api/v1/namespaces/$1/pods/$2')
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'POD-IP',
'X-Frame-Options': 'SAMEORIGIN',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'self'; form-action 'self'; ",
Authorization: `Bearer ${masterToken}`,
},
}),
)

/**
* The endpoint for directly accessing the jolokia service.
Expand All @@ -162,26 +180,29 @@ app.use('/podIP', createProxyMiddleware({
* externally to the cluster AND requires the jolokia port on
* the target app to be exposed as a service
*/
app.use('/proxy', createProxyMiddleware({
target: masterUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
const uri = `/api/v1/namespaces/${namespace}/services/${testService}:${testServicePort}/proxy/${jolokiaPath}`
logger.info(`New proxy uri ${uri}`)
return uri
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'POD-IP',
'X-Frame-Options': 'SAMEORIGIN',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'self'; form-action 'self'; ",
'Authorization': `Bearer ${masterToken}`
}
}))
app.use(
'/proxy',
createProxyMiddleware({
target: masterUri,
logger: logger,
changeOrigin: false,
ws: true,
secure: false,
pathRewrite: (path, req) => {
const uri = `/api/v1/namespaces/${namespace}/services/${testService}:${testServicePort}/proxy/${jolokiaPath}`
logger.info(`New proxy uri ${uri}`)
return uri
},
headers: {
'Content-Type': 'application/json',
'location-rule': 'POD-IP',
'X-Frame-Options': 'SAMEORIGIN',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': "default-src 'self'; frame-ancestors 'self'; form-action 'self'; ",
Authorization: `Bearer ${masterToken}`,
},
}),
)

/*
* These must be declared after the use of proxy
Expand Down
4 changes: 2 additions & 2 deletions docker/gateway/public/ACL.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jolokia.Config.hawtio:
jolokia.Discovery:
lookupAgents: admin, viewer
lookupAgentsWithTimeout: admin, viewer
jolokia.ServerHandler.hawtio:
jolokia.ServerHandler.hawtio:
mBeanServersInfo: admin, viewer

org.apache.aries.blueprint.blueprintMetadata:
Expand Down Expand Up @@ -215,7 +215,7 @@ org.apache.camel.context:
requestBodyAndHeaders: admin
findComponents: admin, viewer
getComponentDocumentation: admin, viewer
removeEndpoints: admin
removeEndpoints: admin
completeEndpointPath: admin, viewer
org.apache.camel.endpoints:
/is.*/: admin, viewer
Expand Down
Loading

0 comments on commit cc06919

Please sign in to comment.