Skip to content

Commit

Permalink
Merge pull request #65 from renoki-co/feature/fix-authentication
Browse files Browse the repository at this point in the history
[fix] Fix authentication
  • Loading branch information
rennokki authored Feb 4, 2021
2 parents d3e6ad0 + cd1203f commit 279fe26
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Can be written like this:
use RenokiCo\PhpK8s\KubernetesCluster;

// Create a new instance of KubernetesCluster
$cluster = new KubernetesCluster('http://127.0.0.1', 8080);
$cluster = new KubernetesCluster('http://127.0.0.1:8080');

// Create a new NGINX service.
$svc = $cluster->service()
Expand Down
2 changes: 1 addition & 1 deletion docs/Cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can initialize a Kubernetes Cluster class by doing so:
```php
use RenokiCo\PhpK8s\KubernetesCluster;

$cluster = new KubernetesCluster('http://127.0.0.1', 8080);
$cluster = new KubernetesCluster('http://127.0.0.1:8080');
```

### Attaching Bearer Token
Expand Down
4 changes: 1 addition & 3 deletions src/KubernetesCluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ class KubernetesCluster
* Create a new class instance.
*
* @param string $url
* @param int $port
* @return void
*/
public function __construct(string $url, int $port = 8080)
public function __construct(string $url)
{
$this->url = $url;
$this->port = $port;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Traits/Cluster/ChecksClusterVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ protected function loadClusterVersion(): void
return;
}

$apiUrl = $this->getApiUrl();

$callableUrl = "{$apiUrl}/version";
$callableUrl = "{$this->url}/version";

try {
$response = $this->getClient()->request('GET', $callableUrl);
Expand Down
5 changes: 1 addition & 4 deletions src/Traits/Cluster/LoadsFromKubeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ protected function loadKubeConfigFromArray(array $kubeconfig, string $context):
throw new KubeConfigUserNotFound("The user {$user} does not exist in the provided Kube Config file.");
}

$serverAndPort = explode(':', $clusterConfig['cluster']['server']);

$this->url = $serverAndPort[0];
$this->port = $serverAndPort[1] ?? 8080;
$this->url = $clusterConfig['cluster']['server'];

if (isset($clusterConfig['cluster']['certificate-authority'])) {
$this->withCaCertificate($clusterConfig['cluster']['certificate-authority']);
Expand Down
12 changes: 1 addition & 11 deletions src/Traits/Cluster/RunsClusterOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ trait RunsClusterOperations
self::WATCH_LOGS_OP => 'GET',
];

/**
* Get the API Cluster URL as string.
*
* @return string
*/
public function getApiUrl(): string
{
return "{$this->url}:{$this->port}";
}

/**
* Get the callable URL for a specific path.
*
Expand All @@ -47,7 +37,7 @@ public function getApiUrl(): string
*/
public function getCallableUrl(string $path, array $query = ['pretty' => 1])
{
return $this->getApiUrl().$path.'?'.http_build_query($query);
return $this->url.$path.'?'.http_build_query($query);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setUp(): void
{
parent::setUp();

$this->cluster = new KubernetesCluster('http://127.0.0.1');
$this->cluster = new KubernetesCluster('http://127.0.0.1:8080');

$this->cluster->withoutSslChecks();
}
Expand Down

0 comments on commit 279fe26

Please sign in to comment.