From d7f085e7e7a31824e268c0464a7b3da79fe3ecbf Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Wed, 25 Feb 2009 11:21:30 -0500 Subject: [PATCH] (refs #41) add ability to send username and password to the svn command --- buildbot/slave/commands.py | 31 +++++++++++++++++++++++-------- buildbot/steps/source.py | 19 ++++++++++++++++++- buildbot/test/test_vc.py | 3 +++ docs/buildbot.texinfo | 10 ++++++++++ 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/buildbot/slave/commands.py b/buildbot/slave/commands.py index 48e1ca7..45b9e99 100644 --- a/buildbot/slave/commands.py +++ b/buildbot/slave/commands.py @@ -15,7 +15,7 @@ from buildbot.slave.registry import registerSlaveCommand # this used to be a CVS $-style "Revision" auto-updated keyword, but since I # moved to Darcs as the primary repository, this is updated manually each # time this file is changed. The last cvs_ver that was here was 1.51 . -command_version = "2.7" +command_version = "2.8" # version history: # >=1.17: commands are interruptable @@ -39,6 +39,7 @@ command_version = "2.7" # >= 2.5: workaround added for remote 'hg clone --rev REV' when hg<0.9.2 # >= 2.6: added uploadDirectory # >= 2.7: added usePTY option to SlaveShellCommand +# >= 2.8: added username and password args to SVN class class CommandInterrupted(Exception): pass @@ -1696,6 +1697,8 @@ class SVN(SourceBase): handled by SourceBase, this command reads the following keys: ['svnurl'] (required): the SVN repository string + ['username'] Username passed to the svn command + ['password'] Password passed to the svn command """ header = "svn operation" @@ -1706,6 +1709,12 @@ class SVN(SourceBase): self.svnurl = args['svnurl'] self.sourcedata = "%s\n" % self.svnurl + self.extra_args = [] + if args.has_key('username'): + self.extra_args.extend(["--username", args['username']]) + if args.has_key('password'): + self.extra_args.extend(["--password", Obfuscated(args['password'], "XXXX")]) + def sourcedirIsUpdateable(self): if os.path.exists(os.path.join(self.builder.basedir, self.srcdir, ".buildbot-patched")): @@ -1717,7 +1726,9 @@ class SVN(SourceBase): revision = self.args['revision'] or 'HEAD' # update: possible for mode in ('copy', 'update') d = os.path.join(self.builder.basedir, self.srcdir) - command = [self.vcexe, 'update', '--revision', str(revision), + command = [self.vcexe, 'update'] + \ + self.extra_args + \ + ['--revision', str(revision), '--non-interactive', '--no-auth-cache'] c = ShellCommand(self.builder, command, d, sendRC=False, timeout=self.timeout, @@ -1729,14 +1740,18 @@ class SVN(SourceBase): revision = self.args['revision'] or 'HEAD' d = self.builder.basedir if self.mode == "export": - command = [self.vcexe, 'export', '--revision', str(revision), - '--non-interactive', '--no-auth-cache', - self.svnurl, self.srcdir] + command = [self.vcexe, 'export'] + \ + self.extra_args + \ + ['--revision', str(revision), + '--non-interactive', '--no-auth-cache', + self.svnurl, self.srcdir] else: # mode=='clobber', or copy/update on a broken workspace - command = [self.vcexe, 'checkout', '--revision', str(revision), - '--non-interactive', '--no-auth-cache', - self.svnurl, self.srcdir] + command = [self.vcexe, 'checkout'] + \ + self.extra_args + \ + ['--revision', str(revision), + '--non-interactive', '--no-auth-cache', + self.svnurl, self.srcdir] c = ShellCommand(self.builder, command, d, sendRC=False, timeout=self.timeout, keepStdout=True, usePTY=False) diff --git a/buildbot/steps/source.py b/buildbot/steps/source.py index 98f51f9..4571ad5 100644 --- a/buildbot/steps/source.py +++ b/buildbot/steps/source.py @@ -351,7 +351,7 @@ class SVN(Source): name = 'svn' def __init__(self, svnurl=None, baseURL=None, defaultBranch=None, - directory=None, **kwargs): + directory=None, username=None, password=None, **kwargs): """ @type svnurl: string @param svnurl: the URL which points to the Subversion server, @@ -372,6 +372,9 @@ class SVN(Source): explicitly. It will simply be appended to C{baseURL} and the result handed to the SVN command. + + @param username: username to pass to svn's --username + @param password: username to pass to svn's --password """ if not kwargs.has_key('workdir') and directory is not None: @@ -382,12 +385,16 @@ class SVN(Source): self.svnurl = svnurl self.baseURL = baseURL self.branch = defaultBranch + self.username = username + self.password = password Source.__init__(self, **kwargs) self.addFactoryArguments(svnurl=svnurl, baseURL=baseURL, defaultBranch=defaultBranch, directory=directory, + username=username, + password=password, ) if not svnurl and not baseURL: @@ -459,6 +466,16 @@ class SVN(Source): self.args['revision'] = revision self.args['patch'] = patch + if self.username is not None or self.password is not None: + if self.slaveVersionIsOlderThan("svn", "2.8"): + m = ("This buildslave (%s) does not support svn usernames " + "and passwords. " + "Refusing to build. Please upgrade the buildslave to " + "buildbot-0.7.10 or newer." % (self.build.slavename,)) + raise BuildSlaveTooOldError(m) + if self.username is not None: self.args['username'] = self.username + if self.password is not None: self.args['password'] = self.password + revstuff = [] if branch is not None and branch != self.branch: revstuff.append("[branch]") diff --git a/buildbot/test/test_vc.py b/buildbot/test/test_vc.py index 66b87e7..4d0c18e 100644 --- a/buildbot/test/test_vc.py +++ b/buildbot/test/test_vc.py @@ -1363,6 +1363,9 @@ class SVN(VCBase, unittest.TestCase): d = self.do_getpatch() return d + ## can't test the username= and password= options, because we do not have an + ## svn repository that requires authentication. + VCS.registerVC(SVN.vc_name, SVNHelper()) diff --git a/docs/buildbot.texinfo b/docs/buildbot.texinfo index 273774b..91bad04 100644 --- a/docs/buildbot.texinfo +++ b/docs/buildbot.texinfo @@ -5018,6 +5018,16 @@ this specifies the name of the branch to use when a Build does not provide one of its own. This will be appended to @code{baseURL} to create the string that will be passed to the @code{svn checkout} command. + +@item username +if specified, this will be passed to the @code{svn} binary with a +@code{--username} option. + +@item password +if specified, this will be passed to the @code{svn} binary with a +@code{--password} option. The password itself will be suitably obfuscated in +the logs. + @end table If you are using branches, you must also make sure your -- 2.11.4.GIT