104 lines
3.4 KiB
PHP
104 lines
3.4 KiB
PHP
<?php
|
|
|
|
|
|
namespace podmanImageManager;
|
|
|
|
use \objectStructs\objectStructs;
|
|
|
|
class image extends objectStructs
|
|
{
|
|
/** @var imageAnnotations */
|
|
public $annotations;
|
|
/** @var imageConfig */
|
|
public $config;
|
|
/** @var string name of hte image*/
|
|
public $imageName;
|
|
/** @var string name of image after the registry domain -- /image:latest */
|
|
public $shortName;
|
|
|
|
|
|
public function __construct($vars)
|
|
{
|
|
$this->Log(__FUNCTION__ . " load image object with: ".print_r($vars,true));
|
|
if (is_array($vars))
|
|
{
|
|
$this->imageName = (isset($vars['image']) ? $vars['image'] :
|
|
(isset($vars['name']) ? $vars['name'] :
|
|
(isset($vars['imageName']) ? $vars['imageName'] : "" ) ) ) ;
|
|
|
|
if (empty($this->imageName))
|
|
throw new \Exception(__FUNCTION__ . " Image name is empty");
|
|
|
|
list($RegistryDomain, $ImageShortName) = explode('/',$this->imageName,2);
|
|
if (!$ImageShortName)
|
|
throw new \Exception(__FUNCTION__ . " Image short name not valid");
|
|
else
|
|
$this->shortName = $ImageShortName;
|
|
|
|
if (isset( $vars['imageBasic']->annotations) )
|
|
$annotations = $vars['imageBasic']->annotations;
|
|
elseif (isset($vars['annotations']))
|
|
$annotations = $vars['annotations'];
|
|
else
|
|
$annotations = array();
|
|
|
|
$this->annotations = new imageAnnotations($annotations);
|
|
if (isset($vars['imageConfig']))
|
|
$this->config = new imageConfig($vars['imageConfig']);
|
|
}
|
|
elseif (is_object($vars))
|
|
{
|
|
$this->imageName = (isset($vars->image ) ? $vars->image :
|
|
(isset($vars->name) ? $vars->name :
|
|
(isset($vars->imageName) ? $vars->imageName : "" ) ) ) ;
|
|
|
|
if (isset( $vars->imageBasic->annotations) )
|
|
$this->annotations = new imageAnnotations($vars->imageBasic->annotations) ;
|
|
elseif (isset($vars->annotations))
|
|
$this->annotations = new imageAnnotations($vars->annotations) ;
|
|
|
|
if (isset($vars->imageConfig))
|
|
$this->config = new imageConfig($vars->imageConfig);
|
|
}
|
|
|
|
}
|
|
|
|
public function getHostControllerName()
|
|
{
|
|
if (isset($this->annotations->hostController))
|
|
return $this->annotations->hostController;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
public function getClientControllerName()
|
|
{
|
|
if (isset($this->annotations->clientController))
|
|
return $this->annotations->clientController;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
public function hasRole( string $Role)
|
|
{
|
|
$this->Log(__FUNCTION__ . " Checking Role: $Role");
|
|
if (isset($this->annotations->roles[$Role]) OR isset($this->annotations->roles[ucfirst($Role) ] ) )
|
|
{
|
|
$this->Log(__FUNCTION__ . "--Image has role: $Role");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
foreach($this->annotations->roles as $RoleRow)
|
|
{
|
|
if ($RoleRow === $Role)
|
|
{
|
|
$this->Log(__FUNCTION__ . "--Image has role (found as role value and not key): $Role");
|
|
}
|
|
}
|
|
}
|
|
$this->Log(__FUNCTION__ . "--Image does not seem to have role as key or as value within ->roles array ");
|
|
|
|
return false;
|
|
}
|
|
} |