[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

View File

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