31 lines
697 B
PHP
31 lines
697 B
PHP
|
<?php
|
||
|
|
||
|
namespace NoccyLabs\FreshDocker\Credentials;
|
||
|
|
||
|
class BasicCredentialsLoader
|
||
|
{
|
||
|
|
||
|
private array $auth = [];
|
||
|
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->load();
|
||
|
}
|
||
|
|
||
|
private function load()
|
||
|
{
|
||
|
$config = getenv("HOME")."/.docker/config.json";
|
||
|
if (!file_exists($config)) return;
|
||
|
|
||
|
$conf = json_decode(file_get_contents($config));
|
||
|
$this->auth = isset($conf->auths) ? (array)$conf->auths : [];
|
||
|
}
|
||
|
|
||
|
public function getCredentials(string $repo): ?array
|
||
|
{
|
||
|
if (!array_key_exists($repo, $this->auth))
|
||
|
return null;
|
||
|
$auth = $this->auth[$repo]->auth;
|
||
|
return explode(":", base64_decode($auth), 2);
|
||
|
}
|
||
|
}
|