[DockerHubBridge] Add tag filter option (#3258)

* [DockerHubBridge] Add tag filter option

* [DockerHubBridge] Add example value

* [DockerHubBridge] lint

* [DockerHubBridge] Fix

* Update DockerHubBridge.php

* [DockerHubBridge] Make repo required

* [DockerHubBridge] Add filter example value for user images
This commit is contained in:
Joseph 2023-02-15 19:15:38 +00:00 committed by GitHub
parent 17fcc72b09
commit 787b4d7cad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 50 additions and 10 deletions

View File

@ -19,6 +19,12 @@ class DockerHubBridge extends BridgeAbstract
'type' => 'text',
'required' => true,
'exampleValue' => 'rss-bridge',
],
'filter' => [
'name' => 'Filter tag',
'type' => 'text',
'required' => false,
'exampleValue' => 'latest',
]
],
'Official Image' => [
@ -27,8 +33,14 @@ class DockerHubBridge extends BridgeAbstract
'type' => 'text',
'required' => true,
'exampleValue' => 'postgres',
],
'filter' => [
'name' => 'Filter tag',
'type' => 'text',
'required' => false,
'exampleValue' => 'alpine3.17',
]
],
]
];
const CACHE_TIMEOUT = 3600; // 1 hour
@ -90,21 +102,33 @@ EOD;
public function getURI()
{
$uri = parent::getURI();
if ($this->queriedContext === 'Official Image') {
return self::URI . '/_/' . $this->getRepo();
$uri = self::URI . '/_/' . $this->getRepo();
}
if ($this->getInput('repo')) {
return self::URI . '/r/' . $this->getRepo();
if ($this->queriedContext === 'User Submitted Image') {
$uri = '/r/' . $this->getRepo();
}
return parent::getURI();
if ($this->getInput('filter')) {
$uri .= '/tags/?&page=1&name=' . $this->getInput('filter');
}
return $uri;
}
public function getName()
{
if ($this->getInput('repo')) {
return $this->getRepo() . ' - Docker Hub';
$name = $this->getRepo();
if ($this->getInput('filter')) {
$name .= ':' . $this->getInput('filter');
}
return $name . ' - Docker Hub';
}
return parent::getName();
@ -121,11 +145,21 @@ EOD;
private function getApiUrl()
{
$url = '';
if ($this->queriedContext === 'Official Image') {
return $this->apiURL . 'library/' . $this->getRepo() . '/tags/?page_size=25&page=1';
$url = $this->apiURL . 'library/' . $this->getRepo() . '/tags/?page_size=25&page=1';
}
return $this->apiURL . $this->getRepo() . '/tags/?page_size=25&page=1';
if ($this->queriedContext === 'User Submitted Image') {
$url = $this->apiURL . $this->getRepo() . '/tags/?page_size=25&page=1';
}
if ($this->getInput('filter')) {
$url .= '&name=' . $this->getInput('filter');
}
return $url;
}
private function getLayerUrl($name, $digest)
@ -140,11 +174,17 @@ EOD;
private function getTagUrl($name)
{
$url = '';
if ($this->queriedContext === 'Official Image') {
return self::URI . '/_/' . $this->getRepo() . '?tab=tags&name=' . $name;
$url = self::URI . '/_/' . $this->getRepo();
}
return self::URI . '/r/' . $this->getRepo() . '/tags?name=' . $name;
if ($this->queriedContext === 'User Submitted Image') {
$url = self::URI . '/r/' . $this->getRepo();
}
return $url . '/tags/?&name=' . $name;
}
private function getImages($result)