@@ -118,8 +118,7 @@ const accessPropagationGuard = (
118
118
119
119
child . stderr . on ( "data" , ( chunk ) => {
120
120
const chunkString : string = chunk . toString ( "utf-8" ) ;
121
-
122
- if ( debug ) print2 ( chunkString ) ;
121
+ parseAndPrintSshOutputToStderr ( chunkString , debug ) ;
123
122
124
123
const match = UNPROVISIONED_ACCESS_MESSAGES . find ( ( message ) =>
125
124
chunkString . match ( message . pattern )
@@ -146,6 +145,36 @@ const accessPropagationGuard = (
146
145
} ;
147
146
} ;
148
147
148
+ /**
149
+ * Parses and prints a chunk of SSH output to stderr.
150
+ *
151
+ * If debug is enabled, all output is printed. Otherwise, only selected messages are printed.
152
+ *
153
+ * @param chunkString the chunk to print
154
+ * @param debug true if debug output is enabled
155
+ */
156
+ const parseAndPrintSshOutputToStderr = (
157
+ chunkString : string ,
158
+ debug ?: boolean
159
+ ) => {
160
+ const lines = chunkString . split ( "\n" ) ;
161
+
162
+ // SSH only prints the "Authenticated to" message if the verbose option (-v) is enabled
163
+ for ( const line of lines ) {
164
+ if ( debug ) {
165
+ print2 ( line ) ;
166
+ } else {
167
+ if ( line . includes ( "Authenticated to" ) ) {
168
+ print2 ( line ) ;
169
+ }
170
+
171
+ if ( line . includes ( "port forwarding failed" ) ) {
172
+ print2 ( line ) ;
173
+ }
174
+ }
175
+ }
176
+ } ;
177
+
149
178
const spawnChildProcess = (
150
179
credential : AwsCredentials | undefined ,
151
180
command : string ,
@@ -315,7 +344,7 @@ const addCommonArgs = (args: CommandArgs, proxyCommand: string[]) => {
315
344
}
316
345
317
346
const verboseOptionExists = sshOptions . some ( ( opt ) => opt === "-v" ) ;
318
- if ( ! verboseOptionExists && args . debug ) {
347
+ if ( ! verboseOptionExists ) {
319
348
sshOptions . push ( "-v" ) ;
320
349
}
321
350
} ;
0 commit comments