Added Vault objects & abstract classes, updated autoloader
This commit is contained in:
parent
6a399261a8
commit
5b9d7b4850
7 changed files with 235 additions and 0 deletions
16
src/ncc/Abstracts/RemoteAuthenticationType.php
Normal file
16
src/ncc/Abstracts/RemoteAuthenticationType.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Abstracts;
|
||||
|
||||
abstract class RemoteAuthenticationType
|
||||
{
|
||||
/**
|
||||
* A combination of a username and password is used for authentication
|
||||
*/
|
||||
const UsernamePassword = 'USERNAME_PASSWORD';
|
||||
|
||||
/**
|
||||
* A single private access token is used for authentication
|
||||
*/
|
||||
const PrivateAccessToken = 'PRIVATE_ACCESS_TOKEN';
|
||||
}
|
16
src/ncc/Abstracts/RemoteSource.php
Normal file
16
src/ncc/Abstracts/RemoteSource.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Abstracts;
|
||||
|
||||
abstract class RemoteSource
|
||||
{
|
||||
/**
|
||||
* The original source is from GitHub (Enterprise not supported yet)
|
||||
*/
|
||||
const GitHub = 'GITHUB';
|
||||
|
||||
/**
|
||||
* The original source is from Gitlab or a Gitlab instance
|
||||
*/
|
||||
const Gitlab = 'GITLAB';
|
||||
}
|
|
@ -56,6 +56,7 @@
|
|||
$options = [
|
||||
new CliHelpSection(['help'], 'Displays this help menu about the value command'),
|
||||
new CliHelpSection(['add'], 'Adds a new credential to the vault'),
|
||||
new CliHelpSection(['remove'], 'Adds a new credential to the vault'),
|
||||
];
|
||||
|
||||
$options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4;
|
||||
|
|
|
@ -2,9 +2,19 @@
|
|||
|
||||
namespace ncc\Objects;
|
||||
|
||||
use ncc\Objects\Vault\Entry;
|
||||
|
||||
class Vault
|
||||
{
|
||||
/**
|
||||
* The vault's current version for backwards compatibility
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $Version;
|
||||
|
||||
/**
|
||||
* @var Entry[]
|
||||
*/
|
||||
public $Entries;
|
||||
}
|
60
src/ncc/Objects/Vault/DefaultEntry.php
Normal file
60
src/ncc/Objects/Vault/DefaultEntry.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
||||
namespace ncc\Objects\Vault;
|
||||
|
||||
class DefaultEntry
|
||||
{
|
||||
/**
|
||||
* The alias entry to use for default authentication
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $Alias;
|
||||
|
||||
/**
|
||||
* The source that the alias is for
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $Source;
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'alias' => $this->Alias,
|
||||
'source' => $this->Source
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return DefaultEntry
|
||||
*/
|
||||
public static function fromArray(array $data): DefaultEntry
|
||||
{
|
||||
$DefaultEntryObject = new DefaultEntry();
|
||||
|
||||
if(isset($data['alias']))
|
||||
{
|
||||
$DefaultEntryObject->Alias = $data['alias'];
|
||||
}
|
||||
|
||||
if(isset($data['source']))
|
||||
{
|
||||
$DefaultEntryObject->Source = $data['source'];
|
||||
}
|
||||
|
||||
return $DefaultEntryObject;
|
||||
}
|
||||
|
||||
}
|
127
src/ncc/Objects/Vault/Entry.php
Normal file
127
src/ncc/Objects/Vault/Entry.php
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
||||
namespace ncc\Objects\Vault;
|
||||
|
||||
use ncc\Abstracts\RemoteAuthenticationType;
|
||||
use ncc\Abstracts\RemoteSource;
|
||||
|
||||
class Entry
|
||||
{
|
||||
/**
|
||||
* The unique alias of the source entry, can also be used for remote resource fetching for dependencies with the
|
||||
* following example schemes;
|
||||
*
|
||||
* - alias@github.com/org/package
|
||||
* - alias@git.example.org/org/package
|
||||
* - alias@gitlab.com/org/package
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $Alias;
|
||||
|
||||
/**
|
||||
* The remote source of the entry, currently only supported sources are allowed.
|
||||
*
|
||||
* @var string|RemoteSource
|
||||
*/
|
||||
public $Source;
|
||||
|
||||
/**
|
||||
* The host of the remote source, eg; github.com or git.example.org, will be used for remote resource fetching
|
||||
* for dependencies with the following example schemes;
|
||||
*
|
||||
* - github.com/org/package
|
||||
* - git.example.org/org/package
|
||||
* - gitlab.com/org/package
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $SourceHost;
|
||||
|
||||
/**
|
||||
* @var string|RemoteAuthenticationType
|
||||
*/
|
||||
public $AuthenticationType;
|
||||
|
||||
/**
|
||||
* Indicates if the authentication details are encrypted or not, if encrypted a passphrase is required
|
||||
* by the user
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $Encrypted;
|
||||
|
||||
/**
|
||||
* The authentication details.
|
||||
*
|
||||
* If the remote authentication type is private access token, the first index (0) would be the key itself
|
||||
* If the remote authentication type is a username and password, first index would be Username and second
|
||||
* would be the password.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $Authentication;
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @return array
|
||||
* @noinspection PhpArrayShapeAttributeCanBeAddedInspection
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'alias' => $this->Alias,
|
||||
'source' => $this->Source,
|
||||
'source_host' => $this->SourceHost,
|
||||
'authentication_type' => $this->AuthenticationType,
|
||||
'encrypted' => $this->Encrypted,
|
||||
'authentication' => $this->Authentication
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @param array $data
|
||||
* @return Entry
|
||||
*/
|
||||
public static function fromArray(array $data): Entry
|
||||
{
|
||||
$EntryObject = new Entry();
|
||||
|
||||
if(isset($data['alias']))
|
||||
{
|
||||
$EntryObject->Alias = $data['alias'];
|
||||
}
|
||||
|
||||
if(isset($data['source']))
|
||||
{
|
||||
$EntryObject->Source = $data['source'];
|
||||
}
|
||||
|
||||
if(isset($data['source_host']))
|
||||
{
|
||||
$EntryObject->SourceHost = $data['source_host'];
|
||||
}
|
||||
|
||||
if(isset($data['authentication_type']))
|
||||
{
|
||||
$EntryObject->AuthenticationType = $data['authentication_type'];
|
||||
}
|
||||
|
||||
if(isset($data['encrypted']))
|
||||
{
|
||||
$EntryObject->Encrypted = $data['encrypted'];
|
||||
}
|
||||
|
||||
if(isset($data['authentication']))
|
||||
{
|
||||
$EntryObject->Authentication = $data['authentication'];
|
||||
}
|
||||
|
||||
return $EntryObject;
|
||||
}
|
||||
}
|
|
@ -11,6 +11,8 @@ spl_autoload_register(
|
|||
'ncc\\abstracts\\exceptioncodes' => '/Abstracts/ExceptionCodes.php',
|
||||
'ncc\\abstracts\\nccbuildflags' => '/Abstracts/NccBuildFlags.php',
|
||||
'ncc\\abstracts\\regexpatterns' => '/Abstracts/RegexPatterns.php',
|
||||
'ncc\\abstracts\\remoteauthenticationtype' => '/Abstracts/RemoteAuthenticationType.php',
|
||||
'ncc\\abstracts\\remotesource' => '/Abstracts/RemoteSource.php',
|
||||
'ncc\\abstracts\\scopes' => '/Abstracts/Scopes.php',
|
||||
'ncc\\abstracts\\stringpaddingmethod' => '/Abstracts/StringPaddingMethod.php',
|
||||
'ncc\\cli\\credentialmenu' => '/CLI/CredentialMenu.php',
|
||||
|
@ -38,6 +40,9 @@ spl_autoload_register(
|
|||
'ncc\\objects\\projectconfiguration\\compiler' => '/Objects/ProjectConfiguration/Compiler.php',
|
||||
'ncc\\objects\\projectconfiguration\\dependency' => '/Objects/ProjectConfiguration/Dependency.php',
|
||||
'ncc\\objects\\projectconfiguration\\project' => '/Objects/ProjectConfiguration/Project.php',
|
||||
'ncc\\objects\\vault' => '/Objects/Vault.php',
|
||||
'ncc\\objects\\vault\\defaultentry' => '/Objects/Vault/DefaultEntry.php',
|
||||
'ncc\\objects\\vault\\entry' => '/Objects/Vault/Entry.php',
|
||||
'ncc\\symfony\\component\\process\\exception\\exceptioninterface' => '/ThirdParty/Symfony/Process/Exception/ExceptionInterface.php',
|
||||
'ncc\\symfony\\component\\process\\exception\\invalidargumentexception' => '/ThirdParty/Symfony/Process/Exception/InvalidArgumentException.php',
|
||||
'ncc\\symfony\\component\\process\\exception\\logicexception' => '/ThirdParty/Symfony/Process/Exception/LogicException.php',
|
||||
|
|
Loading…
Add table
Reference in a new issue