diff options
Diffstat (limited to 'python-coveo-testing-extras.spec')
-rw-r--r-- | python-coveo-testing-extras.spec | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/python-coveo-testing-extras.spec b/python-coveo-testing-extras.spec new file mode 100644 index 0000000..7d0db14 --- /dev/null +++ b/python-coveo-testing-extras.spec @@ -0,0 +1,233 @@ +%global _empty_manifest_terminate_build 0 +Name: python-coveo-testing-extras +Version: 2.1.2 +Release: 1 +Summary: Dependency-hungry testing helpers +License: Apache-2.0 +URL: https://github.com/coveooss/coveo-python-oss/tree/main/coveo-testing-extras +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/d5/d6/8916d01a493bae2ab19c8a68b87a189a04179d9c28fec955e16502535087/coveo_testing_extras-2.1.2.tar.gz +BuildArch: noarch + +Requires: python3-coveo-functools +Requires: python3-coveo-settings +Requires: python3-coveo-systools +Requires: python3-coveo-testing +Requires: python3-docker + +%description +# coveo-testing-extras + +Contains extra testing tools without dependency restrictions. + + +## temporary resource implementation: Docker Container + +The docker container temporary resource can be used to prepare short-lived containers. + +- Supports building from a dockerfile +- Supports pulling images +- Can signal on AWS ECR logout +- Dynamic port mapping retrieval +- Saves log output before removing the container + + +### Automatic AWS ECR login example + +Here's how you can enhance `TemporaryDockerContainerResource` with automatic ECR login: + +```python +from base64 import b64decode + +import boto3 +from coveo_testing_extras.temporary_resource.docker_container import ( + TemporaryDockerContainerResource, + ECRLogoutException, + get_docker_client +) + +class WithECR(TemporaryDockerContainerResource): + def obtain_image(self) -> None: + try: + super().obtain_image() + except ECRLogoutException: + self._do_ecr_login() + super().obtain_image() + + def _do_ecr_login(self) -> None: + """ Performs an ecr login through awscli. """ + assert self.ecr_region + ecr = boto3.client('ecr') + account_id, *_ = self.image_name.split('.') + assert account_id.isdigit() + authorization_data = ecr.get_authorization_token(registryIds=[account_id])['authorizationData'][0] + username, password = b64decode(authorization_data['authorizationToken']).decode().split(':') + with get_docker_client() as client: + login = client.login(username=username, password=password, registry=authorization_data['proxyEndpoint']) + assert login['Status'] == 'Login Succeeded' +``` + + + + +%package -n python3-coveo-testing-extras +Summary: Dependency-hungry testing helpers +Provides: python-coveo-testing-extras +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-coveo-testing-extras +# coveo-testing-extras + +Contains extra testing tools without dependency restrictions. + + +## temporary resource implementation: Docker Container + +The docker container temporary resource can be used to prepare short-lived containers. + +- Supports building from a dockerfile +- Supports pulling images +- Can signal on AWS ECR logout +- Dynamic port mapping retrieval +- Saves log output before removing the container + + +### Automatic AWS ECR login example + +Here's how you can enhance `TemporaryDockerContainerResource` with automatic ECR login: + +```python +from base64 import b64decode + +import boto3 +from coveo_testing_extras.temporary_resource.docker_container import ( + TemporaryDockerContainerResource, + ECRLogoutException, + get_docker_client +) + +class WithECR(TemporaryDockerContainerResource): + def obtain_image(self) -> None: + try: + super().obtain_image() + except ECRLogoutException: + self._do_ecr_login() + super().obtain_image() + + def _do_ecr_login(self) -> None: + """ Performs an ecr login through awscli. """ + assert self.ecr_region + ecr = boto3.client('ecr') + account_id, *_ = self.image_name.split('.') + assert account_id.isdigit() + authorization_data = ecr.get_authorization_token(registryIds=[account_id])['authorizationData'][0] + username, password = b64decode(authorization_data['authorizationToken']).decode().split(':') + with get_docker_client() as client: + login = client.login(username=username, password=password, registry=authorization_data['proxyEndpoint']) + assert login['Status'] == 'Login Succeeded' +``` + + + + +%package help +Summary: Development documents and examples for coveo-testing-extras +Provides: python3-coveo-testing-extras-doc +%description help +# coveo-testing-extras + +Contains extra testing tools without dependency restrictions. + + +## temporary resource implementation: Docker Container + +The docker container temporary resource can be used to prepare short-lived containers. + +- Supports building from a dockerfile +- Supports pulling images +- Can signal on AWS ECR logout +- Dynamic port mapping retrieval +- Saves log output before removing the container + + +### Automatic AWS ECR login example + +Here's how you can enhance `TemporaryDockerContainerResource` with automatic ECR login: + +```python +from base64 import b64decode + +import boto3 +from coveo_testing_extras.temporary_resource.docker_container import ( + TemporaryDockerContainerResource, + ECRLogoutException, + get_docker_client +) + +class WithECR(TemporaryDockerContainerResource): + def obtain_image(self) -> None: + try: + super().obtain_image() + except ECRLogoutException: + self._do_ecr_login() + super().obtain_image() + + def _do_ecr_login(self) -> None: + """ Performs an ecr login through awscli. """ + assert self.ecr_region + ecr = boto3.client('ecr') + account_id, *_ = self.image_name.split('.') + assert account_id.isdigit() + authorization_data = ecr.get_authorization_token(registryIds=[account_id])['authorizationData'][0] + username, password = b64decode(authorization_data['authorizationToken']).decode().split(':') + with get_docker_client() as client: + login = client.login(username=username, password=password, registry=authorization_data['proxyEndpoint']) + assert login['Status'] == 'Login Succeeded' +``` + + + + +%prep +%autosetup -n coveo-testing-extras-2.1.2 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-coveo-testing-extras -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 31 2023 Python_Bot <Python_Bot@openeuler.org> - 2.1.2-1 +- Package Spec generated |