Skip to content

Commit 05e4cca

Browse files
authored
Merge pull request #11 from balbuf/svn-trust-cert
Automatically trust SSL certs for built-in repos
2 parents cdb3748 + a352a50 commit 05e4cca

File tree

9 files changed

+37
-8
lines changed

9 files changed

+37
-8
lines changed

src/Repository/Config/Builtin/WordPressComThemes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function __construct() {
2828
'cache-handler' => [ $this, 'cache' ],
2929
// cache for one week - these rarely change
3030
'cache-ttl' => 604800,
31+
'trust-cert' => true,
3132
];
3233
parent::__construct();
3334
}

src/Repository/Config/Builtin/WordPressCore.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class WordPressCore extends SVNRepositoryConfig {
1818
'package-types' => [ 'wordpress-core' => [ 'wordpress', 'wordpress-core' ] ],
1919
'name-filter' => [ __CLASS__, 'filterProvider' ],
2020
'package-filter' => [ __CLASS__, 'filterPackage' ],
21+
'trust-cert' => true,
2122
];
2223

2324
/**

src/Repository/Config/Builtin/WordPressDevelop.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class WordPressDevelop extends SVNRepositoryConfig {
1818
'package-types' => [ 'wordpress-develop' => [ 'wordpress', 'wordpress-core' ] ],
1919
'name-filter' => [ __CLASS__, 'filterProvider' ],
2020
'package-filter' => [ __CLASS__, 'filterPackage' ],
21+
'trust-cert' => true,
2122
];
2223

2324
/**

src/Repository/Config/Builtin/WordPressPlugins.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function __construct() {
3030
'cache-handler' => [ $this, 'cache' ],
3131
// store the cache for however long the default is - it will likely get invalidated before then
3232
'cache-ttl' => 'config',
33+
'trust-cert' => true,
3334
];
3435
parent::__construct();
3536
}

src/Repository/Config/Builtin/WordPressThemes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function __construct() {
2828
'cache-handler' => [ $this, 'cache' ],
2929
// store the cache for however long the default is - it will likely get invalidated before then
3030
'cache-ttl' => 'config',
31+
'trust-cert' => true,
3132
];
3233
parent::__construct();
3334
}

src/Repository/Config/Builtin/WordPressVIP.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class WordPressVIP extends SVNRepositoryConfig {
2121
'package-filter' => [ __CLASS__, 'filterPackage' ],
2222
// cache for one week - these change infrequently
2323
'cache-ttl' => 604800,
24+
'trust-cert' => true,
2425
];
2526

2627
static function filterProvider( $name, $path, $url ) {

src/Repository/Config/SVNRepositoryConfig.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class SVNRepositoryConfig extends RepositoryConfig {
4646
'cache-ttl' => 0,
4747
// provider cache file
4848
'cache-file' => 'providers.json',
49+
// should the server cert be automatically trusted?
50+
'trust-cert' => false,
4951
];
5052

5153
/**

src/Repository/SVNRepository.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class SVNRepository extends ComposerRepository {
3030

31-
static protected $SvnUtil;
31+
protected $svnUtil;
3232
protected $providerHash; // map {provider name} => {provider url}
3333
protected $distUrl;
3434
protected $plugin; //the plugin class that instantiated this repository
@@ -67,10 +67,8 @@ public function __construct( SVNRepositoryConfig $repoConfig, IOInterface $io, C
6767
$this->vendors = $repoConfig->get( 'vendors' );
6868
$this->defaultVendor = key( $this->vendors );
6969

70-
// set the SvnUtil for all instantiated classes to use
71-
if ( !isset( self::$SvnUtil ) ) {
72-
self::$SvnUtil = new SvnUtil( $io );
73-
}
70+
// create an SvnUtil to execute commands
71+
$this->svnUtil = new SvnUtil( $io, $repoConfig->get( 'trust-cert' ) );
7472
}
7573

7674
public function findPackage( $name, $constraint ) {
@@ -179,7 +177,7 @@ public function whatProvides( Pool $pool, $name, $bypassFilters = false ) {
179177
if ( $this->io->isVerbose() ) {
180178
$this->io->writeError( "Fetching available versions for $name" );
181179
}
182-
$pkgRaw = self::$SvnUtil->execute( 'ls', "$providerUrl/$relPath" );
180+
$pkgRaw = $this->svnUtil->execute( 'ls', "$providerUrl/$relPath" );
183181
} catch( \RuntimeException $e ) {
184182
// @todo maybe don't throw an exception and just pass this one up?
185183
throw new \RuntimeException( "SVN Error: Could not retrieve package listing for $name. " . $e->getMessage() );
@@ -314,7 +312,7 @@ protected function loadProviders() {
314312
if ( substr( $path, -1 ) === '/' ) {
315313
// try to get a listing of providers
316314
try {
317-
$providersRaw = self::$SvnUtil->execute( 'ls', $url );
315+
$providersRaw = $this->svnUtil->execute( 'ls', $url );
318316
} catch( \RuntimeException $e ) {
319317
throw new \RuntimeException( "SVN Error: Could not retrieve provider listing from $url " . $e->getMessage() );
320318
}

src/Util/Svn.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,27 @@
1313
class Svn {
1414

1515
protected $util;
16+
protected $trustCert;
1617

17-
function __construct( IOInterface $io ) {
18+
function __construct( IOInterface $io, $trustCert = false ) {
1819
$this->util = new SvnUtil( '', $io, new Config );
20+
$this->setCertTrusted( $trustCert );
21+
}
22+
23+
/**
24+
* Set whether we will trust the the SSL certificate automatically.
25+
* @param bool $bool yas/nah
26+
*/
27+
function setCertTrusted( $bool ) {
28+
$this->trustCert = (bool) $bool;
29+
}
30+
31+
/**
32+
* Are we automatically trusting the cert?
33+
* @return bool yas/nah
34+
*/
35+
function isCertTrusted() {
36+
return $this->trustCert;
1937
}
2038

2139
/**
@@ -25,6 +43,11 @@ function __construct( IOInterface $io ) {
2543
* @return string response
2644
*/
2745
function execute( $command, $url ) {
46+
// is this an https connection, and do we trust it automatically?
47+
if ( strncasecmp( $url, 'https', 5 ) === 0 && $this->isCertTrusted() ) {
48+
// let svn trust the certificate without prompt
49+
$command .= ' --non-interactive --trust-server-cert';
50+
}
2851
return $this->util->execute( "svn $command", $url );
2952
}
3053

0 commit comments

Comments
 (0)