1 /* 2 Copyright 2015 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package remotecommand 18 19 import ( 20 "context" 21 "io" 22 "net/http" 23 24 "k8s.io/apimachinery/pkg/util/httpstream" 25 ) 26 27 // StreamOptions holds information pertaining to the current streaming session: 28 // input/output streams, if the client is requesting a TTY, and a terminal size queue to 29 // support terminal resizing. 30 type StreamOptions struct { 31 Stdin io.Reader 32 Stdout io.Writer 33 Stderr io.Writer 34 Tty bool 35 TerminalSizeQueue TerminalSizeQueue 36 } 37 38 // Executor is an interface for transporting shell-style streams. 39 type Executor interface { 40 // Deprecated: use StreamWithContext instead to avoid possible resource leaks. 41 // See https://github.com/kubernetes/kubernetes/pull/103177 for details. 42 Stream(options StreamOptions) error 43 44 // StreamWithContext initiates the transport of the standard shell streams. It will 45 // transport any non-nil stream to a remote system, and return an error if a problem 46 // occurs. If tty is set, the stderr stream is not used (raw TTY manages stdout and 47 // stderr over the stdout stream). 48 // The context controls the entire lifetime of stream execution. 49 StreamWithContext(ctx context.Context, options StreamOptions) error 50 } 51 52 type streamCreator interface { 53 CreateStream(headers http.Header) (httpstream.Stream, error) 54 } 55 56 type streamProtocolHandler interface { 57 stream(conn streamCreator) error 58 } 59