Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ports-plugin] don't prompt user to redirect endpoints with exposure: none #301

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,6 @@ export class DevWorkspaceDevfileHandlerImpl implements DevfileHandler {
} as Endpoint;
});

// Add private JWT proxy ports
const jwtProxyEnv: string[] = Object.keys(process.env).filter(key =>
key.includes('_JWTPROXY_SERVICE_PORT_SERVER_')
);
jwtProxyEnv.forEach((key, index) => {
const value = process.env[key]!.toLocaleLowerCase() || '';
const port = parseInt(value);
if (!isNaN(port)) {
const endpoint: Endpoint = {
name: `jwt-proxy-${index + 1}`,
exposure: EndpointExposure.FROM_DEVFILE_PRIVATE,
url: '',
targetPort: port,
protocol: 'tcp',
type: 'jwt-proxy',
category: EndpointCategory.PLUGINS,
};
endpoints.push(endpoint);
}
});

return endpoints;
}
}
36 changes: 26 additions & 10 deletions code/extensions/che-port/src/ports-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,36 @@ export class PortsPlugin {
// check now if the port is in workspace definition ?
const matchingEndpoint = this.devfileEndpoints.find(endpoint => endpoint.targetPort === port.portNumber);

if (matchingEndpoint && matchingEndpoint.exposure === EndpointExposure.FROM_DEVFILE_PRIVATE) {
this.outputChannel.appendLine(
`Endpoint ${matchingEndpoint.name} on port ${matchingEndpoint.targetPort} is defined as Private. Do not prompt to open it.`
);
return;
if (matchingEndpoint) {
if (matchingEndpoint.exposure === EndpointExposure.FROM_DEVFILE_PRIVATE) {
this.outputChannel.appendLine(
`Endpoint ${matchingEndpoint.name} on port ${matchingEndpoint.targetPort} is defined as exposure: internal. Do not prompt to open it.`
);
return;
}
if (matchingEndpoint.exposure === EndpointExposure.FROM_DEVFILE_NONE) {
this.outputChannel.appendLine(
`Endpoint ${matchingEndpoint.name} on port ${matchingEndpoint.targetPort} is defined as exposure: none. Do not prompt to open it.`
);
return;
}
}

// if not listening on 0.0.0.0 then raise a prompt to add a port redirect
if (port.interfaceListen !== PortsPlugin.LISTEN_ALL_IPV4 && port.interfaceListen !== PortsPlugin.LISTEN_ALL_IPV6) {
const desc = `A new process is now listening on port ${port.portNumber} but is listening on interface ${port.interfaceListen} which is internal.
You should change to be remotely available. Would you want to add a redirect for this port so it becomes available ?`;
const err = `A new process is now listening on port ${port.portNumber} but is listening on interface ${port.interfaceListen} which is internal.
This port is not available outside. You should change the code to listen on 0.0.0.0 for example.`;
await this.askRedirect(port, desc, err);
if (matchingEndpoint && matchingEndpoint.exposure === EndpointExposure.FROM_DEVFILE_PUBLIC) {
const desc = `Process ${matchingEndpoint.name} is now listening on port ${matchingEndpoint.targetPort}, but it is listening on ${port.interfaceListen},
which is internal. You should change the code to listen on port 0.0.0.0 instead. Would you like to add a redirect to make this process available anyway?`;
const err = `Process ${matchingEndpoint.name} is now listening on port ${matchingEndpoint.targetPort}, but it is listening on ${port.interfaceListen},
which is internal. You should change the code to listen on port 0.0.0.0 instead.`;
await this.askRedirect(port, desc, err);
} else {
const desc = `A new process is now listening on port ${port.portNumber} but is listening on interface ${port.interfaceListen} which is internal.
You should change to be remotely available. Would you want to add a redirect for this port so it becomes available ?`;
const err = `A new process is now listening on port ${port.portNumber} but is listening on interface ${port.interfaceListen} which is internal.
This port is not available outside. You should change the code to listen on 0.0.0.0 for example.`;
await this.askRedirect(port, desc, err);
}
return;
}

Expand Down
Loading