1.0.0 Alpha Release #59

Merged
netkas merged 213 commits from v1.0.0_alpha into master 2023-01-29 23:27:58 +00:00
Showing only changes of commit 698adff3b5 - Show all commits

View file

@ -3,6 +3,7 @@
namespace ncc\Utilities; namespace ncc\Utilities;
use Exception; use Exception;
use ncc\Abstracts\AuthenticationType;
use ncc\Abstracts\Runners; use ncc\Abstracts\Runners;
use ncc\Abstracts\Scopes; use ncc\Abstracts\Scopes;
use ncc\Classes\BashExtension\BashRunner; use ncc\Classes\BashExtension\BashRunner;
@ -13,7 +14,9 @@
use ncc\Classes\PythonExtension\Python3Runner; use ncc\Classes\PythonExtension\Python3Runner;
use ncc\Classes\PythonExtension\PythonRunner; use ncc\Classes\PythonExtension\PythonRunner;
use ncc\Exceptions\AccessDeniedException; use ncc\Exceptions\AccessDeniedException;
use ncc\Exceptions\AuthenticationException;
use ncc\Exceptions\FileNotFoundException; use ncc\Exceptions\FileNotFoundException;
use ncc\Exceptions\GitlabServiceException;
use ncc\Exceptions\InvalidScopeException; use ncc\Exceptions\InvalidScopeException;
use ncc\Exceptions\IOException; use ncc\Exceptions\IOException;
use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\MalformedJsonException;
@ -23,8 +26,10 @@
use ncc\Managers\PackageLockManager; use ncc\Managers\PackageLockManager;
use ncc\Objects\CliHelpSection; use ncc\Objects\CliHelpSection;
use ncc\Objects\ComposerJson; use ncc\Objects\ComposerJson;
use ncc\Objects\HttpRequest;
use ncc\Objects\Package\ExecutionUnit; use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy; use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Objects\Vault\Entry;
use ncc\ThirdParty\jelix\Version\Parser; use ncc\ThirdParty\jelix\Version\Parser;
use ncc\ThirdParty\Symfony\Filesystem\Filesystem; use ncc\ThirdParty\Symfony\Filesystem\Filesystem;
@ -506,4 +511,36 @@
RuntimeCache::setFileAsTemporary($path); RuntimeCache::setFileAsTemporary($path);
return $path; return $path;
} }
/**
* Applies the authentication to the given HTTP request.
*
* @param HttpRequest $httpRequest
* @param Entry|null $entry
* @return HttpRequest
* @throws AuthenticationException
* @throws GitlabServiceException
*/
public static function prepareGitServiceRequest(HttpRequest $httpRequest, ?Entry $entry=null): HttpRequest
{
if($entry !== null)
{
if (!$entry->isCurrentlyDecrypted())
throw new GitlabServiceException('The given Vault entry is not decrypted.');
switch ($entry->getPassword()->getAuthenticationType()) {
case AuthenticationType::AccessToken:
$httpRequest->Headers[] = "Authorization: Bearer " . $entry->getPassword();
break;
case AuthenticationType::UsernamePassword:
throw new AuthenticationException('Username/Password authentication is not supported');
}
}
$httpRequest->Headers[] = "Accept: application/json";
$httpRequest->Headers[] = "Content-Type: application/json";
return $httpRequest;
}
} }