@@ -20,6 +20,7 @@ import java.nio.file.Files
2020import java .nio .file .Path
2121import java .nio .file .Paths
2222import java .nio .file .attribute .PosixFilePermission
23+ import java .util .regex .Pattern
2324
2425import scala .collection .JavaConverters ._
2526import scala .sys .process .BasicIO
@@ -160,16 +161,21 @@ final class CondaEnvironmentManager(condaBinaryPath: String,
160161 * @return the stdout of the process
161162 */
162163 private [this ] def runOrFail (command : ProcessBuilder , description : String ): String = {
164+ import CondaEnvironmentManager .redactCredentials
163165 val out = new StringBuffer
164166 val err = new StringBuffer
165167 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+ })))
173179 val exitCode = command.run(collectErrOutToBuffer).exitValue()
174180 if (exitCode != 0 ) {
175181 throw new SparkException (s " Attempt to $description exited with code: "
@@ -196,6 +202,13 @@ object CondaEnvironmentManager extends Logging {
196202 sparkConf.contains(CONDA_BINARY_PATH )
197203 }
198204
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+
199212 def fromConf (sparkConf : SparkConf ): CondaEnvironmentManager = {
200213 val condaBinaryPath = sparkConf.get(CONDA_BINARY_PATH ).getOrElse(
201214 sys.error(s " Expected config ${CONDA_BINARY_PATH .key} to be set " ))
0 commit comments