1.0.0 Alpha Release #59
3 changed files with 76 additions and 39 deletions
|
@ -4,13 +4,21 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use ncc\Abstracts\ConsoleColors;
|
use ncc\Abstracts\ConsoleColors;
|
||||||
use ncc\Abstracts\RemoteSource;
|
use ncc\Abstracts\BuiltinRemoteSourceType;
|
||||||
|
use ncc\Abstracts\DefinedRemoteSourceType;
|
||||||
|
use ncc\Abstracts\RemoteSourceType;
|
||||||
use ncc\Abstracts\Scopes;
|
use ncc\Abstracts\Scopes;
|
||||||
use ncc\Classes\ComposerExtension\ComposerSource;
|
use ncc\Classes\ComposerExtension\ComposerSourceBuiltin;
|
||||||
|
use ncc\Classes\GithubExtension\GithubService;
|
||||||
|
use ncc\Classes\GitlabExtension\GitlabService;
|
||||||
use ncc\Exceptions\FileNotFoundException;
|
use ncc\Exceptions\FileNotFoundException;
|
||||||
|
use ncc\Exceptions\InstallationException;
|
||||||
use ncc\Exceptions\PackageLockException;
|
use ncc\Exceptions\PackageLockException;
|
||||||
|
use ncc\Exceptions\RuntimeException;
|
||||||
use ncc\Exceptions\VersionNotFoundException;
|
use ncc\Exceptions\VersionNotFoundException;
|
||||||
|
use ncc\Managers\CredentialManager;
|
||||||
use ncc\Managers\PackageManager;
|
use ncc\Managers\PackageManager;
|
||||||
|
use ncc\Managers\RemoteSourcesManager;
|
||||||
use ncc\Objects\CliHelpSection;
|
use ncc\Objects\CliHelpSection;
|
||||||
use ncc\Objects\Package;
|
use ncc\Objects\Package;
|
||||||
use ncc\Objects\RemotePackageInput;
|
use ncc\Objects\RemotePackageInput;
|
||||||
|
@ -32,6 +40,7 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console::outException('Example Error', new Exception('test'), 1);
|
||||||
self::installPackage($args);
|
self::installPackage($args);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -191,32 +200,57 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $package;
|
// check if authentication is provided
|
||||||
$parsed_source = new RemotePackageInput($path);
|
$entry_arg = ($args['auth'] ?? null);
|
||||||
if($parsed_source->Vendor !== null && $parsed_source->Package !== null)
|
$credential_manager = new CredentialManager();
|
||||||
|
$credential = $credential_manager->getVault()->getEntry($entry_arg);
|
||||||
|
|
||||||
|
if($credential == null)
|
||||||
{
|
{
|
||||||
if($parsed_source->Source == null)
|
Console::outError(sprintf('Unknown credential entry \'%s\'', $entry_arg), true, 1);
|
||||||
{
|
|
||||||
Console::outError('No source specified', true, 1);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($parsed_source->Source)
|
if(!$credential->isCurrentlyDecrypted())
|
||||||
|
{
|
||||||
|
// Try 3 times
|
||||||
|
for($i = 0; $i < 3; $i++)
|
||||||
{
|
{
|
||||||
case RemoteSource::Composer:
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$path = ComposerSource::fetch($parsed_source);
|
$credential->unlock(Console::passwordInput(sprintf('Enter Password for %s: ', $credential->getName())));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch (RuntimeException $e)
|
||||||
{
|
{
|
||||||
Console::outException(sprintf('Failed to fetch package %s', $package), $e, 1);
|
Console::outException(sprintf('Failed to unlock credential %s', $credential->getName()), $e, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
if($credential->isCurrentlyDecrypted())
|
||||||
Console::outError('Cannot install package from source: ' . $parsed_source->Source, true, 1);
|
break;
|
||||||
|
|
||||||
|
Console::outWarning(sprintf('Invalid password, %d attempts remaining', 2 - $i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$credential->isCurrentlyDecrypted())
|
||||||
|
{
|
||||||
|
Console::outError('Failed to unlock credential', true, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = $package;
|
||||||
|
$parsed_source = new RemotePackageInput($path);
|
||||||
|
|
||||||
|
if($parsed_source->Vendor !== null && $parsed_source->Package !== null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$path = $package_manager->fetchFromSource($parsed_source->toString());
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
Console::outException('Failed to fetch package from source', $e, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,10 +110,13 @@
|
||||||
|
|
||||||
$extension = $package->Header->CompilerExtension->Extension;
|
$extension = $package->Header->CompilerExtension->Extension;
|
||||||
$installation_paths = new InstallationPaths($this->PackagesPath . DIRECTORY_SEPARATOR . $package->Assembly->Package . '=' . $package->Assembly->Version);
|
$installation_paths = new InstallationPaths($this->PackagesPath . DIRECTORY_SEPARATOR . $package->Assembly->Package . '=' . $package->Assembly->Version);
|
||||||
$installer = match ($extension) {
|
|
||||||
|
$installer = match ($extension)
|
||||||
|
{
|
||||||
CompilerExtensions::PHP => new PhpInstaller($package),
|
CompilerExtensions::PHP => new PhpInstaller($package),
|
||||||
default => throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $extension . '\' is not supported'),
|
default => throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $extension . '\' is not supported'),
|
||||||
};
|
};
|
||||||
|
|
||||||
$execution_pointer_manager = new ExecutionPointerManager();
|
$execution_pointer_manager = new ExecutionPointerManager();
|
||||||
PackageCompiler::compilePackageConstants($package, [
|
PackageCompiler::compilePackageConstants($package, [
|
||||||
ConstantReferences::Install => $installation_paths
|
ConstantReferences::Install => $installation_paths
|
||||||
|
@ -407,24 +410,19 @@
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
* @return string
|
* @return string
|
||||||
* @throws AccessDeniedException
|
|
||||||
* @throws FileNotFoundException
|
|
||||||
* @throws IOException
|
|
||||||
* @throws InstallationException
|
* @throws InstallationException
|
||||||
* @throws MissingDependencyException
|
|
||||||
* @throws NotImplementedException
|
|
||||||
* @throws PackageAlreadyInstalledException
|
|
||||||
* @throws PackageLockException
|
|
||||||
* @throws PackageNotFoundException
|
|
||||||
* @throws PackageParsingException
|
|
||||||
* @throws UnsupportedCompilerExtensionException
|
|
||||||
* @throws UnsupportedRunnerException
|
|
||||||
* @throws VersionNotFoundException
|
|
||||||
*/
|
*/
|
||||||
public function installFromSource(string $source): string
|
public function installFromSource(string $source): string
|
||||||
{
|
{
|
||||||
$package_path = $this->fetchFromSource($source);
|
try
|
||||||
return $this->install($package_path);
|
{
|
||||||
|
$package = $this->fetchFromSource($source);
|
||||||
|
return $this->install($package);
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new InstallationException('Cannot install package from source, ' . $e->getMessage(), $e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -481,6 +479,11 @@
|
||||||
case DependencySourceType::StaticLinking:
|
case DependencySourceType::StaticLinking:
|
||||||
throw new PackageNotFoundException('Static linking not possible, package ' . $dependency->Name . ' is not installed');
|
throw new PackageNotFoundException('Static linking not possible, package ' . $dependency->Name . ' is not installed');
|
||||||
|
|
||||||
|
case DependencySourceType::RemoteSource:
|
||||||
|
Console::outDebug('installing from remote source ' . $dependency->Source);
|
||||||
|
$this->installFromSource($dependency->Source);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException('Dependency source type ' . $dependency->SourceType . ' is not implemented');
|
throw new NotImplementedException('Dependency source type ' . $dependency->SourceType . ' is not implemented');
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
/**
|
/**
|
||||||
* Optional. The actual source where NCC can fetch the dependency from
|
* Optional. The actual source where NCC can fetch the dependency from
|
||||||
*
|
*
|
||||||
* @var DependencySourceType|string|null
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
public $Source;
|
public $Source;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue