2020-10-06 02:11:36 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace podmanImageManager;
|
|
|
|
|
|
|
|
use \objectStructs\objectStructs;
|
|
|
|
|
|
|
|
class image extends objectStructs
|
|
|
|
{
|
|
|
|
/** @var imageAnnotations */
|
|
|
|
public $annotations;
|
|
|
|
/** @var imageConfig */
|
|
|
|
public $config;
|
2020-12-07 16:50:41 -05:00
|
|
|
/** @var string name of hte image*/
|
|
|
|
public $imageName;
|
|
|
|
/** @var string name of image after the registry domain -- /image:latest */
|
|
|
|
public $shortName;
|
|
|
|
|
2020-10-06 02:11:36 -04:00
|
|
|
|
|
|
|
public function __construct($vars)
|
|
|
|
{
|
2020-12-17 22:31:41 -05:00
|
|
|
$this->Log(__FUNCTION__ . " load image object with: ".print_r($vars,true));
|
2020-12-01 21:31:19 -05:00
|
|
|
if (is_array($vars))
|
|
|
|
{
|
|
|
|
$this->imageName = (isset($vars['image']) ? $vars['image'] :
|
|
|
|
(isset($vars['name']) ? $vars['name'] :
|
|
|
|
(isset($vars['imageName']) ? $vars['imageName'] : "" ) ) ) ;
|
2020-12-07 16:50:41 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-12-01 21:31:19 -05:00
|
|
|
if (isset( $vars['imageBasic']->annotations) )
|
|
|
|
$annotations = $vars['imageBasic']->annotations;
|
|
|
|
elseif (isset($vars['annotations']))
|
|
|
|
$annotations = $vars['annotations'];
|
2020-12-17 22:36:23 -05:00
|
|
|
else
|
|
|
|
$annotations = array();
|
2020-10-06 02:11:36 -04:00
|
|
|
|
|
|
|
$this->annotations = new imageAnnotations($annotations);
|
2020-12-01 21:31:19 -05:00
|
|
|
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) )
|
2020-12-02 21:38:24 -05:00
|
|
|
$this->annotations = new imageAnnotations($vars->imageBasic->annotations) ;
|
2020-12-02 21:41:13 -05:00
|
|
|
elseif (isset($vars->annotations))
|
|
|
|
$this->annotations = new imageAnnotations($vars->annotations) ;
|
2020-12-02 21:45:53 -05:00
|
|
|
|
|
|
|
if (isset($vars->imageConfig))
|
|
|
|
$this->config = new imageConfig($vars->imageConfig);
|
2020-12-01 21:31:19 -05:00
|
|
|
}
|
|
|
|
|
2020-10-06 02:11:36 -04:00
|
|
|
}
|
2020-11-29 16:04:45 -05:00
|
|
|
|
2020-11-29 16:05:10 -05:00
|
|
|
public function getHostControllerName()
|
2020-11-29 16:04:45 -05:00
|
|
|
{
|
|
|
|
if (isset($this->annotations->hostController))
|
|
|
|
return $this->annotations->hostController;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-29 16:05:10 -05:00
|
|
|
public function getClientControllerName()
|
2020-11-29 16:04:45 -05:00
|
|
|
{
|
|
|
|
if (isset($this->annotations->clientController))
|
|
|
|
return $this->annotations->clientController;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-04 21:13:35 -05:00
|
|
|
|
|
|
|
public function hasRole( string $Role)
|
|
|
|
{
|
2020-12-18 22:16:02 -05:00
|
|
|
$this->Log(__FUNCTION__ . " Checking Role: $Role");
|
2020-12-10 22:32:29 -05:00
|
|
|
if (isset($this->annotations->roles[$Role]) OR isset($this->annotations->roles[ucfirst($Role) ] ) )
|
|
|
|
{
|
|
|
|
$this->Log(__FUNCTION__ . "--Image has role: $Role");
|
2020-12-04 21:13:35 -05:00
|
|
|
return true;
|
2020-12-10 22:32:29 -05:00
|
|
|
}
|
2020-12-04 21:13:35 -05:00
|
|
|
else
|
2020-12-18 22:16:02 -05:00
|
|
|
{
|
|
|
|
foreach($this->annotations->roles as $RoleRow)
|
|
|
|
{
|
|
|
|
if ($RoleRow === $Role)
|
|
|
|
{
|
|
|
|
$this->Log(__FUNCTION__ . "--Image has role (found as role value and not key): $Role");
|
2020-12-18 22:18:56 -05:00
|
|
|
return true;
|
2020-12-18 22:16:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->Log(__FUNCTION__ . "--Image does not seem to have role as key or as value within ->roles array ");
|
|
|
|
|
|
|
|
return false;
|
2020-12-04 21:13:35 -05:00
|
|
|
}
|
2020-10-06 02:11:36 -04:00
|
|
|
}
|