@@ -2,7 +2,7 @@ namespace Docker.DotNet;
22
33internal class ExecOperations : IExecOperations
44{
5- internal static readonly ApiResponseErrorHandlingDelegate NoSuchContainerHandler = ( statusCode , responseBody ) =>
5+ private static readonly ApiResponseErrorHandlingDelegate NoSuchContainerHandler = ( statusCode , responseBody ) =>
66 {
77 if ( statusCode == HttpStatusCode . NotFound )
88 {
@@ -17,33 +17,18 @@ internal ExecOperations(DockerClient client)
1717 _client = client ;
1818 }
1919
20- public async Task < ContainerExecCreateResponse > ExecCreateContainerAsync ( string id , ContainerExecCreateParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
20+ public async Task < ContainerExecInspectResponse > InspectContainerExecAsync ( string id , CancellationToken cancellationToken = default )
2121 {
2222 if ( string . IsNullOrEmpty ( id ) )
2323 {
2424 throw new ArgumentNullException ( nameof ( id ) ) ;
2525 }
2626
27- if ( parameters == null )
28- {
29- throw new ArgumentNullException ( nameof ( parameters ) ) ;
30- }
31-
32- var data = new JsonRequestContent < ContainerExecCreateParameters > ( parameters , DockerClient . JsonSerializer ) ;
33- return await _client . MakeRequestAsync < ContainerExecCreateResponse > ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "containers/{ id } /exec", null , data , cancellationToken ) . ConfigureAwait ( false ) ;
34- }
35-
36- public async Task < ContainerExecInspectResponse > InspectContainerExecAsync ( string id , CancellationToken cancellationToken )
37- {
38- if ( string . IsNullOrEmpty ( id ) )
39- {
40- throw new ArgumentNullException ( nameof ( id ) ) ;
41- }
42-
43- return await _client . MakeRequestAsync < ContainerExecInspectResponse > ( new [ ] { NoSuchContainerHandler } , HttpMethod . Get , $ "exec/{ id } /json", null , cancellationToken ) . ConfigureAwait ( false ) ;
27+ return await _client . MakeRequestAsync < ContainerExecInspectResponse > ( [ NoSuchContainerHandler ] , HttpMethod . Get , $ "exec/{ id } /json", null , cancellationToken )
28+ . ConfigureAwait ( false ) ;
4429 }
4530
46- public Task ResizeContainerExecTtyAsync ( string id , ContainerResizeParameters parameters , CancellationToken cancellationToken )
31+ public async Task < ContainerExecCreateResponse > CreateContainerExecAsync ( string id , ContainerExecCreateParameters parameters , CancellationToken cancellationToken = default )
4732 {
4833 if ( string . IsNullOrEmpty ( id ) )
4934 {
@@ -55,43 +40,24 @@ public Task ResizeContainerExecTtyAsync(string id, ContainerResizeParameters par
5540 throw new ArgumentNullException ( nameof ( parameters ) ) ;
5641 }
5742
58- var queryParameters = new QueryString < ContainerResizeParameters > ( parameters ) ;
59- return _client . MakeRequestAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "exec/{ id } /resize", queryParameters , cancellationToken ) ;
43+ var data = new JsonRequestContent < ContainerExecCreateParameters > ( parameters , DockerClient . JsonSerializer ) ;
44+
45+ return await _client . MakeRequestAsync < ContainerExecCreateResponse > ( [ NoSuchContainerHandler ] , HttpMethod . Post , $ "containers/{ id } /exec", null , data , cancellationToken )
46+ . ConfigureAwait ( false ) ;
6047 }
6148
62- // StartContainerExecAsync will start the process specified by id in detach mode with no connected
63- // stdin, stdout, or stderr pipes.
64- public Task StartContainerExecAsync ( string id , CancellationToken cancellationToken )
49+ public async Task < MultiplexedStream > StartContainerExecAsync ( string id , ContainerExecStartParameters parameters , CancellationToken cancellationToken = default )
6550 {
6651 if ( string . IsNullOrEmpty ( id ) )
6752 {
6853 throw new ArgumentNullException ( nameof ( id ) ) ;
6954 }
7055
71- var parameters = new ContainerExecStartParameters
72- {
73- Detach = true ,
74- } ;
7556 var data = new JsonRequestContent < ContainerExecStartParameters > ( parameters , DockerClient . JsonSerializer ) ;
76- return _client . MakeRequestAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "exec/{ id } /start", null , data , cancellationToken ) ;
77- }
7857
79- // StartAndAttachContainerExecAsync will start the process specified by id with stdin, stdout, stderr
80- // connected, and optionally using terminal emulation if tty is true.
81- public async Task < MultiplexedStream > StartAndAttachContainerExecAsync ( string id , bool tty , CancellationToken cancellationToken )
82- {
83- return await StartWithConfigContainerExecAsync ( id , new ContainerExecStartParameters ( ) { AttachStdin = true , AttachStderr = true , AttachStdout = true , Tty = tty } , cancellationToken ) ;
84- }
58+ var result = await _client . MakeRequestForStreamAsync ( [ NoSuchContainerHandler ] , HttpMethod . Post , $ "exec/{ id } /start", null , data , null , cancellationToken )
59+ . ConfigureAwait ( false ) ;
8560
86- public async Task < MultiplexedStream > StartWithConfigContainerExecAsync ( string id , ContainerExecStartParameters parameters , CancellationToken cancellationToken )
87- {
88- if ( string . IsNullOrEmpty ( id ) )
89- {
90- throw new ArgumentNullException ( nameof ( id ) ) ;
91- }
92-
93- var data = new JsonRequestContent < ContainerExecStartParameters > ( parameters , DockerClient . JsonSerializer ) ;
94- var result = await _client . MakeRequestForStreamAsync ( new [ ] { NoSuchContainerHandler } , HttpMethod . Post , $ "exec/{ id } /start", null , data , null , cancellationToken ) . ConfigureAwait ( false ) ;
9561 return new MultiplexedStream ( result , ! parameters . Tty ) ;
9662 }
9763}
0 commit comments