Update Scopes to enum and adjust scope checks

This commit is contained in:
netkas 2024-09-13 13:26:54 -04:00
parent 1ba50cc7ee
commit 7c9f63955a
15 changed files with 33 additions and 33 deletions

View file

@ -101,7 +101,7 @@
if(isset($args['v'])) if(isset($args['v']))
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
Console::outError('Insufficient permissions, cannot modify configuration values', true, 1); Console::outError('Insufficient permissions, cannot modify configuration values', true, 1);
return 1; return 1;

View file

@ -187,7 +187,7 @@
{ {
$ResolvedScope = Resolver::resolveScope(); $ResolvedScope = Resolver::resolveScope();
if($ResolvedScope !== Scopes::SYSTEM) if($ResolvedScope !== Scopes::SYSTEM->value)
{ {
Console::outError('Insufficient permissions to add entries'); Console::outError('Insufficient permissions to add entries');
} }
@ -313,7 +313,7 @@
{ {
$ResolvedScope = Resolver::resolveScope(); $ResolvedScope = Resolver::resolveScope();
if($ResolvedScope !== Scopes::SYSTEM) if($ResolvedScope !== Scopes::SYSTEM->value)
{ {
Console::outError('Insufficient permissions to remove entries'); Console::outError('Insufficient permissions to remove entries');
} }

View file

@ -132,7 +132,7 @@
*/ */
private static function installPackage(array $args): int private static function installPackage(array $args): int
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
Console::outError('You cannot install packages in a user scope, please run this command as root', true, 1); Console::outError('You cannot install packages in a user scope, please run this command as root', true, 1);
return 1; return 1;
@ -388,7 +388,7 @@
*/ */
private static function uninstallPackage($args): int private static function uninstallPackage($args): int
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
Console::outError('You cannot uninstall packages in a user scope, please run this command as root', true, 1); Console::outError('You cannot uninstall packages in a user scope, please run this command as root', true, 1);
return 1; return 1;
@ -419,7 +419,7 @@
*/ */
private static function uninstallAllPackages(array $args): int private static function uninstallAllPackages(array $args): int
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
Console::outError('You cannot uninstall all packages in a user scope, please run this command as root', true, 1); Console::outError('You cannot uninstall all packages in a user scope, please run this command as root', true, 1);
return 1; return 1;
@ -455,7 +455,7 @@
*/ */
private static function fixBrokenPackages(array $args): int private static function fixBrokenPackages(array $args): int
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
Console::outError('You cannot fix broken packages in a user scope, please run this command as root', true, 1); Console::outError('You cannot fix broken packages in a user scope, please run this command as root', true, 1);
return 1; return 1;

View file

@ -134,7 +134,7 @@
*/ */
private static function installProject(array $args): int private static function installProject(array $args): int
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
Console::outError('You cannot install packages in a user scope, please run this command as root', true, 1); Console::outError('You cannot install packages in a user scope, please run this command as root', true, 1);
return 1; return 1;

View file

@ -141,7 +141,7 @@
*/ */
private static function addEntry(array $args): int private static function addEntry(array $args): int
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
Console::outError('You must be running as root to add a new repository', true, 1); Console::outError('You must be running as root to add a new repository', true, 1);
return 1; return 1;
@ -230,7 +230,7 @@
*/ */
private static function removeEntry(array $args): int private static function removeEntry(array $args): int
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
Console::outError('You must be running as root to remove a repository', true, 1); Console::outError('You must be running as root to remove a repository', true, 1);
return 1; return 1;

View file

@ -22,9 +22,9 @@
namespace ncc\Enums; namespace ncc\Enums;
final class Scopes enum Scopes : string
{ {
public const USER = 'USER'; case USER = 'USER';
public const SYSTEM = 'SYSTEM'; case SYSTEM = 'SYSTEM';
} }

View file

@ -89,7 +89,7 @@
{ {
Console::outDebug(sprintf('saving configuration file to %s', PathFinder::getConfigurationFile())); Console::outDebug(sprintf('saving configuration file to %s', PathFinder::getConfigurationFile()));
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new AuthenticationException('Cannot save configuration file, insufficient permissions'); throw new AuthenticationException('Cannot save configuration file, insufficient permissions');
} }

View file

@ -51,7 +51,7 @@
*/ */
public function __construct() public function __construct()
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must have root privileges to access the credentials storage file'); throw new OperationException('You must have root privileges to access the credentials storage file');
} }
@ -86,7 +86,7 @@
{ {
Console::outVerbose(sprintf('Saving credentials store to %s', PathFinder::getCredentialStorage())); Console::outVerbose(sprintf('Saving credentials store to %s', PathFinder::getCredentialStorage()));
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must have root privileges to modify the credentials storage file'); throw new OperationException('You must have root privileges to modify the credentials storage file');
} }
@ -103,7 +103,7 @@
*/ */
public static function initializeCredentialStorage(): void public static function initializeCredentialStorage(): void
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must have root privileges to initialize the credentials storage file'); throw new OperationException('You must have root privileges to initialize the credentials storage file');
} }

