@@ -20,6 +20,7 @@ import java.nio.file.Files
20
20
import java .nio .file .Path
21
21
import java .nio .file .Paths
22
22
import java .nio .file .attribute .PosixFilePermission
23
+ import java .util .regex .Pattern
23
24
24
25
import scala .collection .JavaConverters ._
25
26
import scala .sys .process .BasicIO
@@ -160,16 +161,21 @@ final class CondaEnvironmentManager(condaBinaryPath: String,
160
161
* @return the stdout of the process
161
162
*/
162
163
private [this ] def runOrFail (command : ProcessBuilder , description : String ): String = {
164
+ import CondaEnvironmentManager .redactCredentials
163
165
val out = new StringBuffer
164
166
val err = new StringBuffer
165
167
val collectErrOutToBuffer = new ProcessIO (
166
- BasicIO .input(false ),
167
- BasicIO .processFully(out),
168
- BasicIO .processFully(line => {
169
- err append line
170
- err append BasicIO .Newline
171
- log.info(s " <conda> $line" )
172
- }))
168
+ BasicIO .input(false ),
169
+ BasicIO .processFully((redactCredentials _).andThen(line => {
170
+ out.append(line)
171
+ out.append(BasicIO .Newline )
172
+ ()
173
+ })),
174
+ BasicIO .processFully((redactCredentials _).andThen(line => {
175
+ err.append(line)
176
+ err.append(BasicIO .Newline )
177
+ log.info(s " <conda> $line" )
178
+ })))
173
179
val exitCode = command.run(collectErrOutToBuffer).exitValue()
174
180
if (exitCode != 0 ) {
175
181
throw new SparkException (s " Attempt to $description exited with code: "
@@ -196,6 +202,13 @@ object CondaEnvironmentManager extends Logging {
196
202
sparkConf.contains(CONDA_BINARY_PATH )
197
203
}
198
204
205
+ private [this ] val httpUrlToken =
206
+ Pattern .compile(" (\\ b\\ w+://[^:/@]*:)([^/@]+)(?=@([\\ w-.]+)(:\\ d+)?\\ b)" )
207
+
208
+ private [conda] def redactCredentials (line : String ): String = {
209
+ httpUrlToken.matcher(line).replaceAll(" $1<password>" )
210
+ }
211
+
199
212
def fromConf (sparkConf : SparkConf ): CondaEnvironmentManager = {
200
213
val condaBinaryPath = sparkConf.get(CONDA_BINARY_PATH ).getOrElse(
201
214
sys.error(s " Expected config ${CONDA_BINARY_PATH .key} to be set " ))
0 commit comments