* gen v1.23.0 * fix converter * bump ver * update readme runtime * fix warning * update dep ver * newtonjson -> system.text.json * generate for new json api * readme lf * dotnet fmt * dotnet fmt tests/ * dotnet fmt * Revert "dotnet fmt" This reverts commit e14c59076143fe2218ed899295a00762f0ea2bd6. * fix err introduce by dotnet fmt * fix test * remove deprecated /watch api * generate code after /watch removed * remove /watch related code * trim Microsoft.Rest.Serialization
70 lines
2.6 KiB
C#
70 lines
2.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace k8s.Tests.Mock.Server.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Controller for the mock Kubernetes pod-port-forward API.
|
|
/// </summary>
|
|
[Route("api/v1")]
|
|
public class PodPortForwardController
|
|
: Controller
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="PodPortForwardController"/> class.
|
|
/// Create a new <see cref="PodPortForwardController"/>.
|
|
/// </summary>
|
|
/// <param name="webSocketTestAdapter">
|
|
/// The adapter used to capture sockets accepted by the test server and provide them to the calling test.
|
|
/// </param>
|
|
public PodPortForwardController(WebSocketTestAdapter webSocketTestAdapter)
|
|
{
|
|
if (webSocketTestAdapter == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(webSocketTestAdapter));
|
|
}
|
|
|
|
WebSocketTestAdapter = webSocketTestAdapter;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The adapter used to capture sockets accepted by the test server and provide them to the calling test.
|
|
/// </summary>
|
|
private WebSocketTestAdapter WebSocketTestAdapter { get; }
|
|
|
|
/// <summary>
|
|
/// Mock Kubernetes API: port-forward for pod.
|
|
/// </summary>
|
|
/// <param name="kubeNamespace">
|
|
/// The target pod's containing namespace.
|
|
/// </param>
|
|
/// <param name="podName">
|
|
/// The target pod's name.
|
|
/// </param>
|
|
/// <param name="ports">
|
|
/// The port(s) to forward to the pod.
|
|
/// </param>
|
|
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
|
|
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
|
|
[Route("namespaces/{kubeNamespace}/pods/{podName}/portforward")]
|
|
public async Task<IActionResult> Exec(string kubeNamespace, string podName, IEnumerable<string> ports)
|
|
{
|
|
if (!HttpContext.WebSockets.IsWebSocketRequest)
|
|
{
|
|
return BadRequest("PortForward requires WebSockets");
|
|
}
|
|
|
|
var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync(
|
|
WebSocketProtocol.ChannelWebSocketProtocol).ConfigureAwait(false);
|
|
|
|
WebSocketTestAdapter.AcceptedPodPortForwardV1Connection.AcceptServerSocket(webSocket);
|
|
|
|
await WebSocketTestAdapter.TestCompleted.ConfigureAwait(false);
|
|
|
|
return Ok();
|
|
}
|
|
}
|
|
}
|