View file

@ -80,7 +80,7 @@
*/ */
public function save(): void public function save(): void
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must be running as root to update the system package lock'); throw new OperationException('You must be running as root to update the system package lock');
} }
@ -98,7 +98,7 @@
*/ */
public static function initializePackageLock(): void public static function initializePackageLock(): void
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must be running as root to update the system package lock'); throw new OperationException('You must be running as root to update the system package lock');
} }

View file

@ -151,7 +151,7 @@
*/ */
public function install(string|PackageReader $input, ?AuthenticationInterface $authentication=null, array $options=[]): array public function install(string|PackageReader $input, ?AuthenticationInterface $authentication=null, array $options=[]): array
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must have root privileges to install packages'); throw new OperationException('You must have root privileges to install packages');
} }
@ -188,7 +188,7 @@
*/ */
public function uninstall(string $package_name, ?string $version=null): array public function uninstall(string $package_name, ?string $version=null): array
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must have root privileges to uninstall packages'); throw new OperationException('You must have root privileges to uninstall packages');
} }
@ -285,7 +285,7 @@
*/ */
public function uninstallAll(): array public function uninstallAll(): array
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must have root privileges to uninstall packages'); throw new OperationException('You must have root privileges to uninstall packages');
} }

View file

@ -211,7 +211,7 @@
*/ */
public function installDependencies(?AuthenticationInterface $authentication=null): array public function installDependencies(?AuthenticationInterface $authentication=null): array
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('Unable to install dependencies, you must be running as root'); throw new OperationException('Unable to install dependencies, you must be running as root');
} }

View file

@ -109,7 +109,7 @@
*/ */
public function addRepository(RepositoryConfiguration $source, bool $update=true): void public function addRepository(RepositoryConfiguration $source, bool $update=true): void
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must be running as root to add a new repository'); throw new OperationException('You must be running as root to add a new repository');
} }
@ -160,7 +160,7 @@
*/ */
public function removeRepository(string $name, bool $update=true): void public function removeRepository(string $name, bool $update=true): void
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must be running as root to delete a repository'); throw new OperationException('You must be running as root to delete a repository');
} }
@ -195,7 +195,7 @@
*/ */
public function updateDatabase(): void public function updateDatabase(): void
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must be running as root to update the repository database'); throw new OperationException('You must be running as root to update the repository database');
} }
@ -221,7 +221,7 @@
*/ */
public static function initializeDatabase(array $default_repositories=[]): void public static function initializeDatabase(array $default_repositories=[]): void
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must be running as root to initialize the repository database'); throw new OperationException('You must be running as root to initialize the repository database');
} }

View file

@ -293,7 +293,7 @@
*/ */
public static function initializeFiles(?string $install_path=null, array $default_repositories=[]): void public static function initializeFiles(?string $install_path=null, array $default_repositories=[]): void
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
throw new OperationException('You must be running as root to initialize ncc files'); throw new OperationException('You must be running as root to initialize ncc files');
} }
@ -523,7 +523,7 @@
*/ */
public static function finalizePermissions(): void public static function finalizePermissions(): void
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
{ {
return; return;
} }

View file

@ -56,10 +56,10 @@
if(self::$user_id_cache === 0) if(self::$user_id_cache === 0)
{ {
return Scopes::SYSTEM; return Scopes::SYSTEM->value;
} }
return Scopes::USER; return Scopes::USER->value;
} }
/** /**

View file

@ -111,8 +111,8 @@ namespace ncc\Utilities;
switch($input) switch($input)
{ {
case Scopes::SYSTEM: case Scopes::SYSTEM->value:
case Scopes::USER: case Scopes::USER->value:
return true; return true;
default: default: