benagricola / eks-auth
为现有PHP Kubernetes客户端库提供预认证的HTTPClient
v0.0.3
2021-04-30 23:30 UTC
Requires
- php: >=7.3
- aws/aws-sdk-php: ^3.179
- guzzlehttp/psr7: ^1.8
Requires (Dev)
- overtrue/phplint: ^2.3
Suggests
- flow/jsonpath: ^0.5.0
- maclof/kubernetes-client: ^0.21.0
This package is auto-updated.
Last update: 2024-09-20 00:37:24 UTC
README
此库使用AWS V3 SDK创建一个认证的GuzzleHttp\Client
实例,该实例可以传递给您的兼容PHP Kubernetes客户端(仅与maclof/kubernetes-client
进行了测试)。
您只需要在您的环境中配置有效的AWS凭证即可认证EKS集群。
此库将根据$clusterName
和$region
从AWS拉取EKS端点详情,使用来自aws-sdk-php
的默认凭证提供程序。
GuzzleHttp\Client
实例将预先配置一个DynamicCertificate
中间件,该中间件将集群的CA证书写入临时文件,以便传递给底层的HTTP处理器(通常是Curl)。
临时证书文件将在每次请求时创建和删除,因此无需清理,这意味着连接已完全验证。
用法
要求它
composer require benagricola/eks-auth
然后在您的项目中使用它
use EKSAuth\Client\Factory as ClientFactory; # Example using maclof/kubernetes-client use Maclof\Kubernetes\Client; // Create a new ClientFactory. // EKS Cluster details are cached for the // lifetime of this Factory instance. $cf = new ClientFactory(); // Get our client. A new Token will be generated every // time getClient() is called. // We pass our own function that instantiates a new // Maclof\Kubernetes\Client instance with the // pre-configured \GuzzleHttp\Client. $k8s = $cf->getClient($clusterName, $region, function($httpClient) { return new Client([], $httpClient); }); $namespaces = $k8s->namespaces()->find(); ...
注意:此库仅在请求的集群不存在时捕获并重新抛出错误。您应该将ClientFactory->getClient()
调用包裹在try{} catch(Exception $e){}
块中,以避免从底层库抛出各种错误。
贡献
提交一个pull request。我不是PHP开发者,因此代码库没有测试。