-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add self info command for build tools. (#341)
* Add self info command for build tools. * Don't fatally error if a token is missing. * Minor: spelling fixes. Co-authored-by: Fatima Sarah Khalid <[email protected]>
- Loading branch information
1 parent
de2d8c0
commit 0ae99c3
Showing
7 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Terminus Plugin that contain a collection of commands useful during | ||
* the build step on a [Pantheon](https://www.pantheon.io) site that uses | ||
* a Git PR workflow. | ||
* | ||
* See README.md for usage information. | ||
*/ | ||
|
||
namespace Pantheon\TerminusBuildTools\Commands; | ||
|
||
use Consolidation\OutputFormatters\StructuredData\PropertyList; | ||
use Pantheon\TerminusBuildTools\ServiceProviders\CIProviders\CIProvider; | ||
use Pantheon\TerminusBuildTools\ServiceProviders\RepositoryProviders\BaseGitProvider; | ||
use Pantheon\TerminusBuildTools\ServiceProviders\RepositoryProviders\GitHub\GitHubProvider; | ||
use Pantheon\TerminusBuildTools\ServiceProviders\RepositoryProviders\GitProvider; | ||
use Pantheon\TerminusBuildTools\ServiceProviders\SiteProviders\SiteProvider; | ||
|
||
/** | ||
* Self Info Command | ||
*/ | ||
class SelfInfoCommand extends BuildToolsBase | ||
{ | ||
|
||
/** | ||
* Show information about the Terminus Build Tools local environment. | ||
* | ||
* @field-labels | ||
* build_tools_directory: Build Tools Installation Directory | ||
* supported_providers: Providers with Tokens On Your System | ||
* releases: Releases | ||
* @return PropertyList | ||
* | ||
* @command build:self:info | ||
*/ | ||
public function info() | ||
{ | ||
$buildToolsDirectory = str_replace('/src/Commands', '', dirname(__FILE__)); | ||
|
||
$providerManager = $this->providerManager(); | ||
|
||
$providers = $providerManager->availableProviders(); | ||
foreach ($providers as $provider) { | ||
$providerClass = new \ReflectionClass($provider); | ||
if ($providerClass->implementsInterface(GitProvider::class)) { | ||
$this->createGitProvider($provider); | ||
} | ||
elseif ($providerClass->implementsInterface(CIProvider::class)) { | ||
$this->createCIProvider($provider); | ||
} | ||
elseif ($providerClass->implementsInterface(SiteProvider::class)) { | ||
$this->createSiteProvider($provider); | ||
} | ||
} | ||
|
||
$supportedProviders = []; | ||
foreach ($providerManager->getProviders() as $provider) { | ||
try { | ||
$credentialRequests = $provider->credentialRequests(); | ||
foreach ($credentialRequests as $credentialRequest) { | ||
$this->providerManager()->credentialManager()->addRequest($credentialRequest); | ||
$provider->setCredentials($this->providerManager()->credentialManager()); | ||
} | ||
$secretValues = $provider->getSecretValues(); | ||
$validProvider = TRUE; | ||
foreach ($secretValues as $value) { | ||
if (strlen($value) > 1) { | ||
continue; | ||
} | ||
else { | ||
$validProvider = FALSE; | ||
} | ||
} | ||
if ($validProvider) { | ||
$supportedProviders[] = $provider->getServiceName(); | ||
} | ||
} | ||
catch (\Exception $e) { | ||
// Some providers like to throw a fatal error if they don't have credentials. | ||
// Catch it here and just keep oging, since they shouldn't be on our list anyway. | ||
} | ||
} | ||
|
||
return new PropertyList([ | ||
'build_tools_directory' => $buildToolsDirectory, | ||
'supported_providers' => implode(', ', $supportedProviders), | ||
'releases' => 'https://github.com/pantheon-systems/terminus-build-tools-plugin/releases', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters