-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List traefik urls #126
Open
dantleech
wants to merge
1
commit into
0.4.x
Choose a base branch
from
list-traefik-urls
base: 0.4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
List traefik urls #126
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\File; | ||
|
||
interface ArrayLoader | ||
{ | ||
public function loadArray(string $url): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\File\FileLoader; | ||
|
||
use function file_get_contents; | ||
use my127\Workspace\File\Exception\CouldNotLoadFile; | ||
use my127\Workspace\File\FileLoader; | ||
|
||
final class FileGetContentsLoader implements FileLoader | ||
{ | ||
public function load(string $url): string | ||
{ | ||
$contents = @file_get_contents($url); | ||
|
||
if ($contents === false) { | ||
throw new CouldNotLoadFile(sprintf('Could not load file at "%s"', $url)); | ||
} | ||
|
||
return $contents; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\File\FileLoader; | ||
|
||
use my127\Workspace\File\FileLoader; | ||
|
||
class TestFileLoader implements FileLoader | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $contents; | ||
|
||
public function __construct(string $contents) | ||
{ | ||
$this->contents = $contents; | ||
} | ||
|
||
public function load(string $url): string | ||
{ | ||
return $this->contents; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\Plugin\TraefikEndpoints; | ||
|
||
use my127\Workspace\File\JsonLoader; | ||
|
||
class TraefikEndpointProvider | ||
{ | ||
public const TRAEFIK_BASE_URL = 'https://my127.site'; | ||
|
||
/** | ||
* @var JsonLoader | ||
*/ | ||
private $loader; | ||
|
||
public function __construct(JsonLoader $loader) | ||
{ | ||
$this->loader = $loader; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function links(): array | ||
{ | ||
$providers = $this->loader->loadArray(sprintf( | ||
'%s/api/providers', | ||
self::TRAEFIK_BASE_URL | ||
)); | ||
|
||
$links = []; | ||
foreach ($providers['docker']['frontends'] as $frontend) { | ||
foreach ($frontend['routes'] as $route) { | ||
foreach (explode(',', $route['rule']) as $host) { | ||
$links[] = sprintf('https://%s', preg_replace('{^Host:(.*)$}', '\1', $host)); | ||
} | ||
} | ||
} | ||
|
||
return $links; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\Plugin\TraefikEndpoints; | ||
|
||
use Closure; | ||
use my127\Console\Application\Application; | ||
use my127\Console\Application\Plugin\Plugin; | ||
use my127\Console\Usage\Input; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
||
class TraefikEndpointsPlugin implements Plugin | ||
{ | ||
/** | ||
* @var TraefikEndpointProvider | ||
*/ | ||
private $provider; | ||
|
||
/** | ||
* @var ConsoleOutput | ||
*/ | ||
private $output; | ||
|
||
public function __construct(TraefikEndpointProvider $provider, ConsoleOutput $output) | ||
{ | ||
$this->provider = $provider; | ||
$this->output = $output; | ||
} | ||
|
||
public function setup(Application $application): void | ||
{ | ||
$application->section('traefik urls') | ||
->description('List the Traefik endpoints') | ||
->action($this->action()); | ||
} | ||
|
||
/** | ||
* @return Closure(): <missing> | ||
*/ | ||
private function action(): Closure | ||
{ | ||
return function (Input $args) { | ||
foreach ($this->provider->links() as $link) { | ||
$this->output->writeln($link); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
tests/Test/Plugin/TraefikEndpoints/TraefikEndpointProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\Tests\Test\Plugin\TraefikEndpoints; | ||
|
||
use my127\Workspace\File\FileLoader\TestFileLoader; | ||
use my127\Workspace\File\JsonLoader; | ||
use my127\Workspace\Plugin\TraefikEndpoints\TraefikEndpointProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TraefikEndpointProviderTest extends TestCase | ||
{ | ||
public function testListEndpoints(): void | ||
{ | ||
$loader = new JsonLoader(new TestFileLoader((string) file_get_contents(__DIR__ . '/fixture/traefik-providers.json'))); | ||
self::assertEquals([ | ||
'https://kafka-ui.projectx-notify', | ||
'https://kafka.projectx-ecomm', | ||
'https://mail.my127.site', | ||
'https://my127.site', | ||
'https://search-project.my127.site', | ||
'https://projectx-ecomm.my127.site', | ||
'https://hub-project.my127.site', | ||
'https://a1-project.my127.site', | ||
'https://a2-project.my127.site', | ||
'https://projectx-example.my127.site', | ||
'https://zookeeper.projectx-ecomm', | ||
], (new TraefikEndpointProvider($loader))->links()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be good to get this from the env somehow than assume it exists, but for now probably "fine"