mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
pass queries as params for other apiBase calls, for consistency
Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
parent
f49d3aeb6d
commit
f449966225
@ -99,12 +99,13 @@ interface PortForwardsResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function addPortForward(portForward: ForwardedPort): Promise<number> {
|
export async function addPortForward(portForward: ForwardedPort): Promise<number> {
|
||||||
|
const { port, forwardPort } = portForward;
|
||||||
let response: PortForwardResult;
|
let response: PortForwardResult;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const protocol = portForward.protocol ?? "http";
|
const protocol = portForward.protocol ?? "http";
|
||||||
|
|
||||||
response = await apiBase.post<PortForwardResult>(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}?port=${portForward.port}&forwardPort=${portForward.forwardPort}&protocol=${protocol}`);
|
response = await apiBase.post<PortForwardResult>(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}`, { query: { port, forwardPort, protocol }});
|
||||||
|
|
||||||
// expecting the received port to be the specified port, unless the specified port is 0, which indicates any available port is suitable
|
// expecting the received port to be the specified port, unless the specified port is 0, which indicates any available port is suitable
|
||||||
if (portForward.forwardPort && response?.port && response.port != +portForward.forwardPort) {
|
if (portForward.forwardPort && response?.port && response.port != +portForward.forwardPort) {
|
||||||
@ -119,19 +120,12 @@ export async function addPortForward(portForward: ForwardedPort): Promise<number
|
|||||||
return response?.port;
|
return response?.port;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProtocolQuery(protocol: string) {
|
|
||||||
if (protocol) {
|
|
||||||
return `&protocol=${protocol}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getPortForward(portForward: ForwardedPort): Promise<number> {
|
export async function getPortForward(portForward: ForwardedPort): Promise<number> {
|
||||||
|
const { port, forwardPort, protocol } = portForward;
|
||||||
let response: PortForwardResult;
|
let response: PortForwardResult;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await apiBase.get<PortForwardResult>(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}?port=${portForward.port}&forwardPort=${portForward.forwardPort}${getProtocolQuery(portForward.protocol)}`);
|
response = await apiBase.get<PortForwardResult>(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}`, { query: { port, forwardPort, protocol }});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn("[PORT-FORWARD-STORE] Error getting port-forward:", error, portForward);
|
logger.warn("[PORT-FORWARD-STORE] Error getting port-forward:", error, portForward);
|
||||||
throw (error);
|
throw (error);
|
||||||
@ -154,9 +148,11 @@ export async function modifyPortForward(portForward: ForwardedPort, desiredPort:
|
|||||||
|
|
||||||
|
|
||||||
export async function removePortForward(portForward: ForwardedPort) {
|
export async function removePortForward(portForward: ForwardedPort) {
|
||||||
|
const { port, forwardPort } = portForward;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await apiBase.del(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}?port=${portForward.port}&forwardPort=${portForward.forwardPort}`);
|
await apiBase.del(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}`, { query: { port, forwardPort }});
|
||||||
await waitUntilFree(+portForward.forwardPort, 200, 1000);
|
await waitUntilFree(+forwardPort, 200, 1000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn("[PORT-FORWARD-STORE] Error removing port-forward:", error, portForward);
|
logger.warn("[PORT-FORWARD-STORE] Error removing port-forward:", error, portForward);
|
||||||
throw (error);
|
throw (error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user