From 6ecd8c4afd749f2715f4c9c36f35917270b74441 Mon Sep 17 00:00:00 2001 From: REGGEENR Date: Fri, 13 Jan 2023 23:54:47 +0100 Subject: [PATCH 01/22] synced with latest python template --- .gitignore | 4 ++++ .releaserc | 5 ++--- .travis.yml | 40 +++++++++++++++------------------------- CODE_OF_CONDUCT.md | 2 +- Makefile | 30 +++++++++++++++++++++++++++--- package.json | 15 +++++++++++++++ pyproject.toml | 3 +++ requirements-dev.txt | 19 ++++++------------- requirements.txt | 7 ++++--- setup.py | 26 ++++---------------------- tox.ini | 18 ------------------ 11 files changed, 81 insertions(+), 88 deletions(-) create mode 100644 package.json create mode 100644 pyproject.toml delete mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 23a8eb8..0420b4f 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,7 @@ swagger.json /.pydevproject /.settings/ + +# files produced by "npm install" commands during build +package-lock.json +node_modules/ \ No newline at end of file diff --git a/.releaserc b/.releaserc index f441c3f..dcd2868 100644 --- a/.releaserc +++ b/.releaserc @@ -1,5 +1,6 @@ { "debug": true, + "branches": [ "main" ], "plugins": [ "@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", @@ -13,12 +14,10 @@ [ "@semantic-release/git", { + "assets" : [ "CHANGELOG.md" ], "message": "chore(release): ${nextRelease.version} release notes\n\n${nextRelease.notes}" } ], "@semantic-release/github" - ], - "branches": [ - {name: "main"} ] } \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 74becbf..549b5cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ -os: linux +dist: bionic + language: python -dist: xenial + cache: pip # Only run on main (still tests PRs) @@ -13,43 +14,32 @@ notifications: matrix: include: - - python: 3.6 - python: 3.7 - python: 3.8 + - python: 3.9 + - python: 3.10 -before_install: -- npm install npm@latest -g +install: - sudo apt-get update - sudo apt-get install pandoc - pip install pypandoc -# - '[ "${TRAVIS_PULL_REQUEST}" == "false" ] && openssl aes-256-cbc -K $my_key -iv $my_iv -in myservice.env.enc -out myservice.env -d || true' - -install: -- pip install tox-travis -- pip install -r requirements.txt -- pip install -r requirements-dev.txt -- pip install . -- python setup.py build +- echo -e "machine github.ibm.com\n login $GITHUB_OAUTH_TOKEN" > ~/.netrc +- pip install setuptools=="60.8.2" script: -- tox -- pytest test -- ./test-integration.sh +- make ci before_deploy: +- nvm install 14 +- npm install - pip install bump2version -- nvm install 12 -- npm install @semantic-release/changelog -- npm install @semantic-release/exec -- npm install @semantic-release/git -- npm install @semantic-release/github deploy: - provider: script - script: npx semantic-release + script: npm run semantic-release skip_cleanup: true on: - python: '3.6' + python: '3.7' branch: main - provider: pypi user: __token__ @@ -57,5 +47,5 @@ deploy: repository: https://upload.pypi.org/legacy skip_cleanup: true on: - python: '3.6' - tags: true + python: '3.7' + tags: true \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 7303c87..01ca05c 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -55,7 +55,7 @@ further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at phil_adams@us.ibm.com. All +reported by contacting the project team at devxsdk@us.ibm.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. diff --git a/Makefile b/Makefile index f881382..45ca62d 100644 --- a/Makefile +++ b/Makefile @@ -4,11 +4,35 @@ setup: deps dev_deps install_project +all: upgrade_pip setup test-unit lint + +ci: setup test-unit lint + +upgrade_pip: + python -m pip install --upgrade pip + deps: - pip install -r requirements.txt + python -m pip install -r requirements.txt dev_deps: - pip install -r requirements-dev.txt + python -m pip install -r requirements-dev.txt install_project: - pip install -e . + python -m pip install -e . + +test: test-unit test-int + +test-unit: + python -m pytest --cov=ibm_code_engine_sdk test/unit + +test-int: + python -m pytest test/integration + +test-examples: + python -m pytest example + +lint: + ./pylint.sh && black --check . + +lint-fix: + black . diff --git a/package.json b/package.json new file mode 100644 index 0000000..86fc6e3 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "semantic-release-dependencies", + "version": "0.0.0", + "description": "This package.json is being used to manage semantic-release and its dependencies", + "license": "Apache-2.0", + "devDependencies": { + "semantic-release": "19.0.5", + "@semantic-release/changelog": "6.0.2", + "@semantic-release/exec": "6.0.3", + "@semantic-release/git": "10.0.1" + }, + "scripts": { + "semantic-release": "semantic-release" + } +} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6ae249d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[tool.black] +line-length = 120 +skip-string-normalization = true diff --git a/requirements-dev.txt b/requirements-dev.txt index e14a501..2965c09 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,15 +1,8 @@ # test dependencies -pytest>=5.0 -responses>=0.10 -pylint>=1.4.4 -tox>=2.9.1 +coverage>=4.5.4 +pylint>=2.6.0,<3.0.0 +pytest>=7.0.1,<8.0.0 +pytest-cov>=2.2.1,<3.0.0 pytest-rerunfailures>=3.1 - -# code coverage -coverage<5 -codecov>=1.6.3 -pytest-cov>=2.2.1 - -# documentation -recommonmark>=0.2.0 -Sphinx>=1.3.1 +responses>=0.12.1,<1.0.0 +black>=22.10 diff --git a/requirements.txt b/requirements.txt index 0422e0d..ac10b3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ -requests>=2.0,<3.0 -python_dateutil>=2.5.3 -ibm_cloud_sdk_core>=3.1.0,<4.0.0 +requests>=2.26.0,<3.0.0 +urllib3>=1.26.0,<2.0.0 +python_dateutil>=2.5.3,<3.0.0 +ibm_cloud_sdk_core>=3.16.0,<4.0.0 diff --git a/setup.py b/setup.py index 25f2c4b..b9c8b7f 100644 --- a/setup.py +++ b/setup.py @@ -38,35 +38,16 @@ os.system('python setup.py sdist upload -r pypi') sys.exit() -class PyTest(TestCommand): - def finalize_options(self): - TestCommand.finalize_options(self) - self.test_args = ['--strict', '--verbose', '--tb=long', 'test'] - self.test_suite = True - - def run_tests(self): - import pytest - errcode = pytest.main(self.test_args) - sys.exit(errcode) - -class PyTestUnit(PyTest): - def finalize_options(self): - self.test_args = ['--strict', '--verbose', '--tb=long', 'test/unit'] - -class PyTestIntegration(PyTest): - def finalize_options(self): - self.test_args = ['--strict', '--verbose', '--tb=long', 'test/integration'] - with open("README.md", "r") as fh: readme = fh.read() -setup(name=PACKAGE_NAME.replace('_', '-'), +setup( + name=PACKAGE_NAME.replace('_', '-'), version=__version__, description=PACKAGE_DESC, license='Apache 2.0', install_requires=install_requires, tests_require=tests_require, - cmdclass={'test': PyTest, 'test_unit': PyTestUnit, 'test_integration': PyTestIntegration}, author='IBM', author_email='coligo@de.ibm.com', long_description=readme, @@ -78,9 +59,10 @@ def finalize_options(self): classifiers=[ 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 8e72816..0000000 --- a/tox.ini +++ /dev/null @@ -1,18 +0,0 @@ -[tox] -envlist = py37-lint, py36, py37, py38, py39 - -[testenv:py37-lint] -basepython = python3.7 -deps = pylint -commands = pylint --rcfile=.pylintrc ibm_code_engine_sdk test - -[testenv] -passenv = TOXENV CI TRAVIS* -commands = - py.test --reruns 3 --cov=ibm_code_engine_sdk {posargs} - codecov -e TOXENV -deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/requirements-dev.txt -usedevelop = True -exclude = .venv,.git,.tox,docs From 67048220e842b80c43953b95f042f45569cd42a2 Mon Sep 17 00:00:00 2001 From: REGGEENR Date: Sat, 14 Jan 2023 00:19:23 +0100 Subject: [PATCH 02/22] added missing npmrc --- .npmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..9cf9495 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false \ No newline at end of file From 436cefab9bbd6178f060bebad3df9e754d10d16a Mon Sep 17 00:00:00 2001 From: REGGEENR Date: Mon, 16 Jan 2023 22:56:53 +0100 Subject: [PATCH 03/22] prepared v2 update of the python SDK --- example/example.py | 41 +- example/example_deprecated.py | 21 +- examples/test_code_engine_v2_examples.py | 990 ++ ibm_code_engine_sdk/__init__.py | 1 + ibm_code_engine_sdk/code_engine_v2.py | 8570 +++++++++++++++++ ibm_code_engine_sdk/common.py | 12 +- .../ibm_cloud_code_engine_v1.py | 77 +- sdkgen-config.json => sdkgen_config.json | 2 +- setup.py | 60 +- test/integration/__init__.py | 2 +- test/unit/__init__.py | 2 +- test/unit/test_code_engine_v2.py | 6126 ++++++++++++ test/unit/test_common.py | 5 +- test/unit/test_ibm_cloud_code_engine_v1.py | 81 +- 14 files changed, 15802 insertions(+), 188 deletions(-) create mode 100644 examples/test_code_engine_v2_examples.py create mode 100644 ibm_code_engine_sdk/code_engine_v2.py rename sdkgen-config.json => sdkgen_config.json (77%) create mode 100644 test/unit/test_code_engine_v2.py diff --git a/example/example.py b/example/example.py index 8e5bd52..168a691 100644 --- a/example/example.py +++ b/example/example.py @@ -10,12 +10,14 @@ from ibm_code_engine_sdk.ibm_cloud_code_engine_v1 import IbmCloudCodeEngineV1 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator -if (os.environ.get('CE_API_KEY') == None or - os.environ.get('CE_PROJECT_REGION') == None or - os.environ.get('CE_PROJECT_ID') == None): +if ( + os.environ.get('CE_API_KEY') == None + or os.environ.get('CE_PROJECT_REGION') == None + or os.environ.get('CE_PROJECT_ID') == None +): print( - 'You must set the envrionment variables CE_API_KEY, CE_PROJECT_REGION and CE_PROJECT_ID ' + - 'before using the example.' + 'You must set the envrionment variables CE_API_KEY, CE_PROJECT_REGION and CE_PROJECT_ID ' + + 'before using the example.' ) # Create an IAM authenticator. @@ -27,20 +29,20 @@ # Construct the Code Engine client. ce_client = IbmCloudCodeEngineV1(authenticator=authenticator) -ce_client.set_service_url( - 'https://api.' + os.environ.get('CE_PROJECT_REGION') + '.codeengine.cloud.ibm.com/api/v1' -) +ce_client.set_service_url('https://api.' + os.environ.get('CE_PROJECT_REGION') + '.codeengine.cloud.ibm.com/api/v1') # Get a Delegated Refresh Token from IAM -iam_response = requests.post('https://iam.cloud.ibm.com/identity/token', headers={ - 'Content-Type': 'application/x-www-form-urlencoded' -}, data={ - 'grant_type': 'urn:ibm:params:oauth:grant-type:apikey', - 'apikey': os.environ.get('CE_API_KEY'), - 'response_type': 'delegated_refresh_token', - 'receiver_client_ids': 'ce', - 'delegated_refresh_token_expiry': '3600' -}) +iam_response = requests.post( + 'https://iam.cloud.ibm.com/identity/token', + headers={'Content-Type': 'application/x-www-form-urlencoded'}, + data={ + 'grant_type': 'urn:ibm:params:oauth:grant-type:apikey', + 'apikey': os.environ.get('CE_API_KEY'), + 'response_type': 'delegated_refresh_token', + 'receiver_client_ids': 'ce', + 'delegated_refresh_token_expiry': '3600', + }, +) delegated_refresh_token = iam_response.json()['delegated_refresh_token'] # Get Code Engine project config using the Code Engine client. @@ -60,7 +62,4 @@ contexts = kubernetes.config.list_kube_config_contexts(config_file=kubeconfig_filename)[0][0] namespace = contexts.get('context').get('namespace') configmaps = kube_client.list_namespaced_config_map(namespace) -print( - 'Project ' + os.environ.get('CE_PROJECT_ID') + - ' has ' + str(len(configmaps.items)) + ' configmaps.' -) +print('Project ' + os.environ.get('CE_PROJECT_ID') + ' has ' + str(len(configmaps.items)) + ' configmaps.') diff --git a/example/example_deprecated.py b/example/example_deprecated.py index 1921325..36d78ea 100644 --- a/example/example_deprecated.py +++ b/example/example_deprecated.py @@ -8,12 +8,14 @@ from ibm_code_engine_sdk.ibm_cloud_code_engine_v1 import IbmCloudCodeEngineV1 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator -if (os.environ.get('CE_API_KEY') == None or - os.environ.get('CE_PROJECT_REGION') == None or - os.environ.get('CE_PROJECT_ID') == None): +if ( + os.environ.get('CE_API_KEY') == None + or os.environ.get('CE_PROJECT_REGION') == None + or os.environ.get('CE_PROJECT_ID') == None +): print( - 'You must set the envrionment variables CE_API_KEY, CE_PROJECT_REGION and CE_PROJECT_ID ' + - 'before using the example.' + 'You must set the envrionment variables CE_API_KEY, CE_PROJECT_REGION and CE_PROJECT_ID ' + + 'before using the example.' ) # Create an IAM authenticator. @@ -25,9 +27,7 @@ # Construct the Code Engine client. ce_client = IbmCloudCodeEngineV1(authenticator=authenticator) -ce_client.set_service_url( - 'https://api.' + os.environ.get('CE_PROJECT_REGION') + '.codeengine.cloud.ibm.com/api/v1' -) +ce_client.set_service_url('https://api.' + os.environ.get('CE_PROJECT_REGION') + '.codeengine.cloud.ibm.com/api/v1') # Get IAM tokens using the authenticator refresh_token = authenticator.token_manager.request_token().get('refresh_token') @@ -49,7 +49,4 @@ contexts = kubernetes.config.list_kube_config_contexts(config_file=kubeconfig_filename)[0][0] namespace = contexts.get('context').get('namespace') configmaps = kube_client.list_namespaced_config_map(namespace) -print( - 'Project ' + os.environ.get('CE_PROJECT_ID') + - ' has ' + str(len(configmaps.items)) + ' configmaps.' -) +print('Project ' + os.environ.get('CE_PROJECT_ID') + ' has ' + str(len(configmaps.items)) + ' configmaps.') diff --git a/examples/test_code_engine_v2_examples.py b/examples/test_code_engine_v2_examples.py new file mode 100644 index 0000000..72e3033 --- /dev/null +++ b/examples/test_code_engine_v2_examples.py @@ -0,0 +1,990 @@ +# -*- coding: utf-8 -*- +# (C) Copyright IBM Corp. 2023. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Examples for CodeEngineV2 +""" + +from ibm_cloud_sdk_core import ApiException, read_external_sources +import os +import pytest +from ibm_code_engine_sdk.code_engine_v2 import * + +# +# This file provides an example of how to use the Code Engine service. +# +# The following configuration properties are assumed to be defined: +# CODE_ENGINE_URL= +# CODE_ENGINE_AUTH_TYPE=iam +# CODE_ENGINE_APIKEY= +# CODE_ENGINE_AUTH_URL= +# +# These configuration properties can be exported as environment variables, or stored +# in a configuration file and then: +# export IBM_CREDENTIALS_FILE= +# +config_file = 'code_engine_v2.env' + +code_engine_service = None + +config = None + + +############################################################################## +# Start of Examples for Service: CodeEngineV2 +############################################################################## +# region +class TestCodeEngineV2Examples: + """ + Example Test Class for CodeEngineV2 + """ + + @classmethod + def setup_class(cls): + global code_engine_service + if os.path.exists(config_file): + os.environ['IBM_CREDENTIALS_FILE'] = config_file + + # begin-common + + code_engine_service = CodeEngineV2.new_instance() + + # end-common + assert code_engine_service is not None + + # Load the configuration + global config + config = read_external_sources(CodeEngineV2.DEFAULT_SERVICE_NAME) + + print('Setup complete.') + + needscredentials = pytest.mark.skipif( + not os.path.exists(config_file), reason="External configuration not available, skipping..." + ) + + @needscredentials + def test_list_projects_example(self): + """ + list_projects request example + """ + try: + print('\nlist_projects() result:') + # begin-list_projects + + all_results = [] + pager = ProjectsPager( + client=code_engine_service, + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + print(json.dumps(all_results, indent=2)) + + # end-list_projects + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_project_example(self): + """ + create_project request example + """ + try: + print('\ncreate_project() result:') + # begin-create_project + + response = code_engine_service.create_project( + name='my-project', + ) + project = response.get_result() + + print(json.dumps(project, indent=2)) + + # end-create_project + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_project_example(self): + """ + get_project request example + """ + try: + print('\nget_project() result:') + # begin-get_project + + response = code_engine_service.get_project( + id='15314cc3-85b4-4338-903f-c28cdee6d005', + ) + project = response.get_result() + + print(json.dumps(project, indent=2)) + + # end-get_project + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_apps_example(self): + """ + list_apps request example + """ + try: + print('\nlist_apps() result:') + # begin-list_apps + + all_results = [] + pager = AppsPager( + client=code_engine_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + print(json.dumps(all_results, indent=2)) + + # end-list_apps + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_app_example(self): + """ + create_app request example + """ + try: + print('\ncreate_app() result:') + # begin-create_app + + response = code_engine_service.create_app( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + image_reference='icr.io/codeengine/helloworld', + name='my-app', + ) + app = response.get_result() + + print(json.dumps(app, indent=2)) + + # end-create_app + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_app_example(self): + """ + get_app request example + """ + try: + print('\nget_app() result:') + # begin-get_app + + response = code_engine_service.get_app( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-app', + ) + app = response.get_result() + + print(json.dumps(app, indent=2)) + + # end-get_app + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_update_app_example(self): + """ + update_app request example + """ + try: + print('\nupdate_app() result:') + # begin-update_app + + app_patch_model = {} + + response = code_engine_service.update_app( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-app', + if_match='testString', + app=app_patch_model, + ) + app = response.get_result() + + print(json.dumps(app, indent=2)) + + # end-update_app + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_app_revisions_example(self): + """ + list_app_revisions request example + """ + try: + print('\nlist_app_revisions() result:') + # begin-list_app_revisions + + all_results = [] + pager = AppRevisionsPager( + client=code_engine_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + app_name='my-app', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + print(json.dumps(all_results, indent=2)) + + # end-list_app_revisions + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_app_revision_example(self): + """ + get_app_revision request example + """ + try: + print('\nget_app_revision() result:') + # begin-get_app_revision + + response = code_engine_service.get_app_revision( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + app_name='my-app', + name='my-app-001', + ) + app_revision = response.get_result() + + print(json.dumps(app_revision, indent=2)) + + # end-get_app_revision + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_jobs_example(self): + """ + list_jobs request example + """ + try: + print('\nlist_jobs() result:') + # begin-list_jobs + + all_results = [] + pager = JobsPager( + client=code_engine_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + print(json.dumps(all_results, indent=2)) + + # end-list_jobs + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_job_example(self): + """ + create_job request example + """ + try: + print('\ncreate_job() result:') + # begin-create_job + + response = code_engine_service.create_job( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + image_reference='icr.io/codeengine/helloworld', + name='my-job', + ) + job = response.get_result() + + print(json.dumps(job, indent=2)) + + # end-create_job + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_job_example(self): + """ + get_job request example + """ + try: + print('\nget_job() result:') + # begin-get_job + + response = code_engine_service.get_job( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-job', + ) + job = response.get_result() + + print(json.dumps(job, indent=2)) + + # end-get_job + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_update_job_example(self): + """ + update_job request example + """ + try: + print('\nupdate_job() result:') + # begin-update_job + + job_patch_model = {} + + response = code_engine_service.update_job( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-job', + if_match='testString', + job=job_patch_model, + ) + job = response.get_result() + + print(json.dumps(job, indent=2)) + + # end-update_job + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_job_runs_example(self): + """ + list_job_runs request example + """ + try: + print('\nlist_job_runs() result:') + # begin-list_job_runs + + all_results = [] + pager = JobRunsPager( + client=code_engine_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + job_name='my-job', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + print(json.dumps(all_results, indent=2)) + + # end-list_job_runs + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_job_run_example(self): + """ + create_job_run request example + """ + try: + print('\ncreate_job_run() result:') + # begin-create_job_run + + response = code_engine_service.create_job_run( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + ) + job_run = response.get_result() + + print(json.dumps(job_run, indent=2)) + + # end-create_job_run + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_job_run_example(self): + """ + get_job_run request example + """ + try: + print('\nget_job_run() result:') + # begin-get_job_run + + response = code_engine_service.get_job_run( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-job', + ) + job_run = response.get_result() + + print(json.dumps(job_run, indent=2)) + + # end-get_job_run + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_builds_example(self): + """ + list_builds request example + """ + try: + print('\nlist_builds() result:') + # begin-list_builds + + all_results = [] + pager = BuildsPager( + client=code_engine_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + print(json.dumps(all_results, indent=2)) + + # end-list_builds + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_build_example(self): + """ + create_build request example + """ + try: + print('\ncreate_build() result:') + # begin-create_build + + response = code_engine_service.create_build( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-build', + output_image='private.de.icr.io/icr_namespace/image-name', + output_secret='ce-auto-icr-private-eu-de', + source_url='https://github.com/IBM/CodeEngine', + strategy_type='dockerfile', + ) + build = response.get_result() + + print(json.dumps(build, indent=2)) + + # end-create_build + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_build_example(self): + """ + get_build request example + """ + try: + print('\nget_build() result:') + # begin-get_build + + response = code_engine_service.get_build( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-build', + ) + build = response.get_result() + + print(json.dumps(build, indent=2)) + + # end-get_build + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_update_build_example(self): + """ + update_build request example + """ + try: + print('\nupdate_build() result:') + # begin-update_build + + build_patch_model = {} + + response = code_engine_service.update_build( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-build', + if_match='testString', + build=build_patch_model, + ) + build = response.get_result() + + print(json.dumps(build, indent=2)) + + # end-update_build + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_build_runs_example(self): + """ + list_build_runs request example + """ + try: + print('\nlist_build_runs() result:') + # begin-list_build_runs + + all_results = [] + pager = BuildRunsPager( + client=code_engine_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + build_name='my-build', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + print(json.dumps(all_results, indent=2)) + + # end-list_build_runs + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_build_run_example(self): + """ + create_build_run request example + """ + try: + print('\ncreate_build_run() result:') + # begin-create_build_run + + response = code_engine_service.create_build_run( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + ) + build_run = response.get_result() + + print(json.dumps(build_run, indent=2)) + + # end-create_build_run + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_build_run_example(self): + """ + get_build_run request example + """ + try: + print('\nget_build_run() result:') + # begin-get_build_run + + response = code_engine_service.get_build_run( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-build-run', + ) + build_run = response.get_result() + + print(json.dumps(build_run, indent=2)) + + # end-get_build_run + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_config_maps_example(self): + """ + list_config_maps request example + """ + try: + print('\nlist_config_maps() result:') + # begin-list_config_maps + + all_results = [] + pager = ConfigMapsPager( + client=code_engine_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + print(json.dumps(all_results, indent=2)) + + # end-list_config_maps + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_config_map_example(self): + """ + create_config_map request example + """ + try: + print('\ncreate_config_map() result:') + # begin-create_config_map + + response = code_engine_service.create_config_map( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-configmap', + ) + config_map = response.get_result() + + print(json.dumps(config_map, indent=2)) + + # end-create_config_map + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_config_map_example(self): + """ + get_config_map request example + """ + try: + print('\nget_config_map() result:') + # begin-get_config_map + + response = code_engine_service.get_config_map( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-config-map', + ) + config_map = response.get_result() + + print(json.dumps(config_map, indent=2)) + + # end-get_config_map + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_replace_config_map_example(self): + """ + replace_config_map request example + """ + try: + print('\nreplace_config_map() result:') + # begin-replace_config_map + + response = code_engine_service.replace_config_map( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-config-map', + if_match='testString', + ) + config_map = response.get_result() + + print(json.dumps(config_map, indent=2)) + + # end-replace_config_map + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_secrets_example(self): + """ + list_secrets request example + """ + try: + print('\nlist_secrets() result:') + # begin-list_secrets + + all_results = [] + pager = SecretsPager( + client=code_engine_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + print(json.dumps(all_results, indent=2)) + + # end-list_secrets + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_secret_example(self): + """ + create_secret request example + """ + try: + print('\ncreate_secret() result:') + # begin-create_secret + + response = code_engine_service.create_secret( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + format='generic', + name='my-secret', + ) + secret = response.get_result() + + print(json.dumps(secret, indent=2)) + + # end-create_secret + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_secret_example(self): + """ + get_secret request example + """ + try: + print('\nget_secret() result:') + # begin-get_secret + + response = code_engine_service.get_secret( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-secret', + ) + secret = response.get_result() + + print(json.dumps(secret, indent=2)) + + # end-get_secret + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_replace_secret_example(self): + """ + replace_secret request example + """ + try: + print('\nreplace_secret() result:') + # begin-replace_secret + + response = code_engine_service.replace_secret( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-secret', + if_match='testString', + ) + secret = response.get_result() + + print(json.dumps(secret, indent=2)) + + # end-replace_secret + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_project_example(self): + """ + delete_project request example + """ + try: + # begin-delete_project + + response = code_engine_service.delete_project( + id='15314cc3-85b4-4338-903f-c28cdee6d005', + ) + + # end-delete_project + print('\ndelete_project() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_app_example(self): + """ + delete_app request example + """ + try: + # begin-delete_app + + response = code_engine_service.delete_app( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-app', + ) + + # end-delete_app + print('\ndelete_app() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_app_revision_example(self): + """ + delete_app_revision request example + """ + try: + # begin-delete_app_revision + + response = code_engine_service.delete_app_revision( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + app_name='my-app', + name='my-app-001', + ) + + # end-delete_app_revision + print('\ndelete_app_revision() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_job_example(self): + """ + delete_job request example + """ + try: + # begin-delete_job + + response = code_engine_service.delete_job( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-job', + ) + + # end-delete_job + print('\ndelete_job() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_job_run_example(self): + """ + delete_job_run request example + """ + try: + # begin-delete_job_run + + response = code_engine_service.delete_job_run( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-job', + ) + + # end-delete_job_run + print('\ndelete_job_run() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_build_example(self): + """ + delete_build request example + """ + try: + # begin-delete_build + + response = code_engine_service.delete_build( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-build', + ) + + # end-delete_build + print('\ndelete_build() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_build_run_example(self): + """ + delete_build_run request example + """ + try: + # begin-delete_build_run + + response = code_engine_service.delete_build_run( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-build-run', + ) + + # end-delete_build_run + print('\ndelete_build_run() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_config_map_example(self): + """ + delete_config_map request example + """ + try: + # begin-delete_config_map + + response = code_engine_service.delete_config_map( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-config-map', + ) + + # end-delete_config_map + print('\ndelete_config_map() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_secret_example(self): + """ + delete_secret request example + """ + try: + # begin-delete_secret + + response = code_engine_service.delete_secret( + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + name='my-secret', + ) + + # end-delete_secret + print('\ndelete_secret() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + +# endregion +############################################################################## +# End of Examples for Service: CodeEngineV2 +############################################################################## diff --git a/ibm_code_engine_sdk/__init__.py b/ibm_code_engine_sdk/__init__.py index e00fe3a..840188c 100644 --- a/ibm_code_engine_sdk/__init__.py +++ b/ibm_code_engine_sdk/__init__.py @@ -19,4 +19,5 @@ from .common import get_sdk_headers from .version import __version__ + # from .example_service_v1 import ExampleServiceV1 diff --git a/ibm_code_engine_sdk/code_engine_v2.py b/ibm_code_engine_sdk/code_engine_v2.py new file mode 100644 index 0000000..f9f5b1b --- /dev/null +++ b/ibm_code_engine_sdk/code_engine_v2.py @@ -0,0 +1,8570 @@ +# coding: utf-8 + +# (C) Copyright IBM Corp. 2023. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# IBM OpenAPI SDK Code Generator Version: 3.64.0-959a5845-20230112-195144 + +""" +REST API for Code Engine + +API Version: 2.0.0 +""" + +from enum import Enum +from typing import Dict, List +import json + +from ibm_cloud_sdk_core import BaseService, DetailedResponse +from ibm_cloud_sdk_core.authenticators.authenticator import Authenticator +from ibm_cloud_sdk_core.get_authenticator import get_authenticator_from_environment +from ibm_cloud_sdk_core.utils import convert_model + +from .common import get_sdk_headers + +############################################################################## +# Service +############################################################################## + + +class CodeEngineV2(BaseService): + """The Code Engine V2 service.""" + + DEFAULT_SERVICE_URL = 'https://api.au-syd.codeengine.cloud.ibm.com/v2' + DEFAULT_SERVICE_NAME = 'code_engine' + + @classmethod + def new_instance( + cls, + service_name: str = DEFAULT_SERVICE_NAME, + ) -> 'CodeEngineV2': + """ + Return a new client for the Code Engine service using the specified + parameters and external configuration. + """ + authenticator = get_authenticator_from_environment(service_name) + service = cls(authenticator) + service.configure_service(service_name) + return service + + def __init__( + self, + authenticator: Authenticator = None, + ) -> None: + """ + Construct a new client for the Code Engine service. + + :param Authenticator authenticator: The authenticator specifies the authentication mechanism. + Get up to date information from https://github.com/IBM/python-sdk-core/blob/main/README.md + about initializing the authenticator of your choice. + """ + BaseService.__init__(self, service_url=self.DEFAULT_SERVICE_URL, authenticator=authenticator) + + ######################### + # Projects + ######################### + + def list_projects(self, *, limit: int = None, start: str = None, **kwargs) -> DetailedResponse: + """ + List all projects. + + List all projects in the current account. + + :param int limit: (optional) Optional maximum number of projects per page. + :param str start: (optional) An optional token that indicates the beginning + of the page of results to be returned. Any additional query parameters are + ignored if a page token is present. If omitted, the first page of results + is returned. This value is obtained from the 'start' query parameter in the + 'next_url' field of the operation response. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `ProjectList` object + """ + + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='list_projects' + ) + headers.update(sdk_headers) + + params = { + 'limit': limit, + 'start': start, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/projects' + request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + + response = self.send(request, **kwargs) + return response + + def create_project( + self, name: str, *, resource_group_id: str = None, tags: List[str] = None, **kwargs + ) -> DetailedResponse: + """ + Create a project. + + Create a Code Engine project on IBM Cloud. The project will be created in the + region that corresponds to the API endpoint that is being called. + + :param str name: The name of the project. + :param str resource_group_id: (optional) Optional ID of the resource group + for your project deployment. If this field is not defined, the default + resource group of the account will be used. + :param List[str] tags: (optional) Optional list of labels to assign to your + project. Tags are not part of the project resource that is returned by the + server, but can be obtained and managed through the Global Tagging API in + IBM Cloud. Find more information on [Global Tagging API + docs](https://cloud.ibm.com/apidocs/tagging). + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Project` object + """ + + if name is None: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='create_project' + ) + headers.update(sdk_headers) + + data = { + 'name': name, + 'resource_group_id': resource_group_id, + 'tags': tags, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/projects' + request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def get_project(self, id: str, **kwargs) -> DetailedResponse: + """ + Get a project. + + Display the details of a single project. + + :param str id: The ID of the project. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Project` object + """ + + if not id: + raise ValueError('id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='get_project' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['id'] + path_param_values = self.encode_path_vars(id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{id}'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def delete_project(self, id: str, **kwargs) -> DetailedResponse: + """ + Delete a project. + + Delete a project. + + :param str id: The ID of the project. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not id: + raise ValueError('id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='delete_project' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['id'] + path_param_values = self.encode_path_vars(id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{id}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + ######################### + # Applications + ######################### + + def list_apps(self, project_id: str, *, limit: int = None, start: str = None, **kwargs) -> DetailedResponse: + """ + List applications. + + List all applications in a project. + + :param str project_id: The ID of the project. + :param int limit: (optional) Optional maximum number of apps per page. + :param str start: (optional) An optional token that indicates the beginning + of the page of results to be returned. If omitted, the first page of + results is returned. This value is obtained from the 'start' query + parameter in the 'next_url' field of the operation response. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `AppList` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='list_apps' + ) + headers.update(sdk_headers) + + params = { + 'limit': limit, + 'start': start, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/apps'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + + response = self.send(request, **kwargs) + return response + + def create_app( + self, + project_id: str, + image_reference: str, + name: str, + *, + image_port: int = None, + image_secret: str = None, + managed_domain_mappings: str = None, + run_arguments: List[str] = None, + run_as_user: int = None, + run_commands: List[str] = None, + run_env_variables: List['EnvVarPrototype'] = None, + run_service_account: str = None, + run_volume_mounts: List['VolumeMountPrototype'] = None, + scale_concurrency: int = None, + scale_concurrency_target: int = None, + scale_cpu_limit: str = None, + scale_ephemeral_storage_limit: str = None, + scale_initial_instances: int = None, + scale_max_instances: int = None, + scale_memory_limit: str = None, + scale_min_instances: int = None, + scale_request_timeout: int = None, + **kwargs, + ) -> DetailedResponse: + """ + Create an application. + + Create an application. + + :param str project_id: The ID of the project. + :param str image_reference: The name of the image that is used for this + job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and + `TAG` are optional. If `REGISTRY` is not specified, the default is + `docker.io`. If `TAG` is not specified, the default is `latest`. If the + image reference points to a registry that requires authentication, make + sure to also specify the property `image_secret`. + :param str name: The name of the app. Use a name that is unique within the + project. + :param int image_port: (optional) Optional port the app listens on. While + the app will always be exposed via port `443` for end users, this port is + used to connect to the port that is exposed by the container image. + :param str image_secret: (optional) Optional name of the image registry + access secret. The image registry access secret is used to authenticate + with a private registry when you download the container image. If the image + reference points to a registry that requires authentication, the app will + be created but cannot reach the ready status, until this property is + provided, too. + :param str managed_domain_mappings: (optional) Optional value controlling + which of the system managed domain mappings will be setup for the + application. Valid values are 'local_public', 'local_private' and 'local'. + Visibility can only be 'local_private' if the project supports application + private visibility. + :param List[str] run_arguments: (optional) Optional arguments for the app + that are passed to start the container. If not specified an empty string + array will be applied and the arguments specified by the container image, + will be used to start the container. + :param int run_as_user: (optional) Optional user ID (UID) to run the app + (e.g., `1001`). + :param List[str] run_commands: (optional) Optional commands for the app + that are passed to start the container. If not specified an empty string + array will be applied and the command specified by the container image, + will be used to start the container. + :param List[EnvVarPrototype] run_env_variables: (optional) Optional + references to config maps, secrets or a literal values that are exposed as + environment variables within the running application. + :param str run_service_account: (optional) Optional name of the service + account. For built-in service accounts, you can use the shortened names + `manager` , `none`, `reader`, and `writer`. + :param List[VolumeMountPrototype] run_volume_mounts: (optional) Optional + mounts of config maps or a secrets. + :param int scale_concurrency: (optional) Optional maximum number of + requests that can be processed concurrently per instance. + :param int scale_concurrency_target: (optional) Optional threshold of + concurrent requests per instance at which one or more additional instances + are created. Use this value to scale up instances based on concurrent + number of requests. This option defaults to the value of the + `scale_concurrency` option, if not specified. + :param str scale_cpu_limit: (optional) Optional number of CPU set for the + instance of the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :param str scale_ephemeral_storage_limit: (optional) Optional amount of + ephemeral storage to set for the instance of the app. The amount specified + as ephemeral storage, must not exceed the amount of `scale_memory_limit`. + The units for specifying ephemeral storage are Megabyte (M) or Gigabyte + (G), whereas G and M are the shorthand expressions for GB and MB. For more + information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_initial_instances: (optional) Optional initial number of + instances that are created upon app creation or app update. + :param int scale_max_instances: (optional) Optional maximum number of + instances for this app. If you set this value to `0`, this property does + not set a upper scaling limit. However, the app scaling is still limited by + the project quota for instances. See [Limits and quotas for Code + Engine](https://cloud.ibm.com/docs/codeengine?topic=codeengine-limits). + :param str scale_memory_limit: (optional) Optional amount of memory set for + the instance of the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G + and M are the shorthand expressions for GB and MB. For more information see + [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_min_instances: (optional) Optional minimum number of + instances for this app. If you set this value to `0`, the app will scale + down to zero, if not hit by any request for some time. + :param int scale_request_timeout: (optional) Optional amount of time in + seconds that is allowed for a running app to respond to a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `App` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if image_reference is None: + raise ValueError('image_reference must be provided') + if name is None: + raise ValueError('name must be provided') + if run_env_variables is not None: + run_env_variables = [convert_model(x) for x in run_env_variables] + if run_volume_mounts is not None: + run_volume_mounts = [convert_model(x) for x in run_volume_mounts] + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='create_app' + ) + headers.update(sdk_headers) + + data = { + 'image_reference': image_reference, + 'name': name, + 'image_port': image_port, + 'image_secret': image_secret, + 'managed_domain_mappings': managed_domain_mappings, + 'run_arguments': run_arguments, + 'run_as_user': run_as_user, + 'run_commands': run_commands, + 'run_env_variables': run_env_variables, + 'run_service_account': run_service_account, + 'run_volume_mounts': run_volume_mounts, + 'scale_concurrency': scale_concurrency, + 'scale_concurrency_target': scale_concurrency_target, + 'scale_cpu_limit': scale_cpu_limit, + 'scale_ephemeral_storage_limit': scale_ephemeral_storage_limit, + 'scale_initial_instances': scale_initial_instances, + 'scale_max_instances': scale_max_instances, + 'scale_memory_limit': scale_memory_limit, + 'scale_min_instances': scale_min_instances, + 'scale_request_timeout': scale_request_timeout, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/apps'.format(**path_param_dict) + request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def get_app(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Get an application. + + Display the details of an application. + + :param str project_id: The ID of the project. + :param str name: The name of your application. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `App` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='get_app' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/apps/{name}'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def delete_app(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Delete an application. + + Delete an application. + + :param str project_id: The ID of the project. + :param str name: The name of your application. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='delete_app' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/apps/{name}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def update_app(self, project_id: str, name: str, if_match: str, app: 'AppPatch', **kwargs) -> DetailedResponse: + """ + Update an application. + + An application contains one or more revisions. A revision represents an immutable + version of the configuration properties of the application. Each update of an + application configuration property creates a new revision of the application. + [Learn more](https://cloud.ibm.com/docs/codeengine?topic=codeengine-update-app). + + :param str project_id: The ID of the project. + :param str name: The name of your application. + :param str if_match: Version of the app settings to be updated. Specify the + version that you retrieved as entity_tag (ETag header) when reading the + app. This value helps identifying parallel usage of this API. Pass * to + indicate to update any version available. This might result in stale + updates. + :param AppPatch app: App patch. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `App` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + if not if_match: + raise ValueError('if_match must be provided') + if app is None: + raise ValueError('app must be provided') + if isinstance(app, AppPatch): + app = convert_model(app) + headers = { + 'If-Match': if_match, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='update_app' + ) + headers.update(sdk_headers) + + data = json.dumps(app) + headers['content-type'] = 'application/merge-patch+json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/apps/{name}'.format(**path_param_dict) + request = self.prepare_request(method='PATCH', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def list_app_revisions( + self, project_id: str, app_name: str, *, limit: int = None, start: str = None, **kwargs + ) -> DetailedResponse: + """ + List application revisions. + + List all application revisions in a particular application. + + :param str project_id: The ID of the project. + :param str app_name: The name of your application. + :param int limit: (optional) Optional maximum number of apps per page. + :param str start: (optional) An optional token that indicates the beginning + of the page of results to be returned. If omitted, the first page of + results is returned. This value is obtained from the 'start' query + parameter in the 'next_url' field of the operation response. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `AppRevisionList` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not app_name: + raise ValueError('app_name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='list_app_revisions' + ) + headers.update(sdk_headers) + + params = { + 'limit': limit, + 'start': start, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'app_name'] + path_param_values = self.encode_path_vars(project_id, app_name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/apps/{app_name}/revisions'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + + response = self.send(request, **kwargs) + return response + + def get_app_revision(self, project_id: str, app_name: str, name: str, **kwargs) -> DetailedResponse: + """ + Get an application revision. + + Display the details of an application revision. + + :param str project_id: The ID of the project. + :param str app_name: The name of your application. + :param str name: The name of your application revision. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `AppRevision` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not app_name: + raise ValueError('app_name must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='get_app_revision' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'app_name', 'name'] + path_param_values = self.encode_path_vars(project_id, app_name, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/apps/{app_name}/revisions/{name}'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def delete_app_revision(self, project_id: str, app_name: str, name: str, **kwargs) -> DetailedResponse: + """ + Delete an application revision. + + Delete an application revision. + + :param str project_id: The ID of the project. + :param str app_name: The name of your application. + :param str name: The name of your application revision. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not app_name: + raise ValueError('app_name must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='delete_app_revision' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['project_id', 'app_name', 'name'] + path_param_values = self.encode_path_vars(project_id, app_name, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/apps/{app_name}/revisions/{name}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + ######################### + # Jobs + ######################### + + def list_jobs(self, project_id: str, *, limit: int = None, start: str = None, **kwargs) -> DetailedResponse: + """ + List jobs. + + List all jobs in a project. + + :param str project_id: The ID of the project. + :param int limit: (optional) Optional maximum number of jobs per page. + :param str start: (optional) An optional token that indicates the beginning + of the page of results to be returned. If omitted, the first page of + results is returned. This value is obtained from the 'start' query + parameter in the 'next_url' field of the operation response. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `JobList` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='list_jobs' + ) + headers.update(sdk_headers) + + params = { + 'limit': limit, + 'start': start, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/jobs'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + + response = self.send(request, **kwargs) + return response + + def create_job( + self, + project_id: str, + image_reference: str, + name: str, + *, + image_secret: str = None, + run_arguments: List[str] = None, + run_as_user: int = None, + run_commands: List[str] = None, + run_env_variables: List['EnvVarPrototype'] = None, + run_mode: str = None, + run_service_account: str = None, + run_volume_mounts: List['VolumeMountPrototype'] = None, + scale_array_spec: str = None, + scale_cpu_limit: str = None, + scale_ephemeral_storage_limit: str = None, + scale_max_execution_time: int = None, + scale_memory_limit: str = None, + scale_retry_limit: int = None, + **kwargs, + ) -> DetailedResponse: + """ + Create a job. + + Create a job. + + :param str project_id: The ID of the project. + :param str image_reference: The name of the image that is used for this + job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and + `TAG` are optional. If `REGISTRY` is not specified, the default is + `docker.io`. If `TAG` is not specified, the default is `latest`. If the + image reference points to a registry that requires authentication, make + sure to also specify the property `image_secret`. + :param str name: The name of the job. Use a name that is unique within the + project. + :param str image_secret: (optional) The name of the image registry access + secret. The image registry access secret is used to authenticate with a + private registry when you download the container image. If the image + reference points to a registry that requires authentication, the job / job + runs will be created but submitted job runs will fail, until this property + is provided, too. + :param List[str] run_arguments: (optional) Set arguments for the job that + are passed to start job run containers. If not specified an empty string + array will be applied and the arguments specified by the container image, + will be used to start the container. + :param int run_as_user: (optional) The user ID (UID) to run the application + (e.g., 1001). + :param List[str] run_commands: (optional) Set commands for the job that are + passed to start job run containers. If not specified an empty string array + will be applied and the command specified by the container image, will be + used to start the container. + :param List[EnvVarPrototype] run_env_variables: (optional) Optional + references to config maps, secrets or a literal values. + :param str run_mode: (optional) The mode for runs of the job. Valid values + are `task` and `daemon`. In `task` mode, the `max_execution_time` and + `retry_limit` options apply. In `daemon` mode, since there is no timeout + and failed instances are restarted indefinitely, the `max_execution_time` + and `retry_limit` options are not allowed. + :param str run_service_account: (optional) The name of the service account. + For built-in service accounts, you can use the shortened names `manager`, + `none`, `reader`, and `writer`. + :param List[VolumeMountPrototype] run_volume_mounts: (optional) Optional + mounts of config maps or a secrets. + :param str scale_array_spec: (optional) Define a custom set of array + indices as comma-separated list containing single values and + hyphen-separated ranges like `5,12-14,23,27`. Each instance can pick up its + array index via environment variable `JOB_INDEX`. The number of unique + array indices specified here determines the number of job instances to run. + :param str scale_cpu_limit: (optional) Optional amount of CPU set for the + instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :param str scale_ephemeral_storage_limit: (optional) Optional amount of + ephemeral storage to set for the instance of the job. The amount specified + as ephemeral storage, must not exceed the amount of `scale_memory_limit`. + The units for specifying ephemeral storage are Megabyte (M) or Gigabyte + (G), whereas G and M are the shorthand expressions for GB and MB. For more + information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_max_execution_time: (optional) The maximum execution time + in seconds for runs of the job. This option can only be specified if `mode` + is `task`. + :param str scale_memory_limit: (optional) Optional amount of memory set for + the instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G + and M are the shorthand expressions for GB and MB. For more information see + [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_retry_limit: (optional) The number of times to rerun an + instance of the job before the job is marked as failed. This option can + only be specified if `mode` is `task`. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Job` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if image_reference is None: + raise ValueError('image_reference must be provided') + if name is None: + raise ValueError('name must be provided') + if run_env_variables is not None: + run_env_variables = [convert_model(x) for x in run_env_variables] + if run_volume_mounts is not None: + run_volume_mounts = [convert_model(x) for x in run_volume_mounts] + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='create_job' + ) + headers.update(sdk_headers) + + data = { + 'image_reference': image_reference, + 'name': name, + 'image_secret': image_secret, + 'run_arguments': run_arguments, + 'run_as_user': run_as_user, + 'run_commands': run_commands, + 'run_env_variables': run_env_variables, + 'run_mode': run_mode, + 'run_service_account': run_service_account, + 'run_volume_mounts': run_volume_mounts, + 'scale_array_spec': scale_array_spec, + 'scale_cpu_limit': scale_cpu_limit, + 'scale_ephemeral_storage_limit': scale_ephemeral_storage_limit, + 'scale_max_execution_time': scale_max_execution_time, + 'scale_memory_limit': scale_memory_limit, + 'scale_retry_limit': scale_retry_limit, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/jobs'.format(**path_param_dict) + request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def get_job(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Get a job. + + Display the details of a job. + + :param str project_id: The ID of the project. + :param str name: The name of your job. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Job` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='get_job' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/jobs/{name}'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def delete_job(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Delete a job. + + Delete a job. + + :param str project_id: The ID of the project. + :param str name: The name of your job. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='delete_job' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/jobs/{name}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def update_job(self, project_id: str, name: str, if_match: str, job: 'JobPatch', **kwargs) -> DetailedResponse: + """ + Update a job. + + Update the given job. + + :param str project_id: The ID of the project. + :param str name: The name of your job. + :param str if_match: Version of the job settings to be updated. Specify the + version that you retrieved as entity_tag (ETag header) when reading the + job. This value helps identifying parallel usage of this API. Pass * to + indicate to update any version available. This might result in stale + updates. + :param JobPatch job: Job patch prototype. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Job` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + if not if_match: + raise ValueError('if_match must be provided') + if job is None: + raise ValueError('job must be provided') + if isinstance(job, JobPatch): + job = convert_model(job) + headers = { + 'If-Match': if_match, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='update_job' + ) + headers.update(sdk_headers) + + data = json.dumps(job) + headers['content-type'] = 'application/merge-patch+json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/jobs/{name}'.format(**path_param_dict) + request = self.prepare_request(method='PATCH', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def list_job_runs( + self, project_id: str, *, job_name: str = None, limit: int = None, start: str = None, **kwargs + ) -> DetailedResponse: + """ + List job runs. + + List all job runs in a project. + + :param str project_id: The ID of the project. + :param str job_name: (optional) Optional name of the job that should be + filtered for. + :param int limit: (optional) Optional maximum number of job runs per page. + :param str start: (optional) An optional token that indicates the beginning + of the page of results to be returned. If omitted, the first page of + results is returned. This value is obtained from the 'start' query + parameter in the 'next_url' field of the operation response. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `JobRunList` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='list_job_runs' + ) + headers.update(sdk_headers) + + params = { + 'job_name': job_name, + 'limit': limit, + 'start': start, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/job_runs'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + + response = self.send(request, **kwargs) + return response + + def create_job_run( + self, + project_id: str, + *, + image_reference: str = None, + image_secret: str = None, + job_name: str = None, + name: str = None, + run_arguments: List[str] = None, + run_as_user: int = None, + run_commands: List[str] = None, + run_env_variables: List['EnvVarPrototype'] = None, + run_mode: str = None, + run_service_account: str = None, + run_volume_mounts: List['VolumeMountPrototype'] = None, + scale_array_spec: str = None, + scale_cpu_limit: str = None, + scale_ephemeral_storage_limit: str = None, + scale_max_execution_time: int = None, + scale_memory_limit: str = None, + scale_retry_limit: int = None, + **kwargs, + ) -> DetailedResponse: + """ + Create a job run. + + Create an job run. + + :param str project_id: The ID of the project. + :param str image_reference: (optional) The name of the image that is used + for this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where + `REGISTRY` and `TAG` are optional. If `REGISTRY` is not specified, the + default is `docker.io`. If `TAG` is not specified, the default is `latest`. + If the image reference points to a registry that requires authentication, + make sure to also specify the property `image_secret`. + :param str image_secret: (optional) The name of the image registry access + secret. The image registry access secret is used to authenticate with a + private registry when you download the container image. If the image + reference points to a registry that requires authentication, the job / job + runs will be created but submitted job runs will fail, until this property + is provided, too. + :param str job_name: (optional) Optional name of the job on which this job + run is based on. If specified, the job run will inherit the configuration + of the referenced job. + :param str name: (optional) The name of the job. Use a name that is unique + within the project. + :param List[str] run_arguments: (optional) Set arguments for the job that + are passed to start job run containers. If not specified an empty string + array will be applied and the arguments specified by the container image, + will be used to start the container. + :param int run_as_user: (optional) The user ID (UID) to run the application + (e.g., 1001). + :param List[str] run_commands: (optional) Set commands for the job that are + passed to start job run containers. If not specified an empty string array + will be applied and the command specified by the container image, will be + used to start the container. + :param List[EnvVarPrototype] run_env_variables: (optional) Optional + references to config maps, secrets or a literal values. + :param str run_mode: (optional) The mode for runs of the job. Valid values + are `task` and `daemon`. In `task` mode, the `max_execution_time` and + `retry_limit` options apply. In `daemon` mode, since there is no timeout + and failed instances are restarted indefinitely, the `max_execution_time` + and `retry_limit` options are not allowed. + :param str run_service_account: (optional) The name of the service account. + For built-in service accounts, you can use the shortened names `manager`, + `none`, `reader`, and `writer`. + :param List[VolumeMountPrototype] run_volume_mounts: (optional) Optional + mounts of config maps or a secrets. + :param str scale_array_spec: (optional) Define a custom set of array + indices as comma-separated list containing single values and + hyphen-separated ranges like `5,12-14,23,27`. Each instance can pick up its + array index via environment variable `JOB_INDEX`. The number of unique + array indices specified here determines the number of job instances to run. + :param str scale_cpu_limit: (optional) Optional amount of CPU set for the + instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :param str scale_ephemeral_storage_limit: (optional) Optional amount of + ephemeral storage to set for the instance of the job. The amount specified + as ephemeral storage, must not exceed the amount of `scale_memory_limit`. + The units for specifying ephemeral storage are Megabyte (M) or Gigabyte + (G), whereas G and M are the shorthand expressions for GB and MB. For more + information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_max_execution_time: (optional) The maximum execution time + in seconds for runs of the job. This option can only be specified if `mode` + is `task`. + :param str scale_memory_limit: (optional) Optional amount of memory set for + the instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G + and M are the shorthand expressions for GB and MB. For more information see + [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_retry_limit: (optional) The number of times to rerun an + instance of the job before the job is marked as failed. This option can + only be specified if `mode` is `task`. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `JobRun` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if run_env_variables is not None: + run_env_variables = [convert_model(x) for x in run_env_variables] + if run_volume_mounts is not None: + run_volume_mounts = [convert_model(x) for x in run_volume_mounts] + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='create_job_run' + ) + headers.update(sdk_headers) + + data = { + 'image_reference': image_reference, + 'image_secret': image_secret, + 'job_name': job_name, + 'name': name, + 'run_arguments': run_arguments, + 'run_as_user': run_as_user, + 'run_commands': run_commands, + 'run_env_variables': run_env_variables, + 'run_mode': run_mode, + 'run_service_account': run_service_account, + 'run_volume_mounts': run_volume_mounts, + 'scale_array_spec': scale_array_spec, + 'scale_cpu_limit': scale_cpu_limit, + 'scale_ephemeral_storage_limit': scale_ephemeral_storage_limit, + 'scale_max_execution_time': scale_max_execution_time, + 'scale_memory_limit': scale_memory_limit, + 'scale_retry_limit': scale_retry_limit, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/job_runs'.format(**path_param_dict) + request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def get_job_run(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Get a job run. + + Display the details of a job run. + + :param str project_id: The ID of the project. + :param str name: The name of your job run. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `JobRun` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='get_job_run' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/job_runs/{name}'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def delete_job_run(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Delete a job run. + + Delete a job run. + + :param str project_id: The ID of the project. + :param str name: The name of your job run. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='delete_job_run' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/job_runs/{name}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + ######################### + # Builds + ######################### + + def list_builds(self, project_id: str, *, limit: int = None, start: str = None, **kwargs) -> DetailedResponse: + """ + List builds. + + List all builds in a project. + + :param str project_id: The ID of the project. + :param int limit: (optional) Optional maximum number of builds per page. + :param str start: (optional) The token to continue traversing paginated + list of builds. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `BuildList` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='list_builds' + ) + headers.update(sdk_headers) + + params = { + 'limit': limit, + 'start': start, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/builds'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + + response = self.send(request, **kwargs) + return response + + def create_build( + self, + project_id: str, + name: str, + output_image: str, + output_secret: str, + source_url: str, + strategy_type: str, + *, + source_context_dir: str = None, + source_revision: str = None, + source_secret: str = None, + source_type: str = None, + strategy_size: str = None, + strategy_spec_file: str = None, + timeout: int = None, + **kwargs, + ) -> DetailedResponse: + """ + Create a build. + + Create a build. + + :param str project_id: The ID of the project. + :param str name: The name of the build. Use a name that is unique within + the project. + :param str output_image: The name of the image. + :param str output_secret: The secret that is required to access the image + registry. Make sure that the secret is granted with push permissions + towards the specified container registry namespace. + :param str source_url: The URL of the code repository. This field is + required if the `source_type` is `git`. If the `source_type` value is + `local`, this field must be omitted. If the repository is publicly + available you can provide a 'https' URL like + `https://github.com/IBM/CodeEngine`. If the repository requires + authentication, you need to provide a 'ssh' URL like + `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that + points to a secret of format `ssh_auth`. + :param str strategy_type: The strategy to use for building the image. + :param str source_context_dir: (optional) Option directory in the + repository that contains the buildpacks file or the Dockerfile. + :param str source_revision: (optional) Commit, tag, or branch in the source + repository to pull. This field is optional if the `source_type` is `git` + and uses the HEAD of default branch if not specified. If the `source_type` + value is `local`, this field must be omitted. + :param str source_secret: (optional) Name of the secret that is used access + the repository source. This field is optional if the `source_type` is + `git`. Additionally, if the `source_url` points to a repository that + requires authentication, the build will be created but cannot access any + source code, until this property is provided, too. If the `source_type` + value is `local`, this field must be omitted. + :param str source_type: (optional) Specifies the type of source to + determine if your build source is in a repository or based on local source + code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + :param str strategy_size: (optional) Optional size for the build, which + determines the amount of resources used. Build sizes are `small`, `medium`, + `large`, `xlarge`. + :param str strategy_spec_file: (optional) Optional path to the + specification file that is used for build strategies for building an image. + :param int timeout: (optional) The maximum amount of time, in seconds, that + can pass before the build must succeed or fail. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Build` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if name is None: + raise ValueError('name must be provided') + if output_image is None: + raise ValueError('output_image must be provided') + if output_secret is None: + raise ValueError('output_secret must be provided') + if source_url is None: + raise ValueError('source_url must be provided') + if strategy_type is None: + raise ValueError('strategy_type must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='create_build' + ) + headers.update(sdk_headers) + + data = { + 'name': name, + 'output_image': output_image, + 'output_secret': output_secret, + 'source_url': source_url, + 'strategy_type': strategy_type, + 'source_context_dir': source_context_dir, + 'source_revision': source_revision, + 'source_secret': source_secret, + 'source_type': source_type, + 'strategy_size': strategy_size, + 'strategy_spec_file': strategy_spec_file, + 'timeout': timeout, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/builds'.format(**path_param_dict) + request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def get_build(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Get a build. + + Display the details of a build. + + :param str project_id: The ID of the project. + :param str name: The name of your build. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Build` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='get_build' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/builds/{name}'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def delete_build(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Delete a build. + + Delete a build. + + :param str project_id: The ID of the project. + :param str name: The name of your build. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='delete_build' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/builds/{name}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def update_build( + self, project_id: str, name: str, if_match: str, build: 'BuildPatch', **kwargs + ) -> DetailedResponse: + """ + Update a build. + + Update a build. + + :param str project_id: The ID of the project. + :param str name: The name of your build. + :param str if_match: Version of the build settings to be updated. Specify + the version that you retrieved as entity_tag (ETag header) when reading the + build. This value helps identifying parallel usage of this API. Pass * to + indicate to update any version available. This might result in stale + updates. + :param BuildPatch build: Build patch. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Build` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + if not if_match: + raise ValueError('if_match must be provided') + if build is None: + raise ValueError('build must be provided') + if isinstance(build, BuildPatch): + build = convert_model(build) + headers = { + 'If-Match': if_match, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='update_build' + ) + headers.update(sdk_headers) + + data = json.dumps(build) + headers['content-type'] = 'application/merge-patch+json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/builds/{name}'.format(**path_param_dict) + request = self.prepare_request(method='PATCH', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def list_build_runs( + self, project_id: str, *, build_name: str = None, limit: int = None, start: str = None, **kwargs + ) -> DetailedResponse: + """ + List build runs. + + List all build runs in a project. + + :param str project_id: The ID of the project. + :param str build_name: (optional) Optional name of the build that should be + filtered for. + :param int limit: (optional) Optional maximum number of build runs per + page. + :param str start: (optional) An optional token that indicates the beginning + of the page of results to be returned. If omitted, the first page of + results is returned. This value is obtained from the 'start' query + parameter in the 'next_url' field of the operation response. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `BuildRunList` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='list_build_runs' + ) + headers.update(sdk_headers) + + params = { + 'build_name': build_name, + 'limit': limit, + 'start': start, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/build_runs'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + + response = self.send(request, **kwargs) + return response + + def create_build_run( + self, + project_id: str, + *, + build_name: str = None, + name: str = None, + output_image: str = None, + output_secret: str = None, + service_account: str = None, + source_context_dir: str = None, + source_revision: str = None, + source_secret: str = None, + source_type: str = None, + source_url: str = None, + strategy_size: str = None, + strategy_spec_file: str = None, + strategy_type: str = None, + timeout: int = None, + **kwargs, + ) -> DetailedResponse: + """ + Create a build run. + + Create a build run. + + :param str project_id: The ID of the project. + :param str build_name: (optional) Optional name of the build on which this + build run is based on. If specified, the build run will inherit the + configuration of the referenced build. If not specified, make sure to + specify at least the fields `strategy_type`, `source_url`, `output_image` + and `output_secret` to describe the build run. + :param str name: (optional) Name of the build run. This field is optional, + if the field `build_name` is specified and its value will be generated like + so: `[BUILD_NAME]-run-[timestamp with format: YYMMDD-hhmmss] if not set.`. + :param str output_image: (optional) The name of the image. + :param str output_secret: (optional) The secret that is required to access + the image registry. Make sure that the secret is granted with push + permissions towards the specified container registry namespace. + :param str service_account: (optional) Optional service account which is + used for resource control. + :param str source_context_dir: (optional) Option directory in the + repository that contains the buildpacks file or the Dockerfile. + :param str source_revision: (optional) Commit, tag, or branch in the source + repository to pull. This field is optional if the `source_type` is `git` + and uses the HEAD of default branch if not specified. If the `source_type` + value is `local`, this field must be omitted. + :param str source_secret: (optional) Name of the secret that is used access + the repository source. This field is optional if the `source_type` is + `git`. Additionally, if the `source_url` points to a repository that + requires authentication, the build will be created but cannot access any + source code, until this property is provided, too. If the `source_type` + value is `local`, this field must be omitted. + :param str source_type: (optional) Specifies the type of source to + determine if your build source is in a repository or based on local source + code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + :param str source_url: (optional) The URL of the code repository. This + field is required if the `source_type` is `git`. If the `source_type` value + is `local`, this field must be omitted. If the repository is publicly + available you can provide a 'https' URL like + `https://github.com/IBM/CodeEngine`. If the repository requires + authentication, you need to provide a 'ssh' URL like + `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that + points to a secret of format `ssh_auth`. + :param str strategy_size: (optional) Optional size for the build, which + determines the amount of resources used. Build sizes are `small`, `medium`, + `large`, `xlarge`. + :param str strategy_spec_file: (optional) Optional path to the + specification file that is used for build strategies for building an image. + :param str strategy_type: (optional) The strategy to use for building the + image. + :param int timeout: (optional) The maximum amount of time, in seconds, that + can pass before the build must succeed or fail. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `BuildRun` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='create_build_run' + ) + headers.update(sdk_headers) + + data = { + 'build_name': build_name, + 'name': name, + 'output_image': output_image, + 'output_secret': output_secret, + 'service_account': service_account, + 'source_context_dir': source_context_dir, + 'source_revision': source_revision, + 'source_secret': source_secret, + 'source_type': source_type, + 'source_url': source_url, + 'strategy_size': strategy_size, + 'strategy_spec_file': strategy_spec_file, + 'strategy_type': strategy_type, + 'timeout': timeout, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/build_runs'.format(**path_param_dict) + request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def get_build_run(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Get a build run. + + Display the details of a build run. + + :param str project_id: The ID of the project. + :param str name: The name of your build run. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `BuildRun` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='get_build_run' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/build_runs/{name}'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def delete_build_run(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Delete a build run. + + Delete a build run. + + :param str project_id: The ID of the project. + :param str name: The name of your build run. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='delete_build_run' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/build_runs/{name}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + ######################### + # Secrets and config maps + ######################### + + def list_config_maps(self, project_id: str, *, limit: int = None, start: str = None, **kwargs) -> DetailedResponse: + """ + List config maps. + + List all config maps in a project. + + :param str project_id: The ID of the project. + :param int limit: (optional) Optional maximum number of config maps per + page. + :param str start: (optional) An optional token that indicates the beginning + of the page of results to be returned. If omitted, the first page of + results is returned. This value is obtained from the 'start' query + parameter in the 'next_url' field of the operation response. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `ConfigMapList` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='list_config_maps' + ) + headers.update(sdk_headers) + + params = { + 'limit': limit, + 'start': start, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/config_maps'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + + response = self.send(request, **kwargs) + return response + + def create_config_map(self, project_id: str, name: str, *, data: dict = None, **kwargs) -> DetailedResponse: + """ + Create a config map. + + Create a config map. + + :param str project_id: The ID of the project. + :param str name: The name of the configmap. Use a name that is unique + within the project. + :param dict data: (optional) The key-value pair for the config map. Values + must be specified in `KEY=VALUE` format. Each `KEY` field must consist of + alphanumeric characters, `-`, `_` or `.` and must not be exceed a max + length of 253 characters. Each `VALUE` field can consists of any character + and must not be exceed a max length of 1048576 characters. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `ConfigMap` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if name is None: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='create_config_map' + ) + headers.update(sdk_headers) + + data = { + 'name': name, + 'data': data, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/config_maps'.format(**path_param_dict) + request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def get_config_map(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Get a config map. + + Display the details of a config map. + + :param str project_id: The ID of the project. + :param str name: The name of your configmap. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `ConfigMap` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='get_config_map' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/config_maps/{name}'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def replace_config_map( + self, project_id: str, name: str, if_match: str, *, data: dict = None, **kwargs + ) -> DetailedResponse: + """ + Update a config map. + + Update a config map. + + :param str project_id: The ID of the project. + :param str name: The name of your configmap. + :param str if_match: Version of the config map settings to be updated. + Specify the version that you retrieved as entity_tag (ETag header) when + reading the config map. This value helps identifying parallel usage of this + API. Pass * to indicate to update any version available. This might result + in stale updates. + :param dict data: (optional) The key-value pair for the config map. Values + must be specified in `KEY=VALUE` format. Each `KEY` field must consist of + alphanumeric characters, `-`, `_` or `.` and must not be exceed a max + length of 253 characters. Each `VALUE` field can consists of any character + and must not be exceed a max length of 1048576 characters. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `ConfigMap` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + if not if_match: + raise ValueError('if_match must be provided') + headers = { + 'If-Match': if_match, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='replace_config_map' + ) + headers.update(sdk_headers) + + data = { + 'data': data, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/config_maps/{name}'.format(**path_param_dict) + request = self.prepare_request(method='PUT', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def delete_config_map(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Delete a config map. + + Delete a config map. + + :param str project_id: The ID of the project. + :param str name: The name of your configmap. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='delete_config_map' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/config_maps/{name}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def list_secrets(self, project_id: str, *, limit: int = None, start: str = None, **kwargs) -> DetailedResponse: + """ + List secrets. + + List all secrets in a project. + + :param str project_id: The ID of the project. + :param int limit: (optional) Optional maximum number of secrets per page. + :param str start: (optional) An optional token that indicates the beginning + of the page of results to be returned. If omitted, the first page of + results is returned. This value is obtained from the 'start' query + parameter in the 'next_url' field of the operation response. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `SecretList` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='list_secrets' + ) + headers.update(sdk_headers) + + params = { + 'limit': limit, + 'start': start, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/secrets'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + + response = self.send(request, **kwargs) + return response + + def create_secret( + self, project_id: str, format: str, name: str, *, data: dict = None, **kwargs + ) -> DetailedResponse: + """ + Create a secret. + + Create a secret. + + :param str project_id: The ID of the project. + :param str format: Specify the format of the secret. + :param str name: The name of the secret. + :param dict data: (optional) Data container that allows to specify config + parameters and their values as a key-value map. Each key field must consist + of alphanumeric characters, `-`, `_` or `.` and must not be exceed a max + length of 253 characters. Each value field can consists of any character + and must not be exceed a max length of 1048576 characters. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Secret` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if format is None: + raise ValueError('format must be provided') + if name is None: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='create_secret' + ) + headers.update(sdk_headers) + + data = { + 'format': format, + 'name': name, + 'data': data, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id'] + path_param_values = self.encode_path_vars(project_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/secrets'.format(**path_param_dict) + request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def get_secret(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Get a secret. + + Get a secret. + + :param str project_id: The ID of the project. + :param str name: The name of your secret. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Secret` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='get_secret' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/secrets/{name}'.format(**path_param_dict) + request = self.prepare_request(method='GET', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + def replace_secret( + self, project_id: str, name: str, if_match: str, *, data: dict = None, format: str = None, **kwargs + ) -> DetailedResponse: + """ + Update a secret. + + Update a secret. + + :param str project_id: The ID of the project. + :param str name: The name of your secret. + :param str if_match: Version of the secret settings to be updated. Specify + the version that you retrieved as entity_tag (ETag header) when reading the + secret. This value helps identifying parallel usage of this API. Pass * to + indicate to update any version available. This might result in stale + updates. + :param dict data: (optional) Data container that allows to specify config + parameters and their values as a key-value map. Each key field must consist + of alphanumeric characters, `-`, `_` or `.` and must not be exceed a max + length of 253 characters. Each value field can consists of any character + and must not be exceed a max length of 1048576 characters. + :param str format: (optional) Specify the format of the secret. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Secret` object + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + if not if_match: + raise ValueError('if_match must be provided') + headers = { + 'If-Match': if_match, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='replace_secret' + ) + headers.update(sdk_headers) + + data = { + 'data': data, + 'format': format, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/secrets/{name}'.format(**path_param_dict) + request = self.prepare_request(method='PUT', url=url, headers=headers, data=data) + + response = self.send(request, **kwargs) + return response + + def delete_secret(self, project_id: str, name: str, **kwargs) -> DetailedResponse: + """ + Delete a secret. + + Delete a secret. + + :param str project_id: The ID of the project. + :param str name: The name of your secret. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not project_id: + raise ValueError('project_id must be provided') + if not name: + raise ValueError('name must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V2', operation_id='delete_secret' + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['project_id', 'name'] + path_param_values = self.encode_path_vars(project_id, name) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/projects/{project_id}/secrets/{name}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', url=url, headers=headers) + + response = self.send(request, **kwargs) + return response + + +############################################################################## +# Models +############################################################################## + + +class App: + """ + App is the response model for app resources. + + :attr str created_at: The date when the resource was created. + :attr str endpoint: (optional) Optional URL to invoke app. Depending on + visibility this is accessible publicly ot in the private network only. Empty in + case 'managed_domain_mappings' is set to 'local'. + :attr str endpoint_internal: (optional) URL to app that is only visible within + the project. + :attr str entity_tag: The version of the job instance, which is used to achieve + optimistic locking. + :attr str href: When you provision a new app, a URL is created identifying the + location of the instance. + :attr str id: The identifier of the resource. + :attr int image_port: (optional) Optional port the app listens on. While the app + will always be exposed via port `443` for end users, this port is used to + connect to the port that is exposed by the container image. + :attr str image_reference: The name of the image that is used for this job. The + format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and `TAG` are + optional. If `REGISTRY` is not specified, the default is `docker.io`. If `TAG` + is not specified, the default is `latest`. If the image reference points to a + registry that requires authentication, make sure to also specify the property + `image_secret`. + :attr str image_secret: (optional) Optional name of the image registry access + secret. The image registry access secret is used to authenticate with a private + registry when you download the container image. If the image reference points to + a registry that requires authentication, the app will be created but cannot + reach the ready status, until this property is provided, too. + :attr str managed_domain_mappings: Optional value controlling which of the + system managed domain mappings will be setup for the application. Valid values + are 'local_public', 'local_private' and 'local'. Visibility can only be + 'local_private' if the project supports application private visibility. + :attr str name: The name of the app. + :attr str project_id: The ID of the project the resource is located in. + :attr str resource_type: The type of the app. + :attr List[str] run_arguments: Optional arguments for the app that are passed to + start the container. If not specified an empty string array will be applied and + the arguments specified by the container image, will be used to start the + container. + :attr int run_as_user: (optional) Optional user ID (UID) to run the app (e.g., + `1001`). + :attr List[str] run_commands: Optional commands for the app that are passed to + start the container. If not specified an empty string array will be applied and + the command specified by the container image, will be used to start the + container. + :attr List[EnvVar] run_env_variables: References to config maps, secrets or a + literal values, which are exposed as environment variables in the application. + :attr str run_service_account: (optional) Optional name of the service account. + For built-in service accounts, you can use the shortened names `manager` , + `none`, `reader`, and `writer`. + :attr List[VolumeMount] run_volume_mounts: Mounts of config maps or secrets. + :attr int scale_concurrency: (optional) Optional maximum number of requests that + can be processed concurrently per instance. + :attr int scale_concurrency_target: (optional) Optional threshold of concurrent + requests per instance at which one or more additional instances are created. Use + this value to scale up instances based on concurrent number of requests. This + option defaults to the value of the `scale_concurrency` option, if not + specified. + :attr str scale_cpu_limit: Optional number of CPU set for the instance of the + app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :attr str scale_ephemeral_storage_limit: Optional amount of ephemeral storage to + set for the instance of the app. The amount specified as ephemeral storage, must + not exceed the amount of `scale_memory_limit`. The units for specifying + ephemeral storage are Megabyte (M) or Gigabyte (G), whereas G and M are the + shorthand expressions for GB and MB. For more information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_initial_instances: (optional) Optional initial number of + instances that are created upon app creation or app update. + :attr int scale_max_instances: Optional maximum number of instances for this + app. If you set this value to `0`, this property does not set a upper scaling + limit. However, the app scaling is still limited by the project quota for + instances. See [Limits and quotas for Code + Engine](https://cloud.ibm.com/docs/codeengine?topic=codeengine-limits). + :attr str scale_memory_limit: Optional amount of memory set for the instance of + the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G and + M are the shorthand expressions for GB and MB. For more information see [Units + of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_min_instances: Optional minimum number of instances for this + app. If you set this value to `0`, the app will scale down to zero, if not hit + by any request for some time. + :attr int scale_request_timeout: Optional amount of time in seconds that is + allowed for a running app to respond to a request. + :attr str status: The current status of the app. + :attr AppStatus status_details: (optional) The detailed status of the + application. + """ + + def __init__( + self, + created_at: str, + entity_tag: str, + href: str, + id: str, + image_reference: str, + managed_domain_mappings: str, + name: str, + project_id: str, + resource_type: str, + run_arguments: List[str], + run_commands: List[str], + run_env_variables: List['EnvVar'], + run_volume_mounts: List['VolumeMount'], + scale_cpu_limit: str, + scale_ephemeral_storage_limit: str, + scale_max_instances: int, + scale_memory_limit: str, + scale_min_instances: int, + scale_request_timeout: int, + status: str, + *, + endpoint: str = None, + endpoint_internal: str = None, + image_port: int = None, + image_secret: str = None, + run_as_user: int = None, + run_service_account: str = None, + scale_concurrency: int = None, + scale_concurrency_target: int = None, + scale_initial_instances: int = None, + status_details: 'AppStatus' = None, + ) -> None: + """ + Initialize a App object. + + :param str created_at: The date when the resource was created. + :param str entity_tag: The version of the job instance, which is used to + achieve optimistic locking. + :param str href: When you provision a new app, a URL is created + identifying the location of the instance. + :param str id: The identifier of the resource. + :param str image_reference: The name of the image that is used for this + job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and + `TAG` are optional. If `REGISTRY` is not specified, the default is + `docker.io`. If `TAG` is not specified, the default is `latest`. If the + image reference points to a registry that requires authentication, make + sure to also specify the property `image_secret`. + :param str managed_domain_mappings: Optional value controlling which of the + system managed domain mappings will be setup for the application. Valid + values are 'local_public', 'local_private' and 'local'. Visibility can only + be 'local_private' if the project supports application private visibility. + :param str name: The name of the app. + :param str project_id: The ID of the project the resource is located in. + :param str resource_type: The type of the app. + :param List[str] run_arguments: Optional arguments for the app that are + passed to start the container. If not specified an empty string array will + be applied and the arguments specified by the container image, will be used + to start the container. + :param List[str] run_commands: Optional commands for the app that are + passed to start the container. If not specified an empty string array will + be applied and the command specified by the container image, will be used + to start the container. + :param List[EnvVar] run_env_variables: References to config maps, secrets + or a literal values, which are exposed as environment variables in the + application. + :param List[VolumeMount] run_volume_mounts: Mounts of config maps or + secrets. + :param str scale_cpu_limit: Optional number of CPU set for the instance of + the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :param str scale_ephemeral_storage_limit: Optional amount of ephemeral + storage to set for the instance of the app. The amount specified as + ephemeral storage, must not exceed the amount of `scale_memory_limit`. The + units for specifying ephemeral storage are Megabyte (M) or Gigabyte (G), + whereas G and M are the shorthand expressions for GB and MB. For more + information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_max_instances: Optional maximum number of instances for + this app. If you set this value to `0`, this property does not set a upper + scaling limit. However, the app scaling is still limited by the project + quota for instances. See [Limits and quotas for Code + Engine](https://cloud.ibm.com/docs/codeengine?topic=codeengine-limits). + :param str scale_memory_limit: Optional amount of memory set for the + instance of the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G + and M are the shorthand expressions for GB and MB. For more information see + [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_min_instances: Optional minimum number of instances for + this app. If you set this value to `0`, the app will scale down to zero, if + not hit by any request for some time. + :param int scale_request_timeout: Optional amount of time in seconds that + is allowed for a running app to respond to a request. + :param str status: The current status of the app. + :param str endpoint: (optional) Optional URL to invoke app. Depending on + visibility this is accessible publicly ot in the private network only. + Empty in case 'managed_domain_mappings' is set to 'local'. + :param str endpoint_internal: (optional) URL to app that is only visible + within the project. + :param int image_port: (optional) Optional port the app listens on. While + the app will always be exposed via port `443` for end users, this port is + used to connect to the port that is exposed by the container image. + :param str image_secret: (optional) Optional name of the image registry + access secret. The image registry access secret is used to authenticate + with a private registry when you download the container image. If the image + reference points to a registry that requires authentication, the app will + be created but cannot reach the ready status, until this property is + provided, too. + :param int run_as_user: (optional) Optional user ID (UID) to run the app + (e.g., `1001`). + :param str run_service_account: (optional) Optional name of the service + account. For built-in service accounts, you can use the shortened names + `manager` , `none`, `reader`, and `writer`. + :param int scale_concurrency: (optional) Optional maximum number of + requests that can be processed concurrently per instance. + :param int scale_concurrency_target: (optional) Optional threshold of + concurrent requests per instance at which one or more additional instances + are created. Use this value to scale up instances based on concurrent + number of requests. This option defaults to the value of the + `scale_concurrency` option, if not specified. + :param int scale_initial_instances: (optional) Optional initial number of + instances that are created upon app creation or app update. + :param AppStatus status_details: (optional) The detailed status of the + application. + """ + self.created_at = created_at + self.endpoint = endpoint + self.endpoint_internal = endpoint_internal + self.entity_tag = entity_tag + self.href = href + self.id = id + self.image_port = image_port + self.image_reference = image_reference + self.image_secret = image_secret + self.managed_domain_mappings = managed_domain_mappings + self.name = name + self.project_id = project_id + self.resource_type = resource_type + self.run_arguments = run_arguments + self.run_as_user = run_as_user + self.run_commands = run_commands + self.run_env_variables = run_env_variables + self.run_service_account = run_service_account + self.run_volume_mounts = run_volume_mounts + self.scale_concurrency = scale_concurrency + self.scale_concurrency_target = scale_concurrency_target + self.scale_cpu_limit = scale_cpu_limit + self.scale_ephemeral_storage_limit = scale_ephemeral_storage_limit + self.scale_initial_instances = scale_initial_instances + self.scale_max_instances = scale_max_instances + self.scale_memory_limit = scale_memory_limit + self.scale_min_instances = scale_min_instances + self.scale_request_timeout = scale_request_timeout + self.status = status + self.status_details = status_details + + @classmethod + def from_dict(cls, _dict: Dict) -> 'App': + """Initialize a App object from a json dictionary.""" + args = {} + if 'created_at' in _dict: + args['created_at'] = _dict.get('created_at') + else: + raise ValueError('Required property \'created_at\' not present in App JSON') + if 'endpoint' in _dict: + args['endpoint'] = _dict.get('endpoint') + if 'endpoint_internal' in _dict: + args['endpoint_internal'] = _dict.get('endpoint_internal') + if 'entity_tag' in _dict: + args['entity_tag'] = _dict.get('entity_tag') + else: + raise ValueError('Required property \'entity_tag\' not present in App JSON') + if 'href' in _dict: + args['href'] = _dict.get('href') + else: + raise ValueError('Required property \'href\' not present in App JSON') + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in App JSON') + if 'image_port' in _dict: + args['image_port'] = _dict.get('image_port') + if 'image_reference' in _dict: + args['image_reference'] = _dict.get('image_reference') + else: + raise ValueError('Required property \'image_reference\' not present in App JSON') + if 'image_secret' in _dict: + args['image_secret'] = _dict.get('image_secret') + if 'managed_domain_mappings' in _dict: + args['managed_domain_mappings'] = _dict.get('managed_domain_mappings') + else: + raise ValueError('Required property \'managed_domain_mappings\' not present in App JSON') + if 'name' in _dict: + args['name'] = _dict.get('name') + else: + raise ValueError('Required property \'name\' not present in App JSON') + if 'project_id' in _dict: + args['project_id'] = _dict.get('project_id') + else: + raise ValueError('Required property \'project_id\' not present in App JSON') + if 'resource_type' in _dict: + args['resource_type'] = _dict.get('resource_type') + else: + raise ValueError('Required property \'resource_type\' not present in App JSON') + if 'run_arguments' in _dict: + args['run_arguments'] = _dict.get('run_arguments') + else: + raise ValueError('Required property \'run_arguments\' not present in App JSON') + if 'run_as_user' in _dict: + args['run_as_user'] = _dict.get('run_as_user') + if 'run_commands' in _dict: + args['run_commands'] = _dict.get('run_commands') + else: + raise ValueError('Required property \'run_commands\' not present in App JSON') + if 'run_env_variables' in _dict: + args['run_env_variables'] = [EnvVar.from_dict(v) for v in _dict.get('run_env_variables')] + else: + raise ValueError('Required property \'run_env_variables\' not present in App JSON') + if 'run_service_account' in _dict: + args['run_service_account'] = _dict.get('run_service_account') + if 'run_volume_mounts' in _dict: + args['run_volume_mounts'] = [VolumeMount.from_dict(v) for v in _dict.get('run_volume_mounts')] + else: + raise ValueError('Required property \'run_volume_mounts\' not present in App JSON') + if 'scale_concurrency' in _dict: + args['scale_concurrency'] = _dict.get('scale_concurrency') + if 'scale_concurrency_target' in _dict: + args['scale_concurrency_target'] = _dict.get('scale_concurrency_target') + if 'scale_cpu_limit' in _dict: + args['scale_cpu_limit'] = _dict.get('scale_cpu_limit') + else: + raise ValueError('Required property \'scale_cpu_limit\' not present in App JSON') + if 'scale_ephemeral_storage_limit' in _dict: + args['scale_ephemeral_storage_limit'] = _dict.get('scale_ephemeral_storage_limit') + else: + raise ValueError('Required property \'scale_ephemeral_storage_limit\' not present in App JSON') + if 'scale_initial_instances' in _dict: + args['scale_initial_instances'] = _dict.get('scale_initial_instances') + if 'scale_max_instances' in _dict: + args['scale_max_instances'] = _dict.get('scale_max_instances') + else: + raise ValueError('Required property \'scale_max_instances\' not present in App JSON') + if 'scale_memory_limit' in _dict: + args['scale_memory_limit'] = _dict.get('scale_memory_limit') + else: + raise ValueError('Required property \'scale_memory_limit\' not present in App JSON') + if 'scale_min_instances' in _dict: + args['scale_min_instances'] = _dict.get('scale_min_instances') + else: + raise ValueError('Required property \'scale_min_instances\' not present in App JSON') + if 'scale_request_timeout' in _dict: + args['scale_request_timeout'] = _dict.get('scale_request_timeout') + else: + raise ValueError('Required property \'scale_request_timeout\' not present in App JSON') + if 'status' in _dict: + args['status'] = _dict.get('status') + else: + raise ValueError('Required property \'status\' not present in App JSON') + if 'status_details' in _dict: + args['status_details'] = AppStatus.from_dict(_dict.get('status_details')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a App object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'created_at') and self.created_at is not None: + _dict['created_at'] = self.created_at + if hasattr(self, 'endpoint') and self.endpoint is not None: + _dict['endpoint'] = self.endpoint + if hasattr(self, 'endpoint_internal') and self.endpoint_internal is not None: + _dict['endpoint_internal'] = self.endpoint_internal + if hasattr(self, 'entity_tag') and self.entity_tag is not None: + _dict['entity_tag'] = self.entity_tag + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'image_port') and self.image_port is not None: + _dict['image_port'] = self.image_port + if hasattr(self, 'image_reference') and self.image_reference is not None: + _dict['image_reference'] = self.image_reference + if hasattr(self, 'image_secret') and self.image_secret is not None: + _dict['image_secret'] = self.image_secret + if hasattr(self, 'managed_domain_mappings') and self.managed_domain_mappings is not None: + _dict['managed_domain_mappings'] = self.managed_domain_mappings + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'project_id') and self.project_id is not None: + _dict['project_id'] = self.project_id + if hasattr(self, 'resource_type') and self.resource_type is not None: + _dict['resource_type'] = self.resource_type + if hasattr(self, 'run_arguments') and self.run_arguments is not None: + _dict['run_arguments'] = self.run_arguments + if hasattr(self, 'run_as_user') and self.run_as_user is not None: + _dict['run_as_user'] = self.run_as_user + if hasattr(self, 'run_commands') and self.run_commands is not None: + _dict['run_commands'] = self.run_commands + if hasattr(self, 'run_env_variables') and self.run_env_variables is not None: + run_env_variables_list = [] + for v in self.run_env_variables: + if isinstance(v, dict): + run_env_variables_list.append(v) + else: + run_env_variables_list.append(v.to_dict()) + _dict['run_env_variables'] = run_env_variables_list + if hasattr(self, 'run_service_account') and self.run_service_account is not None: + _dict['run_service_account'] = self.run_service_account + if hasattr(self, 'run_volume_mounts') and self.run_volume_mounts is not None: + run_volume_mounts_list = [] + for v in self.run_volume_mounts: + if isinstance(v, dict): + run_volume_mounts_list.append(v) + else: + run_volume_mounts_list.append(v.to_dict()) + _dict['run_volume_mounts'] = run_volume_mounts_list + if hasattr(self, 'scale_concurrency') and self.scale_concurrency is not None: + _dict['scale_concurrency'] = self.scale_concurrency + if hasattr(self, 'scale_concurrency_target') and self.scale_concurrency_target is not None: + _dict['scale_concurrency_target'] = self.scale_concurrency_target + if hasattr(self, 'scale_cpu_limit') and self.scale_cpu_limit is not None: + _dict['scale_cpu_limit'] = self.scale_cpu_limit + if hasattr(self, 'scale_ephemeral_storage_limit') and self.scale_ephemeral_storage_limit is not None: + _dict['scale_ephemeral_storage_limit'] = self.scale_ephemeral_storage_limit + if hasattr(self, 'scale_initial_instances') and self.scale_initial_instances is not None: + _dict['scale_initial_instances'] = self.scale_initial_instances + if hasattr(self, 'scale_max_instances') and self.scale_max_instances is not None: + _dict['scale_max_instances'] = self.scale_max_instances + if hasattr(self, 'scale_memory_limit') and self.scale_memory_limit is not None: + _dict['scale_memory_limit'] = self.scale_memory_limit + if hasattr(self, 'scale_min_instances') and self.scale_min_instances is not None: + _dict['scale_min_instances'] = self.scale_min_instances + if hasattr(self, 'scale_request_timeout') and self.scale_request_timeout is not None: + _dict['scale_request_timeout'] = self.scale_request_timeout + if hasattr(self, 'status') and self.status is not None: + _dict['status'] = self.status + if hasattr(self, 'status_details') and self.status_details is not None: + if isinstance(self.status_details, dict): + _dict['status_details'] = self.status_details + else: + _dict['status_details'] = self.status_details.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this App object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'App') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'App') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ManagedDomainMappingsEnum(str, Enum): + """ + Optional value controlling which of the system managed domain mappings will be + setup for the application. Valid values are 'local_public', 'local_private' and + 'local'. Visibility can only be 'local_private' if the project supports + application private visibility. + """ + + LOCAL = 'local' + LOCAL_PRIVATE = 'local_private' + LOCAL_PUBLIC = 'local_public' + + class ResourceTypeEnum(str, Enum): + """ + The type of the app. + """ + + APP_V2 = 'app_v2' + + class RunServiceAccountEnum(str, Enum): + """ + Optional name of the service account. For built-in service accounts, you can use + the shortened names `manager` , `none`, `reader`, and `writer`. + """ + + DEFAULT = 'default' + MANAGER = 'manager' + READER = 'reader' + WRITER = 'writer' + NONE = 'none' + + class StatusEnum(str, Enum): + """ + The current status of the app. + """ + + READY = 'ready' + DEPLOYING = 'deploying' + FAILED = 'failed' + WARNING = 'warning' + + +class AppList: + """ + Contains a list of apps and pagination information. + + :attr List[App] apps: List of all apps. + :attr ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :attr int limit: Maximum number of resources per page. + :attr ListNextMetadata next: (optional) Describes properties needed to retrieve + the next page of a result list. + """ + + def __init__( + self, apps: List['App'], limit: int, *, first: 'ListFirstMetadata' = None, next: 'ListNextMetadata' = None + ) -> None: + """ + Initialize a AppList object. + + :param List[App] apps: List of all apps. + :param int limit: Maximum number of resources per page. + :param ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :param ListNextMetadata next: (optional) Describes properties needed to + retrieve the next page of a result list. + """ + self.apps = apps + self.first = first + self.limit = limit + self.next = next + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AppList': + """Initialize a AppList object from a json dictionary.""" + args = {} + if 'apps' in _dict: + args['apps'] = [App.from_dict(v) for v in _dict.get('apps')] + else: + raise ValueError('Required property \'apps\' not present in AppList JSON') + if 'first' in _dict: + args['first'] = ListFirstMetadata.from_dict(_dict.get('first')) + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in AppList JSON') + if 'next' in _dict: + args['next'] = ListNextMetadata.from_dict(_dict.get('next')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a AppList object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'apps') and self.apps is not None: + apps_list = [] + for v in self.apps: + if isinstance(v, dict): + apps_list.append(v) + else: + apps_list.append(v.to_dict()) + _dict['apps'] = apps_list + if hasattr(self, 'first') and self.first is not None: + if isinstance(self.first, dict): + _dict['first'] = self.first + else: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'next') and self.next is not None: + if isinstance(self.next, dict): + _dict['next'] = self.next + else: + _dict['next'] = self.next.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this AppList object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'AppList') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'AppList') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class AppPatch: + """ + App is the request model for app update operations. + + :attr int image_port: (optional) Optional port the app listens on. While the app + will always be exposed via port `443` for end users, this port is used to + connect to the port that is exposed by the container image. + :attr str image_reference: (optional) The name of the image that is used for + this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and + `TAG` are optional. If `REGISTRY` is not specified, the default is `docker.io`. + If `TAG` is not specified, the default is `latest`. If the image reference + points to a registry that requires authentication, make sure to also specify the + property `image_secret`. + :attr str image_secret: (optional) Optional name of the image registry access + secret. The image registry access secret is used to authenticate with a private + registry when you download the container image. If the image reference points to + a registry that requires authentication, the app will be created but cannot + reach the ready status, until this property is provided, too. + :attr str managed_domain_mappings: (optional) Optional value controlling which + of the system managed domain mappings will be setup for the application. Valid + values are 'local_public', 'local_private' and 'local'. Visibility can only be + 'local_private' if the project supports application private visibility. + :attr List[str] run_arguments: (optional) Optional arguments for the app that + are passed to start the container. If not specified an empty string array will + be applied and the arguments specified by the container image, will be used to + start the container. + :attr int run_as_user: (optional) Optional user ID (UID) to run the app (e.g., + `1001`). + :attr List[str] run_commands: (optional) Optional commands for the app that are + passed to start the container. If not specified an empty string array will be + applied and the command specified by the container image, will be used to start + the container. + :attr List[EnvVarPrototype] run_env_variables: (optional) Optional references to + config maps, secrets or a literal values. + :attr str run_service_account: (optional) Optional name of the service account. + For built-in service accounts, you can use the shortened names `manager` , + `none`, `reader`, and `writer`. + :attr List[VolumeMountPrototype] run_volume_mounts: (optional) Optional mounts + of config maps or a secrets. In case this is provided, existing + `run_volume_mounts` will be overwritten. + :attr int scale_concurrency: (optional) Optional maximum number of requests that + can be processed concurrently per instance. + :attr int scale_concurrency_target: (optional) Optional threshold of concurrent + requests per instance at which one or more additional instances are created. Use + this value to scale up instances based on concurrent number of requests. This + option defaults to the value of the `scale_concurrency` option, if not + specified. + :attr str scale_cpu_limit: (optional) Optional number of CPU set for the + instance of the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :attr str scale_ephemeral_storage_limit: (optional) Optional amount of ephemeral + storage to set for the instance of the app. The amount specified as ephemeral + storage, must not exceed the amount of `scale_memory_limit`. The units for + specifying ephemeral storage are Megabyte (M) or Gigabyte (G), whereas G and M + are the shorthand expressions for GB and MB. For more information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_initial_instances: (optional) Optional initial number of + instances that are created upon app creation or app update. + :attr int scale_max_instances: (optional) Optional maximum number of instances + for this app. If you set this value to `0`, this property does not set a upper + scaling limit. However, the app scaling is still limited by the project quota + for instances. See [Limits and quotas for Code + Engine](https://cloud.ibm.com/docs/codeengine?topic=codeengine-limits). + :attr str scale_memory_limit: (optional) Optional amount of memory set for the + instance of the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G and + M are the shorthand expressions for GB and MB. For more information see [Units + of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_min_instances: (optional) Optional minimum number of instances + for this app. If you set this value to `0`, the app will scale down to zero, if + not hit by any request for some time. + :attr int scale_request_timeout: (optional) Optional amount of time in seconds + that is allowed for a running app to respond to a request. + """ + + def __init__( + self, + *, + image_port: int = None, + image_reference: str = None, + image_secret: str = None, + managed_domain_mappings: str = None, + run_arguments: List[str] = None, + run_as_user: int = None, + run_commands: List[str] = None, + run_env_variables: List['EnvVarPrototype'] = None, + run_service_account: str = None, + run_volume_mounts: List['VolumeMountPrototype'] = None, + scale_concurrency: int = None, + scale_concurrency_target: int = None, + scale_cpu_limit: str = None, + scale_ephemeral_storage_limit: str = None, + scale_initial_instances: int = None, + scale_max_instances: int = None, + scale_memory_limit: str = None, + scale_min_instances: int = None, + scale_request_timeout: int = None, + ) -> None: + """ + Initialize a AppPatch object. + + :param int image_port: (optional) Optional port the app listens on. While + the app will always be exposed via port `443` for end users, this port is + used to connect to the port that is exposed by the container image. + :param str image_reference: (optional) The name of the image that is used + for this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where + `REGISTRY` and `TAG` are optional. If `REGISTRY` is not specified, the + default is `docker.io`. If `TAG` is not specified, the default is `latest`. + If the image reference points to a registry that requires authentication, + make sure to also specify the property `image_secret`. + :param str image_secret: (optional) Optional name of the image registry + access secret. The image registry access secret is used to authenticate + with a private registry when you download the container image. If the image + reference points to a registry that requires authentication, the app will + be created but cannot reach the ready status, until this property is + provided, too. + :param str managed_domain_mappings: (optional) Optional value controlling + which of the system managed domain mappings will be setup for the + application. Valid values are 'local_public', 'local_private' and 'local'. + Visibility can only be 'local_private' if the project supports application + private visibility. + :param List[str] run_arguments: (optional) Optional arguments for the app + that are passed to start the container. If not specified an empty string + array will be applied and the arguments specified by the container image, + will be used to start the container. + :param int run_as_user: (optional) Optional user ID (UID) to run the app + (e.g., `1001`). + :param List[str] run_commands: (optional) Optional commands for the app + that are passed to start the container. If not specified an empty string + array will be applied and the command specified by the container image, + will be used to start the container. + :param List[EnvVarPrototype] run_env_variables: (optional) Optional + references to config maps, secrets or a literal values. + :param str run_service_account: (optional) Optional name of the service + account. For built-in service accounts, you can use the shortened names + `manager` , `none`, `reader`, and `writer`. + :param List[VolumeMountPrototype] run_volume_mounts: (optional) Optional + mounts of config maps or a secrets. In case this is provided, existing + `run_volume_mounts` will be overwritten. + :param int scale_concurrency: (optional) Optional maximum number of + requests that can be processed concurrently per instance. + :param int scale_concurrency_target: (optional) Optional threshold of + concurrent requests per instance at which one or more additional instances + are created. Use this value to scale up instances based on concurrent + number of requests. This option defaults to the value of the + `scale_concurrency` option, if not specified. + :param str scale_cpu_limit: (optional) Optional number of CPU set for the + instance of the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :param str scale_ephemeral_storage_limit: (optional) Optional amount of + ephemeral storage to set for the instance of the app. The amount specified + as ephemeral storage, must not exceed the amount of `scale_memory_limit`. + The units for specifying ephemeral storage are Megabyte (M) or Gigabyte + (G), whereas G and M are the shorthand expressions for GB and MB. For more + information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_initial_instances: (optional) Optional initial number of + instances that are created upon app creation or app update. + :param int scale_max_instances: (optional) Optional maximum number of + instances for this app. If you set this value to `0`, this property does + not set a upper scaling limit. However, the app scaling is still limited by + the project quota for instances. See [Limits and quotas for Code + Engine](https://cloud.ibm.com/docs/codeengine?topic=codeengine-limits). + :param str scale_memory_limit: (optional) Optional amount of memory set for + the instance of the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G + and M are the shorthand expressions for GB and MB. For more information see + [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_min_instances: (optional) Optional minimum number of + instances for this app. If you set this value to `0`, the app will scale + down to zero, if not hit by any request for some time. + :param int scale_request_timeout: (optional) Optional amount of time in + seconds that is allowed for a running app to respond to a request. + """ + self.image_port = image_port + self.image_reference = image_reference + self.image_secret = image_secret + self.managed_domain_mappings = managed_domain_mappings + self.run_arguments = run_arguments + self.run_as_user = run_as_user + self.run_commands = run_commands + self.run_env_variables = run_env_variables + self.run_service_account = run_service_account + self.run_volume_mounts = run_volume_mounts + self.scale_concurrency = scale_concurrency + self.scale_concurrency_target = scale_concurrency_target + self.scale_cpu_limit = scale_cpu_limit + self.scale_ephemeral_storage_limit = scale_ephemeral_storage_limit + self.scale_initial_instances = scale_initial_instances + self.scale_max_instances = scale_max_instances + self.scale_memory_limit = scale_memory_limit + self.scale_min_instances = scale_min_instances + self.scale_request_timeout = scale_request_timeout + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AppPatch': + """Initialize a AppPatch object from a json dictionary.""" + args = {} + if 'image_port' in _dict: + args['image_port'] = _dict.get('image_port') + if 'image_reference' in _dict: + args['image_reference'] = _dict.get('image_reference') + if 'image_secret' in _dict: + args['image_secret'] = _dict.get('image_secret') + if 'managed_domain_mappings' in _dict: + args['managed_domain_mappings'] = _dict.get('managed_domain_mappings') + if 'run_arguments' in _dict: + args['run_arguments'] = _dict.get('run_arguments') + if 'run_as_user' in _dict: + args['run_as_user'] = _dict.get('run_as_user') + if 'run_commands' in _dict: + args['run_commands'] = _dict.get('run_commands') + if 'run_env_variables' in _dict: + args['run_env_variables'] = [EnvVarPrototype.from_dict(v) for v in _dict.get('run_env_variables')] + if 'run_service_account' in _dict: + args['run_service_account'] = _dict.get('run_service_account') + if 'run_volume_mounts' in _dict: + args['run_volume_mounts'] = [VolumeMountPrototype.from_dict(v) for v in _dict.get('run_volume_mounts')] + if 'scale_concurrency' in _dict: + args['scale_concurrency'] = _dict.get('scale_concurrency') + if 'scale_concurrency_target' in _dict: + args['scale_concurrency_target'] = _dict.get('scale_concurrency_target') + if 'scale_cpu_limit' in _dict: + args['scale_cpu_limit'] = _dict.get('scale_cpu_limit') + if 'scale_ephemeral_storage_limit' in _dict: + args['scale_ephemeral_storage_limit'] = _dict.get('scale_ephemeral_storage_limit') + if 'scale_initial_instances' in _dict: + args['scale_initial_instances'] = _dict.get('scale_initial_instances') + if 'scale_max_instances' in _dict: + args['scale_max_instances'] = _dict.get('scale_max_instances') + if 'scale_memory_limit' in _dict: + args['scale_memory_limit'] = _dict.get('scale_memory_limit') + if 'scale_min_instances' in _dict: + args['scale_min_instances'] = _dict.get('scale_min_instances') + if 'scale_request_timeout' in _dict: + args['scale_request_timeout'] = _dict.get('scale_request_timeout') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a AppPatch object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'image_port') and self.image_port is not None: + _dict['image_port'] = self.image_port + if hasattr(self, 'image_reference') and self.image_reference is not None: + _dict['image_reference'] = self.image_reference + if hasattr(self, 'image_secret') and self.image_secret is not None: + _dict['image_secret'] = self.image_secret + if hasattr(self, 'managed_domain_mappings') and self.managed_domain_mappings is not None: + _dict['managed_domain_mappings'] = self.managed_domain_mappings + if hasattr(self, 'run_arguments') and self.run_arguments is not None: + _dict['run_arguments'] = self.run_arguments + if hasattr(self, 'run_as_user') and self.run_as_user is not None: + _dict['run_as_user'] = self.run_as_user + if hasattr(self, 'run_commands') and self.run_commands is not None: + _dict['run_commands'] = self.run_commands + if hasattr(self, 'run_env_variables') and self.run_env_variables is not None: + run_env_variables_list = [] + for v in self.run_env_variables: + if isinstance(v, dict): + run_env_variables_list.append(v) + else: + run_env_variables_list.append(v.to_dict()) + _dict['run_env_variables'] = run_env_variables_list + if hasattr(self, 'run_service_account') and self.run_service_account is not None: + _dict['run_service_account'] = self.run_service_account + if hasattr(self, 'run_volume_mounts') and self.run_volume_mounts is not None: + run_volume_mounts_list = [] + for v in self.run_volume_mounts: + if isinstance(v, dict): + run_volume_mounts_list.append(v) + else: + run_volume_mounts_list.append(v.to_dict()) + _dict['run_volume_mounts'] = run_volume_mounts_list + if hasattr(self, 'scale_concurrency') and self.scale_concurrency is not None: + _dict['scale_concurrency'] = self.scale_concurrency + if hasattr(self, 'scale_concurrency_target') and self.scale_concurrency_target is not None: + _dict['scale_concurrency_target'] = self.scale_concurrency_target + if hasattr(self, 'scale_cpu_limit') and self.scale_cpu_limit is not None: + _dict['scale_cpu_limit'] = self.scale_cpu_limit + if hasattr(self, 'scale_ephemeral_storage_limit') and self.scale_ephemeral_storage_limit is not None: + _dict['scale_ephemeral_storage_limit'] = self.scale_ephemeral_storage_limit + if hasattr(self, 'scale_initial_instances') and self.scale_initial_instances is not None: + _dict['scale_initial_instances'] = self.scale_initial_instances + if hasattr(self, 'scale_max_instances') and self.scale_max_instances is not None: + _dict['scale_max_instances'] = self.scale_max_instances + if hasattr(self, 'scale_memory_limit') and self.scale_memory_limit is not None: + _dict['scale_memory_limit'] = self.scale_memory_limit + if hasattr(self, 'scale_min_instances') and self.scale_min_instances is not None: + _dict['scale_min_instances'] = self.scale_min_instances + if hasattr(self, 'scale_request_timeout') and self.scale_request_timeout is not None: + _dict['scale_request_timeout'] = self.scale_request_timeout + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this AppPatch object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'AppPatch') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'AppPatch') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ManagedDomainMappingsEnum(str, Enum): + """ + Optional value controlling which of the system managed domain mappings will be + setup for the application. Valid values are 'local_public', 'local_private' and + 'local'. Visibility can only be 'local_private' if the project supports + application private visibility. + """ + + LOCAL = 'local' + LOCAL_PRIVATE = 'local_private' + LOCAL_PUBLIC = 'local_public' + + class RunServiceAccountEnum(str, Enum): + """ + Optional name of the service account. For built-in service accounts, you can use + the shortened names `manager` , `none`, `reader`, and `writer`. + """ + + DEFAULT = 'default' + MANAGER = 'manager' + READER = 'reader' + WRITER = 'writer' + NONE = 'none' + + +class AppRevision: + """ + AppRevision is the response model for app revision resources. + + :attr str app_name: (optional) Name of the associated app. + :attr str created_at: The date when the resource was created. + :attr str href: When you provision a new revision, a URL is created identifying + the location of the instance. + :attr str id: The identifier of the resource. + :attr int image_port: (optional) Optional port the app listens on. While the app + will always be exposed via port `443` for end users, this port is used to + connect to the port that is exposed by the container image. + :attr str image_reference: The name of the image that is used for this job. The + format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and `TAG` are + optional. If `REGISTRY` is not specified, the default is `docker.io`. If `TAG` + is not specified, the default is `latest`. If the image reference points to a + registry that requires authentication, make sure to also specify the property + `image_secret`. + :attr str image_secret: (optional) Optional name of the image registry access + secret. The image registry access secret is used to authenticate with a private + registry when you download the container image. If the image reference points to + a registry that requires authentication, the app will be created but cannot + reach the ready status, until this property is provided, too. + :attr str name: The name of the app revison. + :attr str project_id: The ID of the project the resource is located in. + :attr str resource_type: The type of the app revision. + :attr List[str] run_arguments: Optional arguments for the app that are passed to + start the container. If not specified an empty string array will be applied and + the arguments specified by the container image, will be used to start the + container. + :attr int run_as_user: (optional) Optional user ID (UID) to run the app (e.g., + `1001`). + :attr List[str] run_commands: Optional commands for the app that are passed to + start the container. If not specified an empty string array will be applied and + the command specified by the container image, will be used to start the + container. + :attr List[EnvVar] run_env_variables: References to config maps, secrets or a + literal values, which are exposed as environment variables in the application. + :attr str run_service_account: (optional) Optional name of the service account. + For built-in service accounts, you can use the shortened names `manager` , + `none`, `reader`, and `writer`. + :attr List[VolumeMount] run_volume_mounts: Mounts of config maps or secrets. + :attr int scale_concurrency: (optional) Optional maximum number of requests that + can be processed concurrently per instance. + :attr int scale_concurrency_target: (optional) Optional threshold of concurrent + requests per instance at which one or more additional instances are created. Use + this value to scale up instances based on concurrent number of requests. This + option defaults to the value of the `scale_concurrency` option, if not + specified. + :attr str scale_cpu_limit: Optional number of CPU set for the instance of the + app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :attr str scale_ephemeral_storage_limit: Optional amount of ephemeral storage to + set for the instance of the app. The amount specified as ephemeral storage, must + not exceed the amount of `scale_memory_limit`. The units for specifying + ephemeral storage are Megabyte (M) or Gigabyte (G), whereas G and M are the + shorthand expressions for GB and MB. For more information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_initial_instances: (optional) Optional initial number of + instances that are created upon app creation or app update. + :attr int scale_max_instances: Optional maximum number of instances for this + app. If you set this value to `0`, this property does not set a upper scaling + limit. However, the app scaling is still limited by the project quota for + instances. See [Limits and quotas for Code + Engine](https://cloud.ibm.com/docs/codeengine?topic=codeengine-limits). + :attr str scale_memory_limit: Optional amount of memory set for the instance of + the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G and + M are the shorthand expressions for GB and MB. For more information see [Units + of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_min_instances: Optional minimum number of instances for this + app. If you set this value to `0`, the app will scale down to zero, if not hit + by any request for some time. + :attr int scale_request_timeout: Optional amount of time in seconds that is + allowed for a running app to respond to a request. + :attr str status: The current status of the app revision. + :attr AppRevisionStatus status_details: (optional) The detailed status of the + application revision. + """ + + def __init__( + self, + created_at: str, + href: str, + id: str, + image_reference: str, + name: str, + project_id: str, + resource_type: str, + run_arguments: List[str], + run_commands: List[str], + run_env_variables: List['EnvVar'], + run_volume_mounts: List['VolumeMount'], + scale_cpu_limit: str, + scale_ephemeral_storage_limit: str, + scale_max_instances: int, + scale_memory_limit: str, + scale_min_instances: int, + scale_request_timeout: int, + status: str, + *, + app_name: str = None, + image_port: int = None, + image_secret: str = None, + run_as_user: int = None, + run_service_account: str = None, + scale_concurrency: int = None, + scale_concurrency_target: int = None, + scale_initial_instances: int = None, + status_details: 'AppRevisionStatus' = None, + ) -> None: + """ + Initialize a AppRevision object. + + :param str created_at: The date when the resource was created. + :param str href: When you provision a new revision, a URL is created + identifying the location of the instance. + :param str id: The identifier of the resource. + :param str image_reference: The name of the image that is used for this + job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and + `TAG` are optional. If `REGISTRY` is not specified, the default is + `docker.io`. If `TAG` is not specified, the default is `latest`. If the + image reference points to a registry that requires authentication, make + sure to also specify the property `image_secret`. + :param str name: The name of the app revison. + :param str project_id: The ID of the project the resource is located in. + :param str resource_type: The type of the app revision. + :param List[str] run_arguments: Optional arguments for the app that are + passed to start the container. If not specified an empty string array will + be applied and the arguments specified by the container image, will be used + to start the container. + :param List[str] run_commands: Optional commands for the app that are + passed to start the container. If not specified an empty string array will + be applied and the command specified by the container image, will be used + to start the container. + :param List[EnvVar] run_env_variables: References to config maps, secrets + or a literal values, which are exposed as environment variables in the + application. + :param List[VolumeMount] run_volume_mounts: Mounts of config maps or + secrets. + :param str scale_cpu_limit: Optional number of CPU set for the instance of + the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :param str scale_ephemeral_storage_limit: Optional amount of ephemeral + storage to set for the instance of the app. The amount specified as + ephemeral storage, must not exceed the amount of `scale_memory_limit`. The + units for specifying ephemeral storage are Megabyte (M) or Gigabyte (G), + whereas G and M are the shorthand expressions for GB and MB. For more + information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_max_instances: Optional maximum number of instances for + this app. If you set this value to `0`, this property does not set a upper + scaling limit. However, the app scaling is still limited by the project + quota for instances. See [Limits and quotas for Code + Engine](https://cloud.ibm.com/docs/codeengine?topic=codeengine-limits). + :param str scale_memory_limit: Optional amount of memory set for the + instance of the app. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G + and M are the shorthand expressions for GB and MB. For more information see + [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_min_instances: Optional minimum number of instances for + this app. If you set this value to `0`, the app will scale down to zero, if + not hit by any request for some time. + :param int scale_request_timeout: Optional amount of time in seconds that + is allowed for a running app to respond to a request. + :param str status: The current status of the app revision. + :param str app_name: (optional) Name of the associated app. + :param int image_port: (optional) Optional port the app listens on. While + the app will always be exposed via port `443` for end users, this port is + used to connect to the port that is exposed by the container image. + :param str image_secret: (optional) Optional name of the image registry + access secret. The image registry access secret is used to authenticate + with a private registry when you download the container image. If the image + reference points to a registry that requires authentication, the app will + be created but cannot reach the ready status, until this property is + provided, too. + :param int run_as_user: (optional) Optional user ID (UID) to run the app + (e.g., `1001`). + :param str run_service_account: (optional) Optional name of the service + account. For built-in service accounts, you can use the shortened names + `manager` , `none`, `reader`, and `writer`. + :param int scale_concurrency: (optional) Optional maximum number of + requests that can be processed concurrently per instance. + :param int scale_concurrency_target: (optional) Optional threshold of + concurrent requests per instance at which one or more additional instances + are created. Use this value to scale up instances based on concurrent + number of requests. This option defaults to the value of the + `scale_concurrency` option, if not specified. + :param int scale_initial_instances: (optional) Optional initial number of + instances that are created upon app creation or app update. + :param AppRevisionStatus status_details: (optional) The detailed status of + the application revision. + """ + self.app_name = app_name + self.created_at = created_at + self.href = href + self.id = id + self.image_port = image_port + self.image_reference = image_reference + self.image_secret = image_secret + self.name = name + self.project_id = project_id + self.resource_type = resource_type + self.run_arguments = run_arguments + self.run_as_user = run_as_user + self.run_commands = run_commands + self.run_env_variables = run_env_variables + self.run_service_account = run_service_account + self.run_volume_mounts = run_volume_mounts + self.scale_concurrency = scale_concurrency + self.scale_concurrency_target = scale_concurrency_target + self.scale_cpu_limit = scale_cpu_limit + self.scale_ephemeral_storage_limit = scale_ephemeral_storage_limit + self.scale_initial_instances = scale_initial_instances + self.scale_max_instances = scale_max_instances + self.scale_memory_limit = scale_memory_limit + self.scale_min_instances = scale_min_instances + self.scale_request_timeout = scale_request_timeout + self.status = status + self.status_details = status_details + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AppRevision': + """Initialize a AppRevision object from a json dictionary.""" + args = {} + if 'app_name' in _dict: + args['app_name'] = _dict.get('app_name') + if 'created_at' in _dict: + args['created_at'] = _dict.get('created_at') + else: + raise ValueError('Required property \'created_at\' not present in AppRevision JSON') + if 'href' in _dict: + args['href'] = _dict.get('href') + else: + raise ValueError('Required property \'href\' not present in AppRevision JSON') + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in AppRevision JSON') + if 'image_port' in _dict: + args['image_port'] = _dict.get('image_port') + if 'image_reference' in _dict: + args['image_reference'] = _dict.get('image_reference') + else: + raise ValueError('Required property \'image_reference\' not present in AppRevision JSON') + if 'image_secret' in _dict: + args['image_secret'] = _dict.get('image_secret') + if 'name' in _dict: + args['name'] = _dict.get('name') + else: + raise ValueError('Required property \'name\' not present in AppRevision JSON') + if 'project_id' in _dict: + args['project_id'] = _dict.get('project_id') + else: + raise ValueError('Required property \'project_id\' not present in AppRevision JSON') + if 'resource_type' in _dict: + args['resource_type'] = _dict.get('resource_type') + else: + raise ValueError('Required property \'resource_type\' not present in AppRevision JSON') + if 'run_arguments' in _dict: + args['run_arguments'] = _dict.get('run_arguments') + else: + raise ValueError('Required property \'run_arguments\' not present in AppRevision JSON') + if 'run_as_user' in _dict: + args['run_as_user'] = _dict.get('run_as_user') + if 'run_commands' in _dict: + args['run_commands'] = _dict.get('run_commands') + else: + raise ValueError('Required property \'run_commands\' not present in AppRevision JSON') + if 'run_env_variables' in _dict: + args['run_env_variables'] = [EnvVar.from_dict(v) for v in _dict.get('run_env_variables')] + else: + raise ValueError('Required property \'run_env_variables\' not present in AppRevision JSON') + if 'run_service_account' in _dict: + args['run_service_account'] = _dict.get('run_service_account') + if 'run_volume_mounts' in _dict: + args['run_volume_mounts'] = [VolumeMount.from_dict(v) for v in _dict.get('run_volume_mounts')] + else: + raise ValueError('Required property \'run_volume_mounts\' not present in AppRevision JSON') + if 'scale_concurrency' in _dict: + args['scale_concurrency'] = _dict.get('scale_concurrency') + if 'scale_concurrency_target' in _dict: + args['scale_concurrency_target'] = _dict.get('scale_concurrency_target') + if 'scale_cpu_limit' in _dict: + args['scale_cpu_limit'] = _dict.get('scale_cpu_limit') + else: + raise ValueError('Required property \'scale_cpu_limit\' not present in AppRevision JSON') + if 'scale_ephemeral_storage_limit' in _dict: + args['scale_ephemeral_storage_limit'] = _dict.get('scale_ephemeral_storage_limit') + else: + raise ValueError('Required property \'scale_ephemeral_storage_limit\' not present in AppRevision JSON') + if 'scale_initial_instances' in _dict: + args['scale_initial_instances'] = _dict.get('scale_initial_instances') + if 'scale_max_instances' in _dict: + args['scale_max_instances'] = _dict.get('scale_max_instances') + else: + raise ValueError('Required property \'scale_max_instances\' not present in AppRevision JSON') + if 'scale_memory_limit' in _dict: + args['scale_memory_limit'] = _dict.get('scale_memory_limit') + else: + raise ValueError('Required property \'scale_memory_limit\' not present in AppRevision JSON') + if 'scale_min_instances' in _dict: + args['scale_min_instances'] = _dict.get('scale_min_instances') + else: + raise ValueError('Required property \'scale_min_instances\' not present in AppRevision JSON') + if 'scale_request_timeout' in _dict: + args['scale_request_timeout'] = _dict.get('scale_request_timeout') + else: + raise ValueError('Required property \'scale_request_timeout\' not present in AppRevision JSON') + if 'status' in _dict: + args['status'] = _dict.get('status') + else: + raise ValueError('Required property \'status\' not present in AppRevision JSON') + if 'status_details' in _dict: + args['status_details'] = AppRevisionStatus.from_dict(_dict.get('status_details')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a AppRevision object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'app_name') and self.app_name is not None: + _dict['app_name'] = self.app_name + if hasattr(self, 'created_at') and self.created_at is not None: + _dict['created_at'] = self.created_at + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'image_port') and self.image_port is not None: + _dict['image_port'] = self.image_port + if hasattr(self, 'image_reference') and self.image_reference is not None: + _dict['image_reference'] = self.image_reference + if hasattr(self, 'image_secret') and self.image_secret is not None: + _dict['image_secret'] = self.image_secret + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'project_id') and self.project_id is not None: + _dict['project_id'] = self.project_id + if hasattr(self, 'resource_type') and self.resource_type is not None: + _dict['resource_type'] = self.resource_type + if hasattr(self, 'run_arguments') and self.run_arguments is not None: + _dict['run_arguments'] = self.run_arguments + if hasattr(self, 'run_as_user') and self.run_as_user is not None: + _dict['run_as_user'] = self.run_as_user + if hasattr(self, 'run_commands') and self.run_commands is not None: + _dict['run_commands'] = self.run_commands + if hasattr(self, 'run_env_variables') and self.run_env_variables is not None: + run_env_variables_list = [] + for v in self.run_env_variables: + if isinstance(v, dict): + run_env_variables_list.append(v) + else: + run_env_variables_list.append(v.to_dict()) + _dict['run_env_variables'] = run_env_variables_list + if hasattr(self, 'run_service_account') and self.run_service_account is not None: + _dict['run_service_account'] = self.run_service_account + if hasattr(self, 'run_volume_mounts') and self.run_volume_mounts is not None: + run_volume_mounts_list = [] + for v in self.run_volume_mounts: + if isinstance(v, dict): + run_volume_mounts_list.append(v) + else: + run_volume_mounts_list.append(v.to_dict()) + _dict['run_volume_mounts'] = run_volume_mounts_list + if hasattr(self, 'scale_concurrency') and self.scale_concurrency is not None: + _dict['scale_concurrency'] = self.scale_concurrency + if hasattr(self, 'scale_concurrency_target') and self.scale_concurrency_target is not None: + _dict['scale_concurrency_target'] = self.scale_concurrency_target + if hasattr(self, 'scale_cpu_limit') and self.scale_cpu_limit is not None: + _dict['scale_cpu_limit'] = self.scale_cpu_limit + if hasattr(self, 'scale_ephemeral_storage_limit') and self.scale_ephemeral_storage_limit is not None: + _dict['scale_ephemeral_storage_limit'] = self.scale_ephemeral_storage_limit + if hasattr(self, 'scale_initial_instances') and self.scale_initial_instances is not None: + _dict['scale_initial_instances'] = self.scale_initial_instances + if hasattr(self, 'scale_max_instances') and self.scale_max_instances is not None: + _dict['scale_max_instances'] = self.scale_max_instances + if hasattr(self, 'scale_memory_limit') and self.scale_memory_limit is not None: + _dict['scale_memory_limit'] = self.scale_memory_limit + if hasattr(self, 'scale_min_instances') and self.scale_min_instances is not None: + _dict['scale_min_instances'] = self.scale_min_instances + if hasattr(self, 'scale_request_timeout') and self.scale_request_timeout is not None: + _dict['scale_request_timeout'] = self.scale_request_timeout + if hasattr(self, 'status') and self.status is not None: + _dict['status'] = self.status + if hasattr(self, 'status_details') and self.status_details is not None: + if isinstance(self.status_details, dict): + _dict['status_details'] = self.status_details + else: + _dict['status_details'] = self.status_details.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this AppRevision object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'AppRevision') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'AppRevision') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ResourceTypeEnum(str, Enum): + """ + The type of the app revision. + """ + + APP_REVISION_V2 = 'app_revision_v2' + + class RunServiceAccountEnum(str, Enum): + """ + Optional name of the service account. For built-in service accounts, you can use + the shortened names `manager` , `none`, `reader`, and `writer`. + """ + + DEFAULT = 'default' + MANAGER = 'manager' + READER = 'reader' + WRITER = 'writer' + NONE = 'none' + + class StatusEnum(str, Enum): + """ + The current status of the app revision. + """ + + READY = 'ready' + LOADING = 'loading' + WARNING = 'warning' + FAILED = 'failed' + + +class AppRevisionList: + """ + Contains a list of app revisions and pagination information. + + :attr ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :attr int limit: Maximum number of resources per page. + :attr ListNextMetadata next: (optional) Describes properties needed to retrieve + the next page of a result list. + :attr List[AppRevision] revisions: List of all app revisions. + """ + + def __init__( + self, + limit: int, + revisions: List['AppRevision'], + *, + first: 'ListFirstMetadata' = None, + next: 'ListNextMetadata' = None, + ) -> None: + """ + Initialize a AppRevisionList object. + + :param int limit: Maximum number of resources per page. + :param List[AppRevision] revisions: List of all app revisions. + :param ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :param ListNextMetadata next: (optional) Describes properties needed to + retrieve the next page of a result list. + """ + self.first = first + self.limit = limit + self.next = next + self.revisions = revisions + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AppRevisionList': + """Initialize a AppRevisionList object from a json dictionary.""" + args = {} + if 'first' in _dict: + args['first'] = ListFirstMetadata.from_dict(_dict.get('first')) + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in AppRevisionList JSON') + if 'next' in _dict: + args['next'] = ListNextMetadata.from_dict(_dict.get('next')) + if 'revisions' in _dict: + args['revisions'] = [AppRevision.from_dict(v) for v in _dict.get('revisions')] + else: + raise ValueError('Required property \'revisions\' not present in AppRevisionList JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a AppRevisionList object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'first') and self.first is not None: + if isinstance(self.first, dict): + _dict['first'] = self.first + else: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'next') and self.next is not None: + if isinstance(self.next, dict): + _dict['next'] = self.next + else: + _dict['next'] = self.next.to_dict() + if hasattr(self, 'revisions') and self.revisions is not None: + revisions_list = [] + for v in self.revisions: + if isinstance(v, dict): + revisions_list.append(v) + else: + revisions_list.append(v.to_dict()) + _dict['revisions'] = revisions_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this AppRevisionList object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'AppRevisionList') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'AppRevisionList') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class AppRevisionStatus: + """ + The detailed status of the application revision. + + :attr int actual_instances: (optional) The number of running instances of the + revision. + :attr str reason: (optional) Optional information to provide more context in + case of a 'failed' or 'warning' status. + """ + + def __init__(self, *, actual_instances: int = None, reason: str = None) -> None: + """ + Initialize a AppRevisionStatus object. + + :param int actual_instances: (optional) The number of running instances of + the revision. + :param str reason: (optional) Optional information to provide more context + in case of a 'failed' or 'warning' status. + """ + self.actual_instances = actual_instances + self.reason = reason + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AppRevisionStatus': + """Initialize a AppRevisionStatus object from a json dictionary.""" + args = {} + if 'actual_instances' in _dict: + args['actual_instances'] = _dict.get('actual_instances') + if 'reason' in _dict: + args['reason'] = _dict.get('reason') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a AppRevisionStatus object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'actual_instances') and self.actual_instances is not None: + _dict['actual_instances'] = self.actual_instances + if hasattr(self, 'reason') and self.reason is not None: + _dict['reason'] = self.reason + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this AppRevisionStatus object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'AppRevisionStatus') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'AppRevisionStatus') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ReasonEnum(str, Enum): + """ + Optional information to provide more context in case of a 'failed' or 'warning' + status. + """ + + READY = 'ready' + WAITING = 'waiting' + DEPLOYING = 'deploying' + DEPLOYING_WAITING_FOR_RESOURCES = 'deploying_waiting_for_resources' + INITIAL_SCALE_NEVER_ACHIEVED = 'initial_scale_never_achieved' + FETCH_IMAGE_FAILED_UNKNOWN_MANIFEST = 'fetch_image_failed_unknown_manifest' + FETCH_IMAGE_FAILED_UNKNOWN_REPOSITORY = 'fetch_image_failed_unknown_repository' + FETCH_IMAGE_FAILED_REGISTRY_NOT_FOUND = 'fetch_image_failed_registry_not_found' + FETCH_IMAGE_FAILED_MISSING_PULL_SECRET = 'fetch_image_failed_missing_pull_secret' + FETCH_IMAGE_FAILED_WRONG_PULL_CREDENTIALS = 'fetch_image_failed_wrong_pull_credentials' + FETCH_IMAGE_FAILED_MISSING_PULL_CREDENTIALS = 'fetch_image_failed_missing_pull_credentials' + CONTAINER_FAILED_EXIT_CODE_0 = 'container_failed_exit_code_0' + CONTAINER_FAILED_EXIT_CODE_1 = 'container_failed_exit_code_1' + CONTAINER_FAILED_EXIT_CODE_139 = 'container_failed_exit_code_139' + CONTAINER_FAILED_EXIT_CODE_24 = 'container_failed_exit_code_24' + IMAGE_PULL_BACK_OFF = 'image_pull_back_off' + INVALID_TAR_HEADER_IMAGE_PULL_ERR = 'invalid_tar_header_image_pull_err' + + +class AppStatus: + """ + The detailed status of the application. + + :attr str latest_created_revision: (optional) Latest app revision that has been + created. + :attr str latest_ready_revision: (optional) Latest app revision that reached a + ready state. + :attr str reason: (optional) Optional information to provide more context in + case of a 'failed' or 'warning' status. + """ + + def __init__( + self, *, latest_created_revision: str = None, latest_ready_revision: str = None, reason: str = None + ) -> None: + """ + Initialize a AppStatus object. + + :param str latest_created_revision: (optional) Latest app revision that has + been created. + :param str latest_ready_revision: (optional) Latest app revision that + reached a ready state. + :param str reason: (optional) Optional information to provide more context + in case of a 'failed' or 'warning' status. + """ + self.latest_created_revision = latest_created_revision + self.latest_ready_revision = latest_ready_revision + self.reason = reason + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AppStatus': + """Initialize a AppStatus object from a json dictionary.""" + args = {} + if 'latest_created_revision' in _dict: + args['latest_created_revision'] = _dict.get('latest_created_revision') + if 'latest_ready_revision' in _dict: + args['latest_ready_revision'] = _dict.get('latest_ready_revision') + if 'reason' in _dict: + args['reason'] = _dict.get('reason') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a AppStatus object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'latest_created_revision') and self.latest_created_revision is not None: + _dict['latest_created_revision'] = self.latest_created_revision + if hasattr(self, 'latest_ready_revision') and self.latest_ready_revision is not None: + _dict['latest_ready_revision'] = self.latest_ready_revision + if hasattr(self, 'reason') and self.reason is not None: + _dict['reason'] = self.reason + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this AppStatus object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'AppStatus') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'AppStatus') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ReasonEnum(str, Enum): + """ + Optional information to provide more context in case of a 'failed' or 'warning' + status. + """ + + READY = 'ready' + DEPLOYING = 'deploying' + WAITING_FOR_RESOURCES = 'waiting_for_resources' + NO_REVISION_READY = 'no_revision_ready' + READY_BUT_LATEST_REVISION_FAILED = 'ready_but_latest_revision_failed' + + +class Build: + """ + Response model for build definitions. + + :attr str created_at: The date when the resource was created. + :attr str entity_tag: The version of the build instance, which is used to + achieve optimistic locking. + :attr str href: (optional) When you provision a new build, a URL is created + identifying the location of the instance. + :attr str id: The identifier of the resource. + :attr str name: (optional) The name of the build. + :attr str output_image: The name of the image. + :attr str output_secret: The secret that is required to access the image + registry. Make sure that the secret is granted with push permissions towards the + specified container registry namespace. + :attr str project_id: The ID of the project the resource is located in. + :attr str resource_type: (optional) The type of the build. + :attr str source_context_dir: (optional) Option directory in the repository that + contains the buildpacks file or the Dockerfile. + :attr str source_revision: (optional) Commit, tag, or branch in the source + repository to pull. This field is optional if the `source_type` is `git` and + uses the HEAD of default branch if not specified. If the `source_type` value is + `local`, this field must be omitted. + :attr str source_secret: (optional) Name of the secret that is used access the + repository source. This field is optional if the `source_type` is `git`. + Additionally, if the `source_url` points to a repository that requires + authentication, the build will be created but cannot access any source code, + until this property is provided, too. If the `source_type` value is `local`, + this field must be omitted. + :attr str source_type: Specifies the type of source to determine if your build + source is in a repository or based on local source code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + :attr str source_url: The URL of the code repository. This field is required if + the `source_type` is `git`. If the `source_type` value is `local`, this field + must be omitted. If the repository is publicly available you can provide a + 'https' URL like `https://github.com/IBM/CodeEngine`. If the repository requires + authentication, you need to provide a 'ssh' URL like + `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that points to + a secret of format `ssh_auth`. + :attr str status: (optional) The current status of the build. + :attr BuildStatus status_details: (optional) The detailed status of the build. + :attr str strategy_size: Optional size for the build, which determines the + amount of resources used. Build sizes are `small`, `medium`, `large`, `xlarge`. + :attr str strategy_spec_file: (optional) Optional path to the specification file + that is used for build strategies for building an image. + :attr str strategy_type: The strategy to use for building the image. + :attr int timeout: (optional) The maximum amount of time, in seconds, that can + pass before the build must succeed or fail. + """ + + def __init__( + self, + created_at: str, + entity_tag: str, + id: str, + output_image: str, + output_secret: str, + project_id: str, + source_type: str, + source_url: str, + strategy_size: str, + strategy_type: str, + *, + href: str = None, + name: str = None, + resource_type: str = None, + source_context_dir: str = None, + source_revision: str = None, + source_secret: str = None, + status: str = None, + status_details: 'BuildStatus' = None, + strategy_spec_file: str = None, + timeout: int = None, + ) -> None: + """ + Initialize a Build object. + + :param str created_at: The date when the resource was created. + :param str entity_tag: The version of the build instance, which is used to + achieve optimistic locking. + :param str id: The identifier of the resource. + :param str output_image: The name of the image. + :param str output_secret: The secret that is required to access the image + registry. Make sure that the secret is granted with push permissions + towards the specified container registry namespace. + :param str project_id: The ID of the project the resource is located in. + :param str source_type: Specifies the type of source to determine if your + build source is in a repository or based on local source code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + :param str source_url: The URL of the code repository. This field is + required if the `source_type` is `git`. If the `source_type` value is + `local`, this field must be omitted. If the repository is publicly + available you can provide a 'https' URL like + `https://github.com/IBM/CodeEngine`. If the repository requires + authentication, you need to provide a 'ssh' URL like + `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that + points to a secret of format `ssh_auth`. + :param str strategy_size: Optional size for the build, which determines the + amount of resources used. Build sizes are `small`, `medium`, `large`, + `xlarge`. + :param str strategy_type: The strategy to use for building the image. + :param str href: (optional) When you provision a new build, a URL is + created identifying the location of the instance. + :param str name: (optional) The name of the build. + :param str resource_type: (optional) The type of the build. + :param str source_context_dir: (optional) Option directory in the + repository that contains the buildpacks file or the Dockerfile. + :param str source_revision: (optional) Commit, tag, or branch in the source + repository to pull. This field is optional if the `source_type` is `git` + and uses the HEAD of default branch if not specified. If the `source_type` + value is `local`, this field must be omitted. + :param str source_secret: (optional) Name of the secret that is used access + the repository source. This field is optional if the `source_type` is + `git`. Additionally, if the `source_url` points to a repository that + requires authentication, the build will be created but cannot access any + source code, until this property is provided, too. If the `source_type` + value is `local`, this field must be omitted. + :param str status: (optional) The current status of the build. + :param BuildStatus status_details: (optional) The detailed status of the + build. + :param str strategy_spec_file: (optional) Optional path to the + specification file that is used for build strategies for building an image. + :param int timeout: (optional) The maximum amount of time, in seconds, that + can pass before the build must succeed or fail. + """ + self.created_at = created_at + self.entity_tag = entity_tag + self.href = href + self.id = id + self.name = name + self.output_image = output_image + self.output_secret = output_secret + self.project_id = project_id + self.resource_type = resource_type + self.source_context_dir = source_context_dir + self.source_revision = source_revision + self.source_secret = source_secret + self.source_type = source_type + self.source_url = source_url + self.status = status + self.status_details = status_details + self.strategy_size = strategy_size + self.strategy_spec_file = strategy_spec_file + self.strategy_type = strategy_type + self.timeout = timeout + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Build': + """Initialize a Build object from a json dictionary.""" + args = {} + if 'created_at' in _dict: + args['created_at'] = _dict.get('created_at') + else: + raise ValueError('Required property \'created_at\' not present in Build JSON') + if 'entity_tag' in _dict: + args['entity_tag'] = _dict.get('entity_tag') + else: + raise ValueError('Required property \'entity_tag\' not present in Build JSON') + if 'href' in _dict: + args['href'] = _dict.get('href') + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in Build JSON') + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'output_image' in _dict: + args['output_image'] = _dict.get('output_image') + else: + raise ValueError('Required property \'output_image\' not present in Build JSON') + if 'output_secret' in _dict: + args['output_secret'] = _dict.get('output_secret') + else: + raise ValueError('Required property \'output_secret\' not present in Build JSON') + if 'project_id' in _dict: + args['project_id'] = _dict.get('project_id') + else: + raise ValueError('Required property \'project_id\' not present in Build JSON') + if 'resource_type' in _dict: + args['resource_type'] = _dict.get('resource_type') + if 'source_context_dir' in _dict: + args['source_context_dir'] = _dict.get('source_context_dir') + if 'source_revision' in _dict: + args['source_revision'] = _dict.get('source_revision') + if 'source_secret' in _dict: + args['source_secret'] = _dict.get('source_secret') + if 'source_type' in _dict: + args['source_type'] = _dict.get('source_type') + else: + raise ValueError('Required property \'source_type\' not present in Build JSON') + if 'source_url' in _dict: + args['source_url'] = _dict.get('source_url') + else: + raise ValueError('Required property \'source_url\' not present in Build JSON') + if 'status' in _dict: + args['status'] = _dict.get('status') + if 'status_details' in _dict: + args['status_details'] = BuildStatus.from_dict(_dict.get('status_details')) + if 'strategy_size' in _dict: + args['strategy_size'] = _dict.get('strategy_size') + else: + raise ValueError('Required property \'strategy_size\' not present in Build JSON') + if 'strategy_spec_file' in _dict: + args['strategy_spec_file'] = _dict.get('strategy_spec_file') + if 'strategy_type' in _dict: + args['strategy_type'] = _dict.get('strategy_type') + else: + raise ValueError('Required property \'strategy_type\' not present in Build JSON') + if 'timeout' in _dict: + args['timeout'] = _dict.get('timeout') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Build object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'created_at') and self.created_at is not None: + _dict['created_at'] = self.created_at + if hasattr(self, 'entity_tag') and self.entity_tag is not None: + _dict['entity_tag'] = self.entity_tag + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'output_image') and self.output_image is not None: + _dict['output_image'] = self.output_image + if hasattr(self, 'output_secret') and self.output_secret is not None: + _dict['output_secret'] = self.output_secret + if hasattr(self, 'project_id') and self.project_id is not None: + _dict['project_id'] = self.project_id + if hasattr(self, 'resource_type') and self.resource_type is not None: + _dict['resource_type'] = self.resource_type + if hasattr(self, 'source_context_dir') and self.source_context_dir is not None: + _dict['source_context_dir'] = self.source_context_dir + if hasattr(self, 'source_revision') and self.source_revision is not None: + _dict['source_revision'] = self.source_revision + if hasattr(self, 'source_secret') and self.source_secret is not None: + _dict['source_secret'] = self.source_secret + if hasattr(self, 'source_type') and self.source_type is not None: + _dict['source_type'] = self.source_type + if hasattr(self, 'source_url') and self.source_url is not None: + _dict['source_url'] = self.source_url + if hasattr(self, 'status') and self.status is not None: + _dict['status'] = self.status + if hasattr(self, 'status_details') and self.status_details is not None: + if isinstance(self.status_details, dict): + _dict['status_details'] = self.status_details + else: + _dict['status_details'] = self.status_details.to_dict() + if hasattr(self, 'strategy_size') and self.strategy_size is not None: + _dict['strategy_size'] = self.strategy_size + if hasattr(self, 'strategy_spec_file') and self.strategy_spec_file is not None: + _dict['strategy_spec_file'] = self.strategy_spec_file + if hasattr(self, 'strategy_type') and self.strategy_type is not None: + _dict['strategy_type'] = self.strategy_type + if hasattr(self, 'timeout') and self.timeout is not None: + _dict['timeout'] = self.timeout + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Build object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Build') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Build') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ResourceTypeEnum(str, Enum): + """ + The type of the build. + """ + + BUILD_V2 = 'build_v2' + + class SourceTypeEnum(str, Enum): + """ + Specifies the type of source to determine if your build source is in a repository + or based on local source code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + """ + + LOCAL = 'local' + GIT = 'git' + + class StatusEnum(str, Enum): + """ + The current status of the build. + """ + + READY = 'ready' + FAILED = 'failed' + + +class BuildList: + """ + Contains a list of builds and pagination information. + + :attr List[Build] builds: List of all builds. + :attr ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :attr int limit: Maximum number of resources per page. + :attr ListNextMetadata next: (optional) Describes properties needed to retrieve + the next page of a result list. + """ + + def __init__( + self, builds: List['Build'], limit: int, *, first: 'ListFirstMetadata' = None, next: 'ListNextMetadata' = None + ) -> None: + """ + Initialize a BuildList object. + + :param List[Build] builds: List of all builds. + :param int limit: Maximum number of resources per page. + :param ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :param ListNextMetadata next: (optional) Describes properties needed to + retrieve the next page of a result list. + """ + self.builds = builds + self.first = first + self.limit = limit + self.next = next + + @classmethod + def from_dict(cls, _dict: Dict) -> 'BuildList': + """Initialize a BuildList object from a json dictionary.""" + args = {} + if 'builds' in _dict: + args['builds'] = [Build.from_dict(v) for v in _dict.get('builds')] + else: + raise ValueError('Required property \'builds\' not present in BuildList JSON') + if 'first' in _dict: + args['first'] = ListFirstMetadata.from_dict(_dict.get('first')) + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in BuildList JSON') + if 'next' in _dict: + args['next'] = ListNextMetadata.from_dict(_dict.get('next')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a BuildList object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'builds') and self.builds is not None: + builds_list = [] + for v in self.builds: + if isinstance(v, dict): + builds_list.append(v) + else: + builds_list.append(v.to_dict()) + _dict['builds'] = builds_list + if hasattr(self, 'first') and self.first is not None: + if isinstance(self.first, dict): + _dict['first'] = self.first + else: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'next') and self.next is not None: + if isinstance(self.next, dict): + _dict['next'] = self.next + else: + _dict['next'] = self.next.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this BuildList object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'BuildList') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'BuildList') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class BuildPatch: + """ + Patch a build object. + + :attr str output_image: (optional) The name of the image. + :attr str output_secret: (optional) The secret that is required to access the + image registry. Make sure that the secret is granted with push permissions + towards the specified container registry namespace. + :attr str source_context_dir: (optional) Option directory in the repository that + contains the buildpacks file or the Dockerfile. + :attr str source_revision: (optional) Commit, tag, or branch in the source + repository to pull. This field is optional if the `source_type` is `git` and + uses the HEAD of default branch if not specified. If the `source_type` value is + `local`, this field must be omitted. + :attr str source_secret: (optional) Name of the secret that is used access the + repository source. This field is optional if the `source_type` is `git`. + Additionally, if the `source_url` points to a repository that requires + authentication, the build will be created but cannot access any source code, + until this property is provided, too. If the `source_type` value is `local`, + this field must be omitted. + :attr str source_type: (optional) Specifies the type of source to determine if + your build source is in a repository or based on local source code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + :attr str source_url: (optional) The URL of the code repository. This field is + required if the `source_type` is `git`. If the `source_type` value is `local`, + this field must be omitted. If the repository is publicly available you can + provide a 'https' URL like `https://github.com/IBM/CodeEngine`. If the + repository requires authentication, you need to provide a 'ssh' URL like + `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that points to + a secret of format `ssh_auth`. + :attr str strategy_size: (optional) Optional size for the build, which + determines the amount of resources used. Build sizes are `small`, `medium`, + `large`, `xlarge`. + :attr str strategy_spec_file: (optional) Optional path to the specification file + that is used for build strategies for building an image. + :attr str strategy_type: (optional) The strategy to use for building the image. + :attr int timeout: (optional) The maximum amount of time, in seconds, that can + pass before the build must succeed or fail. + """ + + def __init__( + self, + *, + output_image: str = None, + output_secret: str = None, + source_context_dir: str = None, + source_revision: str = None, + source_secret: str = None, + source_type: str = None, + source_url: str = None, + strategy_size: str = None, + strategy_spec_file: str = None, + strategy_type: str = None, + timeout: int = None, + ) -> None: + """ + Initialize a BuildPatch object. + + :param str output_image: (optional) The name of the image. + :param str output_secret: (optional) The secret that is required to access + the image registry. Make sure that the secret is granted with push + permissions towards the specified container registry namespace. + :param str source_context_dir: (optional) Option directory in the + repository that contains the buildpacks file or the Dockerfile. + :param str source_revision: (optional) Commit, tag, or branch in the source + repository to pull. This field is optional if the `source_type` is `git` + and uses the HEAD of default branch if not specified. If the `source_type` + value is `local`, this field must be omitted. + :param str source_secret: (optional) Name of the secret that is used access + the repository source. This field is optional if the `source_type` is + `git`. Additionally, if the `source_url` points to a repository that + requires authentication, the build will be created but cannot access any + source code, until this property is provided, too. If the `source_type` + value is `local`, this field must be omitted. + :param str source_type: (optional) Specifies the type of source to + determine if your build source is in a repository or based on local source + code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + :param str source_url: (optional) The URL of the code repository. This + field is required if the `source_type` is `git`. If the `source_type` value + is `local`, this field must be omitted. If the repository is publicly + available you can provide a 'https' URL like + `https://github.com/IBM/CodeEngine`. If the repository requires + authentication, you need to provide a 'ssh' URL like + `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that + points to a secret of format `ssh_auth`. + :param str strategy_size: (optional) Optional size for the build, which + determines the amount of resources used. Build sizes are `small`, `medium`, + `large`, `xlarge`. + :param str strategy_spec_file: (optional) Optional path to the + specification file that is used for build strategies for building an image. + :param str strategy_type: (optional) The strategy to use for building the + image. + :param int timeout: (optional) The maximum amount of time, in seconds, that + can pass before the build must succeed or fail. + """ + self.output_image = output_image + self.output_secret = output_secret + self.source_context_dir = source_context_dir + self.source_revision = source_revision + self.source_secret = source_secret + self.source_type = source_type + self.source_url = source_url + self.strategy_size = strategy_size + self.strategy_spec_file = strategy_spec_file + self.strategy_type = strategy_type + self.timeout = timeout + + @classmethod + def from_dict(cls, _dict: Dict) -> 'BuildPatch': + """Initialize a BuildPatch object from a json dictionary.""" + args = {} + if 'output_image' in _dict: + args['output_image'] = _dict.get('output_image') + if 'output_secret' in _dict: + args['output_secret'] = _dict.get('output_secret') + if 'source_context_dir' in _dict: + args['source_context_dir'] = _dict.get('source_context_dir') + if 'source_revision' in _dict: + args['source_revision'] = _dict.get('source_revision') + if 'source_secret' in _dict: + args['source_secret'] = _dict.get('source_secret') + if 'source_type' in _dict: + args['source_type'] = _dict.get('source_type') + if 'source_url' in _dict: + args['source_url'] = _dict.get('source_url') + if 'strategy_size' in _dict: + args['strategy_size'] = _dict.get('strategy_size') + if 'strategy_spec_file' in _dict: + args['strategy_spec_file'] = _dict.get('strategy_spec_file') + if 'strategy_type' in _dict: + args['strategy_type'] = _dict.get('strategy_type') + if 'timeout' in _dict: + args['timeout'] = _dict.get('timeout') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a BuildPatch object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'output_image') and self.output_image is not None: + _dict['output_image'] = self.output_image + if hasattr(self, 'output_secret') and self.output_secret is not None: + _dict['output_secret'] = self.output_secret + if hasattr(self, 'source_context_dir') and self.source_context_dir is not None: + _dict['source_context_dir'] = self.source_context_dir + if hasattr(self, 'source_revision') and self.source_revision is not None: + _dict['source_revision'] = self.source_revision + if hasattr(self, 'source_secret') and self.source_secret is not None: + _dict['source_secret'] = self.source_secret + if hasattr(self, 'source_type') and self.source_type is not None: + _dict['source_type'] = self.source_type + if hasattr(self, 'source_url') and self.source_url is not None: + _dict['source_url'] = self.source_url + if hasattr(self, 'strategy_size') and self.strategy_size is not None: + _dict['strategy_size'] = self.strategy_size + if hasattr(self, 'strategy_spec_file') and self.strategy_spec_file is not None: + _dict['strategy_spec_file'] = self.strategy_spec_file + if hasattr(self, 'strategy_type') and self.strategy_type is not None: + _dict['strategy_type'] = self.strategy_type + if hasattr(self, 'timeout') and self.timeout is not None: + _dict['timeout'] = self.timeout + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this BuildPatch object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'BuildPatch') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'BuildPatch') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class SourceTypeEnum(str, Enum): + """ + Specifies the type of source to determine if your build source is in a repository + or based on local source code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + """ + + LOCAL = 'local' + GIT = 'git' + + +class BuildRun: + """ + Response model for build run objects. + + :attr str build_name: Optional name of the build on which this build run is + based on. If specified, the build run will inherit the configuration of the + referenced build. If not specified, make sure to specify at least the fields + `strategy_type`, `source_url`, `output_image` and `output_secret` to describe + the build run. + :attr str created_at: The date when the resource was created. + :attr str href: (optional) When you trigger a new build run, a URL is created + identifying the location of the instance. + :attr str id: The identifier of the resource. + :attr str name: The name of the build run. + :attr str output_image: (optional) The name of the image. + :attr str output_secret: (optional) The secret that is required to access the + image registry. Make sure that the secret is granted with push permissions + towards the specified container registry namespace. + :attr str project_id: The ID of the project the resource is located in. + :attr str resource_type: The type of the build run. + :attr str service_account: (optional) Optional service account which is used for + resource control. + :attr str source_context_dir: (optional) Option directory in the repository that + contains the buildpacks file or the Dockerfile. + :attr str source_revision: (optional) Commit, tag, or branch in the source + repository to pull. This field is optional if the `source_type` is `git` and + uses the HEAD of default branch if not specified. If the `source_type` value is + `local`, this field must be omitted. + :attr str source_secret: (optional) Name of the secret that is used access the + repository source. This field is optional if the `source_type` is `git`. + Additionally, if the `source_url` points to a repository that requires + authentication, the build will be created but cannot access any source code, + until this property is provided, too. If the `source_type` value is `local`, + this field must be omitted. + :attr str source_type: (optional) Specifies the type of source to determine if + your build source is in a repository or based on local source code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + :attr str source_url: (optional) The URL of the code repository. This field is + required if the `source_type` is `git`. If the `source_type` value is `local`, + this field must be omitted. If the repository is publicly available you can + provide a 'https' URL like `https://github.com/IBM/CodeEngine`. If the + repository requires authentication, you need to provide a 'ssh' URL like + `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that points to + a secret of format `ssh_auth`. + :attr str status: The current status of the build run. + :attr BuildRunStatus status_details: (optional) Current status condition of a + build run. + :attr str strategy_size: (optional) Optional size for the build, which + determines the amount of resources used. Build sizes are `small`, `medium`, + `large`, `xlarge`. + :attr str strategy_spec_file: (optional) Optional path to the specification file + that is used for build strategies for building an image. + :attr str strategy_type: (optional) The strategy to use for building the image. + :attr int timeout: (optional) The maximum amount of time, in seconds, that can + pass before the build must succeed or fail. + """ + + def __init__( + self, + build_name: str, + created_at: str, + id: str, + name: str, + project_id: str, + resource_type: str, + status: str, + *, + href: str = None, + output_image: str = None, + output_secret: str = None, + service_account: str = None, + source_context_dir: str = None, + source_revision: str = None, + source_secret: str = None, + source_type: str = None, + source_url: str = None, + status_details: 'BuildRunStatus' = None, + strategy_size: str = None, + strategy_spec_file: str = None, + strategy_type: str = None, + timeout: int = None, + ) -> None: + """ + Initialize a BuildRun object. + + :param str build_name: Optional name of the build on which this build run + is based on. If specified, the build run will inherit the configuration of + the referenced build. If not specified, make sure to specify at least the + fields `strategy_type`, `source_url`, `output_image` and `output_secret` to + describe the build run. + :param str created_at: The date when the resource was created. + :param str id: The identifier of the resource. + :param str name: The name of the build run. + :param str project_id: The ID of the project the resource is located in. + :param str resource_type: The type of the build run. + :param str status: The current status of the build run. + :param str href: (optional) When you trigger a new build run, a URL is + created identifying the location of the instance. + :param str output_image: (optional) The name of the image. + :param str output_secret: (optional) The secret that is required to access + the image registry. Make sure that the secret is granted with push + permissions towards the specified container registry namespace. + :param str service_account: (optional) Optional service account which is + used for resource control. + :param str source_context_dir: (optional) Option directory in the + repository that contains the buildpacks file or the Dockerfile. + :param str source_revision: (optional) Commit, tag, or branch in the source + repository to pull. This field is optional if the `source_type` is `git` + and uses the HEAD of default branch if not specified. If the `source_type` + value is `local`, this field must be omitted. + :param str source_secret: (optional) Name of the secret that is used access + the repository source. This field is optional if the `source_type` is + `git`. Additionally, if the `source_url` points to a repository that + requires authentication, the build will be created but cannot access any + source code, until this property is provided, too. If the `source_type` + value is `local`, this field must be omitted. + :param str source_type: (optional) Specifies the type of source to + determine if your build source is in a repository or based on local source + code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + :param str source_url: (optional) The URL of the code repository. This + field is required if the `source_type` is `git`. If the `source_type` value + is `local`, this field must be omitted. If the repository is publicly + available you can provide a 'https' URL like + `https://github.com/IBM/CodeEngine`. If the repository requires + authentication, you need to provide a 'ssh' URL like + `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that + points to a secret of format `ssh_auth`. + :param BuildRunStatus status_details: (optional) Current status condition + of a build run. + :param str strategy_size: (optional) Optional size for the build, which + determines the amount of resources used. Build sizes are `small`, `medium`, + `large`, `xlarge`. + :param str strategy_spec_file: (optional) Optional path to the + specification file that is used for build strategies for building an image. + :param str strategy_type: (optional) The strategy to use for building the + image. + :param int timeout: (optional) The maximum amount of time, in seconds, that + can pass before the build must succeed or fail. + """ + self.build_name = build_name + self.created_at = created_at + self.href = href + self.id = id + self.name = name + self.output_image = output_image + self.output_secret = output_secret + self.project_id = project_id + self.resource_type = resource_type + self.service_account = service_account + self.source_context_dir = source_context_dir + self.source_revision = source_revision + self.source_secret = source_secret + self.source_type = source_type + self.source_url = source_url + self.status = status + self.status_details = status_details + self.strategy_size = strategy_size + self.strategy_spec_file = strategy_spec_file + self.strategy_type = strategy_type + self.timeout = timeout + + @classmethod + def from_dict(cls, _dict: Dict) -> 'BuildRun': + """Initialize a BuildRun object from a json dictionary.""" + args = {} + if 'build_name' in _dict: + args['build_name'] = _dict.get('build_name') + else: + raise ValueError('Required property \'build_name\' not present in BuildRun JSON') + if 'created_at' in _dict: + args['created_at'] = _dict.get('created_at') + else: + raise ValueError('Required property \'created_at\' not present in BuildRun JSON') + if 'href' in _dict: + args['href'] = _dict.get('href') + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in BuildRun JSON') + if 'name' in _dict: + args['name'] = _dict.get('name') + else: + raise ValueError('Required property \'name\' not present in BuildRun JSON') + if 'output_image' in _dict: + args['output_image'] = _dict.get('output_image') + if 'output_secret' in _dict: + args['output_secret'] = _dict.get('output_secret') + if 'project_id' in _dict: + args['project_id'] = _dict.get('project_id') + else: + raise ValueError('Required property \'project_id\' not present in BuildRun JSON') + if 'resource_type' in _dict: + args['resource_type'] = _dict.get('resource_type') + else: + raise ValueError('Required property \'resource_type\' not present in BuildRun JSON') + if 'service_account' in _dict: + args['service_account'] = _dict.get('service_account') + if 'source_context_dir' in _dict: + args['source_context_dir'] = _dict.get('source_context_dir') + if 'source_revision' in _dict: + args['source_revision'] = _dict.get('source_revision') + if 'source_secret' in _dict: + args['source_secret'] = _dict.get('source_secret') + if 'source_type' in _dict: + args['source_type'] = _dict.get('source_type') + if 'source_url' in _dict: + args['source_url'] = _dict.get('source_url') + if 'status' in _dict: + args['status'] = _dict.get('status') + else: + raise ValueError('Required property \'status\' not present in BuildRun JSON') + if 'status_details' in _dict: + args['status_details'] = BuildRunStatus.from_dict(_dict.get('status_details')) + if 'strategy_size' in _dict: + args['strategy_size'] = _dict.get('strategy_size') + if 'strategy_spec_file' in _dict: + args['strategy_spec_file'] = _dict.get('strategy_spec_file') + if 'strategy_type' in _dict: + args['strategy_type'] = _dict.get('strategy_type') + if 'timeout' in _dict: + args['timeout'] = _dict.get('timeout') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a BuildRun object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'build_name') and self.build_name is not None: + _dict['build_name'] = self.build_name + if hasattr(self, 'created_at') and self.created_at is not None: + _dict['created_at'] = self.created_at + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'output_image') and self.output_image is not None: + _dict['output_image'] = self.output_image + if hasattr(self, 'output_secret') and self.output_secret is not None: + _dict['output_secret'] = self.output_secret + if hasattr(self, 'project_id') and self.project_id is not None: + _dict['project_id'] = self.project_id + if hasattr(self, 'resource_type') and self.resource_type is not None: + _dict['resource_type'] = self.resource_type + if hasattr(self, 'service_account') and self.service_account is not None: + _dict['service_account'] = self.service_account + if hasattr(self, 'source_context_dir') and self.source_context_dir is not None: + _dict['source_context_dir'] = self.source_context_dir + if hasattr(self, 'source_revision') and self.source_revision is not None: + _dict['source_revision'] = self.source_revision + if hasattr(self, 'source_secret') and self.source_secret is not None: + _dict['source_secret'] = self.source_secret + if hasattr(self, 'source_type') and self.source_type is not None: + _dict['source_type'] = self.source_type + if hasattr(self, 'source_url') and self.source_url is not None: + _dict['source_url'] = self.source_url + if hasattr(self, 'status') and self.status is not None: + _dict['status'] = self.status + if hasattr(self, 'status_details') and self.status_details is not None: + if isinstance(self.status_details, dict): + _dict['status_details'] = self.status_details + else: + _dict['status_details'] = self.status_details.to_dict() + if hasattr(self, 'strategy_size') and self.strategy_size is not None: + _dict['strategy_size'] = self.strategy_size + if hasattr(self, 'strategy_spec_file') and self.strategy_spec_file is not None: + _dict['strategy_spec_file'] = self.strategy_spec_file + if hasattr(self, 'strategy_type') and self.strategy_type is not None: + _dict['strategy_type'] = self.strategy_type + if hasattr(self, 'timeout') and self.timeout is not None: + _dict['timeout'] = self.timeout + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this BuildRun object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'BuildRun') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'BuildRun') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ResourceTypeEnum(str, Enum): + """ + The type of the build run. + """ + + BUILD_RUN_V2 = 'build_run_v2' + + class ServiceAccountEnum(str, Enum): + """ + Optional service account which is used for resource control. + """ + + DEFAULT = 'default' + MANAGER = 'manager' + READER = 'reader' + WRITER = 'writer' + NONE = 'none' + + class SourceTypeEnum(str, Enum): + """ + Specifies the type of source to determine if your build source is in a repository + or based on local source code. + * local - For builds from local source code. + * git - For builds from git version controlled source code. + """ + + LOCAL = 'local' + GIT = 'git' + + class StatusEnum(str, Enum): + """ + The current status of the build run. + """ + + SUCCEEDED = 'succeeded' + RUNNING = 'running' + PENDING = 'pending' + FAILED = 'failed' + + +class BuildRunList: + """ + Contains a list of build runs and pagination information. + + :attr List[BuildRun] build_runs: List of all build runs. + :attr ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :attr int limit: Maximum number of resources per page. + :attr ListNextMetadata next: (optional) Describes properties needed to retrieve + the next page of a result list. + """ + + def __init__( + self, + build_runs: List['BuildRun'], + limit: int, + *, + first: 'ListFirstMetadata' = None, + next: 'ListNextMetadata' = None, + ) -> None: + """ + Initialize a BuildRunList object. + + :param List[BuildRun] build_runs: List of all build runs. + :param int limit: Maximum number of resources per page. + :param ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :param ListNextMetadata next: (optional) Describes properties needed to + retrieve the next page of a result list. + """ + self.build_runs = build_runs + self.first = first + self.limit = limit + self.next = next + + @classmethod + def from_dict(cls, _dict: Dict) -> 'BuildRunList': + """Initialize a BuildRunList object from a json dictionary.""" + args = {} + if 'build_runs' in _dict: + args['build_runs'] = [BuildRun.from_dict(v) for v in _dict.get('build_runs')] + else: + raise ValueError('Required property \'build_runs\' not present in BuildRunList JSON') + if 'first' in _dict: + args['first'] = ListFirstMetadata.from_dict(_dict.get('first')) + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in BuildRunList JSON') + if 'next' in _dict: + args['next'] = ListNextMetadata.from_dict(_dict.get('next')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a BuildRunList object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'build_runs') and self.build_runs is not None: + build_runs_list = [] + for v in self.build_runs: + if isinstance(v, dict): + build_runs_list.append(v) + else: + build_runs_list.append(v.to_dict()) + _dict['build_runs'] = build_runs_list + if hasattr(self, 'first') and self.first is not None: + if isinstance(self.first, dict): + _dict['first'] = self.first + else: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'next') and self.next is not None: + if isinstance(self.next, dict): + _dict['next'] = self.next + else: + _dict['next'] = self.next.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this BuildRunList object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'BuildRunList') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'BuildRunList') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class BuildRunStatus: + """ + Current status condition of a build run. + + :attr str completion_time: (optional) Time the build run completed. + :attr str output_digest: (optional) Describes the time the build run completed. + :attr str reason: (optional) Optional information to provide more context in + case of a 'failed' or 'warning' status. + :attr str start_time: (optional) Time the build run started. + """ + + def __init__( + self, *, completion_time: str = None, output_digest: str = None, reason: str = None, start_time: str = None + ) -> None: + """ + Initialize a BuildRunStatus object. + + :param str completion_time: (optional) Time the build run completed. + :param str output_digest: (optional) Describes the time the build run + completed. + :param str reason: (optional) Optional information to provide more context + in case of a 'failed' or 'warning' status. + :param str start_time: (optional) Time the build run started. + """ + self.completion_time = completion_time + self.output_digest = output_digest + self.reason = reason + self.start_time = start_time + + @classmethod + def from_dict(cls, _dict: Dict) -> 'BuildRunStatus': + """Initialize a BuildRunStatus object from a json dictionary.""" + args = {} + if 'completion_time' in _dict: + args['completion_time'] = _dict.get('completion_time') + if 'output_digest' in _dict: + args['output_digest'] = _dict.get('output_digest') + if 'reason' in _dict: + args['reason'] = _dict.get('reason') + if 'start_time' in _dict: + args['start_time'] = _dict.get('start_time') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a BuildRunStatus object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'completion_time') and self.completion_time is not None: + _dict['completion_time'] = self.completion_time + if hasattr(self, 'output_digest') and self.output_digest is not None: + _dict['output_digest'] = self.output_digest + if hasattr(self, 'reason') and self.reason is not None: + _dict['reason'] = self.reason + if hasattr(self, 'start_time') and self.start_time is not None: + _dict['start_time'] = self.start_time + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this BuildRunStatus object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'BuildRunStatus') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'BuildRunStatus') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ReasonEnum(str, Enum): + """ + Optional information to provide more context in case of a 'failed' or 'warning' + status. + """ + + SUCCEEDED = 'succeeded' + RUNNING = 'running' + PENDING = 'pending' + FAILED_TO_EXECUTE_BUILD_RUN = 'failed_to_execute_build_run' + EXCEEDED_EPHEMERAL_STORAGE = 'exceeded_ephemeral_storage' + MISSING_REGISTRY_ACCESS = 'missing_registry_access' + MISSING_CODE_REPO_ACCESS = 'missing_code_repo_access' + MISSING_SECRETS = 'missing_secrets' + UNKNOWN_STRATEGY = 'unknown_strategy' + INVALID_BUILD_CONFIGURATION = 'invalid_build_configuration' + POD_EVICTED_BECAUSE_OF_STORAGE_QUOTA_EXCEEDS = 'pod_evicted_because_of_storage_quota_exceeds' + POD_EVICTED = 'pod_evicted' + MISSING_TASK_RUN = 'missing_task_run' + TASK_RUN_GENERATION_FAILED = 'task_run_generation_failed' + BUILD_NOT_FOUND = 'build_not_found' + TIMEOUT = 'timeout' + FAILED = 'failed' + + +class BuildStatus: + """ + The detailed status of the build. + + :attr str reason: (optional) Optional information to provide more context in + case of a 'failed' or 'warning' status. + """ + + def __init__(self, *, reason: str = None) -> None: + """ + Initialize a BuildStatus object. + + :param str reason: (optional) Optional information to provide more context + in case of a 'failed' or 'warning' status. + """ + self.reason = reason + + @classmethod + def from_dict(cls, _dict: Dict) -> 'BuildStatus': + """Initialize a BuildStatus object from a json dictionary.""" + args = {} + if 'reason' in _dict: + args['reason'] = _dict.get('reason') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a BuildStatus object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'reason') and self.reason is not None: + _dict['reason'] = self.reason + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this BuildStatus object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'BuildStatus') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'BuildStatus') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ReasonEnum(str, Enum): + """ + Optional information to provide more context in case of a 'failed' or 'warning' + status. + """ + + REGISTERED = 'registered' + STRATEGY_NOT_FOUND = 'strategy_not_found' + CLUSTER_BUILD_STRATEGY_NOT_FOUND = 'cluster_build_strategy_not_found' + SET_OWNER_REFERENCE_FAILED = 'set_owner_reference_failed' + SPEC_SOURCE_SECRET_NOT_FOUND = 'spec_source_secret_not_found' + SPEC_OUTPUT_SECRET_REF_NOT_FOUND = 'spec_output_secret_ref_not_found' + SPEC_RUNTIME_SECRET_REF_NOT_FOUND = 'spec_runtime_secret_ref_not_found' + MULTIPLE_SECRET_REF_NOT_FOUND = 'multiple_secret_ref_not_found' + RUNTIME_PATHS_CAN_NOT_BE_EMPTY = 'runtime_paths_can_not_be_empty' + REMOTE_REPOSITORY_UNREACHABLE = 'remote_repository_unreachable' + FAILED = 'failed' + + +class ConfigMap: + """ + Describes the model of a configmap. + + :attr str created_at: The date when the resource was created. + :attr dict data: (optional) The key-value pair for the config map. Values must + be specified in `KEY=VALUE` format. + :attr str entity_tag: The version of the config map instance, which is used to + achieve optimistic locking. + :attr str href: (optional) When you provision a new config map, a URL is + created identifying the location of the instance. + :attr str id: The identifier of the resource. + :attr str name: The name of the config map. + :attr str project_id: The ID of the project the resource is located in. + :attr str resource_type: The type of the config map. + """ + + def __init__( + self, + created_at: str, + entity_tag: str, + id: str, + name: str, + project_id: str, + resource_type: str, + *, + data: dict = None, + href: str = None, + ) -> None: + """ + Initialize a ConfigMap object. + + :param str created_at: The date when the resource was created. + :param str entity_tag: The version of the config map instance, which is + used to achieve optimistic locking. + :param str id: The identifier of the resource. + :param str name: The name of the config map. + :param str project_id: The ID of the project the resource is located in. + :param str resource_type: The type of the config map. + :param dict data: (optional) The key-value pair for the config map. Values + must be specified in `KEY=VALUE` format. + :param str href: (optional) When you provision a new config map, a URL is + created identifying the location of the instance. + """ + self.created_at = created_at + self.data = data + self.entity_tag = entity_tag + self.href = href + self.id = id + self.name = name + self.project_id = project_id + self.resource_type = resource_type + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ConfigMap': + """Initialize a ConfigMap object from a json dictionary.""" + args = {} + if 'created_at' in _dict: + args['created_at'] = _dict.get('created_at') + else: + raise ValueError('Required property \'created_at\' not present in ConfigMap JSON') + if 'data' in _dict: + args['data'] = _dict.get('data') + if 'entity_tag' in _dict: + args['entity_tag'] = _dict.get('entity_tag') + else: + raise ValueError('Required property \'entity_tag\' not present in ConfigMap JSON') + if 'href' in _dict: + args['href'] = _dict.get('href') + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in ConfigMap JSON') + if 'name' in _dict: + args['name'] = _dict.get('name') + else: + raise ValueError('Required property \'name\' not present in ConfigMap JSON') + if 'project_id' in _dict: + args['project_id'] = _dict.get('project_id') + else: + raise ValueError('Required property \'project_id\' not present in ConfigMap JSON') + if 'resource_type' in _dict: + args['resource_type'] = _dict.get('resource_type') + else: + raise ValueError('Required property \'resource_type\' not present in ConfigMap JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ConfigMap object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'created_at') and self.created_at is not None: + _dict['created_at'] = self.created_at + if hasattr(self, 'data') and self.data is not None: + _dict['data'] = self.data + if hasattr(self, 'entity_tag') and self.entity_tag is not None: + _dict['entity_tag'] = self.entity_tag + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'project_id') and self.project_id is not None: + _dict['project_id'] = self.project_id + if hasattr(self, 'resource_type') and self.resource_type is not None: + _dict['resource_type'] = self.resource_type + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ConfigMap object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ConfigMap') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ConfigMap') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ResourceTypeEnum(str, Enum): + """ + The type of the config map. + """ + + CONFIG_MAP_V2 = 'config_map_v2' + + +class ConfigMapList: + """ + Contains a list of configmaps and pagination information. + + :attr List[ConfigMap] config_maps: List of all configmaps. + :attr ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :attr int limit: Maximum number of resources per page. + :attr ListNextMetadata next: (optional) Describes properties needed to retrieve + the next page of a result list. + """ + + def __init__( + self, + config_maps: List['ConfigMap'], + limit: int, + *, + first: 'ListFirstMetadata' = None, + next: 'ListNextMetadata' = None, + ) -> None: + """ + Initialize a ConfigMapList object. + + :param List[ConfigMap] config_maps: List of all configmaps. + :param int limit: Maximum number of resources per page. + :param ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :param ListNextMetadata next: (optional) Describes properties needed to + retrieve the next page of a result list. + """ + self.config_maps = config_maps + self.first = first + self.limit = limit + self.next = next + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ConfigMapList': + """Initialize a ConfigMapList object from a json dictionary.""" + args = {} + if 'config_maps' in _dict: + args['config_maps'] = [ConfigMap.from_dict(v) for v in _dict.get('config_maps')] + else: + raise ValueError('Required property \'config_maps\' not present in ConfigMapList JSON') + if 'first' in _dict: + args['first'] = ListFirstMetadata.from_dict(_dict.get('first')) + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in ConfigMapList JSON') + if 'next' in _dict: + args['next'] = ListNextMetadata.from_dict(_dict.get('next')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ConfigMapList object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'config_maps') and self.config_maps is not None: + config_maps_list = [] + for v in self.config_maps: + if isinstance(v, dict): + config_maps_list.append(v) + else: + config_maps_list.append(v.to_dict()) + _dict['config_maps'] = config_maps_list + if hasattr(self, 'first') and self.first is not None: + if isinstance(self.first, dict): + _dict['first'] = self.first + else: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'next') and self.next is not None: + if isinstance(self.next, dict): + _dict['next'] = self.next + else: + _dict['next'] = self.next.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ConfigMapList object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ConfigMapList') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ConfigMapList') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class EnvVar: + """ + Response model for environment variables. + + :attr str key: (optional) The key to reference as environment variable. + :attr str name: (optional) The name of the environment variable. + :attr str prefix: (optional) A prefix that can be added to all keys of a full + secret or config map reference. + :attr str reference: (optional) The name of the secret or config map. + :attr str type: Specify the type of the environment variable. + :attr str value: (optional) The literal value of the environment variable. + """ + + def __init__( + self, + type: str, + *, + key: str = None, + name: str = None, + prefix: str = None, + reference: str = None, + value: str = None, + ) -> None: + """ + Initialize a EnvVar object. + + :param str type: Specify the type of the environment variable. + :param str key: (optional) The key to reference as environment variable. + :param str name: (optional) The name of the environment variable. + :param str prefix: (optional) A prefix that can be added to all keys of a + full secret or config map reference. + :param str reference: (optional) The name of the secret or config map. + :param str value: (optional) The literal value of the environment variable. + """ + self.key = key + self.name = name + self.prefix = prefix + self.reference = reference + self.type = type + self.value = value + + @classmethod + def from_dict(cls, _dict: Dict) -> 'EnvVar': + """Initialize a EnvVar object from a json dictionary.""" + args = {} + if 'key' in _dict: + args['key'] = _dict.get('key') + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'prefix' in _dict: + args['prefix'] = _dict.get('prefix') + if 'reference' in _dict: + args['reference'] = _dict.get('reference') + if 'type' in _dict: + args['type'] = _dict.get('type') + else: + raise ValueError('Required property \'type\' not present in EnvVar JSON') + if 'value' in _dict: + args['value'] = _dict.get('value') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a EnvVar object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'key') and self.key is not None: + _dict['key'] = self.key + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'prefix') and self.prefix is not None: + _dict['prefix'] = self.prefix + if hasattr(self, 'reference') and self.reference is not None: + _dict['reference'] = self.reference + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + if hasattr(self, 'value') and self.value is not None: + _dict['value'] = self.value + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this EnvVar object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'EnvVar') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'EnvVar') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class TypeEnum(str, Enum): + """ + Specify the type of the environment variable. + """ + + LITERAL = 'literal' + CONFIG_MAP_FULL_REFERENCE = 'config_map_full_reference' + SECRET_FULL_REFERENCE = 'secret_full_reference' + CONFIG_MAP_KEY_REFERENCE = 'config_map_key_reference' + SECRET_KEY_REFERENCE = 'secret_key_reference' + + +class EnvVarPrototype: + """ + Prototype model for environment variables. + + :attr str key: (optional) The key to reference as environment variable. + :attr str name: (optional) The name of the environment variable. + :attr str prefix: (optional) A prefix that can be added to all keys of a full + secret or config map reference. + :attr str reference: (optional) The name of the secret or config map. + :attr str type: (optional) Specify the type of the environment variable. + :attr str value: (optional) The literal value of the environment variable. + """ + + def __init__( + self, + *, + key: str = None, + name: str = None, + prefix: str = None, + reference: str = None, + type: str = None, + value: str = None, + ) -> None: + """ + Initialize a EnvVarPrototype object. + + :param str key: (optional) The key to reference as environment variable. + :param str name: (optional) The name of the environment variable. + :param str prefix: (optional) A prefix that can be added to all keys of a + full secret or config map reference. + :param str reference: (optional) The name of the secret or config map. + :param str type: (optional) Specify the type of the environment variable. + :param str value: (optional) The literal value of the environment variable. + """ + self.key = key + self.name = name + self.prefix = prefix + self.reference = reference + self.type = type + self.value = value + + @classmethod + def from_dict(cls, _dict: Dict) -> 'EnvVarPrototype': + """Initialize a EnvVarPrototype object from a json dictionary.""" + args = {} + if 'key' in _dict: + args['key'] = _dict.get('key') + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'prefix' in _dict: + args['prefix'] = _dict.get('prefix') + if 'reference' in _dict: + args['reference'] = _dict.get('reference') + if 'type' in _dict: + args['type'] = _dict.get('type') + if 'value' in _dict: + args['value'] = _dict.get('value') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a EnvVarPrototype object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'key') and self.key is not None: + _dict['key'] = self.key + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'prefix') and self.prefix is not None: + _dict['prefix'] = self.prefix + if hasattr(self, 'reference') and self.reference is not None: + _dict['reference'] = self.reference + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + if hasattr(self, 'value') and self.value is not None: + _dict['value'] = self.value + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this EnvVarPrototype object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'EnvVarPrototype') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'EnvVarPrototype') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class TypeEnum(str, Enum): + """ + Specify the type of the environment variable. + """ + + LITERAL = 'literal' + CONFIG_MAP_FULL_REFERENCE = 'config_map_full_reference' + SECRET_FULL_REFERENCE = 'secret_full_reference' + CONFIG_MAP_KEY_REFERENCE = 'config_map_key_reference' + SECRET_KEY_REFERENCE = 'secret_key_reference' + + +class Job: + """ + Job is the response model for job resources. + + :attr str created_at: The date when the resource was created. + :attr str entity_tag: The version of the job instance, which is used to achieve + optimistic locking. + :attr str href: When you provision a new job, a URL is created identifying the + location of the instance. + :attr str id: The identifier of the resource. + :attr str image_reference: The name of the image that is used for this job. The + format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and `TAG` are + optional. If `REGISTRY` is not specified, the default is `docker.io`. If `TAG` + is not specified, the default is `latest`. If the image reference points to a + registry that requires authentication, make sure to also specify the property + `image_secret`. + :attr str image_secret: (optional) The name of the image registry access secret. + The image registry access secret is used to authenticate with a private registry + when you download the container image. If the image reference points to a + registry that requires authentication, the job / job runs will be created but + submitted job runs will fail, until this property is provided, too. + :attr str name: The name of the job. + :attr str project_id: The ID of the project the resource is located in. + :attr str resource_type: The type of the job. + :attr List[str] run_arguments: Set arguments for the job that are passed to + start job run containers. If not specified an empty string array will be applied + and the arguments specified by the container image, will be used to start the + container. + :attr int run_as_user: (optional) The user ID (UID) to run the application + (e.g., 1001). + :attr List[str] run_commands: Set commands for the job that are passed to start + job run containers. If not specified an empty string array will be applied and + the command specified by the container image, will be used to start the + container. + :attr List[EnvVar] run_env_variables: References to config maps, secrets or a + literal values, which are exposed as environment variables in the job run. + :attr str run_mode: The mode for runs of the job. Valid values are `task` and + `daemon`. In `task` mode, the `max_execution_time` and `retry_limit` options + apply. In `daemon` mode, since there is no timeout and failed instances are + restarted indefinitely, the `max_execution_time` and `retry_limit` options are + not allowed. + :attr str run_service_account: (optional) The name of the service account. For + built-in service accounts, you can use the shortened names `manager`, `none`, + `reader`, and `writer`. + :attr List[VolumeMount] run_volume_mounts: Optional mounts of config maps or a + secrets. + :attr str scale_array_spec: Define a custom set of array indices as + comma-separated list containing single values and hyphen-separated ranges like + `5,12-14,23,27`. Each instance can pick up its array index via environment + variable `JOB_INDEX`. The number of unique array indices specified here + determines the number of job instances to run. + :attr str scale_cpu_limit: Optional amount of CPU set for the instance of the + job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :attr str scale_ephemeral_storage_limit: Optional amount of ephemeral storage to + set for the instance of the job. The amount specified as ephemeral storage, must + not exceed the amount of `scale_memory_limit`. The units for specifying + ephemeral storage are Megabyte (M) or Gigabyte (G), whereas G and M are the + shorthand expressions for GB and MB. For more information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_max_execution_time: (optional) The maximum execution time in + seconds for runs of the job. This option can only be specified if `mode` is + `task`. + :attr str scale_memory_limit: Optional amount of memory set for the instance of + the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G and + M are the shorthand expressions for GB and MB. For more information see [Units + of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_retry_limit: (optional) The number of times to rerun an instance + of the job before the job is marked as failed. This option can only be specified + if `mode` is `task`. + """ + + def __init__( + self, + created_at: str, + entity_tag: str, + href: str, + id: str, + image_reference: str, + name: str, + project_id: str, + resource_type: str, + run_arguments: List[str], + run_commands: List[str], + run_env_variables: List['EnvVar'], + run_mode: str, + run_volume_mounts: List['VolumeMount'], + scale_array_spec: str, + scale_cpu_limit: str, + scale_ephemeral_storage_limit: str, + scale_memory_limit: str, + *, + image_secret: str = None, + run_as_user: int = None, + run_service_account: str = None, + scale_max_execution_time: int = None, + scale_retry_limit: int = None, + ) -> None: + """ + Initialize a Job object. + + :param str created_at: The date when the resource was created. + :param str entity_tag: The version of the job instance, which is used to + achieve optimistic locking. + :param str href: When you provision a new job, a URL is created + identifying the location of the instance. + :param str id: The identifier of the resource. + :param str image_reference: The name of the image that is used for this + job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and + `TAG` are optional. If `REGISTRY` is not specified, the default is + `docker.io`. If `TAG` is not specified, the default is `latest`. If the + image reference points to a registry that requires authentication, make + sure to also specify the property `image_secret`. + :param str name: The name of the job. + :param str project_id: The ID of the project the resource is located in. + :param str resource_type: The type of the job. + :param List[str] run_arguments: Set arguments for the job that are passed + to start job run containers. If not specified an empty string array will be + applied and the arguments specified by the container image, will be used to + start the container. + :param List[str] run_commands: Set commands for the job that are passed to + start job run containers. If not specified an empty string array will be + applied and the command specified by the container image, will be used to + start the container. + :param List[EnvVar] run_env_variables: References to config maps, secrets + or a literal values, which are exposed as environment variables in the job + run. + :param str run_mode: The mode for runs of the job. Valid values are `task` + and `daemon`. In `task` mode, the `max_execution_time` and `retry_limit` + options apply. In `daemon` mode, since there is no timeout and failed + instances are restarted indefinitely, the `max_execution_time` and + `retry_limit` options are not allowed. + :param List[VolumeMount] run_volume_mounts: Optional mounts of config maps + or a secrets. + :param str scale_array_spec: Define a custom set of array indices as + comma-separated list containing single values and hyphen-separated ranges + like `5,12-14,23,27`. Each instance can pick up its array index via + environment variable `JOB_INDEX`. The number of unique array indices + specified here determines the number of job instances to run. + :param str scale_cpu_limit: Optional amount of CPU set for the instance of + the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :param str scale_ephemeral_storage_limit: Optional amount of ephemeral + storage to set for the instance of the job. The amount specified as + ephemeral storage, must not exceed the amount of `scale_memory_limit`. The + units for specifying ephemeral storage are Megabyte (M) or Gigabyte (G), + whereas G and M are the shorthand expressions for GB and MB. For more + information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param str scale_memory_limit: Optional amount of memory set for the + instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G + and M are the shorthand expressions for GB and MB. For more information see + [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param str image_secret: (optional) The name of the image registry access + secret. The image registry access secret is used to authenticate with a + private registry when you download the container image. If the image + reference points to a registry that requires authentication, the job / job + runs will be created but submitted job runs will fail, until this property + is provided, too. + :param int run_as_user: (optional) The user ID (UID) to run the application + (e.g., 1001). + :param str run_service_account: (optional) The name of the service account. + For built-in service accounts, you can use the shortened names `manager`, + `none`, `reader`, and `writer`. + :param int scale_max_execution_time: (optional) The maximum execution time + in seconds for runs of the job. This option can only be specified if `mode` + is `task`. + :param int scale_retry_limit: (optional) The number of times to rerun an + instance of the job before the job is marked as failed. This option can + only be specified if `mode` is `task`. + """ + self.created_at = created_at + self.entity_tag = entity_tag + self.href = href + self.id = id + self.image_reference = image_reference + self.image_secret = image_secret + self.name = name + self.project_id = project_id + self.resource_type = resource_type + self.run_arguments = run_arguments + self.run_as_user = run_as_user + self.run_commands = run_commands + self.run_env_variables = run_env_variables + self.run_mode = run_mode + self.run_service_account = run_service_account + self.run_volume_mounts = run_volume_mounts + self.scale_array_spec = scale_array_spec + self.scale_cpu_limit = scale_cpu_limit + self.scale_ephemeral_storage_limit = scale_ephemeral_storage_limit + self.scale_max_execution_time = scale_max_execution_time + self.scale_memory_limit = scale_memory_limit + self.scale_retry_limit = scale_retry_limit + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Job': + """Initialize a Job object from a json dictionary.""" + args = {} + if 'created_at' in _dict: + args['created_at'] = _dict.get('created_at') + else: + raise ValueError('Required property \'created_at\' not present in Job JSON') + if 'entity_tag' in _dict: + args['entity_tag'] = _dict.get('entity_tag') + else: + raise ValueError('Required property \'entity_tag\' not present in Job JSON') + if 'href' in _dict: + args['href'] = _dict.get('href') + else: + raise ValueError('Required property \'href\' not present in Job JSON') + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in Job JSON') + if 'image_reference' in _dict: + args['image_reference'] = _dict.get('image_reference') + else: + raise ValueError('Required property \'image_reference\' not present in Job JSON') + if 'image_secret' in _dict: + args['image_secret'] = _dict.get('image_secret') + if 'name' in _dict: + args['name'] = _dict.get('name') + else: + raise ValueError('Required property \'name\' not present in Job JSON') + if 'project_id' in _dict: + args['project_id'] = _dict.get('project_id') + else: + raise ValueError('Required property \'project_id\' not present in Job JSON') + if 'resource_type' in _dict: + args['resource_type'] = _dict.get('resource_type') + else: + raise ValueError('Required property \'resource_type\' not present in Job JSON') + if 'run_arguments' in _dict: + args['run_arguments'] = _dict.get('run_arguments') + else: + raise ValueError('Required property \'run_arguments\' not present in Job JSON') + if 'run_as_user' in _dict: + args['run_as_user'] = _dict.get('run_as_user') + if 'run_commands' in _dict: + args['run_commands'] = _dict.get('run_commands') + else: + raise ValueError('Required property \'run_commands\' not present in Job JSON') + if 'run_env_variables' in _dict: + args['run_env_variables'] = [EnvVar.from_dict(v) for v in _dict.get('run_env_variables')] + else: + raise ValueError('Required property \'run_env_variables\' not present in Job JSON') + if 'run_mode' in _dict: + args['run_mode'] = _dict.get('run_mode') + else: + raise ValueError('Required property \'run_mode\' not present in Job JSON') + if 'run_service_account' in _dict: + args['run_service_account'] = _dict.get('run_service_account') + if 'run_volume_mounts' in _dict: + args['run_volume_mounts'] = [VolumeMount.from_dict(v) for v in _dict.get('run_volume_mounts')] + else: + raise ValueError('Required property \'run_volume_mounts\' not present in Job JSON') + if 'scale_array_spec' in _dict: + args['scale_array_spec'] = _dict.get('scale_array_spec') + else: + raise ValueError('Required property \'scale_array_spec\' not present in Job JSON') + if 'scale_cpu_limit' in _dict: + args['scale_cpu_limit'] = _dict.get('scale_cpu_limit') + else: + raise ValueError('Required property \'scale_cpu_limit\' not present in Job JSON') + if 'scale_ephemeral_storage_limit' in _dict: + args['scale_ephemeral_storage_limit'] = _dict.get('scale_ephemeral_storage_limit') + else: + raise ValueError('Required property \'scale_ephemeral_storage_limit\' not present in Job JSON') + if 'scale_max_execution_time' in _dict: + args['scale_max_execution_time'] = _dict.get('scale_max_execution_time') + if 'scale_memory_limit' in _dict: + args['scale_memory_limit'] = _dict.get('scale_memory_limit') + else: + raise ValueError('Required property \'scale_memory_limit\' not present in Job JSON') + if 'scale_retry_limit' in _dict: + args['scale_retry_limit'] = _dict.get('scale_retry_limit') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Job object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'created_at') and self.created_at is not None: + _dict['created_at'] = self.created_at + if hasattr(self, 'entity_tag') and self.entity_tag is not None: + _dict['entity_tag'] = self.entity_tag + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'image_reference') and self.image_reference is not None: + _dict['image_reference'] = self.image_reference + if hasattr(self, 'image_secret') and self.image_secret is not None: + _dict['image_secret'] = self.image_secret + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'project_id') and self.project_id is not None: + _dict['project_id'] = self.project_id + if hasattr(self, 'resource_type') and self.resource_type is not None: + _dict['resource_type'] = self.resource_type + if hasattr(self, 'run_arguments') and self.run_arguments is not None: + _dict['run_arguments'] = self.run_arguments + if hasattr(self, 'run_as_user') and self.run_as_user is not None: + _dict['run_as_user'] = self.run_as_user + if hasattr(self, 'run_commands') and self.run_commands is not None: + _dict['run_commands'] = self.run_commands + if hasattr(self, 'run_env_variables') and self.run_env_variables is not None: + run_env_variables_list = [] + for v in self.run_env_variables: + if isinstance(v, dict): + run_env_variables_list.append(v) + else: + run_env_variables_list.append(v.to_dict()) + _dict['run_env_variables'] = run_env_variables_list + if hasattr(self, 'run_mode') and self.run_mode is not None: + _dict['run_mode'] = self.run_mode + if hasattr(self, 'run_service_account') and self.run_service_account is not None: + _dict['run_service_account'] = self.run_service_account + if hasattr(self, 'run_volume_mounts') and self.run_volume_mounts is not None: + run_volume_mounts_list = [] + for v in self.run_volume_mounts: + if isinstance(v, dict): + run_volume_mounts_list.append(v) + else: + run_volume_mounts_list.append(v.to_dict()) + _dict['run_volume_mounts'] = run_volume_mounts_list + if hasattr(self, 'scale_array_spec') and self.scale_array_spec is not None: + _dict['scale_array_spec'] = self.scale_array_spec + if hasattr(self, 'scale_cpu_limit') and self.scale_cpu_limit is not None: + _dict['scale_cpu_limit'] = self.scale_cpu_limit + if hasattr(self, 'scale_ephemeral_storage_limit') and self.scale_ephemeral_storage_limit is not None: + _dict['scale_ephemeral_storage_limit'] = self.scale_ephemeral_storage_limit + if hasattr(self, 'scale_max_execution_time') and self.scale_max_execution_time is not None: + _dict['scale_max_execution_time'] = self.scale_max_execution_time + if hasattr(self, 'scale_memory_limit') and self.scale_memory_limit is not None: + _dict['scale_memory_limit'] = self.scale_memory_limit + if hasattr(self, 'scale_retry_limit') and self.scale_retry_limit is not None: + _dict['scale_retry_limit'] = self.scale_retry_limit + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Job object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Job') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Job') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ResourceTypeEnum(str, Enum): + """ + The type of the job. + """ + + JOB_V2 = 'job_v2' + + class RunModeEnum(str, Enum): + """ + The mode for runs of the job. Valid values are `task` and `daemon`. In `task` + mode, the `max_execution_time` and `retry_limit` options apply. In `daemon` mode, + since there is no timeout and failed instances are restarted indefinitely, the + `max_execution_time` and `retry_limit` options are not allowed. + """ + + TASK = 'task' + DAEMON = 'daemon' + + class RunServiceAccountEnum(str, Enum): + """ + The name of the service account. For built-in service accounts, you can use the + shortened names `manager`, `none`, `reader`, and `writer`. + """ + + DEFAULT = 'default' + MANAGER = 'manager' + READER = 'reader' + WRITER = 'writer' + NONE = 'none' + + +class JobList: + """ + Contains a list of jobs and pagination information. + + :attr ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :attr List[Job] jobs: List of all jobs. + :attr int limit: Maximum number of resources per page. + :attr ListNextMetadata next: (optional) Describes properties needed to retrieve + the next page of a result list. + """ + + def __init__( + self, jobs: List['Job'], limit: int, *, first: 'ListFirstMetadata' = None, next: 'ListNextMetadata' = None + ) -> None: + """ + Initialize a JobList object. + + :param List[Job] jobs: List of all jobs. + :param int limit: Maximum number of resources per page. + :param ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :param ListNextMetadata next: (optional) Describes properties needed to + retrieve the next page of a result list. + """ + self.first = first + self.jobs = jobs + self.limit = limit + self.next = next + + @classmethod + def from_dict(cls, _dict: Dict) -> 'JobList': + """Initialize a JobList object from a json dictionary.""" + args = {} + if 'first' in _dict: + args['first'] = ListFirstMetadata.from_dict(_dict.get('first')) + if 'jobs' in _dict: + args['jobs'] = [Job.from_dict(v) for v in _dict.get('jobs')] + else: + raise ValueError('Required property \'jobs\' not present in JobList JSON') + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in JobList JSON') + if 'next' in _dict: + args['next'] = ListNextMetadata.from_dict(_dict.get('next')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a JobList object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'first') and self.first is not None: + if isinstance(self.first, dict): + _dict['first'] = self.first + else: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'jobs') and self.jobs is not None: + jobs_list = [] + for v in self.jobs: + if isinstance(v, dict): + jobs_list.append(v) + else: + jobs_list.append(v.to_dict()) + _dict['jobs'] = jobs_list + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'next') and self.next is not None: + if isinstance(self.next, dict): + _dict['next'] = self.next + else: + _dict['next'] = self.next.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this JobList object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'JobList') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'JobList') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class JobPatch: + """ + Request model for job update operations. + + :attr str image_reference: (optional) The name of the image that is used for + this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and + `TAG` are optional. If `REGISTRY` is not specified, the default is `docker.io`. + If `TAG` is not specified, the default is `latest`. If the image reference + points to a registry that requires authentication, make sure to also specify the + property `image_secret`. + :attr str image_secret: (optional) The name of the image registry access secret. + The image registry access secret is used to authenticate with a private registry + when you download the container image. If the image reference points to a + registry that requires authentication, the job / job runs will be created but + submitted job runs will fail, until this property is provided, too. + :attr List[str] run_arguments: (optional) Set arguments for the job that are + passed to start job run containers. If not specified an empty string array will + be applied and the arguments specified by the container image, will be used to + start the container. + :attr int run_as_user: (optional) The user ID (UID) to run the application + (e.g., 1001). + :attr List[str] run_commands: (optional) Set commands for the job that are + passed to start job run containers. If not specified an empty string array will + be applied and the command specified by the container image, will be used to + start the container. + :attr List[EnvVarPrototype] run_env_variables: (optional) Optional references to + config maps, secrets or a literal values. + :attr str run_mode: (optional) The mode for runs of the job. Valid values are + `task` and `daemon`. In `task` mode, the `max_execution_time` and `retry_limit` + options apply. In `daemon` mode, since there is no timeout and failed instances + are restarted indefinitely, the `max_execution_time` and `retry_limit` options + are not allowed. + :attr str run_service_account: (optional) The name of the service account. For + built-in service accounts, you can use the shortened names `manager`, `none`, + `reader`, and `writer`. + :attr List[VolumeMountPrototype] run_volume_mounts: (optional) Optional mounts + of config maps or a secrets. In case this is provided, existing + `run_volume_mounts` will be overwritten. + :attr str scale_array_spec: (optional) Define a custom set of array indices as + comma-separated list containing single values and hyphen-separated ranges like + `5,12-14,23,27`. Each instance can pick up its array index via environment + variable `JOB_INDEX`. The number of unique array indices specified here + determines the number of job instances to run. + :attr str scale_cpu_limit: (optional) Optional amount of CPU set for the + instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :attr str scale_ephemeral_storage_limit: (optional) Optional amount of ephemeral + storage to set for the instance of the job. The amount specified as ephemeral + storage, must not exceed the amount of `scale_memory_limit`. The units for + specifying ephemeral storage are Megabyte (M) or Gigabyte (G), whereas G and M + are the shorthand expressions for GB and MB. For more information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_max_execution_time: (optional) The maximum execution time in + seconds for runs of the job. This option can only be specified if `mode` is + `task`. + :attr str scale_memory_limit: (optional) Optional amount of memory set for the + instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G and + M are the shorthand expressions for GB and MB. For more information see [Units + of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_retry_limit: (optional) The number of times to rerun an instance + of the job before the job is marked as failed. This option can only be specified + if `mode` is `task`. + """ + + def __init__( + self, + *, + image_reference: str = None, + image_secret: str = None, + run_arguments: List[str] = None, + run_as_user: int = None, + run_commands: List[str] = None, + run_env_variables: List['EnvVarPrototype'] = None, + run_mode: str = None, + run_service_account: str = None, + run_volume_mounts: List['VolumeMountPrototype'] = None, + scale_array_spec: str = None, + scale_cpu_limit: str = None, + scale_ephemeral_storage_limit: str = None, + scale_max_execution_time: int = None, + scale_memory_limit: str = None, + scale_retry_limit: int = None, + ) -> None: + """ + Initialize a JobPatch object. + + :param str image_reference: (optional) The name of the image that is used + for this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where + `REGISTRY` and `TAG` are optional. If `REGISTRY` is not specified, the + default is `docker.io`. If `TAG` is not specified, the default is `latest`. + If the image reference points to a registry that requires authentication, + make sure to also specify the property `image_secret`. + :param str image_secret: (optional) The name of the image registry access + secret. The image registry access secret is used to authenticate with a + private registry when you download the container image. If the image + reference points to a registry that requires authentication, the job / job + runs will be created but submitted job runs will fail, until this property + is provided, too. + :param List[str] run_arguments: (optional) Set arguments for the job that + are passed to start job run containers. If not specified an empty string + array will be applied and the arguments specified by the container image, + will be used to start the container. + :param int run_as_user: (optional) The user ID (UID) to run the application + (e.g., 1001). + :param List[str] run_commands: (optional) Set commands for the job that are + passed to start job run containers. If not specified an empty string array + will be applied and the command specified by the container image, will be + used to start the container. + :param List[EnvVarPrototype] run_env_variables: (optional) Optional + references to config maps, secrets or a literal values. + :param str run_mode: (optional) The mode for runs of the job. Valid values + are `task` and `daemon`. In `task` mode, the `max_execution_time` and + `retry_limit` options apply. In `daemon` mode, since there is no timeout + and failed instances are restarted indefinitely, the `max_execution_time` + and `retry_limit` options are not allowed. + :param str run_service_account: (optional) The name of the service account. + For built-in service accounts, you can use the shortened names `manager`, + `none`, `reader`, and `writer`. + :param List[VolumeMountPrototype] run_volume_mounts: (optional) Optional + mounts of config maps or a secrets. In case this is provided, existing + `run_volume_mounts` will be overwritten. + :param str scale_array_spec: (optional) Define a custom set of array + indices as comma-separated list containing single values and + hyphen-separated ranges like `5,12-14,23,27`. Each instance can pick up its + array index via environment variable `JOB_INDEX`. The number of unique + array indices specified here determines the number of job instances to run. + :param str scale_cpu_limit: (optional) Optional amount of CPU set for the + instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :param str scale_ephemeral_storage_limit: (optional) Optional amount of + ephemeral storage to set for the instance of the job. The amount specified + as ephemeral storage, must not exceed the amount of `scale_memory_limit`. + The units for specifying ephemeral storage are Megabyte (M) or Gigabyte + (G), whereas G and M are the shorthand expressions for GB and MB. For more + information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_max_execution_time: (optional) The maximum execution time + in seconds for runs of the job. This option can only be specified if `mode` + is `task`. + :param str scale_memory_limit: (optional) Optional amount of memory set for + the instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G + and M are the shorthand expressions for GB and MB. For more information see + [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_retry_limit: (optional) The number of times to rerun an + instance of the job before the job is marked as failed. This option can + only be specified if `mode` is `task`. + """ + self.image_reference = image_reference + self.image_secret = image_secret + self.run_arguments = run_arguments + self.run_as_user = run_as_user + self.run_commands = run_commands + self.run_env_variables = run_env_variables + self.run_mode = run_mode + self.run_service_account = run_service_account + self.run_volume_mounts = run_volume_mounts + self.scale_array_spec = scale_array_spec + self.scale_cpu_limit = scale_cpu_limit + self.scale_ephemeral_storage_limit = scale_ephemeral_storage_limit + self.scale_max_execution_time = scale_max_execution_time + self.scale_memory_limit = scale_memory_limit + self.scale_retry_limit = scale_retry_limit + + @classmethod + def from_dict(cls, _dict: Dict) -> 'JobPatch': + """Initialize a JobPatch object from a json dictionary.""" + args = {} + if 'image_reference' in _dict: + args['image_reference'] = _dict.get('image_reference') + if 'image_secret' in _dict: + args['image_secret'] = _dict.get('image_secret') + if 'run_arguments' in _dict: + args['run_arguments'] = _dict.get('run_arguments') + if 'run_as_user' in _dict: + args['run_as_user'] = _dict.get('run_as_user') + if 'run_commands' in _dict: + args['run_commands'] = _dict.get('run_commands') + if 'run_env_variables' in _dict: + args['run_env_variables'] = [EnvVarPrototype.from_dict(v) for v in _dict.get('run_env_variables')] + if 'run_mode' in _dict: + args['run_mode'] = _dict.get('run_mode') + if 'run_service_account' in _dict: + args['run_service_account'] = _dict.get('run_service_account') + if 'run_volume_mounts' in _dict: + args['run_volume_mounts'] = [VolumeMountPrototype.from_dict(v) for v in _dict.get('run_volume_mounts')] + if 'scale_array_spec' in _dict: + args['scale_array_spec'] = _dict.get('scale_array_spec') + if 'scale_cpu_limit' in _dict: + args['scale_cpu_limit'] = _dict.get('scale_cpu_limit') + if 'scale_ephemeral_storage_limit' in _dict: + args['scale_ephemeral_storage_limit'] = _dict.get('scale_ephemeral_storage_limit') + if 'scale_max_execution_time' in _dict: + args['scale_max_execution_time'] = _dict.get('scale_max_execution_time') + if 'scale_memory_limit' in _dict: + args['scale_memory_limit'] = _dict.get('scale_memory_limit') + if 'scale_retry_limit' in _dict: + args['scale_retry_limit'] = _dict.get('scale_retry_limit') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a JobPatch object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'image_reference') and self.image_reference is not None: + _dict['image_reference'] = self.image_reference + if hasattr(self, 'image_secret') and self.image_secret is not None: + _dict['image_secret'] = self.image_secret + if hasattr(self, 'run_arguments') and self.run_arguments is not None: + _dict['run_arguments'] = self.run_arguments + if hasattr(self, 'run_as_user') and self.run_as_user is not None: + _dict['run_as_user'] = self.run_as_user + if hasattr(self, 'run_commands') and self.run_commands is not None: + _dict['run_commands'] = self.run_commands + if hasattr(self, 'run_env_variables') and self.run_env_variables is not None: + run_env_variables_list = [] + for v in self.run_env_variables: + if isinstance(v, dict): + run_env_variables_list.append(v) + else: + run_env_variables_list.append(v.to_dict()) + _dict['run_env_variables'] = run_env_variables_list + if hasattr(self, 'run_mode') and self.run_mode is not None: + _dict['run_mode'] = self.run_mode + if hasattr(self, 'run_service_account') and self.run_service_account is not None: + _dict['run_service_account'] = self.run_service_account + if hasattr(self, 'run_volume_mounts') and self.run_volume_mounts is not None: + run_volume_mounts_list = [] + for v in self.run_volume_mounts: + if isinstance(v, dict): + run_volume_mounts_list.append(v) + else: + run_volume_mounts_list.append(v.to_dict()) + _dict['run_volume_mounts'] = run_volume_mounts_list + if hasattr(self, 'scale_array_spec') and self.scale_array_spec is not None: + _dict['scale_array_spec'] = self.scale_array_spec + if hasattr(self, 'scale_cpu_limit') and self.scale_cpu_limit is not None: + _dict['scale_cpu_limit'] = self.scale_cpu_limit + if hasattr(self, 'scale_ephemeral_storage_limit') and self.scale_ephemeral_storage_limit is not None: + _dict['scale_ephemeral_storage_limit'] = self.scale_ephemeral_storage_limit + if hasattr(self, 'scale_max_execution_time') and self.scale_max_execution_time is not None: + _dict['scale_max_execution_time'] = self.scale_max_execution_time + if hasattr(self, 'scale_memory_limit') and self.scale_memory_limit is not None: + _dict['scale_memory_limit'] = self.scale_memory_limit + if hasattr(self, 'scale_retry_limit') and self.scale_retry_limit is not None: + _dict['scale_retry_limit'] = self.scale_retry_limit + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this JobPatch object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'JobPatch') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'JobPatch') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class RunModeEnum(str, Enum): + """ + The mode for runs of the job. Valid values are `task` and `daemon`. In `task` + mode, the `max_execution_time` and `retry_limit` options apply. In `daemon` mode, + since there is no timeout and failed instances are restarted indefinitely, the + `max_execution_time` and `retry_limit` options are not allowed. + """ + + TASK = 'task' + DAEMON = 'daemon' + + class RunServiceAccountEnum(str, Enum): + """ + The name of the service account. For built-in service accounts, you can use the + shortened names `manager`, `none`, `reader`, and `writer`. + """ + + DEFAULT = 'default' + MANAGER = 'manager' + READER = 'reader' + WRITER = 'writer' + NONE = 'none' + + +class JobRun: + """ + Response model for job run resources. + + :attr str created_at: (optional) The date when the resource was created. + :attr str href: (optional) When you provision a new job run, a URL is created + identifying the location of the instance. + :attr str id: (optional) The identifier of the resource. + :attr str image_reference: (optional) The name of the image that is used for + this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and + `TAG` are optional. If `REGISTRY` is not specified, the default is `docker.io`. + If `TAG` is not specified, the default is `latest`. If the image reference + points to a registry that requires authentication, make sure to also specify the + property `image_secret`. + :attr str image_secret: (optional) The name of the image registry access secret. + The image registry access secret is used to authenticate with a private registry + when you download the container image. If the image reference points to a + registry that requires authentication, the job / job runs will be created but + submitted job runs will fail, until this property is provided, too. + :attr str job_name: (optional) Optional name of the job reference of this job + run. If specified, the job run will inherit the configuration of the referenced + job. + :attr str name: (optional) The name of the job run. + :attr str project_id: The ID of the project the resource is located in. + :attr str resource_type: (optional) The type of the job run. + :attr List[str] run_arguments: Set arguments for the job that are passed to + start job run containers. If not specified an empty string array will be applied + and the arguments specified by the container image, will be used to start the + container. + :attr int run_as_user: (optional) The user ID (UID) to run the application + (e.g., 1001). + :attr List[str] run_commands: Set commands for the job that are passed to start + job run containers. If not specified an empty string array will be applied and + the command specified by the container image, will be used to start the + container. + :attr List[EnvVar] run_env_variables: References to config maps, secrets or a + literal values, which are exposed as environment variables in the job run. + :attr str run_mode: (optional) The mode for runs of the job. Valid values are + `task` and `daemon`. In `task` mode, the `max_execution_time` and `retry_limit` + options apply. In `daemon` mode, since there is no timeout and failed instances + are restarted indefinitely, the `max_execution_time` and `retry_limit` options + are not allowed. + :attr str run_service_account: (optional) The name of the service account. For + built-in service accounts, you can use the shortened names `manager`, `none`, + `reader`, and `writer`. + :attr List[VolumeMount] run_volume_mounts: Optional mounts of config maps or a + secrets. + :attr str scale_array_spec: (optional) Define a custom set of array indices as + comma-separated list containing single values and hyphen-separated ranges like + `5,12-14,23,27`. Each instance can pick up its array index via environment + variable `JOB_INDEX`. The number of unique array indices specified here + determines the number of job instances to run. + :attr str scale_cpu_limit: (optional) Optional amount of CPU set for the + instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :attr str scale_ephemeral_storage_limit: (optional) Optional amount of ephemeral + storage to set for the instance of the job. The amount specified as ephemeral + storage, must not exceed the amount of `scale_memory_limit`. The units for + specifying ephemeral storage are Megabyte (M) or Gigabyte (G), whereas G and M + are the shorthand expressions for GB and MB. For more information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_max_execution_time: (optional) The maximum execution time in + seconds for runs of the job. This option can only be specified if `mode` is + `task`. + :attr str scale_memory_limit: (optional) Optional amount of memory set for the + instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G and + M are the shorthand expressions for GB and MB. For more information see [Units + of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :attr int scale_retry_limit: (optional) The number of times to rerun an instance + of the job before the job is marked as failed. This option can only be specified + if `mode` is `task`. + :attr str status: (optional) The current status of the job run. + :attr JobRunStatus status_details: (optional) The detailed status of the job + run. + """ + + def __init__( + self, + project_id: str, + run_arguments: List[str], + run_commands: List[str], + run_env_variables: List['EnvVar'], + run_volume_mounts: List['VolumeMount'], + *, + created_at: str = None, + href: str = None, + id: str = None, + image_reference: str = None, + image_secret: str = None, + job_name: str = None, + name: str = None, + resource_type: str = None, + run_as_user: int = None, + run_mode: str = None, + run_service_account: str = None, + scale_array_spec: str = None, + scale_cpu_limit: str = None, + scale_ephemeral_storage_limit: str = None, + scale_max_execution_time: int = None, + scale_memory_limit: str = None, + scale_retry_limit: int = None, + status: str = None, + status_details: 'JobRunStatus' = None, + ) -> None: + """ + Initialize a JobRun object. + + :param str project_id: The ID of the project the resource is located in. + :param List[str] run_arguments: Set arguments for the job that are passed + to start job run containers. If not specified an empty string array will be + applied and the arguments specified by the container image, will be used to + start the container. + :param List[str] run_commands: Set commands for the job that are passed to + start job run containers. If not specified an empty string array will be + applied and the command specified by the container image, will be used to + start the container. + :param List[EnvVar] run_env_variables: References to config maps, secrets + or a literal values, which are exposed as environment variables in the job + run. + :param List[VolumeMount] run_volume_mounts: Optional mounts of config maps + or a secrets. + :param str created_at: (optional) The date when the resource was created. + :param str href: (optional) When you provision a new job run, a URL is + created identifying the location of the instance. + :param str id: (optional) The identifier of the resource. + :param str image_reference: (optional) The name of the image that is used + for this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where + `REGISTRY` and `TAG` are optional. If `REGISTRY` is not specified, the + default is `docker.io`. If `TAG` is not specified, the default is `latest`. + If the image reference points to a registry that requires authentication, + make sure to also specify the property `image_secret`. + :param str image_secret: (optional) The name of the image registry access + secret. The image registry access secret is used to authenticate with a + private registry when you download the container image. If the image + reference points to a registry that requires authentication, the job / job + runs will be created but submitted job runs will fail, until this property + is provided, too. + :param str job_name: (optional) Optional name of the job reference of this + job run. If specified, the job run will inherit the configuration of the + referenced job. + :param str name: (optional) The name of the job run. + :param str resource_type: (optional) The type of the job run. + :param int run_as_user: (optional) The user ID (UID) to run the application + (e.g., 1001). + :param str run_mode: (optional) The mode for runs of the job. Valid values + are `task` and `daemon`. In `task` mode, the `max_execution_time` and + `retry_limit` options apply. In `daemon` mode, since there is no timeout + and failed instances are restarted indefinitely, the `max_execution_time` + and `retry_limit` options are not allowed. + :param str run_service_account: (optional) The name of the service account. + For built-in service accounts, you can use the shortened names `manager`, + `none`, `reader`, and `writer`. + :param str scale_array_spec: (optional) Define a custom set of array + indices as comma-separated list containing single values and + hyphen-separated ranges like `5,12-14,23,27`. Each instance can pick up its + array index via environment variable `JOB_INDEX`. The number of unique + array indices specified here determines the number of job instances to run. + :param str scale_cpu_limit: (optional) Optional amount of CPU set for the + instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + :param str scale_ephemeral_storage_limit: (optional) Optional amount of + ephemeral storage to set for the instance of the job. The amount specified + as ephemeral storage, must not exceed the amount of `scale_memory_limit`. + The units for specifying ephemeral storage are Megabyte (M) or Gigabyte + (G), whereas G and M are the shorthand expressions for GB and MB. For more + information see [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_max_execution_time: (optional) The maximum execution time + in seconds for runs of the job. This option can only be specified if `mode` + is `task`. + :param str scale_memory_limit: (optional) Optional amount of memory set for + the instance of the job. For valid values see [Supported memory and CPU + combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + The units for specifying memory are Megabyte (M) or Gigabyte (G), whereas G + and M are the shorthand expressions for GB and MB. For more information see + [Units of + measurement](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo#unit-measurements). + :param int scale_retry_limit: (optional) The number of times to rerun an + instance of the job before the job is marked as failed. This option can + only be specified if `mode` is `task`. + :param str status: (optional) The current status of the job run. + :param JobRunStatus status_details: (optional) The detailed status of the + job run. + """ + self.created_at = created_at + self.href = href + self.id = id + self.image_reference = image_reference + self.image_secret = image_secret + self.job_name = job_name + self.name = name + self.project_id = project_id + self.resource_type = resource_type + self.run_arguments = run_arguments + self.run_as_user = run_as_user + self.run_commands = run_commands + self.run_env_variables = run_env_variables + self.run_mode = run_mode + self.run_service_account = run_service_account + self.run_volume_mounts = run_volume_mounts + self.scale_array_spec = scale_array_spec + self.scale_cpu_limit = scale_cpu_limit + self.scale_ephemeral_storage_limit = scale_ephemeral_storage_limit + self.scale_max_execution_time = scale_max_execution_time + self.scale_memory_limit = scale_memory_limit + self.scale_retry_limit = scale_retry_limit + self.status = status + self.status_details = status_details + + @classmethod + def from_dict(cls, _dict: Dict) -> 'JobRun': + """Initialize a JobRun object from a json dictionary.""" + args = {} + if 'created_at' in _dict: + args['created_at'] = _dict.get('created_at') + if 'href' in _dict: + args['href'] = _dict.get('href') + if 'id' in _dict: + args['id'] = _dict.get('id') + if 'image_reference' in _dict: + args['image_reference'] = _dict.get('image_reference') + if 'image_secret' in _dict: + args['image_secret'] = _dict.get('image_secret') + if 'job_name' in _dict: + args['job_name'] = _dict.get('job_name') + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'project_id' in _dict: + args['project_id'] = _dict.get('project_id') + else: + raise ValueError('Required property \'project_id\' not present in JobRun JSON') + if 'resource_type' in _dict: + args['resource_type'] = _dict.get('resource_type') + if 'run_arguments' in _dict: + args['run_arguments'] = _dict.get('run_arguments') + else: + raise ValueError('Required property \'run_arguments\' not present in JobRun JSON') + if 'run_as_user' in _dict: + args['run_as_user'] = _dict.get('run_as_user') + if 'run_commands' in _dict: + args['run_commands'] = _dict.get('run_commands') + else: + raise ValueError('Required property \'run_commands\' not present in JobRun JSON') + if 'run_env_variables' in _dict: + args['run_env_variables'] = [EnvVar.from_dict(v) for v in _dict.get('run_env_variables')] + else: + raise ValueError('Required property \'run_env_variables\' not present in JobRun JSON') + if 'run_mode' in _dict: + args['run_mode'] = _dict.get('run_mode') + if 'run_service_account' in _dict: + args['run_service_account'] = _dict.get('run_service_account') + if 'run_volume_mounts' in _dict: + args['run_volume_mounts'] = [VolumeMount.from_dict(v) for v in _dict.get('run_volume_mounts')] + else: + raise ValueError('Required property \'run_volume_mounts\' not present in JobRun JSON') + if 'scale_array_spec' in _dict: + args['scale_array_spec'] = _dict.get('scale_array_spec') + if 'scale_cpu_limit' in _dict: + args['scale_cpu_limit'] = _dict.get('scale_cpu_limit') + if 'scale_ephemeral_storage_limit' in _dict: + args['scale_ephemeral_storage_limit'] = _dict.get('scale_ephemeral_storage_limit') + if 'scale_max_execution_time' in _dict: + args['scale_max_execution_time'] = _dict.get('scale_max_execution_time') + if 'scale_memory_limit' in _dict: + args['scale_memory_limit'] = _dict.get('scale_memory_limit') + if 'scale_retry_limit' in _dict: + args['scale_retry_limit'] = _dict.get('scale_retry_limit') + if 'status' in _dict: + args['status'] = _dict.get('status') + if 'status_details' in _dict: + args['status_details'] = JobRunStatus.from_dict(_dict.get('status_details')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a JobRun object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'created_at') and self.created_at is not None: + _dict['created_at'] = self.created_at + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'image_reference') and self.image_reference is not None: + _dict['image_reference'] = self.image_reference + if hasattr(self, 'image_secret') and self.image_secret is not None: + _dict['image_secret'] = self.image_secret + if hasattr(self, 'job_name') and self.job_name is not None: + _dict['job_name'] = self.job_name + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'project_id') and self.project_id is not None: + _dict['project_id'] = self.project_id + if hasattr(self, 'resource_type') and self.resource_type is not None: + _dict['resource_type'] = self.resource_type + if hasattr(self, 'run_arguments') and self.run_arguments is not None: + _dict['run_arguments'] = self.run_arguments + if hasattr(self, 'run_as_user') and self.run_as_user is not None: + _dict['run_as_user'] = self.run_as_user + if hasattr(self, 'run_commands') and self.run_commands is not None: + _dict['run_commands'] = self.run_commands + if hasattr(self, 'run_env_variables') and self.run_env_variables is not None: + run_env_variables_list = [] + for v in self.run_env_variables: + if isinstance(v, dict): + run_env_variables_list.append(v) + else: + run_env_variables_list.append(v.to_dict()) + _dict['run_env_variables'] = run_env_variables_list + if hasattr(self, 'run_mode') and self.run_mode is not None: + _dict['run_mode'] = self.run_mode + if hasattr(self, 'run_service_account') and self.run_service_account is not None: + _dict['run_service_account'] = self.run_service_account + if hasattr(self, 'run_volume_mounts') and self.run_volume_mounts is not None: + run_volume_mounts_list = [] + for v in self.run_volume_mounts: + if isinstance(v, dict): + run_volume_mounts_list.append(v) + else: + run_volume_mounts_list.append(v.to_dict()) + _dict['run_volume_mounts'] = run_volume_mounts_list + if hasattr(self, 'scale_array_spec') and self.scale_array_spec is not None: + _dict['scale_array_spec'] = self.scale_array_spec + if hasattr(self, 'scale_cpu_limit') and self.scale_cpu_limit is not None: + _dict['scale_cpu_limit'] = self.scale_cpu_limit + if hasattr(self, 'scale_ephemeral_storage_limit') and self.scale_ephemeral_storage_limit is not None: + _dict['scale_ephemeral_storage_limit'] = self.scale_ephemeral_storage_limit + if hasattr(self, 'scale_max_execution_time') and self.scale_max_execution_time is not None: + _dict['scale_max_execution_time'] = self.scale_max_execution_time + if hasattr(self, 'scale_memory_limit') and self.scale_memory_limit is not None: + _dict['scale_memory_limit'] = self.scale_memory_limit + if hasattr(self, 'scale_retry_limit') and self.scale_retry_limit is not None: + _dict['scale_retry_limit'] = self.scale_retry_limit + if hasattr(self, 'status') and self.status is not None: + _dict['status'] = self.status + if hasattr(self, 'status_details') and self.status_details is not None: + if isinstance(self.status_details, dict): + _dict['status_details'] = self.status_details + else: + _dict['status_details'] = self.status_details.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this JobRun object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'JobRun') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'JobRun') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ResourceTypeEnum(str, Enum): + """ + The type of the job run. + """ + + JOB_RUN_V2 = 'job_run_v2' + + class RunModeEnum(str, Enum): + """ + The mode for runs of the job. Valid values are `task` and `daemon`. In `task` + mode, the `max_execution_time` and `retry_limit` options apply. In `daemon` mode, + since there is no timeout and failed instances are restarted indefinitely, the + `max_execution_time` and `retry_limit` options are not allowed. + """ + + TASK = 'task' + DAEMON = 'daemon' + + class RunServiceAccountEnum(str, Enum): + """ + The name of the service account. For built-in service accounts, you can use the + shortened names `manager`, `none`, `reader`, and `writer`. + """ + + DEFAULT = 'default' + MANAGER = 'manager' + READER = 'reader' + WRITER = 'writer' + NONE = 'none' + + class StatusEnum(str, Enum): + """ + The current status of the job run. + """ + + COMPLETED = 'completed' + RUNNING = 'running' + PENDING = 'pending' + + +class JobRunList: + """ + Contains a list of job runs and pagination information. + + :attr ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :attr List[JobRun] job_runs: List of all jobs. + :attr int limit: Maximum number of resources per page. + :attr ListNextMetadata next: (optional) Describes properties needed to retrieve + the next page of a result list. + """ + + def __init__( + self, + job_runs: List['JobRun'], + limit: int, + *, + first: 'ListFirstMetadata' = None, + next: 'ListNextMetadata' = None, + ) -> None: + """ + Initialize a JobRunList object. + + :param List[JobRun] job_runs: List of all jobs. + :param int limit: Maximum number of resources per page. + :param ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :param ListNextMetadata next: (optional) Describes properties needed to + retrieve the next page of a result list. + """ + self.first = first + self.job_runs = job_runs + self.limit = limit + self.next = next + + @classmethod + def from_dict(cls, _dict: Dict) -> 'JobRunList': + """Initialize a JobRunList object from a json dictionary.""" + args = {} + if 'first' in _dict: + args['first'] = ListFirstMetadata.from_dict(_dict.get('first')) + if 'job_runs' in _dict: + args['job_runs'] = [JobRun.from_dict(v) for v in _dict.get('job_runs')] + else: + raise ValueError('Required property \'job_runs\' not present in JobRunList JSON') + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in JobRunList JSON') + if 'next' in _dict: + args['next'] = ListNextMetadata.from_dict(_dict.get('next')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a JobRunList object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'first') and self.first is not None: + if isinstance(self.first, dict): + _dict['first'] = self.first + else: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'job_runs') and self.job_runs is not None: + job_runs_list = [] + for v in self.job_runs: + if isinstance(v, dict): + job_runs_list.append(v) + else: + job_runs_list.append(v.to_dict()) + _dict['job_runs'] = job_runs_list + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'next') and self.next is not None: + if isinstance(self.next, dict): + _dict['next'] = self.next + else: + _dict['next'] = self.next.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this JobRunList object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'JobRunList') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'JobRunList') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class JobRunStatus: + """ + The detailed status of the job run. + + :attr str completion_time: (optional) Time the job run completed. + :attr int failed: (optional) Number of failed job run instances. + :attr int pending: (optional) Number of pending job run instances. + :attr int requested: (optional) Number of requested job run instances. + :attr int running: (optional) Number of running job run instances. + :attr str start_time: (optional) Time the job run started. + :attr int succeeded: (optional) Number of succeeded job run instances. + :attr int unknown: (optional) Number of job run instances with unknown state. + """ + + def __init__( + self, + *, + completion_time: str = None, + failed: int = None, + pending: int = None, + requested: int = None, + running: int = None, + start_time: str = None, + succeeded: int = None, + unknown: int = None, + ) -> None: + """ + Initialize a JobRunStatus object. + + :param str completion_time: (optional) Time the job run completed. + :param int failed: (optional) Number of failed job run instances. + :param int pending: (optional) Number of pending job run instances. + :param int requested: (optional) Number of requested job run instances. + :param int running: (optional) Number of running job run instances. + :param str start_time: (optional) Time the job run started. + :param int succeeded: (optional) Number of succeeded job run instances. + :param int unknown: (optional) Number of job run instances with unknown + state. + """ + self.completion_time = completion_time + self.failed = failed + self.pending = pending + self.requested = requested + self.running = running + self.start_time = start_time + self.succeeded = succeeded + self.unknown = unknown + + @classmethod + def from_dict(cls, _dict: Dict) -> 'JobRunStatus': + """Initialize a JobRunStatus object from a json dictionary.""" + args = {} + if 'completion_time' in _dict: + args['completion_time'] = _dict.get('completion_time') + if 'failed' in _dict: + args['failed'] = _dict.get('failed') + if 'pending' in _dict: + args['pending'] = _dict.get('pending') + if 'requested' in _dict: + args['requested'] = _dict.get('requested') + if 'running' in _dict: + args['running'] = _dict.get('running') + if 'start_time' in _dict: + args['start_time'] = _dict.get('start_time') + if 'succeeded' in _dict: + args['succeeded'] = _dict.get('succeeded') + if 'unknown' in _dict: + args['unknown'] = _dict.get('unknown') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a JobRunStatus object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'completion_time') and self.completion_time is not None: + _dict['completion_time'] = self.completion_time + if hasattr(self, 'failed') and self.failed is not None: + _dict['failed'] = self.failed + if hasattr(self, 'pending') and self.pending is not None: + _dict['pending'] = self.pending + if hasattr(self, 'requested') and self.requested is not None: + _dict['requested'] = self.requested + if hasattr(self, 'running') and self.running is not None: + _dict['running'] = self.running + if hasattr(self, 'start_time') and self.start_time is not None: + _dict['start_time'] = self.start_time + if hasattr(self, 'succeeded') and self.succeeded is not None: + _dict['succeeded'] = self.succeeded + if hasattr(self, 'unknown') and self.unknown is not None: + _dict['unknown'] = self.unknown + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this JobRunStatus object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'JobRunStatus') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'JobRunStatus') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class ListFirstMetadata: + """ + Describes properties needed to retrieve the first page of a result list. + + :attr str href: (optional) Href that points to the first page. + """ + + def __init__(self, *, href: str = None) -> None: + """ + Initialize a ListFirstMetadata object. + + :param str href: (optional) Href that points to the first page. + """ + self.href = href + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ListFirstMetadata': + """Initialize a ListFirstMetadata object from a json dictionary.""" + args = {} + if 'href' in _dict: + args['href'] = _dict.get('href') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ListFirstMetadata object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ListFirstMetadata object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ListFirstMetadata') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ListFirstMetadata') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class ListNextMetadata: + """ + Describes properties needed to retrieve the next page of a result list. + + :attr str href: (optional) Href that points to the next page. + :attr str start: (optional) Token. + """ + + def __init__(self, *, href: str = None, start: str = None) -> None: + """ + Initialize a ListNextMetadata object. + + :param str href: (optional) Href that points to the next page. + :param str start: (optional) Token. + """ + self.href = href + self.start = start + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ListNextMetadata': + """Initialize a ListNextMetadata object from a json dictionary.""" + args = {} + if 'href' in _dict: + args['href'] = _dict.get('href') + if 'start' in _dict: + args['start'] = _dict.get('start') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ListNextMetadata object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'start') and self.start is not None: + _dict['start'] = self.start + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ListNextMetadata object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ListNextMetadata') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ListNextMetadata') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class Project: + """ + Describes the model of a project. + + :attr str account_id: An alphanumeric value identifying the account ID. + :attr str created_at: The date when the project was created. + :attr str crn: The CRN of the project. + :attr str href: When you provision a new resource, a URL is created identifying + the location of the instance. + :attr str id: The ID of the project. + :attr str name: The name of the project. + :attr str region: The region for your project deployment. Possible values: + 'au-syd', 'br-sao', 'ca-tor', 'eu-de', 'eu-gb', 'jp-osa', 'jp-tok', 'us-east', + 'us-south'. + :attr str resource_group_id: The ID of the resource group. + :attr str resource_type: The type of the project. + :attr str status: The current state of the project. For example, if the project + is created and ready to get used, it will return active. + """ + + def __init__( + self, + account_id: str, + created_at: str, + crn: str, + href: str, + id: str, + name: str, + region: str, + resource_group_id: str, + resource_type: str, + status: str, + ) -> None: + """ + Initialize a Project object. + + :param str account_id: An alphanumeric value identifying the account ID. + :param str created_at: The date when the project was created. + :param str crn: The CRN of the project. + :param str href: When you provision a new resource, a URL is created + identifying the location of the instance. + :param str id: The ID of the project. + :param str name: The name of the project. + :param str region: The region for your project deployment. Possible values: + 'au-syd', 'br-sao', 'ca-tor', 'eu-de', 'eu-gb', 'jp-osa', 'jp-tok', + 'us-east', 'us-south'. + :param str resource_group_id: The ID of the resource group. + :param str resource_type: The type of the project. + :param str status: The current state of the project. For example, if the + project is created and ready to get used, it will return active. + """ + self.account_id = account_id + self.created_at = created_at + self.crn = crn + self.href = href + self.id = id + self.name = name + self.region = region + self.resource_group_id = resource_group_id + self.resource_type = resource_type + self.status = status + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Project': + """Initialize a Project object from a json dictionary.""" + args = {} + if 'account_id' in _dict: + args['account_id'] = _dict.get('account_id') + else: + raise ValueError('Required property \'account_id\' not present in Project JSON') + if 'created_at' in _dict: + args['created_at'] = _dict.get('created_at') + else: + raise ValueError('Required property \'created_at\' not present in Project JSON') + if 'crn' in _dict: + args['crn'] = _dict.get('crn') + else: + raise ValueError('Required property \'crn\' not present in Project JSON') + if 'href' in _dict: + args['href'] = _dict.get('href') + else: + raise ValueError('Required property \'href\' not present in Project JSON') + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in Project JSON') + if 'name' in _dict: + args['name'] = _dict.get('name') + else: + raise ValueError('Required property \'name\' not present in Project JSON') + if 'region' in _dict: + args['region'] = _dict.get('region') + else: + raise ValueError('Required property \'region\' not present in Project JSON') + if 'resource_group_id' in _dict: + args['resource_group_id'] = _dict.get('resource_group_id') + else: + raise ValueError('Required property \'resource_group_id\' not present in Project JSON') + if 'resource_type' in _dict: + args['resource_type'] = _dict.get('resource_type') + else: + raise ValueError('Required property \'resource_type\' not present in Project JSON') + if 'status' in _dict: + args['status'] = _dict.get('status') + else: + raise ValueError('Required property \'status\' not present in Project JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Project object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'account_id') and self.account_id is not None: + _dict['account_id'] = self.account_id + if hasattr(self, 'created_at') and self.created_at is not None: + _dict['created_at'] = self.created_at + if hasattr(self, 'crn') and self.crn is not None: + _dict['crn'] = self.crn + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'region') and self.region is not None: + _dict['region'] = self.region + if hasattr(self, 'resource_group_id') and self.resource_group_id is not None: + _dict['resource_group_id'] = self.resource_group_id + if hasattr(self, 'resource_type') and self.resource_type is not None: + _dict['resource_type'] = self.resource_type + if hasattr(self, 'status') and self.status is not None: + _dict['status'] = self.status + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Project object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Project') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Project') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ResourceTypeEnum(str, Enum): + """ + The type of the project. + """ + + PROJECT_V2 = 'project_v2' + + class StatusEnum(str, Enum): + """ + The current state of the project. For example, if the project is created and ready + to get used, it will return active. + """ + + ACTIVE = 'active' + INACTIVE = 'inactive' + PENDING_REMOVAL = 'pending_removal' + HARD_DELETING = 'hard_deleting' + HARD_DELETION_FAILED = 'hard_deletion_failed' + HARD_DELETED = 'hard_deleted' + DELETING = 'deleting' + DELETION_FAILED = 'deletion_failed' + SOFT_DELETED = 'soft_deleted' + PREPARING = 'preparing' + CREATING = 'creating' + CREATION_FAILED = 'creation_failed' + + +class ProjectList: + """ + Contains a list of projects and pagination information. + + :attr ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :attr int limit: Maximum number of resources per page. + :attr ListNextMetadata next: (optional) Describes properties needed to retrieve + the next page of a result list. + :attr List[Project] projects: List of projects. + """ + + def __init__( + self, + limit: int, + projects: List['Project'], + *, + first: 'ListFirstMetadata' = None, + next: 'ListNextMetadata' = None, + ) -> None: + """ + Initialize a ProjectList object. + + :param int limit: Maximum number of resources per page. + :param List[Project] projects: List of projects. + :param ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :param ListNextMetadata next: (optional) Describes properties needed to + retrieve the next page of a result list. + """ + self.first = first + self.limit = limit + self.next = next + self.projects = projects + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ProjectList': + """Initialize a ProjectList object from a json dictionary.""" + args = {} + if 'first' in _dict: + args['first'] = ListFirstMetadata.from_dict(_dict.get('first')) + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in ProjectList JSON') + if 'next' in _dict: + args['next'] = ListNextMetadata.from_dict(_dict.get('next')) + if 'projects' in _dict: + args['projects'] = [Project.from_dict(v) for v in _dict.get('projects')] + else: + raise ValueError('Required property \'projects\' not present in ProjectList JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ProjectList object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'first') and self.first is not None: + if isinstance(self.first, dict): + _dict['first'] = self.first + else: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'next') and self.next is not None: + if isinstance(self.next, dict): + _dict['next'] = self.next + else: + _dict['next'] = self.next.to_dict() + if hasattr(self, 'projects') and self.projects is not None: + projects_list = [] + for v in self.projects: + if isinstance(v, dict): + projects_list.append(v) + else: + projects_list.append(v.to_dict()) + _dict['projects'] = projects_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ProjectList object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ProjectList') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ProjectList') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class Secret: + """ + Describes the model of a secret. + + :attr str created_at: The date when the resource was created. + :attr dict data: (optional) Data container that allows to specify config + parameters and their values as a key-value map. Each key field must consist of + alphanumeric characters, `-`, `_` or `.` and must not be exceed a max length of + 253 characters. Each value field can consists of any character and must not be + exceed a max length of 1048576 characters. + :attr str entity_tag: The version of the secret instance, which is used to + achieve optimistic locking. + :attr str format: (optional) Specify the format of the secret. + :attr str href: (optional) When you provision a new secret, a URL is created + identifying the location of the instance. + :attr str id: The identifier of the resource. + :attr str name: The name of the secret. + :attr str project_id: The ID of the project the resource is located in. + :attr str resource_type: The type of the secret. + """ + + def __init__( + self, + created_at: str, + entity_tag: str, + id: str, + name: str, + project_id: str, + resource_type: str, + *, + data: dict = None, + format: str = None, + href: str = None, + ) -> None: + """ + Initialize a Secret object. + + :param str created_at: The date when the resource was created. + :param str entity_tag: The version of the secret instance, which is used to + achieve optimistic locking. + :param str id: The identifier of the resource. + :param str name: The name of the secret. + :param str project_id: The ID of the project the resource is located in. + :param str resource_type: The type of the secret. + :param dict data: (optional) Data container that allows to specify config + parameters and their values as a key-value map. Each key field must consist + of alphanumeric characters, `-`, `_` or `.` and must not be exceed a max + length of 253 characters. Each value field can consists of any character + and must not be exceed a max length of 1048576 characters. + :param str format: (optional) Specify the format of the secret. + :param str href: (optional) When you provision a new secret, a URL is + created identifying the location of the instance. + """ + self.created_at = created_at + self.data = data + self.entity_tag = entity_tag + self.format = format + self.href = href + self.id = id + self.name = name + self.project_id = project_id + self.resource_type = resource_type + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Secret': + """Initialize a Secret object from a json dictionary.""" + args = {} + if 'created_at' in _dict: + args['created_at'] = _dict.get('created_at') + else: + raise ValueError('Required property \'created_at\' not present in Secret JSON') + if 'data' in _dict: + args['data'] = _dict.get('data') + if 'entity_tag' in _dict: + args['entity_tag'] = _dict.get('entity_tag') + else: + raise ValueError('Required property \'entity_tag\' not present in Secret JSON') + if 'format' in _dict: + args['format'] = _dict.get('format') + if 'href' in _dict: + args['href'] = _dict.get('href') + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in Secret JSON') + if 'name' in _dict: + args['name'] = _dict.get('name') + else: + raise ValueError('Required property \'name\' not present in Secret JSON') + if 'project_id' in _dict: + args['project_id'] = _dict.get('project_id') + else: + raise ValueError('Required property \'project_id\' not present in Secret JSON') + if 'resource_type' in _dict: + args['resource_type'] = _dict.get('resource_type') + else: + raise ValueError('Required property \'resource_type\' not present in Secret JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Secret object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'created_at') and self.created_at is not None: + _dict['created_at'] = self.created_at + if hasattr(self, 'data') and self.data is not None: + _dict['data'] = self.data + if hasattr(self, 'entity_tag') and self.entity_tag is not None: + _dict['entity_tag'] = self.entity_tag + if hasattr(self, 'format') and self.format is not None: + _dict['format'] = self.format + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'project_id') and self.project_id is not None: + _dict['project_id'] = self.project_id + if hasattr(self, 'resource_type') and self.resource_type is not None: + _dict['resource_type'] = self.resource_type + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Secret object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Secret') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Secret') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class FormatEnum(str, Enum): + """ + Specify the format of the secret. + """ + + GENERIC = 'generic' + SSH_AUTH = 'ssh_auth' + BASIC_AUTH = 'basic_auth' + TLS = 'tls' + SERVICE_ACCESS = 'service_access' + REGISTRY = 'registry' + OTHER = 'other' + + +class SecretList: + """ + List of secret resources. + + :attr ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :attr int limit: Maximum number of resources per page. + :attr ListNextMetadata next: (optional) Describes properties needed to retrieve + the next page of a result list. + :attr List[Secret] secrets: List of Secrets. + """ + + def __init__( + self, limit: int, secrets: List['Secret'], *, first: 'ListFirstMetadata' = None, next: 'ListNextMetadata' = None + ) -> None: + """ + Initialize a SecretList object. + + :param int limit: Maximum number of resources per page. + :param List[Secret] secrets: List of Secrets. + :param ListFirstMetadata first: (optional) Describes properties needed to + retrieve the first page of a result list. + :param ListNextMetadata next: (optional) Describes properties needed to + retrieve the next page of a result list. + """ + self.first = first + self.limit = limit + self.next = next + self.secrets = secrets + + @classmethod + def from_dict(cls, _dict: Dict) -> 'SecretList': + """Initialize a SecretList object from a json dictionary.""" + args = {} + if 'first' in _dict: + args['first'] = ListFirstMetadata.from_dict(_dict.get('first')) + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in SecretList JSON') + if 'next' in _dict: + args['next'] = ListNextMetadata.from_dict(_dict.get('next')) + if 'secrets' in _dict: + args['secrets'] = [Secret.from_dict(v) for v in _dict.get('secrets')] + else: + raise ValueError('Required property \'secrets\' not present in SecretList JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a SecretList object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'first') and self.first is not None: + if isinstance(self.first, dict): + _dict['first'] = self.first + else: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'next') and self.next is not None: + if isinstance(self.next, dict): + _dict['next'] = self.next + else: + _dict['next'] = self.next.to_dict() + if hasattr(self, 'secrets') and self.secrets is not None: + secrets_list = [] + for v in self.secrets: + if isinstance(v, dict): + secrets_list.append(v) + else: + secrets_list.append(v.to_dict()) + _dict['secrets'] = secrets_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this SecretList object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'SecretList') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'SecretList') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class VolumeMount: + """ + Response model of a volume mount. + + :attr str mount_path: The path that should be mounted. + :attr str name: The name of the mount. + :attr str reference: The name of the referenced secret or config map. + :attr str type: Specify the type of the volume mount. Allowed types are: + 'config_map', 'secret'. + """ + + def __init__(self, mount_path: str, name: str, reference: str, type: str) -> None: + """ + Initialize a VolumeMount object. + + :param str mount_path: The path that should be mounted. + :param str name: The name of the mount. + :param str reference: The name of the referenced secret or config map. + :param str type: Specify the type of the volume mount. Allowed types are: + 'config_map', 'secret'. + """ + self.mount_path = mount_path + self.name = name + self.reference = reference + self.type = type + + @classmethod + def from_dict(cls, _dict: Dict) -> 'VolumeMount': + """Initialize a VolumeMount object from a json dictionary.""" + args = {} + if 'mount_path' in _dict: + args['mount_path'] = _dict.get('mount_path') + else: + raise ValueError('Required property \'mount_path\' not present in VolumeMount JSON') + if 'name' in _dict: + args['name'] = _dict.get('name') + else: + raise ValueError('Required property \'name\' not present in VolumeMount JSON') + if 'reference' in _dict: + args['reference'] = _dict.get('reference') + else: + raise ValueError('Required property \'reference\' not present in VolumeMount JSON') + if 'type' in _dict: + args['type'] = _dict.get('type') + else: + raise ValueError('Required property \'type\' not present in VolumeMount JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a VolumeMount object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'mount_path') and self.mount_path is not None: + _dict['mount_path'] = self.mount_path + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'reference') and self.reference is not None: + _dict['reference'] = self.reference + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this VolumeMount object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'VolumeMount') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'VolumeMount') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class TypeEnum(str, Enum): + """ + Specify the type of the volume mount. Allowed types are: 'config_map', 'secret'. + """ + + CONFIG_MAP = 'config_map' + SECRET = 'secret' + + +class VolumeMountPrototype: + """ + Prototype model of a volume mount. + + :attr str mount_path: The path that should be mounted. + :attr str name: (optional) Optional name of the mount. If not set, it will be + generated based on the `ref` and a random ID. In case the `ref` is longer than + 58 characters, it will be cut off. + :attr str reference: The name of the referenced secret or config map. + :attr str type: Specify the type of the volume mount. Allowed types are: + 'config_map', 'secret'. + """ + + def __init__(self, mount_path: str, reference: str, type: str, *, name: str = None) -> None: + """ + Initialize a VolumeMountPrototype object. + + :param str mount_path: The path that should be mounted. + :param str reference: The name of the referenced secret or config map. + :param str type: Specify the type of the volume mount. Allowed types are: + 'config_map', 'secret'. + :param str name: (optional) Optional name of the mount. If not set, it will + be generated based on the `ref` and a random ID. In case the `ref` is + longer than 58 characters, it will be cut off. + """ + self.mount_path = mount_path + self.name = name + self.reference = reference + self.type = type + + @classmethod + def from_dict(cls, _dict: Dict) -> 'VolumeMountPrototype': + """Initialize a VolumeMountPrototype object from a json dictionary.""" + args = {} + if 'mount_path' in _dict: + args['mount_path'] = _dict.get('mount_path') + else: + raise ValueError('Required property \'mount_path\' not present in VolumeMountPrototype JSON') + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'reference' in _dict: + args['reference'] = _dict.get('reference') + else: + raise ValueError('Required property \'reference\' not present in VolumeMountPrototype JSON') + if 'type' in _dict: + args['type'] = _dict.get('type') + else: + raise ValueError('Required property \'type\' not present in VolumeMountPrototype JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a VolumeMountPrototype object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'mount_path') and self.mount_path is not None: + _dict['mount_path'] = self.mount_path + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'reference') and self.reference is not None: + _dict['reference'] = self.reference + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this VolumeMountPrototype object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'VolumeMountPrototype') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'VolumeMountPrototype') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class TypeEnum(str, Enum): + """ + Specify the type of the volume mount. Allowed types are: 'config_map', 'secret'. + """ + + CONFIG_MAP = 'config_map' + SECRET = 'secret' + + +############################################################################## +# Pagers +############################################################################## + + +class ProjectsPager: + """ + ProjectsPager can be used to simplify the use of the "list_projects" method. + """ + + def __init__( + self, + *, + client: CodeEngineV2, + limit: int = None, + ) -> None: + """ + Initialize a ProjectsPager object. + :param int limit: (optional) Optional maximum number of projects per page. + """ + self._has_next = True + self._client = client + self._page_context = {'next': None} + self._limit = limit + + def has_next(self) -> bool: + """ + Returns true if there are potentially more results to be retrieved. + """ + return self._has_next + + def get_next(self) -> List[dict]: + """ + Returns the next page of results. + :return: A List[dict], where each element is a dict that represents an instance of Project. + :rtype: List[dict] + """ + if not self.has_next(): + raise StopIteration(message='No more results available') + + result = self._client.list_projects( + limit=self._limit, + start=self._page_context.get('next'), + ).get_result() + + next = None + next_page_link = result.get('next') + if next_page_link is not None: + next = next_page_link.get('start') + self._page_context['next'] = next + if next is None: + self._has_next = False + + return result.get('projects') + + def get_all(self) -> List[dict]: + """ + Returns all results by invoking get_next() repeatedly + until all pages of results have been retrieved. + :return: A List[dict], where each element is a dict that represents an instance of Project. + :rtype: List[dict] + """ + results = [] + while self.has_next(): + next_page = self.get_next() + results.extend(next_page) + return results + + +class AppsPager: + """ + AppsPager can be used to simplify the use of the "list_apps" method. + """ + + def __init__( + self, + *, + client: CodeEngineV2, + project_id: str, + limit: int = None, + ) -> None: + """ + Initialize a AppsPager object. + :param str project_id: The ID of the project. + :param int limit: (optional) Optional maximum number of apps per page. + """ + self._has_next = True + self._client = client + self._page_context = {'next': None} + self._project_id = project_id + self._limit = limit + + def has_next(self) -> bool: + """ + Returns true if there are potentially more results to be retrieved. + """ + return self._has_next + + def get_next(self) -> List[dict]: + """ + Returns the next page of results. + :return: A List[dict], where each element is a dict that represents an instance of App. + :rtype: List[dict] + """ + if not self.has_next(): + raise StopIteration(message='No more results available') + + result = self._client.list_apps( + project_id=self._project_id, + limit=self._limit, + start=self._page_context.get('next'), + ).get_result() + + next = None + next_page_link = result.get('next') + if next_page_link is not None: + next = next_page_link.get('start') + self._page_context['next'] = next + if next is None: + self._has_next = False + + return result.get('apps') + + def get_all(self) -> List[dict]: + """ + Returns all results by invoking get_next() repeatedly + until all pages of results have been retrieved. + :return: A List[dict], where each element is a dict that represents an instance of App. + :rtype: List[dict] + """ + results = [] + while self.has_next(): + next_page = self.get_next() + results.extend(next_page) + return results + + +class AppRevisionsPager: + """ + AppRevisionsPager can be used to simplify the use of the "list_app_revisions" method. + """ + + def __init__( + self, + *, + client: CodeEngineV2, + project_id: str, + app_name: str, + limit: int = None, + ) -> None: + """ + Initialize a AppRevisionsPager object. + :param str project_id: The ID of the project. + :param str app_name: The name of your application. + :param int limit: (optional) Optional maximum number of apps per page. + """ + self._has_next = True + self._client = client + self._page_context = {'next': None} + self._project_id = project_id + self._app_name = app_name + self._limit = limit + + def has_next(self) -> bool: + """ + Returns true if there are potentially more results to be retrieved. + """ + return self._has_next + + def get_next(self) -> List[dict]: + """ + Returns the next page of results. + :return: A List[dict], where each element is a dict that represents an instance of AppRevision. + :rtype: List[dict] + """ + if not self.has_next(): + raise StopIteration(message='No more results available') + + result = self._client.list_app_revisions( + project_id=self._project_id, + app_name=self._app_name, + limit=self._limit, + start=self._page_context.get('next'), + ).get_result() + + next = None + next_page_link = result.get('next') + if next_page_link is not None: + next = next_page_link.get('start') + self._page_context['next'] = next + if next is None: + self._has_next = False + + return result.get('revisions') + + def get_all(self) -> List[dict]: + """ + Returns all results by invoking get_next() repeatedly + until all pages of results have been retrieved. + :return: A List[dict], where each element is a dict that represents an instance of AppRevision. + :rtype: List[dict] + """ + results = [] + while self.has_next(): + next_page = self.get_next() + results.extend(next_page) + return results + + +class JobsPager: + """ + JobsPager can be used to simplify the use of the "list_jobs" method. + """ + + def __init__( + self, + *, + client: CodeEngineV2, + project_id: str, + limit: int = None, + ) -> None: + """ + Initialize a JobsPager object. + :param str project_id: The ID of the project. + :param int limit: (optional) Optional maximum number of jobs per page. + """ + self._has_next = True + self._client = client + self._page_context = {'next': None} + self._project_id = project_id + self._limit = limit + + def has_next(self) -> bool: + """ + Returns true if there are potentially more results to be retrieved. + """ + return self._has_next + + def get_next(self) -> List[dict]: + """ + Returns the next page of results. + :return: A List[dict], where each element is a dict that represents an instance of Job. + :rtype: List[dict] + """ + if not self.has_next(): + raise StopIteration(message='No more results available') + + result = self._client.list_jobs( + project_id=self._project_id, + limit=self._limit, + start=self._page_context.get('next'), + ).get_result() + + next = None + next_page_link = result.get('next') + if next_page_link is not None: + next = next_page_link.get('start') + self._page_context['next'] = next + if next is None: + self._has_next = False + + return result.get('jobs') + + def get_all(self) -> List[dict]: + """ + Returns all results by invoking get_next() repeatedly + until all pages of results have been retrieved. + :return: A List[dict], where each element is a dict that represents an instance of Job. + :rtype: List[dict] + """ + results = [] + while self.has_next(): + next_page = self.get_next() + results.extend(next_page) + return results + + +class JobRunsPager: + """ + JobRunsPager can be used to simplify the use of the "list_job_runs" method. + """ + + def __init__( + self, + *, + client: CodeEngineV2, + project_id: str, + job_name: str = None, + limit: int = None, + ) -> None: + """ + Initialize a JobRunsPager object. + :param str project_id: The ID of the project. + :param str job_name: (optional) Optional name of the job that should be + filtered for. + :param int limit: (optional) Optional maximum number of job runs per page. + """ + self._has_next = True + self._client = client + self._page_context = {'next': None} + self._project_id = project_id + self._job_name = job_name + self._limit = limit + + def has_next(self) -> bool: + """ + Returns true if there are potentially more results to be retrieved. + """ + return self._has_next + + def get_next(self) -> List[dict]: + """ + Returns the next page of results. + :return: A List[dict], where each element is a dict that represents an instance of JobRun. + :rtype: List[dict] + """ + if not self.has_next(): + raise StopIteration(message='No more results available') + + result = self._client.list_job_runs( + project_id=self._project_id, + job_name=self._job_name, + limit=self._limit, + start=self._page_context.get('next'), + ).get_result() + + next = None + next_page_link = result.get('next') + if next_page_link is not None: + next = next_page_link.get('start') + self._page_context['next'] = next + if next is None: + self._has_next = False + + return result.get('job_runs') + + def get_all(self) -> List[dict]: + """ + Returns all results by invoking get_next() repeatedly + until all pages of results have been retrieved. + :return: A List[dict], where each element is a dict that represents an instance of JobRun. + :rtype: List[dict] + """ + results = [] + while self.has_next(): + next_page = self.get_next() + results.extend(next_page) + return results + + +class BuildsPager: + """ + BuildsPager can be used to simplify the use of the "list_builds" method. + """ + + def __init__( + self, + *, + client: CodeEngineV2, + project_id: str, + limit: int = None, + ) -> None: + """ + Initialize a BuildsPager object. + :param str project_id: The ID of the project. + :param int limit: (optional) Optional maximum number of builds per page. + """ + self._has_next = True + self._client = client + self._page_context = {'next': None} + self._project_id = project_id + self._limit = limit + + def has_next(self) -> bool: + """ + Returns true if there are potentially more results to be retrieved. + """ + return self._has_next + + def get_next(self) -> List[dict]: + """ + Returns the next page of results. + :return: A List[dict], where each element is a dict that represents an instance of Build. + :rtype: List[dict] + """ + if not self.has_next(): + raise StopIteration(message='No more results available') + + result = self._client.list_builds( + project_id=self._project_id, + limit=self._limit, + start=self._page_context.get('next'), + ).get_result() + + next = None + next_page_link = result.get('next') + if next_page_link is not None: + next = next_page_link.get('start') + self._page_context['next'] = next + if next is None: + self._has_next = False + + return result.get('builds') + + def get_all(self) -> List[dict]: + """ + Returns all results by invoking get_next() repeatedly + until all pages of results have been retrieved. + :return: A List[dict], where each element is a dict that represents an instance of Build. + :rtype: List[dict] + """ + results = [] + while self.has_next(): + next_page = self.get_next() + results.extend(next_page) + return results + + +class BuildRunsPager: + """ + BuildRunsPager can be used to simplify the use of the "list_build_runs" method. + """ + + def __init__( + self, + *, + client: CodeEngineV2, + project_id: str, + build_name: str = None, + limit: int = None, + ) -> None: + """ + Initialize a BuildRunsPager object. + :param str project_id: The ID of the project. + :param str build_name: (optional) Optional name of the build that should be + filtered for. + :param int limit: (optional) Optional maximum number of build runs per + page. + """ + self._has_next = True + self._client = client + self._page_context = {'next': None} + self._project_id = project_id + self._build_name = build_name + self._limit = limit + + def has_next(self) -> bool: + """ + Returns true if there are potentially more results to be retrieved. + """ + return self._has_next + + def get_next(self) -> List[dict]: + """ + Returns the next page of results. + :return: A List[dict], where each element is a dict that represents an instance of BuildRun. + :rtype: List[dict] + """ + if not self.has_next(): + raise StopIteration(message='No more results available') + + result = self._client.list_build_runs( + project_id=self._project_id, + build_name=self._build_name, + limit=self._limit, + start=self._page_context.get('next'), + ).get_result() + + next = None + next_page_link = result.get('next') + if next_page_link is not None: + next = next_page_link.get('start') + self._page_context['next'] = next + if next is None: + self._has_next = False + + return result.get('build_runs') + + def get_all(self) -> List[dict]: + """ + Returns all results by invoking get_next() repeatedly + until all pages of results have been retrieved. + :return: A List[dict], where each element is a dict that represents an instance of BuildRun. + :rtype: List[dict] + """ + results = [] + while self.has_next(): + next_page = self.get_next() + results.extend(next_page) + return results + + +class ConfigMapsPager: + """ + ConfigMapsPager can be used to simplify the use of the "list_config_maps" method. + """ + + def __init__( + self, + *, + client: CodeEngineV2, + project_id: str, + limit: int = None, + ) -> None: + """ + Initialize a ConfigMapsPager object. + :param str project_id: The ID of the project. + :param int limit: (optional) Optional maximum number of config maps per + page. + """ + self._has_next = True + self._client = client + self._page_context = {'next': None} + self._project_id = project_id + self._limit = limit + + def has_next(self) -> bool: + """ + Returns true if there are potentially more results to be retrieved. + """ + return self._has_next + + def get_next(self) -> List[dict]: + """ + Returns the next page of results. + :return: A List[dict], where each element is a dict that represents an instance of ConfigMap. + :rtype: List[dict] + """ + if not self.has_next(): + raise StopIteration(message='No more results available') + + result = self._client.list_config_maps( + project_id=self._project_id, + limit=self._limit, + start=self._page_context.get('next'), + ).get_result() + + next = None + next_page_link = result.get('next') + if next_page_link is not None: + next = next_page_link.get('start') + self._page_context['next'] = next + if next is None: + self._has_next = False + + return result.get('config_maps') + + def get_all(self) -> List[dict]: + """ + Returns all results by invoking get_next() repeatedly + until all pages of results have been retrieved. + :return: A List[dict], where each element is a dict that represents an instance of ConfigMap. + :rtype: List[dict] + """ + results = [] + while self.has_next(): + next_page = self.get_next() + results.extend(next_page) + return results + + +class SecretsPager: + """ + SecretsPager can be used to simplify the use of the "list_secrets" method. + """ + + def __init__( + self, + *, + client: CodeEngineV2, + project_id: str, + limit: int = None, + ) -> None: + """ + Initialize a SecretsPager object. + :param str project_id: The ID of the project. + :param int limit: (optional) Optional maximum number of secrets per page. + """ + self._has_next = True + self._client = client + self._page_context = {'next': None} + self._project_id = project_id + self._limit = limit + + def has_next(self) -> bool: + """ + Returns true if there are potentially more results to be retrieved. + """ + return self._has_next + + def get_next(self) -> List[dict]: + """ + Returns the next page of results. + :return: A List[dict], where each element is a dict that represents an instance of Secret. + :rtype: List[dict] + """ + if not self.has_next(): + raise StopIteration(message='No more results available') + + result = self._client.list_secrets( + project_id=self._project_id, + limit=self._limit, + start=self._page_context.get('next'), + ).get_result() + + next = None + next_page_link = result.get('next') + if next_page_link is not None: + next = next_page_link.get('start') + self._page_context['next'] = next + if next is None: + self._has_next = False + + return result.get('secrets') + + def get_all(self) -> List[dict]: + """ + Returns all results by invoking get_next() repeatedly + until all pages of results have been retrieved. + :return: A List[dict], where each element is a dict that represents an instance of Secret. + :rtype: List[dict] + """ + results = [] + while self.has_next(): + next_page = self.get_next() + results.extend(next_page) + return results diff --git a/ibm_code_engine_sdk/common.py b/ibm_code_engine_sdk/common.py index 59d9b4a..457dd7a 100644 --- a/ibm_code_engine_sdk/common.py +++ b/ibm_code_engine_sdk/common.py @@ -24,14 +24,14 @@ HEADER_NAME_USER_AGENT = 'User-Agent' SDK_NAME = 'code-engine-python-sdk' + def get_system_info(): """ Get information about the system to be inserted into the User-Agent header. """ - return 'lang={0}; arch={1}; os={2}; python.version={3}'.format('python', - platform.machine(), # Architecture - platform.system(), # OS - platform.python_version()) # Python version + return 'lang={0}; arch={1}; os={2}; python.version={3}'.format( + 'python', platform.machine(), platform.system(), platform.python_version() # Architecture # OS + ) # Python version def get_user_agent(): @@ -45,10 +45,10 @@ def get_user_agent(): def get_sdk_headers(service_name, service_version, operation_id): - #pylint: disable=unused-argument + # pylint: disable=unused-argument """ Get the request headers to be sent in requests by the SDK. - + If you plan to gather metrics for your SDK, the User-Agent header value must be a string similar to the following: code-engine-python-sdk/0.0.1 (lang=python; arch=x86_64; os=Linux; python.version=3.7.4) diff --git a/ibm_code_engine_sdk/ibm_cloud_code_engine_v1.py b/ibm_code_engine_sdk/ibm_cloud_code_engine_v1.py index e546458..eed9049 100644 --- a/ibm_code_engine_sdk/ibm_cloud_code_engine_v1.py +++ b/ibm_code_engine_sdk/ibm_cloud_code_engine_v1.py @@ -15,7 +15,7 @@ # limitations under the License. # IBM OpenAPI SDK Code Generator Version: 3.15.0-45841b53-20201019-214802 - + """ The purpose is to provide an API to get Kubeconfig file for IBM Cloud Code Engine Project """ @@ -32,6 +32,7 @@ # Service ############################################################################## + class IbmCloudCodeEngineV1(BaseService): """The IBM Cloud Code Engine V1 service.""" @@ -39,23 +40,23 @@ class IbmCloudCodeEngineV1(BaseService): DEFAULT_SERVICE_NAME = 'ibm_cloud_code_engine' @classmethod - def new_instance(cls, - service_name: str = DEFAULT_SERVICE_NAME, - ) -> 'IbmCloudCodeEngineV1': + def new_instance( + cls, + service_name: str = DEFAULT_SERVICE_NAME, + ) -> 'IbmCloudCodeEngineV1': """ Return a new client for the IBM Cloud Code Engine service using the specified parameters and external configuration. """ authenticator = get_authenticator_from_environment(service_name) - service = cls( - authenticator - ) + service = cls(authenticator) service.configure_service(service_name) return service - def __init__(self, - authenticator: Authenticator = None, - ) -> None: + def __init__( + self, + authenticator: Authenticator = None, + ) -> None: """ Construct a new client for the IBM Cloud Code Engine service. @@ -63,23 +64,13 @@ def __init__(self, Get up to date information from https://github.com/IBM/python-sdk-core/blob/main/README.md about initializing the authenticator of your choice. """ - BaseService.__init__(self, - service_url=self.DEFAULT_SERVICE_URL, - authenticator=authenticator) - + BaseService.__init__(self, service_url=self.DEFAULT_SERVICE_URL, authenticator=authenticator) ######################### # getKubeconfig ######################### - - def list_kubeconfig(self, - refresh_token: str, - id: str, - *, - accept: str = None, - **kwargs - ) -> DetailedResponse: + def list_kubeconfig(self, refresh_token: str, id: str, *, accept: str = None, **kwargs) -> DetailedResponse: """ Deprecated soon: Retrieve KUBECONFIG for a specified project. @@ -103,13 +94,10 @@ def list_kubeconfig(self, raise ValueError('refresh_token must be provided') if id is None: raise ValueError('id must be provided') - headers = { - 'Refresh-Token': refresh_token, - 'Accept': accept - } - sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='list_kubeconfig') + headers = {'Refresh-Token': refresh_token, 'Accept': accept} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='list_kubeconfig' + ) headers.update(sdk_headers) if 'headers' in kwargs: @@ -119,20 +107,13 @@ def list_kubeconfig(self, path_param_values = self.encode_path_vars(id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/namespaces/{id}/config'.format(**path_param_dict) - request = self.prepare_request(method='GET', - url=url, - headers=headers) + request = self.prepare_request(method='GET', url=url, headers=headers) response = self.send(request) return response - - def get_kubeconfig(self, - x_delegated_refresh_token: str, - id: str, - *, - accept: str = None, - **kwargs + def get_kubeconfig( + self, x_delegated_refresh_token: str, id: str, *, accept: str = None, **kwargs ) -> DetailedResponse: """ Retrieve KUBECONFIG for a specified project. @@ -175,13 +156,10 @@ def get_kubeconfig(self, raise ValueError('x_delegated_refresh_token must be provided') if id is None: raise ValueError('id must be provided') - headers = { - 'X-Delegated-Refresh-Token': x_delegated_refresh_token, - 'Accept': accept - } - sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='get_kubeconfig') + headers = {'X-Delegated-Refresh-Token': x_delegated_refresh_token, 'Accept': accept} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='get_kubeconfig' + ) headers.update(sdk_headers) if 'headers' in kwargs: @@ -191,9 +169,7 @@ def get_kubeconfig(self, path_param_values = self.encode_path_vars(id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/project/{id}/config'.format(**path_param_dict) - request = self.prepare_request(method='GET', - url=url, - headers=headers) + request = self.prepare_request(method='GET', url=url, headers=headers) response = self.send(request) return response @@ -210,6 +186,7 @@ class Accept(str, Enum): be specified by including a `charset` parameter. For example, 'text/plain;charset=utf-8'. """ + TEXT_PLAIN = 'text/plain' APPLICATION_JSON = 'application/json' @@ -225,6 +202,7 @@ class Accept(str, Enum): be specified by including a `charset` parameter. For example, 'text/plain;charset=utf-8'. """ + TEXT_PLAIN = 'text/plain' APPLICATION_JSON = 'application/json' @@ -232,4 +210,3 @@ class Accept(str, Enum): ############################################################################## # Models ############################################################################## - diff --git a/sdkgen-config.json b/sdkgen_config.json similarity index 77% rename from sdkgen-config.json rename to sdkgen_config.json index a684723..70dcdd3 100644 --- a/sdkgen-config.json +++ b/sdkgen_config.json @@ -1,6 +1,6 @@ { "apiPackage": "ibm_code_engine_sdk", - "serviceClass": "CodeEngineV1", + "serviceClass": "CodeEngineV2", "unitTestFolder": "test/unit/", "intTestFolder": "test/integration" } diff --git a/setup.py b/setup.py index b9c8b7f..a5f1180 100644 --- a/setup.py +++ b/setup.py @@ -42,33 +42,33 @@ readme = fh.read() setup( - name=PACKAGE_NAME.replace('_', '-'), - version=__version__, - description=PACKAGE_DESC, - license='Apache 2.0', - install_requires=install_requires, - tests_require=tests_require, - author='IBM', - author_email='coligo@de.ibm.com', - long_description=readme, - long_description_content_type='text/markdown', - url='https://github.com/IBM/code-engine-python-sdk', - packages=[PACKAGE_NAME], - include_package_data=True, - keywords=PACKAGE_NAME, - classifiers=[ - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: OS Independent', - 'Topic :: Software Development :: Libraries :: Python Modules', - 'Topic :: Software Development :: Libraries :: Application Frameworks', - ], - zip_safe=True - ) + name=PACKAGE_NAME.replace('_', '-'), + version=__version__, + description=PACKAGE_DESC, + license='Apache 2.0', + install_requires=install_requires, + tests_require=tests_require, + author='IBM', + author_email='coligo@de.ibm.com', + long_description=readme, + long_description_content_type='text/markdown', + url='https://github.com/IBM/code-engine-python-sdk', + packages=[PACKAGE_NAME], + include_package_data=True, + keywords=PACKAGE_NAME, + classifiers=[ + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Apache Software License', + 'Operating System :: OS Independent', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Software Development :: Libraries :: Application Frameworks', + ], + zip_safe=True, +) diff --git a/test/integration/__init__.py b/test/integration/__init__.py index e868f23..a9bcd0a 100644 --- a/test/integration/__init__.py +++ b/test/integration/__init__.py @@ -2,4 +2,4 @@ """Integration tests""" -# This file is only here to get pylint to check the files in this directory \ No newline at end of file +# This file is only here to get pylint to check the files in this directory diff --git a/test/unit/__init__.py b/test/unit/__init__.py index e29b565..6dafaf6 100644 --- a/test/unit/__init__.py +++ b/test/unit/__init__.py @@ -2,4 +2,4 @@ """Unit tests""" -# This file is only here to get pylint to check the files in this directory \ No newline at end of file +# This file is only here to get pylint to check the files in this directory diff --git a/test/unit/test_code_engine_v2.py b/test/unit/test_code_engine_v2.py new file mode 100644 index 0000000..04ad236 --- /dev/null +++ b/test/unit/test_code_engine_v2.py @@ -0,0 +1,6126 @@ +# -*- coding: utf-8 -*- +# (C) Copyright IBM Corp. 2023. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Unit Tests for CodeEngineV2 +""" + +from ibm_cloud_sdk_core.authenticators.no_auth_authenticator import NoAuthAuthenticator +import inspect +import json +import os +import pytest +import re +import requests +import responses +import urllib +from ibm_code_engine_sdk.code_engine_v2 import * + + +_service = CodeEngineV2(authenticator=NoAuthAuthenticator()) + +_base_url = 'https://api.au-syd.codeengine.cloud.ibm.com/v2' +_service.set_service_url(_base_url) + + +def preprocess_url(operation_path: str): + """ + Returns the request url associated with the specified operation path. + This will be base_url concatenated with a quoted version of operation_path. + The returned request URL is used to register the mock response so it needs + to match the request URL that is formed by the requests library. + """ + # First, unquote the path since it might have some quoted/escaped characters in it + # due to how the generator inserts the operation paths into the unit test code. + operation_path = urllib.parse.unquote(operation_path) + + # Next, quote the path using urllib so that we approximate what will + # happen during request processing. + operation_path = urllib.parse.quote(operation_path, safe='/') + + # Finally, form the request URL from the base URL and operation path. + request_url = _base_url + operation_path + + # If the request url does NOT end with a /, then just return it as-is. + # Otherwise, return a regular expression that matches one or more trailing /. + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + +############################################################################## +# Start of Service: Projects +############################################################################## +# region + + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = CodeEngineV2.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, CodeEngineV2) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = CodeEngineV2.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestListProjects: + """ + Test Class for list_projects + """ + + @responses.activate + def test_list_projects_all_params(self): + """ + list_projects() + """ + # Set up mock + url = preprocess_url('/projects') + mock_response = '{"first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}, "projects": [{"account_id": "4329073d16d2f3663f74bfa955259139", "created_at": "2021-03-29T12:18:13.992359829Z", "crn": "crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "name": "project-name", "region": "us-east", "resource_group_id": "5c49eabcf5e85881a37e2d100a33b3df", "resource_type": "project_v2", "status": "active"}]}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + limit = 100 + start = 'testString' + + # Invoke method + response = _service.list_projects(limit=limit, start=start, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'limit={}'.format(limit) in query_string + assert 'start={}'.format(start) in query_string + + def test_list_projects_all_params_with_retries(self): + # Enable retries and run test_list_projects_all_params. + _service.enable_retries() + self.test_list_projects_all_params() + + # Disable retries and run test_list_projects_all_params. + _service.disable_retries() + self.test_list_projects_all_params() + + @responses.activate + def test_list_projects_required_params(self): + """ + test_list_projects_required_params() + """ + # Set up mock + url = preprocess_url('/projects') + mock_response = '{"first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}, "projects": [{"account_id": "4329073d16d2f3663f74bfa955259139", "created_at": "2021-03-29T12:18:13.992359829Z", "crn": "crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "name": "project-name", "region": "us-east", "resource_group_id": "5c49eabcf5e85881a37e2d100a33b3df", "resource_type": "project_v2", "status": "active"}]}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Invoke method + response = _service.list_projects() + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_projects_required_params_with_retries(self): + # Enable retries and run test_list_projects_required_params. + _service.enable_retries() + self.test_list_projects_required_params() + + # Disable retries and run test_list_projects_required_params. + _service.disable_retries() + self.test_list_projects_required_params() + + @responses.activate + def test_list_projects_with_pager_get_next(self): + """ + test_list_projects_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/projects') + mock_response1 = '{"next":{"start":"1"},"projects":[{"account_id":"4329073d16d2f3663f74bfa955259139","created_at":"2021-03-29T12:18:13.992359829Z","crn":"crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b","id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","name":"project-name","region":"us-east","resource_group_id":"5c49eabcf5e85881a37e2d100a33b3df","resource_type":"project_v2","status":"active"}],"total_count":2,"limit":1}' + mock_response2 = '{"projects":[{"account_id":"4329073d16d2f3663f74bfa955259139","created_at":"2021-03-29T12:18:13.992359829Z","crn":"crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b","id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","name":"project-name","region":"us-east","resource_group_id":"5c49eabcf5e85881a37e2d100a33b3df","resource_type":"project_v2","status":"active"}],"total_count":2,"limit":1}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + all_results = [] + pager = ProjectsPager( + client=_service, + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_projects_with_pager_get_all(self): + """ + test_list_projects_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/projects') + mock_response1 = '{"next":{"start":"1"},"projects":[{"account_id":"4329073d16d2f3663f74bfa955259139","created_at":"2021-03-29T12:18:13.992359829Z","crn":"crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b","id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","name":"project-name","region":"us-east","resource_group_id":"5c49eabcf5e85881a37e2d100a33b3df","resource_type":"project_v2","status":"active"}],"total_count":2,"limit":1}' + mock_response2 = '{"projects":[{"account_id":"4329073d16d2f3663f74bfa955259139","created_at":"2021-03-29T12:18:13.992359829Z","crn":"crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b","id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","name":"project-name","region":"us-east","resource_group_id":"5c49eabcf5e85881a37e2d100a33b3df","resource_type":"project_v2","status":"active"}],"total_count":2,"limit":1}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + pager = ProjectsPager( + client=_service, + limit=100, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestCreateProject: + """ + Test Class for create_project + """ + + @responses.activate + def test_create_project_all_params(self): + """ + create_project() + """ + # Set up mock + url = preprocess_url('/projects') + mock_response = '{"account_id": "4329073d16d2f3663f74bfa955259139", "created_at": "2021-03-29T12:18:13.992359829Z", "crn": "crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "name": "project-name", "region": "us-east", "resource_group_id": "5c49eabcf5e85881a37e2d100a33b3df", "resource_type": "project_v2", "status": "active"}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=202) + + # Set up parameter values + name = 'my-project' + resource_group_id = 'b91e849cedb04e7e92bd68c040c672dc' + tags = ['testString'] + + # Invoke method + response = _service.create_project(name, resource_group_id=resource_group_id, tags=tags, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'my-project' + assert req_body['resource_group_id'] == 'b91e849cedb04e7e92bd68c040c672dc' + assert req_body['tags'] == ['testString'] + + def test_create_project_all_params_with_retries(self): + # Enable retries and run test_create_project_all_params. + _service.enable_retries() + self.test_create_project_all_params() + + # Disable retries and run test_create_project_all_params. + _service.disable_retries() + self.test_create_project_all_params() + + @responses.activate + def test_create_project_value_error(self): + """ + test_create_project_value_error() + """ + # Set up mock + url = preprocess_url('/projects') + mock_response = '{"account_id": "4329073d16d2f3663f74bfa955259139", "created_at": "2021-03-29T12:18:13.992359829Z", "crn": "crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "name": "project-name", "region": "us-east", "resource_group_id": "5c49eabcf5e85881a37e2d100a33b3df", "resource_type": "project_v2", "status": "active"}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=202) + + # Set up parameter values + name = 'my-project' + resource_group_id = 'b91e849cedb04e7e92bd68c040c672dc' + tags = ['testString'] + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_project(**req_copy) + + def test_create_project_value_error_with_retries(self): + # Enable retries and run test_create_project_value_error. + _service.enable_retries() + self.test_create_project_value_error() + + # Disable retries and run test_create_project_value_error. + _service.disable_retries() + self.test_create_project_value_error() + + +class TestGetProject: + """ + Test Class for get_project + """ + + @responses.activate + def test_get_project_all_params(self): + """ + get_project() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005') + mock_response = '{"account_id": "4329073d16d2f3663f74bfa955259139", "created_at": "2021-03-29T12:18:13.992359829Z", "crn": "crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "name": "project-name", "region": "us-east", "resource_group_id": "5c49eabcf5e85881a37e2d100a33b3df", "resource_type": "project_v2", "status": "active"}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Invoke method + response = _service.get_project(id, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_project_all_params_with_retries(self): + # Enable retries and run test_get_project_all_params. + _service.enable_retries() + self.test_get_project_all_params() + + # Disable retries and run test_get_project_all_params. + _service.disable_retries() + self.test_get_project_all_params() + + @responses.activate + def test_get_project_value_error(self): + """ + test_get_project_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005') + mock_response = '{"account_id": "4329073d16d2f3663f74bfa955259139", "created_at": "2021-03-29T12:18:13.992359829Z", "crn": "crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "name": "project-name", "region": "us-east", "resource_group_id": "5c49eabcf5e85881a37e2d100a33b3df", "resource_type": "project_v2", "status": "active"}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "id": id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_project(**req_copy) + + def test_get_project_value_error_with_retries(self): + # Enable retries and run test_get_project_value_error. + _service.enable_retries() + self.test_get_project_value_error() + + # Disable retries and run test_get_project_value_error. + _service.disable_retries() + self.test_get_project_value_error() + + +class TestDeleteProject: + """ + Test Class for delete_project + """ + + @responses.activate + def test_delete_project_all_params(self): + """ + delete_project() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Invoke method + response = _service.delete_project(id, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + + def test_delete_project_all_params_with_retries(self): + # Enable retries and run test_delete_project_all_params. + _service.enable_retries() + self.test_delete_project_all_params() + + # Disable retries and run test_delete_project_all_params. + _service.disable_retries() + self.test_delete_project_all_params() + + @responses.activate + def test_delete_project_value_error(self): + """ + test_delete_project_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "id": id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_project(**req_copy) + + def test_delete_project_value_error_with_retries(self): + # Enable retries and run test_delete_project_value_error. + _service.enable_retries() + self.test_delete_project_value_error() + + # Disable retries and run test_delete_project_value_error. + _service.disable_retries() + self.test_delete_project_value_error() + + +# endregion +############################################################################## +# End of Service: Projects +############################################################################## + +############################################################################## +# Start of Service: Applications +############################################################################## +# region + + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = CodeEngineV2.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, CodeEngineV2) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = CodeEngineV2.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestListApps: + """ + Test Class for list_apps + """ + + @responses.activate + def test_list_apps_all_params(self): + """ + list_apps() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps') + mock_response = '{"apps": [{"created_at": "2022-09-13T11:41:35+02:00", "endpoint": "https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud", "endpoint_internal": "http://my-app.vg67hzldruk.svc.cluster.local", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "managed_domain_mappings": "local_public", "name": "my-app", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"latest_created_revision": "my-app-00001", "latest_ready_revision": "my-app-00001", "reason": "ready"}}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + limit = 100 + start = 'testString' + + # Invoke method + response = _service.list_apps(project_id, limit=limit, start=start, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'limit={}'.format(limit) in query_string + assert 'start={}'.format(start) in query_string + + def test_list_apps_all_params_with_retries(self): + # Enable retries and run test_list_apps_all_params. + _service.enable_retries() + self.test_list_apps_all_params() + + # Disable retries and run test_list_apps_all_params. + _service.disable_retries() + self.test_list_apps_all_params() + + @responses.activate + def test_list_apps_required_params(self): + """ + test_list_apps_required_params() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps') + mock_response = '{"apps": [{"created_at": "2022-09-13T11:41:35+02:00", "endpoint": "https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud", "endpoint_internal": "http://my-app.vg67hzldruk.svc.cluster.local", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "managed_domain_mappings": "local_public", "name": "my-app", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"latest_created_revision": "my-app-00001", "latest_ready_revision": "my-app-00001", "reason": "ready"}}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Invoke method + response = _service.list_apps(project_id, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_apps_required_params_with_retries(self): + # Enable retries and run test_list_apps_required_params. + _service.enable_retries() + self.test_list_apps_required_params() + + # Disable retries and run test_list_apps_required_params. + _service.disable_retries() + self.test_list_apps_required_params() + + @responses.activate + def test_list_apps_value_error(self): + """ + test_list_apps_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps') + mock_response = '{"apps": [{"created_at": "2022-09-13T11:41:35+02:00", "endpoint": "https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud", "endpoint_internal": "http://my-app.vg67hzldruk.svc.cluster.local", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "managed_domain_mappings": "local_public", "name": "my-app", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"latest_created_revision": "my-app-00001", "latest_ready_revision": "my-app-00001", "reason": "ready"}}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_apps(**req_copy) + + def test_list_apps_value_error_with_retries(self): + # Enable retries and run test_list_apps_value_error. + _service.enable_retries() + self.test_list_apps_value_error() + + # Disable retries and run test_list_apps_value_error. + _service.disable_retries() + self.test_list_apps_value_error() + + @responses.activate + def test_list_apps_with_pager_get_next(self): + """ + test_list_apps_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"apps":[{"created_at":"2022-09-13T11:41:35+02:00","endpoint":"https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud","endpoint_internal":"http://my-app.vg67hzldruk.svc.cluster.local","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","managed_domain_mappings":"local_public","name":"my-app","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"latest_created_revision":"my-app-00001","latest_ready_revision":"my-app-00001","reason":"ready"}}]}' + mock_response2 = '{"total_count":2,"limit":1,"apps":[{"created_at":"2022-09-13T11:41:35+02:00","endpoint":"https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud","endpoint_internal":"http://my-app.vg67hzldruk.svc.cluster.local","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","managed_domain_mappings":"local_public","name":"my-app","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"latest_created_revision":"my-app-00001","latest_ready_revision":"my-app-00001","reason":"ready"}}]}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + all_results = [] + pager = AppsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_apps_with_pager_get_all(self): + """ + test_list_apps_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"apps":[{"created_at":"2022-09-13T11:41:35+02:00","endpoint":"https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud","endpoint_internal":"http://my-app.vg67hzldruk.svc.cluster.local","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","managed_domain_mappings":"local_public","name":"my-app","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"latest_created_revision":"my-app-00001","latest_ready_revision":"my-app-00001","reason":"ready"}}]}' + mock_response2 = '{"total_count":2,"limit":1,"apps":[{"created_at":"2022-09-13T11:41:35+02:00","endpoint":"https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud","endpoint_internal":"http://my-app.vg67hzldruk.svc.cluster.local","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","managed_domain_mappings":"local_public","name":"my-app","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"latest_created_revision":"my-app-00001","latest_ready_revision":"my-app-00001","reason":"ready"}}]}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + pager = AppsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestCreateApp: + """ + Test Class for create_app + """ + + @responses.activate + def test_create_app_all_params(self): + """ + create_app() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "endpoint": "https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud", "endpoint_internal": "http://my-app.vg67hzldruk.svc.cluster.local", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "managed_domain_mappings": "local_public", "name": "my-app", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"latest_created_revision": "my-app-00001", "latest_ready_revision": "my-app-00001", "reason": "ready"}}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + + # Construct a dict representation of a EnvVarPrototype model + env_var_prototype_model = {} + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + # Construct a dict representation of a VolumeMountPrototype model + volume_mount_prototype_model = {} + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + image_reference = 'icr.io/codeengine/helloworld' + name = 'my-app' + image_port = 8080 + image_secret = 'my-secret' + managed_domain_mappings = 'local_public' + run_arguments = ['testString'] + run_as_user = 1001 + run_commands = ['testString'] + run_env_variables = [env_var_prototype_model] + run_service_account = 'default' + run_volume_mounts = [volume_mount_prototype_model] + scale_concurrency = 100 + scale_concurrency_target = 80 + scale_cpu_limit = '1' + scale_ephemeral_storage_limit = '4G' + scale_initial_instances = 1 + scale_max_instances = 10 + scale_memory_limit = '4G' + scale_min_instances = 1 + scale_request_timeout = 300 + + # Invoke method + response = _service.create_app( + project_id, + image_reference, + name, + image_port=image_port, + image_secret=image_secret, + managed_domain_mappings=managed_domain_mappings, + run_arguments=run_arguments, + run_as_user=run_as_user, + run_commands=run_commands, + run_env_variables=run_env_variables, + run_service_account=run_service_account, + run_volume_mounts=run_volume_mounts, + scale_concurrency=scale_concurrency, + scale_concurrency_target=scale_concurrency_target, + scale_cpu_limit=scale_cpu_limit, + scale_ephemeral_storage_limit=scale_ephemeral_storage_limit, + scale_initial_instances=scale_initial_instances, + scale_max_instances=scale_max_instances, + scale_memory_limit=scale_memory_limit, + scale_min_instances=scale_min_instances, + scale_request_timeout=scale_request_timeout, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['image_reference'] == 'icr.io/codeengine/helloworld' + assert req_body['name'] == 'my-app' + assert req_body['image_port'] == 8080 + assert req_body['image_secret'] == 'my-secret' + assert req_body['managed_domain_mappings'] == 'local_public' + assert req_body['run_arguments'] == ['testString'] + assert req_body['run_as_user'] == 1001 + assert req_body['run_commands'] == ['testString'] + assert req_body['run_env_variables'] == [env_var_prototype_model] + assert req_body['run_service_account'] == 'default' + assert req_body['run_volume_mounts'] == [volume_mount_prototype_model] + assert req_body['scale_concurrency'] == 100 + assert req_body['scale_concurrency_target'] == 80 + assert req_body['scale_cpu_limit'] == '1' + assert req_body['scale_ephemeral_storage_limit'] == '4G' + assert req_body['scale_initial_instances'] == 1 + assert req_body['scale_max_instances'] == 10 + assert req_body['scale_memory_limit'] == '4G' + assert req_body['scale_min_instances'] == 1 + assert req_body['scale_request_timeout'] == 300 + + def test_create_app_all_params_with_retries(self): + # Enable retries and run test_create_app_all_params. + _service.enable_retries() + self.test_create_app_all_params() + + # Disable retries and run test_create_app_all_params. + _service.disable_retries() + self.test_create_app_all_params() + + @responses.activate + def test_create_app_value_error(self): + """ + test_create_app_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "endpoint": "https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud", "endpoint_internal": "http://my-app.vg67hzldruk.svc.cluster.local", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "managed_domain_mappings": "local_public", "name": "my-app", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"latest_created_revision": "my-app-00001", "latest_ready_revision": "my-app-00001", "reason": "ready"}}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + + # Construct a dict representation of a EnvVarPrototype model + env_var_prototype_model = {} + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + # Construct a dict representation of a VolumeMountPrototype model + volume_mount_prototype_model = {} + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + image_reference = 'icr.io/codeengine/helloworld' + name = 'my-app' + image_port = 8080 + image_secret = 'my-secret' + managed_domain_mappings = 'local_public' + run_arguments = ['testString'] + run_as_user = 1001 + run_commands = ['testString'] + run_env_variables = [env_var_prototype_model] + run_service_account = 'default' + run_volume_mounts = [volume_mount_prototype_model] + scale_concurrency = 100 + scale_concurrency_target = 80 + scale_cpu_limit = '1' + scale_ephemeral_storage_limit = '4G' + scale_initial_instances = 1 + scale_max_instances = 10 + scale_memory_limit = '4G' + scale_min_instances = 1 + scale_request_timeout = 300 + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "image_reference": image_reference, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_app(**req_copy) + + def test_create_app_value_error_with_retries(self): + # Enable retries and run test_create_app_value_error. + _service.enable_retries() + self.test_create_app_value_error() + + # Disable retries and run test_create_app_value_error. + _service.disable_retries() + self.test_create_app_value_error() + + +class TestGetApp: + """ + Test Class for get_app + """ + + @responses.activate + def test_get_app_all_params(self): + """ + get_app() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "endpoint": "https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud", "endpoint_internal": "http://my-app.vg67hzldruk.svc.cluster.local", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "managed_domain_mappings": "local_public", "name": "my-app", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"latest_created_revision": "my-app-00001", "latest_ready_revision": "my-app-00001", "reason": "ready"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-app' + + # Invoke method + response = _service.get_app(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_app_all_params_with_retries(self): + # Enable retries and run test_get_app_all_params. + _service.enable_retries() + self.test_get_app_all_params() + + # Disable retries and run test_get_app_all_params. + _service.disable_retries() + self.test_get_app_all_params() + + @responses.activate + def test_get_app_value_error(self): + """ + test_get_app_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "endpoint": "https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud", "endpoint_internal": "http://my-app.vg67hzldruk.svc.cluster.local", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "managed_domain_mappings": "local_public", "name": "my-app", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"latest_created_revision": "my-app-00001", "latest_ready_revision": "my-app-00001", "reason": "ready"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-app' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_app(**req_copy) + + def test_get_app_value_error_with_retries(self): + # Enable retries and run test_get_app_value_error. + _service.enable_retries() + self.test_get_app_value_error() + + # Disable retries and run test_get_app_value_error. + _service.disable_retries() + self.test_get_app_value_error() + + +class TestDeleteApp: + """ + Test Class for delete_app + """ + + @responses.activate + def test_delete_app_all_params(self): + """ + delete_app() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-app' + + # Invoke method + response = _service.delete_app(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + + def test_delete_app_all_params_with_retries(self): + # Enable retries and run test_delete_app_all_params. + _service.enable_retries() + self.test_delete_app_all_params() + + # Disable retries and run test_delete_app_all_params. + _service.disable_retries() + self.test_delete_app_all_params() + + @responses.activate + def test_delete_app_value_error(self): + """ + test_delete_app_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-app' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_app(**req_copy) + + def test_delete_app_value_error_with_retries(self): + # Enable retries and run test_delete_app_value_error. + _service.enable_retries() + self.test_delete_app_value_error() + + # Disable retries and run test_delete_app_value_error. + _service.disable_retries() + self.test_delete_app_value_error() + + +class TestUpdateApp: + """ + Test Class for update_app + """ + + @responses.activate + def test_update_app_all_params(self): + """ + update_app() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "endpoint": "https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud", "endpoint_internal": "http://my-app.vg67hzldruk.svc.cluster.local", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "managed_domain_mappings": "local_public", "name": "my-app", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"latest_created_revision": "my-app-00001", "latest_ready_revision": "my-app-00001", "reason": "ready"}}' + responses.add(responses.PATCH, url, body=mock_response, content_type='application/json', status=200) + + # Construct a dict representation of a EnvVarPrototype model + env_var_prototype_model = {} + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + # Construct a dict representation of a VolumeMountPrototype model + volume_mount_prototype_model = {} + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Construct a dict representation of a AppPatch model + app_patch_model = {} + app_patch_model['image_port'] = 8080 + app_patch_model['image_reference'] = 'icr.io/codeengine/helloworld' + app_patch_model['image_secret'] = 'my-secret' + app_patch_model['managed_domain_mappings'] = 'local_public' + app_patch_model['run_arguments'] = ['testString'] + app_patch_model['run_as_user'] = 1001 + app_patch_model['run_commands'] = ['testString'] + app_patch_model['run_env_variables'] = [env_var_prototype_model] + app_patch_model['run_service_account'] = 'default' + app_patch_model['run_volume_mounts'] = [volume_mount_prototype_model] + app_patch_model['scale_concurrency'] = 100 + app_patch_model['scale_concurrency_target'] = 80 + app_patch_model['scale_cpu_limit'] = '1' + app_patch_model['scale_ephemeral_storage_limit'] = '4G' + app_patch_model['scale_initial_instances'] = 1 + app_patch_model['scale_max_instances'] = 10 + app_patch_model['scale_memory_limit'] = '4G' + app_patch_model['scale_min_instances'] = 1 + app_patch_model['scale_request_timeout'] = 300 + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-app' + if_match = 'testString' + app = app_patch_model + + # Invoke method + response = _service.update_app(project_id, name, if_match, app, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body == app + + def test_update_app_all_params_with_retries(self): + # Enable retries and run test_update_app_all_params. + _service.enable_retries() + self.test_update_app_all_params() + + # Disable retries and run test_update_app_all_params. + _service.disable_retries() + self.test_update_app_all_params() + + @responses.activate + def test_update_app_value_error(self): + """ + test_update_app_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "endpoint": "https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud", "endpoint_internal": "http://my-app.vg67hzldruk.svc.cluster.local", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "managed_domain_mappings": "local_public", "name": "my-app", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"latest_created_revision": "my-app-00001", "latest_ready_revision": "my-app-00001", "reason": "ready"}}' + responses.add(responses.PATCH, url, body=mock_response, content_type='application/json', status=200) + + # Construct a dict representation of a EnvVarPrototype model + env_var_prototype_model = {} + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + # Construct a dict representation of a VolumeMountPrototype model + volume_mount_prototype_model = {} + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Construct a dict representation of a AppPatch model + app_patch_model = {} + app_patch_model['image_port'] = 8080 + app_patch_model['image_reference'] = 'icr.io/codeengine/helloworld' + app_patch_model['image_secret'] = 'my-secret' + app_patch_model['managed_domain_mappings'] = 'local_public' + app_patch_model['run_arguments'] = ['testString'] + app_patch_model['run_as_user'] = 1001 + app_patch_model['run_commands'] = ['testString'] + app_patch_model['run_env_variables'] = [env_var_prototype_model] + app_patch_model['run_service_account'] = 'default' + app_patch_model['run_volume_mounts'] = [volume_mount_prototype_model] + app_patch_model['scale_concurrency'] = 100 + app_patch_model['scale_concurrency_target'] = 80 + app_patch_model['scale_cpu_limit'] = '1' + app_patch_model['scale_ephemeral_storage_limit'] = '4G' + app_patch_model['scale_initial_instances'] = 1 + app_patch_model['scale_max_instances'] = 10 + app_patch_model['scale_memory_limit'] = '4G' + app_patch_model['scale_min_instances'] = 1 + app_patch_model['scale_request_timeout'] = 300 + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-app' + if_match = 'testString' + app = app_patch_model + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + "if_match": if_match, + "app": app, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.update_app(**req_copy) + + def test_update_app_value_error_with_retries(self): + # Enable retries and run test_update_app_value_error. + _service.enable_retries() + self.test_update_app_value_error() + + # Disable retries and run test_update_app_value_error. + _service.disable_retries() + self.test_update_app_value_error() + + +class TestListAppRevisions: + """ + Test Class for list_app_revisions + """ + + @responses.activate + def test_list_app_revisions_all_params(self): + """ + list_app_revisions() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app/revisions') + mock_response = '{"first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}, "revisions": [{"app_name": "my-app", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-app-00001", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_revision_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"actual_instances": 1, "reason": "ready"}}]}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + app_name = 'my-app' + limit = 100 + start = 'testString' + + # Invoke method + response = _service.list_app_revisions(project_id, app_name, limit=limit, start=start, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'limit={}'.format(limit) in query_string + assert 'start={}'.format(start) in query_string + + def test_list_app_revisions_all_params_with_retries(self): + # Enable retries and run test_list_app_revisions_all_params. + _service.enable_retries() + self.test_list_app_revisions_all_params() + + # Disable retries and run test_list_app_revisions_all_params. + _service.disable_retries() + self.test_list_app_revisions_all_params() + + @responses.activate + def test_list_app_revisions_required_params(self): + """ + test_list_app_revisions_required_params() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app/revisions') + mock_response = '{"first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}, "revisions": [{"app_name": "my-app", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-app-00001", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_revision_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"actual_instances": 1, "reason": "ready"}}]}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + app_name = 'my-app' + + # Invoke method + response = _service.list_app_revisions(project_id, app_name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_app_revisions_required_params_with_retries(self): + # Enable retries and run test_list_app_revisions_required_params. + _service.enable_retries() + self.test_list_app_revisions_required_params() + + # Disable retries and run test_list_app_revisions_required_params. + _service.disable_retries() + self.test_list_app_revisions_required_params() + + @responses.activate + def test_list_app_revisions_value_error(self): + """ + test_list_app_revisions_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app/revisions') + mock_response = '{"first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}, "revisions": [{"app_name": "my-app", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-app-00001", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_revision_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"actual_instances": 1, "reason": "ready"}}]}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + app_name = 'my-app' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "app_name": app_name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_app_revisions(**req_copy) + + def test_list_app_revisions_value_error_with_retries(self): + # Enable retries and run test_list_app_revisions_value_error. + _service.enable_retries() + self.test_list_app_revisions_value_error() + + # Disable retries and run test_list_app_revisions_value_error. + _service.disable_retries() + self.test_list_app_revisions_value_error() + + @responses.activate + def test_list_app_revisions_with_pager_get_next(self): + """ + test_list_app_revisions_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app/revisions') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"revisions":[{"app_name":"my-app","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-app-00001","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_revision_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"actual_instances":1,"reason":"ready"}}]}' + mock_response2 = '{"total_count":2,"limit":1,"revisions":[{"app_name":"my-app","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-app-00001","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_revision_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"actual_instances":1,"reason":"ready"}}]}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + all_results = [] + pager = AppRevisionsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + app_name='my-app', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_app_revisions_with_pager_get_all(self): + """ + test_list_app_revisions_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app/revisions') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"revisions":[{"app_name":"my-app","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-app-00001","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_revision_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"actual_instances":1,"reason":"ready"}}]}' + mock_response2 = '{"total_count":2,"limit":1,"revisions":[{"app_name":"my-app","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-app-00001","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_revision_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"actual_instances":1,"reason":"ready"}}]}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + pager = AppRevisionsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + app_name='my-app', + limit=100, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestGetAppRevision: + """ + Test Class for get_app_revision + """ + + @responses.activate + def test_get_app_revision_all_params(self): + """ + get_app_revision() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app/revisions/my-app-001') + mock_response = '{"app_name": "my-app", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-app-00001", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_revision_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"actual_instances": 1, "reason": "ready"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + app_name = 'my-app' + name = 'my-app-001' + + # Invoke method + response = _service.get_app_revision(project_id, app_name, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_app_revision_all_params_with_retries(self): + # Enable retries and run test_get_app_revision_all_params. + _service.enable_retries() + self.test_get_app_revision_all_params() + + # Disable retries and run test_get_app_revision_all_params. + _service.disable_retries() + self.test_get_app_revision_all_params() + + @responses.activate + def test_get_app_revision_value_error(self): + """ + test_get_app_revision_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app/revisions/my-app-001') + mock_response = '{"app_name": "my-app", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_port": 8080, "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-app-00001", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "app_revision_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_concurrency": 100, "scale_concurrency_target": 80, "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_initial_instances": 1, "scale_max_instances": 10, "scale_memory_limit": "4G", "scale_min_instances": 1, "scale_request_timeout": 300, "status": "ready", "status_details": {"actual_instances": 1, "reason": "ready"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + app_name = 'my-app' + name = 'my-app-001' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "app_name": app_name, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_app_revision(**req_copy) + + def test_get_app_revision_value_error_with_retries(self): + # Enable retries and run test_get_app_revision_value_error. + _service.enable_retries() + self.test_get_app_revision_value_error() + + # Disable retries and run test_get_app_revision_value_error. + _service.disable_retries() + self.test_get_app_revision_value_error() + + +class TestDeleteAppRevision: + """ + Test Class for delete_app_revision + """ + + @responses.activate + def test_delete_app_revision_all_params(self): + """ + delete_app_revision() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app/revisions/my-app-001') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + app_name = 'my-app' + name = 'my-app-001' + + # Invoke method + response = _service.delete_app_revision(project_id, app_name, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + + def test_delete_app_revision_all_params_with_retries(self): + # Enable retries and run test_delete_app_revision_all_params. + _service.enable_retries() + self.test_delete_app_revision_all_params() + + # Disable retries and run test_delete_app_revision_all_params. + _service.disable_retries() + self.test_delete_app_revision_all_params() + + @responses.activate + def test_delete_app_revision_value_error(self): + """ + test_delete_app_revision_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app/revisions/my-app-001') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + app_name = 'my-app' + name = 'my-app-001' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "app_name": app_name, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_app_revision(**req_copy) + + def test_delete_app_revision_value_error_with_retries(self): + # Enable retries and run test_delete_app_revision_value_error. + _service.enable_retries() + self.test_delete_app_revision_value_error() + + # Disable retries and run test_delete_app_revision_value_error. + _service.disable_retries() + self.test_delete_app_revision_value_error() + + +# endregion +############################################################################## +# End of Service: Applications +############################################################################## + +############################################################################## +# Start of Service: Jobs +############################################################################## +# region + + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = CodeEngineV2.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, CodeEngineV2) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = CodeEngineV2.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestListJobs: + """ + Test Class for list_jobs + """ + + @responses.activate + def test_list_jobs_all_params(self): + """ + list_jobs() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs') + mock_response = '{"first": {"href": "href"}, "jobs": [{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-job", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3}], "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + limit = 100 + start = 'testString' + + # Invoke method + response = _service.list_jobs(project_id, limit=limit, start=start, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'limit={}'.format(limit) in query_string + assert 'start={}'.format(start) in query_string + + def test_list_jobs_all_params_with_retries(self): + # Enable retries and run test_list_jobs_all_params. + _service.enable_retries() + self.test_list_jobs_all_params() + + # Disable retries and run test_list_jobs_all_params. + _service.disable_retries() + self.test_list_jobs_all_params() + + @responses.activate + def test_list_jobs_required_params(self): + """ + test_list_jobs_required_params() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs') + mock_response = '{"first": {"href": "href"}, "jobs": [{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-job", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3}], "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Invoke method + response = _service.list_jobs(project_id, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_jobs_required_params_with_retries(self): + # Enable retries and run test_list_jobs_required_params. + _service.enable_retries() + self.test_list_jobs_required_params() + + # Disable retries and run test_list_jobs_required_params. + _service.disable_retries() + self.test_list_jobs_required_params() + + @responses.activate + def test_list_jobs_value_error(self): + """ + test_list_jobs_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs') + mock_response = '{"first": {"href": "href"}, "jobs": [{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-job", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3}], "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_jobs(**req_copy) + + def test_list_jobs_value_error_with_retries(self): + # Enable retries and run test_list_jobs_value_error. + _service.enable_retries() + self.test_list_jobs_value_error() + + # Disable retries and run test_list_jobs_value_error. + _service.disable_retries() + self.test_list_jobs_value_error() + + @responses.activate + def test_list_jobs_with_pager_get_next(self): + """ + test_list_jobs_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"jobs":[{"created_at":"2022-09-13T11:41:35+02:00","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-job","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"job_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_mode":"daemon","run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_array_spec":"1-5,7-8,10","scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_max_execution_time":7200,"scale_memory_limit":"4G","scale_retry_limit":3}],"limit":1}' + mock_response2 = '{"total_count":2,"jobs":[{"created_at":"2022-09-13T11:41:35+02:00","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-job","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"job_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_mode":"daemon","run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_array_spec":"1-5,7-8,10","scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_max_execution_time":7200,"scale_memory_limit":"4G","scale_retry_limit":3}],"limit":1}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + all_results = [] + pager = JobsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_jobs_with_pager_get_all(self): + """ + test_list_jobs_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"jobs":[{"created_at":"2022-09-13T11:41:35+02:00","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-job","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"job_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_mode":"daemon","run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_array_spec":"1-5,7-8,10","scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_max_execution_time":7200,"scale_memory_limit":"4G","scale_retry_limit":3}],"limit":1}' + mock_response2 = '{"total_count":2,"jobs":[{"created_at":"2022-09-13T11:41:35+02:00","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-job","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"job_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_mode":"daemon","run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_array_spec":"1-5,7-8,10","scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_max_execution_time":7200,"scale_memory_limit":"4G","scale_retry_limit":3}],"limit":1}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + pager = JobsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestCreateJob: + """ + Test Class for create_job + """ + + @responses.activate + def test_create_job_all_params(self): + """ + create_job() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-job", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + + # Construct a dict representation of a EnvVarPrototype model + env_var_prototype_model = {} + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + # Construct a dict representation of a VolumeMountPrototype model + volume_mount_prototype_model = {} + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + image_reference = 'icr.io/codeengine/helloworld' + name = 'my-job' + image_secret = 'my-secret' + run_arguments = ['testString'] + run_as_user = 1001 + run_commands = ['testString'] + run_env_variables = [env_var_prototype_model] + run_mode = 'daemon' + run_service_account = 'default' + run_volume_mounts = [volume_mount_prototype_model] + scale_array_spec = '1-5,7-8,10' + scale_cpu_limit = '1' + scale_ephemeral_storage_limit = '4G' + scale_max_execution_time = 7200 + scale_memory_limit = '4G' + scale_retry_limit = 3 + + # Invoke method + response = _service.create_job( + project_id, + image_reference, + name, + image_secret=image_secret, + run_arguments=run_arguments, + run_as_user=run_as_user, + run_commands=run_commands, + run_env_variables=run_env_variables, + run_mode=run_mode, + run_service_account=run_service_account, + run_volume_mounts=run_volume_mounts, + scale_array_spec=scale_array_spec, + scale_cpu_limit=scale_cpu_limit, + scale_ephemeral_storage_limit=scale_ephemeral_storage_limit, + scale_max_execution_time=scale_max_execution_time, + scale_memory_limit=scale_memory_limit, + scale_retry_limit=scale_retry_limit, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['image_reference'] == 'icr.io/codeengine/helloworld' + assert req_body['name'] == 'my-job' + assert req_body['image_secret'] == 'my-secret' + assert req_body['run_arguments'] == ['testString'] + assert req_body['run_as_user'] == 1001 + assert req_body['run_commands'] == ['testString'] + assert req_body['run_env_variables'] == [env_var_prototype_model] + assert req_body['run_mode'] == 'daemon' + assert req_body['run_service_account'] == 'default' + assert req_body['run_volume_mounts'] == [volume_mount_prototype_model] + assert req_body['scale_array_spec'] == '1-5,7-8,10' + assert req_body['scale_cpu_limit'] == '1' + assert req_body['scale_ephemeral_storage_limit'] == '4G' + assert req_body['scale_max_execution_time'] == 7200 + assert req_body['scale_memory_limit'] == '4G' + assert req_body['scale_retry_limit'] == 3 + + def test_create_job_all_params_with_retries(self): + # Enable retries and run test_create_job_all_params. + _service.enable_retries() + self.test_create_job_all_params() + + # Disable retries and run test_create_job_all_params. + _service.disable_retries() + self.test_create_job_all_params() + + @responses.activate + def test_create_job_value_error(self): + """ + test_create_job_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-job", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + + # Construct a dict representation of a EnvVarPrototype model + env_var_prototype_model = {} + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + # Construct a dict representation of a VolumeMountPrototype model + volume_mount_prototype_model = {} + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + image_reference = 'icr.io/codeengine/helloworld' + name = 'my-job' + image_secret = 'my-secret' + run_arguments = ['testString'] + run_as_user = 1001 + run_commands = ['testString'] + run_env_variables = [env_var_prototype_model] + run_mode = 'daemon' + run_service_account = 'default' + run_volume_mounts = [volume_mount_prototype_model] + scale_array_spec = '1-5,7-8,10' + scale_cpu_limit = '1' + scale_ephemeral_storage_limit = '4G' + scale_max_execution_time = 7200 + scale_memory_limit = '4G' + scale_retry_limit = 3 + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "image_reference": image_reference, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_job(**req_copy) + + def test_create_job_value_error_with_retries(self): + # Enable retries and run test_create_job_value_error. + _service.enable_retries() + self.test_create_job_value_error() + + # Disable retries and run test_create_job_value_error. + _service.disable_retries() + self.test_create_job_value_error() + + +class TestGetJob: + """ + Test Class for get_job + """ + + @responses.activate + def test_get_job_all_params(self): + """ + get_job() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs/my-job') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-job", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-job' + + # Invoke method + response = _service.get_job(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_job_all_params_with_retries(self): + # Enable retries and run test_get_job_all_params. + _service.enable_retries() + self.test_get_job_all_params() + + # Disable retries and run test_get_job_all_params. + _service.disable_retries() + self.test_get_job_all_params() + + @responses.activate + def test_get_job_value_error(self): + """ + test_get_job_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs/my-job') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-job", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-job' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_job(**req_copy) + + def test_get_job_value_error_with_retries(self): + # Enable retries and run test_get_job_value_error. + _service.enable_retries() + self.test_get_job_value_error() + + # Disable retries and run test_get_job_value_error. + _service.disable_retries() + self.test_get_job_value_error() + + +class TestDeleteJob: + """ + Test Class for delete_job + """ + + @responses.activate + def test_delete_job_all_params(self): + """ + delete_job() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs/my-job') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-job' + + # Invoke method + response = _service.delete_job(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + + def test_delete_job_all_params_with_retries(self): + # Enable retries and run test_delete_job_all_params. + _service.enable_retries() + self.test_delete_job_all_params() + + # Disable retries and run test_delete_job_all_params. + _service.disable_retries() + self.test_delete_job_all_params() + + @responses.activate + def test_delete_job_value_error(self): + """ + test_delete_job_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs/my-job') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-job' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_job(**req_copy) + + def test_delete_job_value_error_with_retries(self): + # Enable retries and run test_delete_job_value_error. + _service.enable_retries() + self.test_delete_job_value_error() + + # Disable retries and run test_delete_job_value_error. + _service.disable_retries() + self.test_delete_job_value_error() + + +class TestUpdateJob: + """ + Test Class for update_job + """ + + @responses.activate + def test_update_job_all_params(self): + """ + update_job() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs/my-job') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-job", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3}' + responses.add(responses.PATCH, url, body=mock_response, content_type='application/json', status=200) + + # Construct a dict representation of a EnvVarPrototype model + env_var_prototype_model = {} + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + # Construct a dict representation of a VolumeMountPrototype model + volume_mount_prototype_model = {} + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Construct a dict representation of a JobPatch model + job_patch_model = {} + job_patch_model['image_reference'] = 'icr.io/codeengine/helloworld' + job_patch_model['image_secret'] = 'my-secret' + job_patch_model['run_arguments'] = ['testString'] + job_patch_model['run_as_user'] = 1001 + job_patch_model['run_commands'] = ['testString'] + job_patch_model['run_env_variables'] = [env_var_prototype_model] + job_patch_model['run_mode'] = 'daemon' + job_patch_model['run_service_account'] = 'default' + job_patch_model['run_volume_mounts'] = [volume_mount_prototype_model] + job_patch_model['scale_array_spec'] = '1-5,7-8,10' + job_patch_model['scale_cpu_limit'] = '1' + job_patch_model['scale_ephemeral_storage_limit'] = '4G' + job_patch_model['scale_max_execution_time'] = 7200 + job_patch_model['scale_memory_limit'] = '4G' + job_patch_model['scale_retry_limit'] = 3 + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-job' + if_match = 'testString' + job = job_patch_model + + # Invoke method + response = _service.update_job(project_id, name, if_match, job, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body == job + + def test_update_job_all_params_with_retries(self): + # Enable retries and run test_update_job_all_params. + _service.enable_retries() + self.test_update_job_all_params() + + # Disable retries and run test_update_job_all_params. + _service.disable_retries() + self.test_update_job_all_params() + + @responses.activate + def test_update_job_value_error(self): + """ + test_update_job_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/jobs/my-job') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "name": "my-job", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3}' + responses.add(responses.PATCH, url, body=mock_response, content_type='application/json', status=200) + + # Construct a dict representation of a EnvVarPrototype model + env_var_prototype_model = {} + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + # Construct a dict representation of a VolumeMountPrototype model + volume_mount_prototype_model = {} + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Construct a dict representation of a JobPatch model + job_patch_model = {} + job_patch_model['image_reference'] = 'icr.io/codeengine/helloworld' + job_patch_model['image_secret'] = 'my-secret' + job_patch_model['run_arguments'] = ['testString'] + job_patch_model['run_as_user'] = 1001 + job_patch_model['run_commands'] = ['testString'] + job_patch_model['run_env_variables'] = [env_var_prototype_model] + job_patch_model['run_mode'] = 'daemon' + job_patch_model['run_service_account'] = 'default' + job_patch_model['run_volume_mounts'] = [volume_mount_prototype_model] + job_patch_model['scale_array_spec'] = '1-5,7-8,10' + job_patch_model['scale_cpu_limit'] = '1' + job_patch_model['scale_ephemeral_storage_limit'] = '4G' + job_patch_model['scale_max_execution_time'] = 7200 + job_patch_model['scale_memory_limit'] = '4G' + job_patch_model['scale_retry_limit'] = 3 + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-job' + if_match = 'testString' + job = job_patch_model + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + "if_match": if_match, + "job": job, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.update_job(**req_copy) + + def test_update_job_value_error_with_retries(self): + # Enable retries and run test_update_job_value_error. + _service.enable_retries() + self.test_update_job_value_error() + + # Disable retries and run test_update_job_value_error. + _service.disable_retries() + self.test_update_job_value_error() + + +class TestListJobRuns: + """ + Test Class for list_job_runs + """ + + @responses.activate + def test_list_job_runs_all_params(self): + """ + list_job_runs() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs') + mock_response = '{"first": {"href": "href"}, "job_runs": [{"created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "job_name": "my-job", "name": "my-job-run", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_run_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3, "status": "completed", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "failed": 0, "pending": 0, "requested": 0, "running": 0, "start_time": "2022-09-22T17:34:00Z", "succeeded": 1, "unknown": 0}}], "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + job_name = 'my-job' + limit = 100 + start = 'testString' + + # Invoke method + response = _service.list_job_runs(project_id, job_name=job_name, limit=limit, start=start, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'job_name={}'.format(job_name) in query_string + assert 'limit={}'.format(limit) in query_string + assert 'start={}'.format(start) in query_string + + def test_list_job_runs_all_params_with_retries(self): + # Enable retries and run test_list_job_runs_all_params. + _service.enable_retries() + self.test_list_job_runs_all_params() + + # Disable retries and run test_list_job_runs_all_params. + _service.disable_retries() + self.test_list_job_runs_all_params() + + @responses.activate + def test_list_job_runs_required_params(self): + """ + test_list_job_runs_required_params() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs') + mock_response = '{"first": {"href": "href"}, "job_runs": [{"created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "job_name": "my-job", "name": "my-job-run", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_run_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3, "status": "completed", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "failed": 0, "pending": 0, "requested": 0, "running": 0, "start_time": "2022-09-22T17:34:00Z", "succeeded": 1, "unknown": 0}}], "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Invoke method + response = _service.list_job_runs(project_id, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_job_runs_required_params_with_retries(self): + # Enable retries and run test_list_job_runs_required_params. + _service.enable_retries() + self.test_list_job_runs_required_params() + + # Disable retries and run test_list_job_runs_required_params. + _service.disable_retries() + self.test_list_job_runs_required_params() + + @responses.activate + def test_list_job_runs_value_error(self): + """ + test_list_job_runs_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs') + mock_response = '{"first": {"href": "href"}, "job_runs": [{"created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "job_name": "my-job", "name": "my-job-run", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_run_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3, "status": "completed", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "failed": 0, "pending": 0, "requested": 0, "running": 0, "start_time": "2022-09-22T17:34:00Z", "succeeded": 1, "unknown": 0}}], "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_job_runs(**req_copy) + + def test_list_job_runs_value_error_with_retries(self): + # Enable retries and run test_list_job_runs_value_error. + _service.enable_retries() + self.test_list_job_runs_value_error() + + # Disable retries and run test_list_job_runs_value_error. + _service.disable_retries() + self.test_list_job_runs_value_error() + + @responses.activate + def test_list_job_runs_with_pager_get_next(self): + """ + test_list_job_runs_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs') + mock_response1 = '{"next":{"start":"1"},"job_runs":[{"created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","job_name":"my-job","name":"my-job-run","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"job_run_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_mode":"daemon","run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_array_spec":"1-5,7-8,10","scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_max_execution_time":7200,"scale_memory_limit":"4G","scale_retry_limit":3,"status":"completed","status_details":{"completion_time":"2022-09-22T17:40:00Z","failed":0,"pending":0,"requested":0,"running":0,"start_time":"2022-09-22T17:34:00Z","succeeded":1,"unknown":0}}],"total_count":2,"limit":1}' + mock_response2 = '{"job_runs":[{"created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","job_name":"my-job","name":"my-job-run","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"job_run_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_mode":"daemon","run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_array_spec":"1-5,7-8,10","scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_max_execution_time":7200,"scale_memory_limit":"4G","scale_retry_limit":3,"status":"completed","status_details":{"completion_time":"2022-09-22T17:40:00Z","failed":0,"pending":0,"requested":0,"running":0,"start_time":"2022-09-22T17:34:00Z","succeeded":1,"unknown":0}}],"total_count":2,"limit":1}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + all_results = [] + pager = JobRunsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + job_name='my-job', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_job_runs_with_pager_get_all(self): + """ + test_list_job_runs_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs') + mock_response1 = '{"next":{"start":"1"},"job_runs":[{"created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","job_name":"my-job","name":"my-job-run","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"job_run_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_mode":"daemon","run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_array_spec":"1-5,7-8,10","scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_max_execution_time":7200,"scale_memory_limit":"4G","scale_retry_limit":3,"status":"completed","status_details":{"completion_time":"2022-09-22T17:40:00Z","failed":0,"pending":0,"requested":0,"running":0,"start_time":"2022-09-22T17:34:00Z","succeeded":1,"unknown":0}}],"total_count":2,"limit":1}' + mock_response2 = '{"job_runs":[{"created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","job_name":"my-job","name":"my-job-run","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"job_run_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_mode":"daemon","run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_array_spec":"1-5,7-8,10","scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_max_execution_time":7200,"scale_memory_limit":"4G","scale_retry_limit":3,"status":"completed","status_details":{"completion_time":"2022-09-22T17:40:00Z","failed":0,"pending":0,"requested":0,"running":0,"start_time":"2022-09-22T17:34:00Z","succeeded":1,"unknown":0}}],"total_count":2,"limit":1}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + pager = JobRunsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + job_name='my-job', + limit=100, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestCreateJobRun: + """ + Test Class for create_job_run + """ + + @responses.activate + def test_create_job_run_all_params(self): + """ + create_job_run() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "job_name": "my-job", "name": "my-job-run", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_run_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3, "status": "completed", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "failed": 0, "pending": 0, "requested": 0, "running": 0, "start_time": "2022-09-22T17:34:00Z", "succeeded": 1, "unknown": 0}}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=202) + + # Construct a dict representation of a EnvVarPrototype model + env_var_prototype_model = {} + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + # Construct a dict representation of a VolumeMountPrototype model + volume_mount_prototype_model = {} + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + image_reference = 'icr.io/codeengine/helloworld' + image_secret = 'my-secret' + job_name = 'my-job' + name = 'my-job-run' + run_arguments = ['testString'] + run_as_user = 1001 + run_commands = ['testString'] + run_env_variables = [env_var_prototype_model] + run_mode = 'daemon' + run_service_account = 'default' + run_volume_mounts = [volume_mount_prototype_model] + scale_array_spec = '1-5,7-8,10' + scale_cpu_limit = '1' + scale_ephemeral_storage_limit = '4G' + scale_max_execution_time = 7200 + scale_memory_limit = '4G' + scale_retry_limit = 3 + + # Invoke method + response = _service.create_job_run( + project_id, + image_reference=image_reference, + image_secret=image_secret, + job_name=job_name, + name=name, + run_arguments=run_arguments, + run_as_user=run_as_user, + run_commands=run_commands, + run_env_variables=run_env_variables, + run_mode=run_mode, + run_service_account=run_service_account, + run_volume_mounts=run_volume_mounts, + scale_array_spec=scale_array_spec, + scale_cpu_limit=scale_cpu_limit, + scale_ephemeral_storage_limit=scale_ephemeral_storage_limit, + scale_max_execution_time=scale_max_execution_time, + scale_memory_limit=scale_memory_limit, + scale_retry_limit=scale_retry_limit, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['image_reference'] == 'icr.io/codeengine/helloworld' + assert req_body['image_secret'] == 'my-secret' + assert req_body['job_name'] == 'my-job' + assert req_body['name'] == 'my-job-run' + assert req_body['run_arguments'] == ['testString'] + assert req_body['run_as_user'] == 1001 + assert req_body['run_commands'] == ['testString'] + assert req_body['run_env_variables'] == [env_var_prototype_model] + assert req_body['run_mode'] == 'daemon' + assert req_body['run_service_account'] == 'default' + assert req_body['run_volume_mounts'] == [volume_mount_prototype_model] + assert req_body['scale_array_spec'] == '1-5,7-8,10' + assert req_body['scale_cpu_limit'] == '1' + assert req_body['scale_ephemeral_storage_limit'] == '4G' + assert req_body['scale_max_execution_time'] == 7200 + assert req_body['scale_memory_limit'] == '4G' + assert req_body['scale_retry_limit'] == 3 + + def test_create_job_run_all_params_with_retries(self): + # Enable retries and run test_create_job_run_all_params. + _service.enable_retries() + self.test_create_job_run_all_params() + + # Disable retries and run test_create_job_run_all_params. + _service.disable_retries() + self.test_create_job_run_all_params() + + @responses.activate + def test_create_job_run_value_error(self): + """ + test_create_job_run_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "job_name": "my-job", "name": "my-job-run", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_run_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3, "status": "completed", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "failed": 0, "pending": 0, "requested": 0, "running": 0, "start_time": "2022-09-22T17:34:00Z", "succeeded": 1, "unknown": 0}}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=202) + + # Construct a dict representation of a EnvVarPrototype model + env_var_prototype_model = {} + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + # Construct a dict representation of a VolumeMountPrototype model + volume_mount_prototype_model = {} + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + image_reference = 'icr.io/codeengine/helloworld' + image_secret = 'my-secret' + job_name = 'my-job' + name = 'my-job-run' + run_arguments = ['testString'] + run_as_user = 1001 + run_commands = ['testString'] + run_env_variables = [env_var_prototype_model] + run_mode = 'daemon' + run_service_account = 'default' + run_volume_mounts = [volume_mount_prototype_model] + scale_array_spec = '1-5,7-8,10' + scale_cpu_limit = '1' + scale_ephemeral_storage_limit = '4G' + scale_max_execution_time = 7200 + scale_memory_limit = '4G' + scale_retry_limit = 3 + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_job_run(**req_copy) + + def test_create_job_run_value_error_with_retries(self): + # Enable retries and run test_create_job_run_value_error. + _service.enable_retries() + self.test_create_job_run_value_error() + + # Disable retries and run test_create_job_run_value_error. + _service.disable_retries() + self.test_create_job_run_value_error() + + +class TestGetJobRun: + """ + Test Class for get_job_run + """ + + @responses.activate + def test_get_job_run_all_params(self): + """ + get_job_run() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs/my-job') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "job_name": "my-job", "name": "my-job-run", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_run_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3, "status": "completed", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "failed": 0, "pending": 0, "requested": 0, "running": 0, "start_time": "2022-09-22T17:34:00Z", "succeeded": 1, "unknown": 0}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-job' + + # Invoke method + response = _service.get_job_run(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_job_run_all_params_with_retries(self): + # Enable retries and run test_get_job_run_all_params. + _service.enable_retries() + self.test_get_job_run_all_params() + + # Disable retries and run test_get_job_run_all_params. + _service.disable_retries() + self.test_get_job_run_all_params() + + @responses.activate + def test_get_job_run_value_error(self): + """ + test_get_job_run_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs/my-job') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "image_reference": "icr.io/codeengine/helloworld", "image_secret": "my-secret", "job_name": "my-job", "name": "my-job-run", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "job_run_v2", "run_arguments": ["run_arguments"], "run_as_user": 1001, "run_commands": ["run_commands"], "run_env_variables": [{"key": "MY_VARIABLE", "name": "SOME", "prefix": "PREFIX_", "reference": "my-secret", "type": "literal", "value": "VALUE"}], "run_mode": "daemon", "run_service_account": "default", "run_volume_mounts": [{"mount_path": "/app", "name": "codeengine-mount-b69u90", "reference": "my-secret", "type": "secret"}], "scale_array_spec": "1-5,7-8,10", "scale_cpu_limit": "1", "scale_ephemeral_storage_limit": "4G", "scale_max_execution_time": 7200, "scale_memory_limit": "4G", "scale_retry_limit": 3, "status": "completed", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "failed": 0, "pending": 0, "requested": 0, "running": 0, "start_time": "2022-09-22T17:34:00Z", "succeeded": 1, "unknown": 0}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-job' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_job_run(**req_copy) + + def test_get_job_run_value_error_with_retries(self): + # Enable retries and run test_get_job_run_value_error. + _service.enable_retries() + self.test_get_job_run_value_error() + + # Disable retries and run test_get_job_run_value_error. + _service.disable_retries() + self.test_get_job_run_value_error() + + +class TestDeleteJobRun: + """ + Test Class for delete_job_run + """ + + @responses.activate + def test_delete_job_run_all_params(self): + """ + delete_job_run() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs/my-job') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-job' + + # Invoke method + response = _service.delete_job_run(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + + def test_delete_job_run_all_params_with_retries(self): + # Enable retries and run test_delete_job_run_all_params. + _service.enable_retries() + self.test_delete_job_run_all_params() + + # Disable retries and run test_delete_job_run_all_params. + _service.disable_retries() + self.test_delete_job_run_all_params() + + @responses.activate + def test_delete_job_run_value_error(self): + """ + test_delete_job_run_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/job_runs/my-job') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-job' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_job_run(**req_copy) + + def test_delete_job_run_value_error_with_retries(self): + # Enable retries and run test_delete_job_run_value_error. + _service.enable_retries() + self.test_delete_job_run_value_error() + + # Disable retries and run test_delete_job_run_value_error. + _service.disable_retries() + self.test_delete_job_run_value_error() + + +# endregion +############################################################################## +# End of Service: Jobs +############################################################################## + +############################################################################## +# Start of Service: Builds +############################################################################## +# region + + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = CodeEngineV2.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, CodeEngineV2) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = CodeEngineV2.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestListBuilds: + """ + Test Class for list_builds + """ + + @responses.activate + def test_list_builds_all_params(self): + """ + list_builds() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds') + mock_response = '{"builds": [{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_v2", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "ready", "status_details": {"reason": "registered"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + limit = 100 + start = 'testString' + + # Invoke method + response = _service.list_builds(project_id, limit=limit, start=start, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'limit={}'.format(limit) in query_string + assert 'start={}'.format(start) in query_string + + def test_list_builds_all_params_with_retries(self): + # Enable retries and run test_list_builds_all_params. + _service.enable_retries() + self.test_list_builds_all_params() + + # Disable retries and run test_list_builds_all_params. + _service.disable_retries() + self.test_list_builds_all_params() + + @responses.activate + def test_list_builds_required_params(self): + """ + test_list_builds_required_params() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds') + mock_response = '{"builds": [{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_v2", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "ready", "status_details": {"reason": "registered"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Invoke method + response = _service.list_builds(project_id, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_builds_required_params_with_retries(self): + # Enable retries and run test_list_builds_required_params. + _service.enable_retries() + self.test_list_builds_required_params() + + # Disable retries and run test_list_builds_required_params. + _service.disable_retries() + self.test_list_builds_required_params() + + @responses.activate + def test_list_builds_value_error(self): + """ + test_list_builds_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds') + mock_response = '{"builds": [{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_v2", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "ready", "status_details": {"reason": "registered"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_builds(**req_copy) + + def test_list_builds_value_error_with_retries(self): + # Enable retries and run test_list_builds_value_error. + _service.enable_retries() + self.test_list_builds_value_error() + + # Disable retries and run test_list_builds_value_error. + _service.disable_retries() + self.test_list_builds_value_error() + + @responses.activate + def test_list_builds_with_pager_get_next(self): + """ + test_list_builds_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"builds":[{"created_at":"2022-09-13T11:41:35+02:00","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-build","output_image":"private.de.icr.io/icr_namespace/image-name","output_secret":"ce-auto-icr-private-eu-de","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"build_v2","source_context_dir":"some/subfolder","source_revision":"main","source_secret":"source_secret","source_type":"git","source_url":"https://github.com/IBM/CodeEngine","status":"ready","status_details":{"reason":"registered"},"strategy_size":"medium","strategy_spec_file":"Dockerfile","strategy_type":"dockerfile","timeout":600}]}' + mock_response2 = '{"total_count":2,"limit":1,"builds":[{"created_at":"2022-09-13T11:41:35+02:00","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-build","output_image":"private.de.icr.io/icr_namespace/image-name","output_secret":"ce-auto-icr-private-eu-de","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"build_v2","source_context_dir":"some/subfolder","source_revision":"main","source_secret":"source_secret","source_type":"git","source_url":"https://github.com/IBM/CodeEngine","status":"ready","status_details":{"reason":"registered"},"strategy_size":"medium","strategy_spec_file":"Dockerfile","strategy_type":"dockerfile","timeout":600}]}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + all_results = [] + pager = BuildsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_builds_with_pager_get_all(self): + """ + test_list_builds_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"builds":[{"created_at":"2022-09-13T11:41:35+02:00","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-build","output_image":"private.de.icr.io/icr_namespace/image-name","output_secret":"ce-auto-icr-private-eu-de","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"build_v2","source_context_dir":"some/subfolder","source_revision":"main","source_secret":"source_secret","source_type":"git","source_url":"https://github.com/IBM/CodeEngine","status":"ready","status_details":{"reason":"registered"},"strategy_size":"medium","strategy_spec_file":"Dockerfile","strategy_type":"dockerfile","timeout":600}]}' + mock_response2 = '{"total_count":2,"limit":1,"builds":[{"created_at":"2022-09-13T11:41:35+02:00","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-build","output_image":"private.de.icr.io/icr_namespace/image-name","output_secret":"ce-auto-icr-private-eu-de","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"build_v2","source_context_dir":"some/subfolder","source_revision":"main","source_secret":"source_secret","source_type":"git","source_url":"https://github.com/IBM/CodeEngine","status":"ready","status_details":{"reason":"registered"},"strategy_size":"medium","strategy_spec_file":"Dockerfile","strategy_type":"dockerfile","timeout":600}]}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + pager = BuildsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestCreateBuild: + """ + Test Class for create_build + """ + + @responses.activate + def test_create_build_all_params(self): + """ + create_build() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_v2", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "ready", "status_details": {"reason": "registered"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build' + output_image = 'private.de.icr.io/icr_namespace/image-name' + output_secret = 'ce-auto-icr-private-eu-de' + source_url = 'https://github.com/IBM/CodeEngine' + strategy_type = 'dockerfile' + source_context_dir = 'some/subfolder' + source_revision = 'main' + source_secret = 'testString' + source_type = 'git' + strategy_size = 'medium' + strategy_spec_file = 'Dockerfile' + timeout = 600 + + # Invoke method + response = _service.create_build( + project_id, + name, + output_image, + output_secret, + source_url, + strategy_type, + source_context_dir=source_context_dir, + source_revision=source_revision, + source_secret=source_secret, + source_type=source_type, + strategy_size=strategy_size, + strategy_spec_file=strategy_spec_file, + timeout=timeout, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'my-build' + assert req_body['output_image'] == 'private.de.icr.io/icr_namespace/image-name' + assert req_body['output_secret'] == 'ce-auto-icr-private-eu-de' + assert req_body['source_url'] == 'https://github.com/IBM/CodeEngine' + assert req_body['strategy_type'] == 'dockerfile' + assert req_body['source_context_dir'] == 'some/subfolder' + assert req_body['source_revision'] == 'main' + assert req_body['source_secret'] == 'testString' + assert req_body['source_type'] == 'git' + assert req_body['strategy_size'] == 'medium' + assert req_body['strategy_spec_file'] == 'Dockerfile' + assert req_body['timeout'] == 600 + + def test_create_build_all_params_with_retries(self): + # Enable retries and run test_create_build_all_params. + _service.enable_retries() + self.test_create_build_all_params() + + # Disable retries and run test_create_build_all_params. + _service.disable_retries() + self.test_create_build_all_params() + + @responses.activate + def test_create_build_value_error(self): + """ + test_create_build_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_v2", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "ready", "status_details": {"reason": "registered"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build' + output_image = 'private.de.icr.io/icr_namespace/image-name' + output_secret = 'ce-auto-icr-private-eu-de' + source_url = 'https://github.com/IBM/CodeEngine' + strategy_type = 'dockerfile' + source_context_dir = 'some/subfolder' + source_revision = 'main' + source_secret = 'testString' + source_type = 'git' + strategy_size = 'medium' + strategy_spec_file = 'Dockerfile' + timeout = 600 + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + "output_image": output_image, + "output_secret": output_secret, + "source_url": source_url, + "strategy_type": strategy_type, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_build(**req_copy) + + def test_create_build_value_error_with_retries(self): + # Enable retries and run test_create_build_value_error. + _service.enable_retries() + self.test_create_build_value_error() + + # Disable retries and run test_create_build_value_error. + _service.disable_retries() + self.test_create_build_value_error() + + +class TestGetBuild: + """ + Test Class for get_build + """ + + @responses.activate + def test_get_build_all_params(self): + """ + get_build() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds/my-build') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_v2", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "ready", "status_details": {"reason": "registered"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build' + + # Invoke method + response = _service.get_build(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_build_all_params_with_retries(self): + # Enable retries and run test_get_build_all_params. + _service.enable_retries() + self.test_get_build_all_params() + + # Disable retries and run test_get_build_all_params. + _service.disable_retries() + self.test_get_build_all_params() + + @responses.activate + def test_get_build_value_error(self): + """ + test_get_build_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds/my-build') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_v2", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "ready", "status_details": {"reason": "registered"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_build(**req_copy) + + def test_get_build_value_error_with_retries(self): + # Enable retries and run test_get_build_value_error. + _service.enable_retries() + self.test_get_build_value_error() + + # Disable retries and run test_get_build_value_error. + _service.disable_retries() + self.test_get_build_value_error() + + +class TestDeleteBuild: + """ + Test Class for delete_build + """ + + @responses.activate + def test_delete_build_all_params(self): + """ + delete_build() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds/my-build') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build' + + # Invoke method + response = _service.delete_build(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + + def test_delete_build_all_params_with_retries(self): + # Enable retries and run test_delete_build_all_params. + _service.enable_retries() + self.test_delete_build_all_params() + + # Disable retries and run test_delete_build_all_params. + _service.disable_retries() + self.test_delete_build_all_params() + + @responses.activate + def test_delete_build_value_error(self): + """ + test_delete_build_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds/my-build') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_build(**req_copy) + + def test_delete_build_value_error_with_retries(self): + # Enable retries and run test_delete_build_value_error. + _service.enable_retries() + self.test_delete_build_value_error() + + # Disable retries and run test_delete_build_value_error. + _service.disable_retries() + self.test_delete_build_value_error() + + +class TestUpdateBuild: + """ + Test Class for update_build + """ + + @responses.activate + def test_update_build_all_params(self): + """ + update_build() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds/my-build') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_v2", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "ready", "status_details": {"reason": "registered"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}' + responses.add(responses.PATCH, url, body=mock_response, content_type='application/json', status=200) + + # Construct a dict representation of a BuildPatch model + build_patch_model = {} + build_patch_model['output_image'] = 'private.de.icr.io/icr_namespace/image-name' + build_patch_model['output_secret'] = 'ce-auto-icr-private-eu-de' + build_patch_model['source_context_dir'] = 'some/subfolder' + build_patch_model['source_revision'] = 'main' + build_patch_model['source_secret'] = 'testString' + build_patch_model['source_type'] = 'git' + build_patch_model['source_url'] = 'https://github.com/IBM/CodeEngine' + build_patch_model['strategy_size'] = 'medium' + build_patch_model['strategy_spec_file'] = 'Dockerfile' + build_patch_model['strategy_type'] = 'dockerfile' + build_patch_model['timeout'] = 600 + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build' + if_match = 'testString' + build = build_patch_model + + # Invoke method + response = _service.update_build(project_id, name, if_match, build, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body == build + + def test_update_build_all_params_with_retries(self): + # Enable retries and run test_update_build_all_params. + _service.enable_retries() + self.test_update_build_all_params() + + # Disable retries and run test_update_build_all_params. + _service.disable_retries() + self.test_update_build_all_params() + + @responses.activate + def test_update_build_value_error(self): + """ + test_update_build_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/builds/my-build') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_v2", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "ready", "status_details": {"reason": "registered"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}' + responses.add(responses.PATCH, url, body=mock_response, content_type='application/json', status=200) + + # Construct a dict representation of a BuildPatch model + build_patch_model = {} + build_patch_model['output_image'] = 'private.de.icr.io/icr_namespace/image-name' + build_patch_model['output_secret'] = 'ce-auto-icr-private-eu-de' + build_patch_model['source_context_dir'] = 'some/subfolder' + build_patch_model['source_revision'] = 'main' + build_patch_model['source_secret'] = 'testString' + build_patch_model['source_type'] = 'git' + build_patch_model['source_url'] = 'https://github.com/IBM/CodeEngine' + build_patch_model['strategy_size'] = 'medium' + build_patch_model['strategy_spec_file'] = 'Dockerfile' + build_patch_model['strategy_type'] = 'dockerfile' + build_patch_model['timeout'] = 600 + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build' + if_match = 'testString' + build = build_patch_model + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + "if_match": if_match, + "build": build, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.update_build(**req_copy) + + def test_update_build_value_error_with_retries(self): + # Enable retries and run test_update_build_value_error. + _service.enable_retries() + self.test_update_build_value_error() + + # Disable retries and run test_update_build_value_error. + _service.disable_retries() + self.test_update_build_value_error() + + +class TestListBuildRuns: + """ + Test Class for list_build_runs + """ + + @responses.activate + def test_list_build_runs_all_params(self): + """ + list_build_runs() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs') + mock_response = '{"build_runs": [{"build_name": "build_name", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build-run", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_run_v2", "service_account": "default", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "succeeded", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "output_digest": "sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384", "reason": "succeeded", "start_time": "2022-09-22T17:34:00Z"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + build_name = 'my-build' + limit = 100 + start = 'testString' + + # Invoke method + response = _service.list_build_runs(project_id, build_name=build_name, limit=limit, start=start, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'build_name={}'.format(build_name) in query_string + assert 'limit={}'.format(limit) in query_string + assert 'start={}'.format(start) in query_string + + def test_list_build_runs_all_params_with_retries(self): + # Enable retries and run test_list_build_runs_all_params. + _service.enable_retries() + self.test_list_build_runs_all_params() + + # Disable retries and run test_list_build_runs_all_params. + _service.disable_retries() + self.test_list_build_runs_all_params() + + @responses.activate + def test_list_build_runs_required_params(self): + """ + test_list_build_runs_required_params() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs') + mock_response = '{"build_runs": [{"build_name": "build_name", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build-run", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_run_v2", "service_account": "default", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "succeeded", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "output_digest": "sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384", "reason": "succeeded", "start_time": "2022-09-22T17:34:00Z"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Invoke method + response = _service.list_build_runs(project_id, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_build_runs_required_params_with_retries(self): + # Enable retries and run test_list_build_runs_required_params. + _service.enable_retries() + self.test_list_build_runs_required_params() + + # Disable retries and run test_list_build_runs_required_params. + _service.disable_retries() + self.test_list_build_runs_required_params() + + @responses.activate + def test_list_build_runs_value_error(self): + """ + test_list_build_runs_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs') + mock_response = '{"build_runs": [{"build_name": "build_name", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build-run", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_run_v2", "service_account": "default", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "succeeded", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "output_digest": "sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384", "reason": "succeeded", "start_time": "2022-09-22T17:34:00Z"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_build_runs(**req_copy) + + def test_list_build_runs_value_error_with_retries(self): + # Enable retries and run test_list_build_runs_value_error. + _service.enable_retries() + self.test_list_build_runs_value_error() + + # Disable retries and run test_list_build_runs_value_error. + _service.disable_retries() + self.test_list_build_runs_value_error() + + @responses.activate + def test_list_build_runs_with_pager_get_next(self): + """ + test_list_build_runs_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"build_runs":[{"build_name":"build_name","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-build-run","output_image":"private.de.icr.io/icr_namespace/image-name","output_secret":"ce-auto-icr-private-eu-de","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"build_run_v2","service_account":"default","source_context_dir":"some/subfolder","source_revision":"main","source_secret":"source_secret","source_type":"git","source_url":"https://github.com/IBM/CodeEngine","status":"succeeded","status_details":{"completion_time":"2022-09-22T17:40:00Z","output_digest":"sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384","reason":"succeeded","start_time":"2022-09-22T17:34:00Z"},"strategy_size":"medium","strategy_spec_file":"Dockerfile","strategy_type":"dockerfile","timeout":600}]}' + mock_response2 = '{"total_count":2,"limit":1,"build_runs":[{"build_name":"build_name","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-build-run","output_image":"private.de.icr.io/icr_namespace/image-name","output_secret":"ce-auto-icr-private-eu-de","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"build_run_v2","service_account":"default","source_context_dir":"some/subfolder","source_revision":"main","source_secret":"source_secret","source_type":"git","source_url":"https://github.com/IBM/CodeEngine","status":"succeeded","status_details":{"completion_time":"2022-09-22T17:40:00Z","output_digest":"sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384","reason":"succeeded","start_time":"2022-09-22T17:34:00Z"},"strategy_size":"medium","strategy_spec_file":"Dockerfile","strategy_type":"dockerfile","timeout":600}]}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + all_results = [] + pager = BuildRunsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + build_name='my-build', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_build_runs_with_pager_get_all(self): + """ + test_list_build_runs_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"build_runs":[{"build_name":"build_name","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-build-run","output_image":"private.de.icr.io/icr_namespace/image-name","output_secret":"ce-auto-icr-private-eu-de","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"build_run_v2","service_account":"default","source_context_dir":"some/subfolder","source_revision":"main","source_secret":"source_secret","source_type":"git","source_url":"https://github.com/IBM/CodeEngine","status":"succeeded","status_details":{"completion_time":"2022-09-22T17:40:00Z","output_digest":"sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384","reason":"succeeded","start_time":"2022-09-22T17:34:00Z"},"strategy_size":"medium","strategy_spec_file":"Dockerfile","strategy_type":"dockerfile","timeout":600}]}' + mock_response2 = '{"total_count":2,"limit":1,"build_runs":[{"build_name":"build_name","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-build-run","output_image":"private.de.icr.io/icr_namespace/image-name","output_secret":"ce-auto-icr-private-eu-de","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"build_run_v2","service_account":"default","source_context_dir":"some/subfolder","source_revision":"main","source_secret":"source_secret","source_type":"git","source_url":"https://github.com/IBM/CodeEngine","status":"succeeded","status_details":{"completion_time":"2022-09-22T17:40:00Z","output_digest":"sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384","reason":"succeeded","start_time":"2022-09-22T17:34:00Z"},"strategy_size":"medium","strategy_spec_file":"Dockerfile","strategy_type":"dockerfile","timeout":600}]}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + pager = BuildRunsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + build_name='my-build', + limit=100, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestCreateBuildRun: + """ + Test Class for create_build_run + """ + + @responses.activate + def test_create_build_run_all_params(self): + """ + create_build_run() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs') + mock_response = '{"build_name": "build_name", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build-run", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_run_v2", "service_account": "default", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "succeeded", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "output_digest": "sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384", "reason": "succeeded", "start_time": "2022-09-22T17:34:00Z"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + build_name = 'testString' + name = 'testString' + output_image = 'private.de.icr.io/icr_namespace/image-name' + output_secret = 'ce-auto-icr-private-eu-de' + service_account = 'default' + source_context_dir = 'some/subfolder' + source_revision = 'main' + source_secret = 'testString' + source_type = 'git' + source_url = 'https://github.com/IBM/CodeEngine' + strategy_size = 'medium' + strategy_spec_file = 'Dockerfile' + strategy_type = 'dockerfile' + timeout = 600 + + # Invoke method + response = _service.create_build_run( + project_id, + build_name=build_name, + name=name, + output_image=output_image, + output_secret=output_secret, + service_account=service_account, + source_context_dir=source_context_dir, + source_revision=source_revision, + source_secret=source_secret, + source_type=source_type, + source_url=source_url, + strategy_size=strategy_size, + strategy_spec_file=strategy_spec_file, + strategy_type=strategy_type, + timeout=timeout, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['build_name'] == 'testString' + assert req_body['name'] == 'testString' + assert req_body['output_image'] == 'private.de.icr.io/icr_namespace/image-name' + assert req_body['output_secret'] == 'ce-auto-icr-private-eu-de' + assert req_body['service_account'] == 'default' + assert req_body['source_context_dir'] == 'some/subfolder' + assert req_body['source_revision'] == 'main' + assert req_body['source_secret'] == 'testString' + assert req_body['source_type'] == 'git' + assert req_body['source_url'] == 'https://github.com/IBM/CodeEngine' + assert req_body['strategy_size'] == 'medium' + assert req_body['strategy_spec_file'] == 'Dockerfile' + assert req_body['strategy_type'] == 'dockerfile' + assert req_body['timeout'] == 600 + + def test_create_build_run_all_params_with_retries(self): + # Enable retries and run test_create_build_run_all_params. + _service.enable_retries() + self.test_create_build_run_all_params() + + # Disable retries and run test_create_build_run_all_params. + _service.disable_retries() + self.test_create_build_run_all_params() + + @responses.activate + def test_create_build_run_value_error(self): + """ + test_create_build_run_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs') + mock_response = '{"build_name": "build_name", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build-run", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_run_v2", "service_account": "default", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "succeeded", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "output_digest": "sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384", "reason": "succeeded", "start_time": "2022-09-22T17:34:00Z"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + build_name = 'testString' + name = 'testString' + output_image = 'private.de.icr.io/icr_namespace/image-name' + output_secret = 'ce-auto-icr-private-eu-de' + service_account = 'default' + source_context_dir = 'some/subfolder' + source_revision = 'main' + source_secret = 'testString' + source_type = 'git' + source_url = 'https://github.com/IBM/CodeEngine' + strategy_size = 'medium' + strategy_spec_file = 'Dockerfile' + strategy_type = 'dockerfile' + timeout = 600 + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_build_run(**req_copy) + + def test_create_build_run_value_error_with_retries(self): + # Enable retries and run test_create_build_run_value_error. + _service.enable_retries() + self.test_create_build_run_value_error() + + # Disable retries and run test_create_build_run_value_error. + _service.disable_retries() + self.test_create_build_run_value_error() + + +class TestGetBuildRun: + """ + Test Class for get_build_run + """ + + @responses.activate + def test_get_build_run_all_params(self): + """ + get_build_run() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs/my-build-run') + mock_response = '{"build_name": "build_name", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build-run", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_run_v2", "service_account": "default", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "succeeded", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "output_digest": "sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384", "reason": "succeeded", "start_time": "2022-09-22T17:34:00Z"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build-run' + + # Invoke method + response = _service.get_build_run(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_build_run_all_params_with_retries(self): + # Enable retries and run test_get_build_run_all_params. + _service.enable_retries() + self.test_get_build_run_all_params() + + # Disable retries and run test_get_build_run_all_params. + _service.disable_retries() + self.test_get_build_run_all_params() + + @responses.activate + def test_get_build_run_value_error(self): + """ + test_get_build_run_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs/my-build-run') + mock_response = '{"build_name": "build_name", "created_at": "2022-09-13T11:41:35+02:00", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-build-run", "output_image": "private.de.icr.io/icr_namespace/image-name", "output_secret": "ce-auto-icr-private-eu-de", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "build_run_v2", "service_account": "default", "source_context_dir": "some/subfolder", "source_revision": "main", "source_secret": "source_secret", "source_type": "git", "source_url": "https://github.com/IBM/CodeEngine", "status": "succeeded", "status_details": {"completion_time": "2022-09-22T17:40:00Z", "output_digest": "sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384", "reason": "succeeded", "start_time": "2022-09-22T17:34:00Z"}, "strategy_size": "medium", "strategy_spec_file": "Dockerfile", "strategy_type": "dockerfile", "timeout": 600}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build-run' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_build_run(**req_copy) + + def test_get_build_run_value_error_with_retries(self): + # Enable retries and run test_get_build_run_value_error. + _service.enable_retries() + self.test_get_build_run_value_error() + + # Disable retries and run test_get_build_run_value_error. + _service.disable_retries() + self.test_get_build_run_value_error() + + +class TestDeleteBuildRun: + """ + Test Class for delete_build_run + """ + + @responses.activate + def test_delete_build_run_all_params(self): + """ + delete_build_run() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs/my-build-run') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build-run' + + # Invoke method + response = _service.delete_build_run(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + + def test_delete_build_run_all_params_with_retries(self): + # Enable retries and run test_delete_build_run_all_params. + _service.enable_retries() + self.test_delete_build_run_all_params() + + # Disable retries and run test_delete_build_run_all_params. + _service.disable_retries() + self.test_delete_build_run_all_params() + + @responses.activate + def test_delete_build_run_value_error(self): + """ + test_delete_build_run_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/build_runs/my-build-run') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-build-run' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_build_run(**req_copy) + + def test_delete_build_run_value_error_with_retries(self): + # Enable retries and run test_delete_build_run_value_error. + _service.enable_retries() + self.test_delete_build_run_value_error() + + # Disable retries and run test_delete_build_run_value_error. + _service.disable_retries() + self.test_delete_build_run_value_error() + + +# endregion +############################################################################## +# End of Service: Builds +############################################################################## + +############################################################################## +# Start of Service: SecretsAndConfigMaps +############################################################################## +# region + + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = CodeEngineV2.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, CodeEngineV2) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = CodeEngineV2.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestListConfigMaps: + """ + Test Class for list_config_maps + """ + + @responses.activate + def test_list_config_maps_all_params(self): + """ + list_config_maps() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps') + mock_response = '{"config_maps": [{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-config-map", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "config_map_v2"}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + limit = 100 + start = 'testString' + + # Invoke method + response = _service.list_config_maps(project_id, limit=limit, start=start, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'limit={}'.format(limit) in query_string + assert 'start={}'.format(start) in query_string + + def test_list_config_maps_all_params_with_retries(self): + # Enable retries and run test_list_config_maps_all_params. + _service.enable_retries() + self.test_list_config_maps_all_params() + + # Disable retries and run test_list_config_maps_all_params. + _service.disable_retries() + self.test_list_config_maps_all_params() + + @responses.activate + def test_list_config_maps_required_params(self): + """ + test_list_config_maps_required_params() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps') + mock_response = '{"config_maps": [{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-config-map", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "config_map_v2"}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Invoke method + response = _service.list_config_maps(project_id, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_config_maps_required_params_with_retries(self): + # Enable retries and run test_list_config_maps_required_params. + _service.enable_retries() + self.test_list_config_maps_required_params() + + # Disable retries and run test_list_config_maps_required_params. + _service.disable_retries() + self.test_list_config_maps_required_params() + + @responses.activate + def test_list_config_maps_value_error(self): + """ + test_list_config_maps_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps') + mock_response = '{"config_maps": [{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-config-map", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "config_map_v2"}], "first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_config_maps(**req_copy) + + def test_list_config_maps_value_error_with_retries(self): + # Enable retries and run test_list_config_maps_value_error. + _service.enable_retries() + self.test_list_config_maps_value_error() + + # Disable retries and run test_list_config_maps_value_error. + _service.disable_retries() + self.test_list_config_maps_value_error() + + @responses.activate + def test_list_config_maps_with_pager_get_next(self): + """ + test_list_config_maps_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps') + mock_response1 = '{"next":{"start":"1"},"config_maps":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-config-map","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"config_map_v2"}],"total_count":2,"limit":1}' + mock_response2 = '{"config_maps":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-config-map","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"config_map_v2"}],"total_count":2,"limit":1}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + all_results = [] + pager = ConfigMapsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_config_maps_with_pager_get_all(self): + """ + test_list_config_maps_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps') + mock_response1 = '{"next":{"start":"1"},"config_maps":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-config-map","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"config_map_v2"}],"total_count":2,"limit":1}' + mock_response2 = '{"config_maps":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-config-map","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"config_map_v2"}],"total_count":2,"limit":1}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + pager = ConfigMapsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestCreateConfigMap: + """ + Test Class for create_config_map + """ + + @responses.activate + def test_create_config_map_all_params(self): + """ + create_config_map() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-config-map", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "config_map_v2"}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-configmap' + data = {'key1': 'testString'} + + # Invoke method + response = _service.create_config_map(project_id, name, data=data, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'my-configmap' + assert req_body['data'] == {'key1': 'testString'} + + def test_create_config_map_all_params_with_retries(self): + # Enable retries and run test_create_config_map_all_params. + _service.enable_retries() + self.test_create_config_map_all_params() + + # Disable retries and run test_create_config_map_all_params. + _service.disable_retries() + self.test_create_config_map_all_params() + + @responses.activate + def test_create_config_map_value_error(self): + """ + test_create_config_map_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-config-map", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "config_map_v2"}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-configmap' + data = {'key1': 'testString'} + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_config_map(**req_copy) + + def test_create_config_map_value_error_with_retries(self): + # Enable retries and run test_create_config_map_value_error. + _service.enable_retries() + self.test_create_config_map_value_error() + + # Disable retries and run test_create_config_map_value_error. + _service.disable_retries() + self.test_create_config_map_value_error() + + +class TestGetConfigMap: + """ + Test Class for get_config_map + """ + + @responses.activate + def test_get_config_map_all_params(self): + """ + get_config_map() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps/my-config-map') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-config-map", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "config_map_v2"}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-config-map' + + # Invoke method + response = _service.get_config_map(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_config_map_all_params_with_retries(self): + # Enable retries and run test_get_config_map_all_params. + _service.enable_retries() + self.test_get_config_map_all_params() + + # Disable retries and run test_get_config_map_all_params. + _service.disable_retries() + self.test_get_config_map_all_params() + + @responses.activate + def test_get_config_map_value_error(self): + """ + test_get_config_map_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps/my-config-map') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-config-map", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "config_map_v2"}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-config-map' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_config_map(**req_copy) + + def test_get_config_map_value_error_with_retries(self): + # Enable retries and run test_get_config_map_value_error. + _service.enable_retries() + self.test_get_config_map_value_error() + + # Disable retries and run test_get_config_map_value_error. + _service.disable_retries() + self.test_get_config_map_value_error() + + +class TestReplaceConfigMap: + """ + Test Class for replace_config_map + """ + + @responses.activate + def test_replace_config_map_all_params(self): + """ + replace_config_map() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps/my-config-map') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-config-map", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "config_map_v2"}' + responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-config-map' + if_match = 'testString' + data = {'key1': 'testString'} + + # Invoke method + response = _service.replace_config_map(project_id, name, if_match, data=data, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['data'] == {'key1': 'testString'} + + def test_replace_config_map_all_params_with_retries(self): + # Enable retries and run test_replace_config_map_all_params. + _service.enable_retries() + self.test_replace_config_map_all_params() + + # Disable retries and run test_replace_config_map_all_params. + _service.disable_retries() + self.test_replace_config_map_all_params() + + @responses.activate + def test_replace_config_map_value_error(self): + """ + test_replace_config_map_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps/my-config-map') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-config-map", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "config_map_v2"}' + responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-config-map' + if_match = 'testString' + data = {'key1': 'testString'} + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + "if_match": if_match, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.replace_config_map(**req_copy) + + def test_replace_config_map_value_error_with_retries(self): + # Enable retries and run test_replace_config_map_value_error. + _service.enable_retries() + self.test_replace_config_map_value_error() + + # Disable retries and run test_replace_config_map_value_error. + _service.disable_retries() + self.test_replace_config_map_value_error() + + +class TestDeleteConfigMap: + """ + Test Class for delete_config_map + """ + + @responses.activate + def test_delete_config_map_all_params(self): + """ + delete_config_map() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps/my-config-map') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-config-map' + + # Invoke method + response = _service.delete_config_map(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + + def test_delete_config_map_all_params_with_retries(self): + # Enable retries and run test_delete_config_map_all_params. + _service.enable_retries() + self.test_delete_config_map_all_params() + + # Disable retries and run test_delete_config_map_all_params. + _service.disable_retries() + self.test_delete_config_map_all_params() + + @responses.activate + def test_delete_config_map_value_error(self): + """ + test_delete_config_map_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/config_maps/my-config-map') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-config-map' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_config_map(**req_copy) + + def test_delete_config_map_value_error_with_retries(self): + # Enable retries and run test_delete_config_map_value_error. + _service.enable_retries() + self.test_delete_config_map_value_error() + + # Disable retries and run test_delete_config_map_value_error. + _service.disable_retries() + self.test_delete_config_map_value_error() + + +class TestListSecrets: + """ + Test Class for list_secrets + """ + + @responses.activate + def test_list_secrets_all_params(self): + """ + list_secrets() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets') + mock_response = '{"first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}, "secrets": [{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "format": "generic", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-secret", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "resource_type"}]}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + limit = 100 + start = 'testString' + + # Invoke method + response = _service.list_secrets(project_id, limit=limit, start=start, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'limit={}'.format(limit) in query_string + assert 'start={}'.format(start) in query_string + + def test_list_secrets_all_params_with_retries(self): + # Enable retries and run test_list_secrets_all_params. + _service.enable_retries() + self.test_list_secrets_all_params() + + # Disable retries and run test_list_secrets_all_params. + _service.disable_retries() + self.test_list_secrets_all_params() + + @responses.activate + def test_list_secrets_required_params(self): + """ + test_list_secrets_required_params() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets') + mock_response = '{"first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}, "secrets": [{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "format": "generic", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-secret", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "resource_type"}]}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Invoke method + response = _service.list_secrets(project_id, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_secrets_required_params_with_retries(self): + # Enable retries and run test_list_secrets_required_params. + _service.enable_retries() + self.test_list_secrets_required_params() + + # Disable retries and run test_list_secrets_required_params. + _service.disable_retries() + self.test_list_secrets_required_params() + + @responses.activate + def test_list_secrets_value_error(self): + """ + test_list_secrets_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets') + mock_response = '{"first": {"href": "href"}, "limit": 100, "next": {"href": "href", "start": "start"}, "secrets": [{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "format": "generic", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-secret", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "resource_type"}]}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_secrets(**req_copy) + + def test_list_secrets_value_error_with_retries(self): + # Enable retries and run test_list_secrets_value_error. + _service.enable_retries() + self.test_list_secrets_value_error() + + # Disable retries and run test_list_secrets_value_error. + _service.disable_retries() + self.test_list_secrets_value_error() + + @responses.activate + def test_list_secrets_with_pager_get_next(self): + """ + test_list_secrets_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"secrets":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","format":"generic","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-secret","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"resource_type"}]}' + mock_response2 = '{"total_count":2,"limit":1,"secrets":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","format":"generic","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-secret","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"resource_type"}]}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + all_results = [] + pager = SecretsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_secrets_with_pager_get_all(self): + """ + test_list_secrets_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"secrets":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","format":"generic","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-secret","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"resource_type"}]}' + mock_response2 = '{"total_count":2,"limit":1,"secrets":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","format":"generic","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-secret","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"resource_type"}]}' + responses.add(responses.GET, url, body=mock_response1, content_type='application/json', status=200) + responses.add(responses.GET, url, body=mock_response2, content_type='application/json', status=200) + + # Exercise the pager class for this operation + pager = SecretsPager( + client=_service, + project_id='15314cc3-85b4-4338-903f-c28cdee6d005', + limit=100, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestCreateSecret: + """ + Test Class for create_secret + """ + + @responses.activate + def test_create_secret_all_params(self): + """ + create_secret() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "format": "generic", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-secret", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "resource_type"}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + format = 'generic' + name = 'my-secret' + data = {'key1': 'testString'} + + # Invoke method + response = _service.create_secret(project_id, format, name, data=data, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['format'] == 'generic' + assert req_body['name'] == 'my-secret' + assert req_body['data'] == {'key1': 'testString'} + + def test_create_secret_all_params_with_retries(self): + # Enable retries and run test_create_secret_all_params. + _service.enable_retries() + self.test_create_secret_all_params() + + # Disable retries and run test_create_secret_all_params. + _service.disable_retries() + self.test_create_secret_all_params() + + @responses.activate + def test_create_secret_value_error(self): + """ + test_create_secret_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "format": "generic", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-secret", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "resource_type"}' + responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + format = 'generic' + name = 'my-secret' + data = {'key1': 'testString'} + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "format": format, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_secret(**req_copy) + + def test_create_secret_value_error_with_retries(self): + # Enable retries and run test_create_secret_value_error. + _service.enable_retries() + self.test_create_secret_value_error() + + # Disable retries and run test_create_secret_value_error. + _service.disable_retries() + self.test_create_secret_value_error() + + +class TestGetSecret: + """ + Test Class for get_secret + """ + + @responses.activate + def test_get_secret_all_params(self): + """ + get_secret() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets/my-secret') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "format": "generic", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-secret", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "resource_type"}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-secret' + + # Invoke method + response = _service.get_secret(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_secret_all_params_with_retries(self): + # Enable retries and run test_get_secret_all_params. + _service.enable_retries() + self.test_get_secret_all_params() + + # Disable retries and run test_get_secret_all_params. + _service.disable_retries() + self.test_get_secret_all_params() + + @responses.activate + def test_get_secret_value_error(self): + """ + test_get_secret_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets/my-secret') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "format": "generic", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-secret", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "resource_type"}' + responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-secret' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_secret(**req_copy) + + def test_get_secret_value_error_with_retries(self): + # Enable retries and run test_get_secret_value_error. + _service.enable_retries() + self.test_get_secret_value_error() + + # Disable retries and run test_get_secret_value_error. + _service.disable_retries() + self.test_get_secret_value_error() + + +class TestReplaceSecret: + """ + Test Class for replace_secret + """ + + @responses.activate + def test_replace_secret_all_params(self): + """ + replace_secret() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets/my-secret') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "format": "generic", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-secret", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "resource_type"}' + responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-secret' + if_match = 'testString' + data = {'key1': 'testString'} + format = 'generic' + + # Invoke method + response = _service.replace_secret(project_id, name, if_match, data=data, format=format, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['data'] == {'key1': 'testString'} + assert req_body['format'] == 'generic' + + def test_replace_secret_all_params_with_retries(self): + # Enable retries and run test_replace_secret_all_params. + _service.enable_retries() + self.test_replace_secret_all_params() + + # Disable retries and run test_replace_secret_all_params. + _service.disable_retries() + self.test_replace_secret_all_params() + + @responses.activate + def test_replace_secret_value_error(self): + """ + test_replace_secret_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets/my-secret') + mock_response = '{"created_at": "2022-09-13T11:41:35+02:00", "data": {"mapKey": "inner"}, "entity_tag": "2385407409", "format": "generic", "href": "https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret", "id": "e33b1cv7-7390-4437-a5c2-130d5ccdddc3", "name": "my-secret", "project_id": "4e49b3e0-27a8-48d2-a784-c7ee48bb863b", "resource_type": "resource_type"}' + responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-secret' + if_match = 'testString' + data = {'key1': 'testString'} + format = 'generic' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + "if_match": if_match, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.replace_secret(**req_copy) + + def test_replace_secret_value_error_with_retries(self): + # Enable retries and run test_replace_secret_value_error. + _service.enable_retries() + self.test_replace_secret_value_error() + + # Disable retries and run test_replace_secret_value_error. + _service.disable_retries() + self.test_replace_secret_value_error() + + +class TestDeleteSecret: + """ + Test Class for delete_secret + """ + + @responses.activate + def test_delete_secret_all_params(self): + """ + delete_secret() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets/my-secret') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-secret' + + # Invoke method + response = _service.delete_secret(project_id, name, headers={}) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + + def test_delete_secret_all_params_with_retries(self): + # Enable retries and run test_delete_secret_all_params. + _service.enable_retries() + self.test_delete_secret_all_params() + + # Disable retries and run test_delete_secret_all_params. + _service.disable_retries() + self.test_delete_secret_all_params() + + @responses.activate + def test_delete_secret_value_error(self): + """ + test_delete_secret_value_error() + """ + # Set up mock + url = preprocess_url('/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets/my-secret') + responses.add(responses.DELETE, url, status=202) + + # Set up parameter values + project_id = '15314cc3-85b4-4338-903f-c28cdee6d005' + name = 'my-secret' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "project_id": project_id, + "name": name, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_secret(**req_copy) + + def test_delete_secret_value_error_with_retries(self): + # Enable retries and run test_delete_secret_value_error. + _service.enable_retries() + self.test_delete_secret_value_error() + + # Disable retries and run test_delete_secret_value_error. + _service.disable_retries() + self.test_delete_secret_value_error() + + +# endregion +############################################################################## +# End of Service: SecretsAndConfigMaps +############################################################################## + + +############################################################################## +# Start of Model Tests +############################################################################## +# region +class TestModel_App: + """ + Test Class for App + """ + + def test_app_serialization(self): + """ + Test serialization/deserialization for App + """ + + # Construct dict forms of any model objects needed in order to build this model. + + env_var_model = {} # EnvVar + env_var_model['key'] = 'MY_VARIABLE' + env_var_model['name'] = 'CE_SUBDOMAIN' + env_var_model['prefix'] = 'PREFIX_' + env_var_model['reference'] = 'my-secret' + env_var_model['type'] = 'literal' + env_var_model['value'] = 'uyh5shf7s0f' + + volume_mount_model = {} # VolumeMount + volume_mount_model['mount_path'] = '/app' + volume_mount_model['name'] = 'codeengine-mount-b69u90' + volume_mount_model['reference'] = 'my-secret' + volume_mount_model['type'] = 'secret' + + app_status_model = {} # AppStatus + app_status_model['latest_created_revision'] = 'my-app-00001' + app_status_model['latest_ready_revision'] = 'my-app-00001' + app_status_model['reason'] = 'ready' + + # Construct a json representation of a App model + app_model_json = {} + app_model_json['created_at'] = '2022-09-13T11:41:35+02:00' + app_model_json['endpoint'] = 'https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud' + app_model_json['endpoint_internal'] = 'http://my-app.vg67hzldruk.svc.cluster.local' + app_model_json['entity_tag'] = '2385407409' + app_model_json[ + 'href' + ] = 'https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app' + app_model_json['id'] = 'e33b1cv7-7390-4437-a5c2-130d5ccdddc3' + app_model_json['image_port'] = 8080 + app_model_json['image_reference'] = 'icr.io/codeengine/helloworld' + app_model_json['image_secret'] = 'my-secret' + app_model_json['managed_domain_mappings'] = 'local_public' + app_model_json['name'] = 'my-app' + app_model_json['project_id'] = '4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + app_model_json['resource_type'] = 'app_v2' + app_model_json['run_arguments'] = ['testString'] + app_model_json['run_as_user'] = 1001 + app_model_json['run_commands'] = ['testString'] + app_model_json['run_env_variables'] = [env_var_model] + app_model_json['run_service_account'] = 'default' + app_model_json['run_volume_mounts'] = [volume_mount_model] + app_model_json['scale_concurrency'] = 100 + app_model_json['scale_concurrency_target'] = 80 + app_model_json['scale_cpu_limit'] = '1' + app_model_json['scale_ephemeral_storage_limit'] = '4G' + app_model_json['scale_initial_instances'] = 1 + app_model_json['scale_max_instances'] = 10 + app_model_json['scale_memory_limit'] = '4G' + app_model_json['scale_min_instances'] = 1 + app_model_json['scale_request_timeout'] = 300 + app_model_json['status'] = 'ready' + app_model_json['status_details'] = app_status_model + + # Construct a model instance of App by calling from_dict on the json representation + app_model = App.from_dict(app_model_json) + assert app_model != False + + # Construct a model instance of App by calling from_dict on the json representation + app_model_dict = App.from_dict(app_model_json).__dict__ + app_model2 = App(**app_model_dict) + + # Verify the model instances are equivalent + assert app_model == app_model2 + + # Convert model instance back to dict and verify no loss of data + app_model_json2 = app_model.to_dict() + assert app_model_json2 == app_model_json + + +class TestModel_AppList: + """ + Test Class for AppList + """ + + def test_app_list_serialization(self): + """ + Test serialization/deserialization for AppList + """ + + # Construct dict forms of any model objects needed in order to build this model. + + env_var_model = {} # EnvVar + env_var_model['key'] = 'MY_VARIABLE' + env_var_model['name'] = 'CE_SUBDOMAIN' + env_var_model['prefix'] = 'PREFIX_' + env_var_model['reference'] = 'my-secret' + env_var_model['type'] = 'literal' + env_var_model['value'] = 'uyh5shf7s0f' + + volume_mount_model = {} # VolumeMount + volume_mount_model['mount_path'] = '/app' + volume_mount_model['name'] = 'codeengine-mount-b69u90' + volume_mount_model['reference'] = 'my-secret' + volume_mount_model['type'] = 'secret' + + app_status_model = {} # AppStatus + app_status_model['latest_created_revision'] = 'my-app-00001' + app_status_model['latest_ready_revision'] = 'my-app-00001' + app_status_model['reason'] = 'ready' + + app_model = {} # App + app_model['created_at'] = '2022-11-15T22:07:55+01:00' + app_model['endpoint'] = 'https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud' + app_model['endpoint_internal'] = 'http://my-app.vg67hzldruk.svc.cluster.local' + app_model['entity_tag'] = '1' + app_model[ + 'href' + ] = 'https://api.us-east.codeengine.cloud.ibm.com/v2/projects/230828b4-4f15-40a9-b183-1268c6ab88d5/apps/my-app' + app_model['id'] = '230828b4-4f15-40a9-b183-1268c6ab88d5' + app_model['image_port'] = 8080 + app_model['image_reference'] = 'icr.io/codeengine/helloworld' + app_model['image_secret'] = 'my-secret' + app_model['managed_domain_mappings'] = 'local_public' + app_model['name'] = 'my-app' + app_model['project_id'] = '15314cc3-85b4-4338-903f-c28cdee6d005' + app_model['resource_type'] = 'app_v2' + app_model['run_arguments'] = [] + app_model['run_as_user'] = 1001 + app_model['run_commands'] = [] + app_model['run_env_variables'] = [env_var_model] + app_model['run_service_account'] = 'default' + app_model['run_volume_mounts'] = [volume_mount_model] + app_model['scale_concurrency'] = 100 + app_model['scale_concurrency_target'] = 80 + app_model['scale_cpu_limit'] = '1' + app_model['scale_ephemeral_storage_limit'] = '400M' + app_model['scale_initial_instances'] = 1 + app_model['scale_max_instances'] = 10 + app_model['scale_memory_limit'] = '4G' + app_model['scale_min_instances'] = 0 + app_model['scale_request_timeout'] = 300 + app_model['status'] = 'ready' + app_model['status_details'] = app_status_model + + list_first_metadata_model = {} # ListFirstMetadata + list_first_metadata_model['href'] = 'testString' + + list_next_metadata_model = {} # ListNextMetadata + list_next_metadata_model['href'] = 'testString' + list_next_metadata_model['start'] = 'testString' + + # Construct a json representation of a AppList model + app_list_model_json = {} + app_list_model_json['apps'] = [app_model] + app_list_model_json['first'] = list_first_metadata_model + app_list_model_json['limit'] = 100 + app_list_model_json['next'] = list_next_metadata_model + + # Construct a model instance of AppList by calling from_dict on the json representation + app_list_model = AppList.from_dict(app_list_model_json) + assert app_list_model != False + + # Construct a model instance of AppList by calling from_dict on the json representation + app_list_model_dict = AppList.from_dict(app_list_model_json).__dict__ + app_list_model2 = AppList(**app_list_model_dict) + + # Verify the model instances are equivalent + assert app_list_model == app_list_model2 + + # Convert model instance back to dict and verify no loss of data + app_list_model_json2 = app_list_model.to_dict() + assert app_list_model_json2 == app_list_model_json + + +class TestModel_AppPatch: + """ + Test Class for AppPatch + """ + + def test_app_patch_serialization(self): + """ + Test serialization/deserialization for AppPatch + """ + + # Construct dict forms of any model objects needed in order to build this model. + + env_var_prototype_model = {} # EnvVarPrototype + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'SOME' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'VALUE' + + volume_mount_prototype_model = {} # VolumeMountPrototype + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Construct a json representation of a AppPatch model + app_patch_model_json = {} + app_patch_model_json['image_port'] = 8080 + app_patch_model_json['image_reference'] = 'icr.io/codeengine/helloworld' + app_patch_model_json['image_secret'] = 'my-secret' + app_patch_model_json['managed_domain_mappings'] = 'local_public' + app_patch_model_json['run_arguments'] = ['testString'] + app_patch_model_json['run_as_user'] = 1001 + app_patch_model_json['run_commands'] = ['testString'] + app_patch_model_json['run_env_variables'] = [env_var_prototype_model] + app_patch_model_json['run_service_account'] = 'default' + app_patch_model_json['run_volume_mounts'] = [volume_mount_prototype_model] + app_patch_model_json['scale_concurrency'] = 100 + app_patch_model_json['scale_concurrency_target'] = 80 + app_patch_model_json['scale_cpu_limit'] = '1' + app_patch_model_json['scale_ephemeral_storage_limit'] = '4G' + app_patch_model_json['scale_initial_instances'] = 1 + app_patch_model_json['scale_max_instances'] = 10 + app_patch_model_json['scale_memory_limit'] = '4G' + app_patch_model_json['scale_min_instances'] = 1 + app_patch_model_json['scale_request_timeout'] = 300 + + # Construct a model instance of AppPatch by calling from_dict on the json representation + app_patch_model = AppPatch.from_dict(app_patch_model_json) + assert app_patch_model != False + + # Construct a model instance of AppPatch by calling from_dict on the json representation + app_patch_model_dict = AppPatch.from_dict(app_patch_model_json).__dict__ + app_patch_model2 = AppPatch(**app_patch_model_dict) + + # Verify the model instances are equivalent + assert app_patch_model == app_patch_model2 + + # Convert model instance back to dict and verify no loss of data + app_patch_model_json2 = app_patch_model.to_dict() + assert app_patch_model_json2 == app_patch_model_json + + +class TestModel_AppRevision: + """ + Test Class for AppRevision + """ + + def test_app_revision_serialization(self): + """ + Test serialization/deserialization for AppRevision + """ + + # Construct dict forms of any model objects needed in order to build this model. + + env_var_model = {} # EnvVar + env_var_model['key'] = 'MY_VARIABLE' + env_var_model['name'] = 'CE_SUBDOMAIN' + env_var_model['prefix'] = 'PREFIX_' + env_var_model['reference'] = 'my-secret' + env_var_model['type'] = 'literal' + env_var_model['value'] = 'uyh5shf7s0f' + + volume_mount_model = {} # VolumeMount + volume_mount_model['mount_path'] = '/app' + volume_mount_model['name'] = 'codeengine-mount-b69u90' + volume_mount_model['reference'] = 'my-secret' + volume_mount_model['type'] = 'secret' + + app_revision_status_model = {} # AppRevisionStatus + app_revision_status_model['actual_instances'] = 1 + app_revision_status_model['reason'] = 'ready' + + # Construct a json representation of a AppRevision model + app_revision_model_json = {} + app_revision_model_json['app_name'] = 'my-app' + app_revision_model_json['created_at'] = '2022-09-13T11:41:35+02:00' + app_revision_model_json[ + 'href' + ] = 'https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001' + app_revision_model_json['id'] = 'e33b1cv7-7390-4437-a5c2-130d5ccdddc3' + app_revision_model_json['image_port'] = 8080 + app_revision_model_json['image_reference'] = 'icr.io/codeengine/helloworld' + app_revision_model_json['image_secret'] = 'my-secret' + app_revision_model_json['name'] = 'my-app-00001' + app_revision_model_json['project_id'] = '4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + app_revision_model_json['resource_type'] = 'app_revision_v2' + app_revision_model_json['run_arguments'] = ['testString'] + app_revision_model_json['run_as_user'] = 1001 + app_revision_model_json['run_commands'] = ['testString'] + app_revision_model_json['run_env_variables'] = [env_var_model] + app_revision_model_json['run_service_account'] = 'default' + app_revision_model_json['run_volume_mounts'] = [volume_mount_model] + app_revision_model_json['scale_concurrency'] = 100 + app_revision_model_json['scale_concurrency_target'] = 80 + app_revision_model_json['scale_cpu_limit'] = '1' + app_revision_model_json['scale_ephemeral_storage_limit'] = '4G' + app_revision_model_json['scale_initial_instances'] = 1 + app_revision_model_json['scale_max_instances'] = 10 + app_revision_model_json['scale_memory_limit'] = '4G' + app_revision_model_json['scale_min_instances'] = 1 + app_revision_model_json['scale_request_timeout'] = 300 + app_revision_model_json['status'] = 'ready' + app_revision_model_json['status_details'] = app_revision_status_model + + # Construct a model instance of AppRevision by calling from_dict on the json representation + app_revision_model = AppRevision.from_dict(app_revision_model_json) + assert app_revision_model != False + + # Construct a model instance of AppRevision by calling from_dict on the json representation + app_revision_model_dict = AppRevision.from_dict(app_revision_model_json).__dict__ + app_revision_model2 = AppRevision(**app_revision_model_dict) + + # Verify the model instances are equivalent + assert app_revision_model == app_revision_model2 + + # Convert model instance back to dict and verify no loss of data + app_revision_model_json2 = app_revision_model.to_dict() + assert app_revision_model_json2 == app_revision_model_json + + +class TestModel_AppRevisionList: + """ + Test Class for AppRevisionList + """ + + def test_app_revision_list_serialization(self): + """ + Test serialization/deserialization for AppRevisionList + """ + + # Construct dict forms of any model objects needed in order to build this model. + + list_first_metadata_model = {} # ListFirstMetadata + list_first_metadata_model['href'] = 'testString' + + list_next_metadata_model = {} # ListNextMetadata + list_next_metadata_model['href'] = 'testString' + list_next_metadata_model['start'] = 'testString' + + env_var_model = {} # EnvVar + env_var_model['key'] = 'MY_VARIABLE' + env_var_model['name'] = 'CE_SUBDOMAIN' + env_var_model['prefix'] = 'PREFIX_' + env_var_model['reference'] = 'my-secret' + env_var_model['type'] = 'literal' + env_var_model['value'] = 'uyh5shf7s0f' + + volume_mount_model = {} # VolumeMount + volume_mount_model['mount_path'] = '/app' + volume_mount_model['name'] = 'codeengine-mount-b69u90' + volume_mount_model['reference'] = 'my-secret' + volume_mount_model['type'] = 'secret' + + app_revision_status_model = {} # AppRevisionStatus + app_revision_status_model['actual_instances'] = 1 + app_revision_status_model['reason'] = 'ready' + + app_revision_model = {} # AppRevision + app_revision_model['app_name'] = 'my-app' + app_revision_model['created_at'] = '2022-11-15T22:07:55+01:00' + app_revision_model[ + 'href' + ] = 'https://api.us-east.codeengine.cloud.ibm.com/v2/projects/230828b4-4f15-40a9-b183-1268c6ab88d5/apps/my-app/revisions/my-app-00001' + app_revision_model['id'] = 'b63b3e28-2c1b-4784-9cd6-18c201fc6806' + app_revision_model['image_port'] = 8080 + app_revision_model['image_reference'] = 'icr.io/codeengine/helloworld' + app_revision_model['image_secret'] = 'my-secret' + app_revision_model['name'] = 'my-app-00001' + app_revision_model['project_id'] = '230828b4-4f15-40a9-b183-1268c6ab88d5' + app_revision_model['resource_type'] = 'app_revision_v2' + app_revision_model['run_arguments'] = [] + app_revision_model['run_as_user'] = 1001 + app_revision_model['run_commands'] = [] + app_revision_model['run_env_variables'] = [env_var_model] + app_revision_model['run_service_account'] = 'default' + app_revision_model['run_volume_mounts'] = [volume_mount_model] + app_revision_model['scale_concurrency'] = 100 + app_revision_model['scale_concurrency_target'] = 80 + app_revision_model['scale_cpu_limit'] = '1' + app_revision_model['scale_ephemeral_storage_limit'] = '400M' + app_revision_model['scale_initial_instances'] = 1 + app_revision_model['scale_max_instances'] = 10 + app_revision_model['scale_memory_limit'] = '4G' + app_revision_model['scale_min_instances'] = 0 + app_revision_model['scale_request_timeout'] = 300 + app_revision_model['status'] = 'ready' + app_revision_model['status_details'] = app_revision_status_model + + # Construct a json representation of a AppRevisionList model + app_revision_list_model_json = {} + app_revision_list_model_json['first'] = list_first_metadata_model + app_revision_list_model_json['limit'] = 100 + app_revision_list_model_json['next'] = list_next_metadata_model + app_revision_list_model_json['revisions'] = [app_revision_model] + + # Construct a model instance of AppRevisionList by calling from_dict on the json representation + app_revision_list_model = AppRevisionList.from_dict(app_revision_list_model_json) + assert app_revision_list_model != False + + # Construct a model instance of AppRevisionList by calling from_dict on the json representation + app_revision_list_model_dict = AppRevisionList.from_dict(app_revision_list_model_json).__dict__ + app_revision_list_model2 = AppRevisionList(**app_revision_list_model_dict) + + # Verify the model instances are equivalent + assert app_revision_list_model == app_revision_list_model2 + + # Convert model instance back to dict and verify no loss of data + app_revision_list_model_json2 = app_revision_list_model.to_dict() + assert app_revision_list_model_json2 == app_revision_list_model_json + + +class TestModel_AppRevisionStatus: + """ + Test Class for AppRevisionStatus + """ + + def test_app_revision_status_serialization(self): + """ + Test serialization/deserialization for AppRevisionStatus + """ + + # Construct a json representation of a AppRevisionStatus model + app_revision_status_model_json = {} + app_revision_status_model_json['actual_instances'] = 1 + app_revision_status_model_json['reason'] = 'ready' + + # Construct a model instance of AppRevisionStatus by calling from_dict on the json representation + app_revision_status_model = AppRevisionStatus.from_dict(app_revision_status_model_json) + assert app_revision_status_model != False + + # Construct a model instance of AppRevisionStatus by calling from_dict on the json representation + app_revision_status_model_dict = AppRevisionStatus.from_dict(app_revision_status_model_json).__dict__ + app_revision_status_model2 = AppRevisionStatus(**app_revision_status_model_dict) + + # Verify the model instances are equivalent + assert app_revision_status_model == app_revision_status_model2 + + # Convert model instance back to dict and verify no loss of data + app_revision_status_model_json2 = app_revision_status_model.to_dict() + assert app_revision_status_model_json2 == app_revision_status_model_json + + +class TestModel_AppStatus: + """ + Test Class for AppStatus + """ + + def test_app_status_serialization(self): + """ + Test serialization/deserialization for AppStatus + """ + + # Construct a json representation of a AppStatus model + app_status_model_json = {} + app_status_model_json['latest_created_revision'] = 'my-app-00001' + app_status_model_json['latest_ready_revision'] = 'my-app-00001' + app_status_model_json['reason'] = 'ready' + + # Construct a model instance of AppStatus by calling from_dict on the json representation + app_status_model = AppStatus.from_dict(app_status_model_json) + assert app_status_model != False + + # Construct a model instance of AppStatus by calling from_dict on the json representation + app_status_model_dict = AppStatus.from_dict(app_status_model_json).__dict__ + app_status_model2 = AppStatus(**app_status_model_dict) + + # Verify the model instances are equivalent + assert app_status_model == app_status_model2 + + # Convert model instance back to dict and verify no loss of data + app_status_model_json2 = app_status_model.to_dict() + assert app_status_model_json2 == app_status_model_json + + +class TestModel_Build: + """ + Test Class for Build + """ + + def test_build_serialization(self): + """ + Test serialization/deserialization for Build + """ + + # Construct dict forms of any model objects needed in order to build this model. + + build_status_model = {} # BuildStatus + build_status_model['reason'] = 'registered' + + # Construct a json representation of a Build model + build_model_json = {} + build_model_json['created_at'] = '2022-09-13T11:41:35+02:00' + build_model_json['entity_tag'] = '2385407409' + build_model_json[ + 'href' + ] = 'https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/builds/my-build' + build_model_json['id'] = 'e33b1cv7-7390-4437-a5c2-130d5ccdddc3' + build_model_json['name'] = 'my-build' + build_model_json['output_image'] = 'private.de.icr.io/icr_namespace/image-name' + build_model_json['output_secret'] = 'ce-auto-icr-private-eu-de' + build_model_json['project_id'] = '4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + build_model_json['resource_type'] = 'build_v2' + build_model_json['source_context_dir'] = 'some/subfolder' + build_model_json['source_revision'] = 'main' + build_model_json['source_secret'] = 'testString' + build_model_json['source_type'] = 'git' + build_model_json['source_url'] = 'https://github.com/IBM/CodeEngine' + build_model_json['status'] = 'ready' + build_model_json['status_details'] = build_status_model + build_model_json['strategy_size'] = 'medium' + build_model_json['strategy_spec_file'] = 'Dockerfile' + build_model_json['strategy_type'] = 'dockerfile' + build_model_json['timeout'] = 600 + + # Construct a model instance of Build by calling from_dict on the json representation + build_model = Build.from_dict(build_model_json) + assert build_model != False + + # Construct a model instance of Build by calling from_dict on the json representation + build_model_dict = Build.from_dict(build_model_json).__dict__ + build_model2 = Build(**build_model_dict) + + # Verify the model instances are equivalent + assert build_model == build_model2 + + # Convert model instance back to dict and verify no loss of data + build_model_json2 = build_model.to_dict() + assert build_model_json2 == build_model_json + + +class TestModel_BuildList: + """ + Test Class for BuildList + """ + + def test_build_list_serialization(self): + """ + Test serialization/deserialization for BuildList + """ + + # Construct dict forms of any model objects needed in order to build this model. + + build_status_model = {} # BuildStatus + build_status_model['reason'] = 'registered' + + build_model = {} # Build + build_model['created_at'] = '2022-11-15T11:31:27+01:00' + build_model['entity_tag'] = '2385407409' + build_model[ + 'href' + ] = 'https://api.us-east.codeengine.cloud.ibm.com/v2/projects/230828b4-4f15-40a9-b183-1268c6ab88d5/builds/my-build' + build_model['id'] = '27587824-aba8-4f70-8c1d-416326907049' + build_model['name'] = 'my-build' + build_model['output_image'] = 'private.de.icr.io/icr_namespace/test-image-1' + build_model['output_secret'] = 'ce-auto-icr-private-eu-de' + build_model['project_id'] = '230828b4-4f15-40a9-b183-1268c6ab88d5' + build_model['resource_type'] = 'build_v2' + build_model['source_context_dir'] = 'some/subfolder' + build_model['source_revision'] = 'main' + build_model['source_secret'] = 'testString' + build_model['source_type'] = 'git' + build_model['source_url'] = 'https://github.com/IBM/CodeEngine' + build_model['status'] = 'ready' + build_model['status_details'] = build_status_model + build_model['strategy_size'] = 'medium' + build_model['strategy_spec_file'] = 'Dockerfile' + build_model['strategy_type'] = 'dockerfile' + build_model['timeout'] = 600 + + list_first_metadata_model = {} # ListFirstMetadata + list_first_metadata_model['href'] = 'testString' + + list_next_metadata_model = {} # ListNextMetadata + list_next_metadata_model['href'] = 'testString' + list_next_metadata_model['start'] = 'testString' + + # Construct a json representation of a BuildList model + build_list_model_json = {} + build_list_model_json['builds'] = [build_model] + build_list_model_json['first'] = list_first_metadata_model + build_list_model_json['limit'] = 100 + build_list_model_json['next'] = list_next_metadata_model + + # Construct a model instance of BuildList by calling from_dict on the json representation + build_list_model = BuildList.from_dict(build_list_model_json) + assert build_list_model != False + + # Construct a model instance of BuildList by calling from_dict on the json representation + build_list_model_dict = BuildList.from_dict(build_list_model_json).__dict__ + build_list_model2 = BuildList(**build_list_model_dict) + + # Verify the model instances are equivalent + assert build_list_model == build_list_model2 + + # Convert model instance back to dict and verify no loss of data + build_list_model_json2 = build_list_model.to_dict() + assert build_list_model_json2 == build_list_model_json + + +class TestModel_BuildPatch: + """ + Test Class for BuildPatch + """ + + def test_build_patch_serialization(self): + """ + Test serialization/deserialization for BuildPatch + """ + + # Construct a json representation of a BuildPatch model + build_patch_model_json = {} + build_patch_model_json['output_image'] = 'private.de.icr.io/icr_namespace/image-name' + build_patch_model_json['output_secret'] = 'ce-auto-icr-private-eu-de' + build_patch_model_json['source_context_dir'] = 'some/subfolder' + build_patch_model_json['source_revision'] = 'main' + build_patch_model_json['source_secret'] = 'testString' + build_patch_model_json['source_type'] = 'git' + build_patch_model_json['source_url'] = 'https://github.com/IBM/CodeEngine' + build_patch_model_json['strategy_size'] = 'medium' + build_patch_model_json['strategy_spec_file'] = 'Dockerfile' + build_patch_model_json['strategy_type'] = 'dockerfile' + build_patch_model_json['timeout'] = 600 + + # Construct a model instance of BuildPatch by calling from_dict on the json representation + build_patch_model = BuildPatch.from_dict(build_patch_model_json) + assert build_patch_model != False + + # Construct a model instance of BuildPatch by calling from_dict on the json representation + build_patch_model_dict = BuildPatch.from_dict(build_patch_model_json).__dict__ + build_patch_model2 = BuildPatch(**build_patch_model_dict) + + # Verify the model instances are equivalent + assert build_patch_model == build_patch_model2 + + # Convert model instance back to dict and verify no loss of data + build_patch_model_json2 = build_patch_model.to_dict() + assert build_patch_model_json2 == build_patch_model_json + + +class TestModel_BuildRun: + """ + Test Class for BuildRun + """ + + def test_build_run_serialization(self): + """ + Test serialization/deserialization for BuildRun + """ + + # Construct dict forms of any model objects needed in order to build this model. + + build_run_status_model = {} # BuildRunStatus + build_run_status_model['completion_time'] = '2022-09-22T17:40:00Z' + build_run_status_model[ + 'output_digest' + ] = 'sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384' + build_run_status_model['reason'] = 'succeeded' + build_run_status_model['start_time'] = '2022-09-22T17:34:00Z' + + # Construct a json representation of a BuildRun model + build_run_model_json = {} + build_run_model_json['build_name'] = 'testString' + build_run_model_json['created_at'] = '2022-09-13T11:41:35+02:00' + build_run_model_json[ + 'href' + ] = 'https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-build-run' + build_run_model_json['id'] = 'e33b1cv7-7390-4437-a5c2-130d5ccdddc3' + build_run_model_json['name'] = 'my-build-run' + build_run_model_json['output_image'] = 'private.de.icr.io/icr_namespace/image-name' + build_run_model_json['output_secret'] = 'ce-auto-icr-private-eu-de' + build_run_model_json['project_id'] = '4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + build_run_model_json['resource_type'] = 'build_run_v2' + build_run_model_json['service_account'] = 'default' + build_run_model_json['source_context_dir'] = 'some/subfolder' + build_run_model_json['source_revision'] = 'main' + build_run_model_json['source_secret'] = 'testString' + build_run_model_json['source_type'] = 'git' + build_run_model_json['source_url'] = 'https://github.com/IBM/CodeEngine' + build_run_model_json['status'] = 'succeeded' + build_run_model_json['status_details'] = build_run_status_model + build_run_model_json['strategy_size'] = 'medium' + build_run_model_json['strategy_spec_file'] = 'Dockerfile' + build_run_model_json['strategy_type'] = 'dockerfile' + build_run_model_json['timeout'] = 600 + + # Construct a model instance of BuildRun by calling from_dict on the json representation + build_run_model = BuildRun.from_dict(build_run_model_json) + assert build_run_model != False + + # Construct a model instance of BuildRun by calling from_dict on the json representation + build_run_model_dict = BuildRun.from_dict(build_run_model_json).__dict__ + build_run_model2 = BuildRun(**build_run_model_dict) + + # Verify the model instances are equivalent + assert build_run_model == build_run_model2 + + # Convert model instance back to dict and verify no loss of data + build_run_model_json2 = build_run_model.to_dict() + assert build_run_model_json2 == build_run_model_json + + +class TestModel_BuildRunList: + """ + Test Class for BuildRunList + """ + + def test_build_run_list_serialization(self): + """ + Test serialization/deserialization for BuildRunList + """ + + # Construct dict forms of any model objects needed in order to build this model. + + build_run_status_model = {} # BuildRunStatus + build_run_status_model['completion_time'] = '2022-09-22T17:40:00Z' + build_run_status_model[ + 'output_digest' + ] = 'sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384' + build_run_status_model['reason'] = 'succeeded' + build_run_status_model['start_time'] = '2022-09-22T17:34:00Z' + + build_run_model = {} # BuildRun + build_run_model['build_name'] = 'my-build' + build_run_model['created_at'] = '2022-06-20T10:10:00+02:00' + build_run_model[ + 'href' + ] = 'https://api.us-east.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/build_runs/my-buildrun-1' + build_run_model['id'] = 'ca151bf7-b1bf-4e18-a1cb-857329c2d097' + build_run_model['name'] = 'my-buildrun-1' + build_run_model['output_image'] = 'private.de.icr.io/icr_namespace/image-name' + build_run_model['output_secret'] = 'ce-auto-icr-private-eu-de' + build_run_model['project_id'] = '4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + build_run_model['resource_type'] = 'build_run_v2' + build_run_model['service_account'] = 'default' + build_run_model['source_context_dir'] = 'some/subfolder' + build_run_model['source_revision'] = 'main' + build_run_model['source_secret'] = 'testString' + build_run_model['source_type'] = 'git' + build_run_model['source_url'] = 'https://github.com/IBM/CodeEngine' + build_run_model['status'] = 'succeeded' + build_run_model['status_details'] = build_run_status_model + build_run_model['strategy_size'] = 'medium' + build_run_model['strategy_spec_file'] = 'Dockerfile' + build_run_model['strategy_type'] = 'dockerfile' + build_run_model['timeout'] = 600 + + list_first_metadata_model = {} # ListFirstMetadata + list_first_metadata_model['href'] = 'testString' + + list_next_metadata_model = {} # ListNextMetadata + list_next_metadata_model['href'] = 'testString' + list_next_metadata_model['start'] = 'testString' + + # Construct a json representation of a BuildRunList model + build_run_list_model_json = {} + build_run_list_model_json['build_runs'] = [build_run_model] + build_run_list_model_json['first'] = list_first_metadata_model + build_run_list_model_json['limit'] = 100 + build_run_list_model_json['next'] = list_next_metadata_model + + # Construct a model instance of BuildRunList by calling from_dict on the json representation + build_run_list_model = BuildRunList.from_dict(build_run_list_model_json) + assert build_run_list_model != False + + # Construct a model instance of BuildRunList by calling from_dict on the json representation + build_run_list_model_dict = BuildRunList.from_dict(build_run_list_model_json).__dict__ + build_run_list_model2 = BuildRunList(**build_run_list_model_dict) + + # Verify the model instances are equivalent + assert build_run_list_model == build_run_list_model2 + + # Convert model instance back to dict and verify no loss of data + build_run_list_model_json2 = build_run_list_model.to_dict() + assert build_run_list_model_json2 == build_run_list_model_json + + +class TestModel_BuildRunStatus: + """ + Test Class for BuildRunStatus + """ + + def test_build_run_status_serialization(self): + """ + Test serialization/deserialization for BuildRunStatus + """ + + # Construct a json representation of a BuildRunStatus model + build_run_status_model_json = {} + build_run_status_model_json['completion_time'] = '2022-09-22T17:40:00Z' + build_run_status_model_json[ + 'output_digest' + ] = 'sha256:9a3d845c629d2b4a6b271b1d526dfafc1e7d9511f8863b43b5bb0483ef626384' + build_run_status_model_json['reason'] = 'succeeded' + build_run_status_model_json['start_time'] = '2022-09-22T17:34:00Z' + + # Construct a model instance of BuildRunStatus by calling from_dict on the json representation + build_run_status_model = BuildRunStatus.from_dict(build_run_status_model_json) + assert build_run_status_model != False + + # Construct a model instance of BuildRunStatus by calling from_dict on the json representation + build_run_status_model_dict = BuildRunStatus.from_dict(build_run_status_model_json).__dict__ + build_run_status_model2 = BuildRunStatus(**build_run_status_model_dict) + + # Verify the model instances are equivalent + assert build_run_status_model == build_run_status_model2 + + # Convert model instance back to dict and verify no loss of data + build_run_status_model_json2 = build_run_status_model.to_dict() + assert build_run_status_model_json2 == build_run_status_model_json + + +class TestModel_BuildStatus: + """ + Test Class for BuildStatus + """ + + def test_build_status_serialization(self): + """ + Test serialization/deserialization for BuildStatus + """ + + # Construct a json representation of a BuildStatus model + build_status_model_json = {} + build_status_model_json['reason'] = 'registered' + + # Construct a model instance of BuildStatus by calling from_dict on the json representation + build_status_model = BuildStatus.from_dict(build_status_model_json) + assert build_status_model != False + + # Construct a model instance of BuildStatus by calling from_dict on the json representation + build_status_model_dict = BuildStatus.from_dict(build_status_model_json).__dict__ + build_status_model2 = BuildStatus(**build_status_model_dict) + + # Verify the model instances are equivalent + assert build_status_model == build_status_model2 + + # Convert model instance back to dict and verify no loss of data + build_status_model_json2 = build_status_model.to_dict() + assert build_status_model_json2 == build_status_model_json + + +class TestModel_ConfigMap: + """ + Test Class for ConfigMap + """ + + def test_config_map_serialization(self): + """ + Test serialization/deserialization for ConfigMap + """ + + # Construct a json representation of a ConfigMap model + config_map_model_json = {} + config_map_model_json['created_at'] = '2022-09-13T11:41:35+02:00' + config_map_model_json['data'] = {'key1': 'testString'} + config_map_model_json['entity_tag'] = '2385407409' + config_map_model_json[ + 'href' + ] = 'https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/config_maps/my-config-map' + config_map_model_json['id'] = 'e33b1cv7-7390-4437-a5c2-130d5ccdddc3' + config_map_model_json['name'] = 'my-config-map' + config_map_model_json['project_id'] = '4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + config_map_model_json['resource_type'] = 'config_map_v2' + + # Construct a model instance of ConfigMap by calling from_dict on the json representation + config_map_model = ConfigMap.from_dict(config_map_model_json) + assert config_map_model != False + + # Construct a model instance of ConfigMap by calling from_dict on the json representation + config_map_model_dict = ConfigMap.from_dict(config_map_model_json).__dict__ + config_map_model2 = ConfigMap(**config_map_model_dict) + + # Verify the model instances are equivalent + assert config_map_model == config_map_model2 + + # Convert model instance back to dict and verify no loss of data + config_map_model_json2 = config_map_model.to_dict() + assert config_map_model_json2 == config_map_model_json + + +class TestModel_ConfigMapList: + """ + Test Class for ConfigMapList + """ + + def test_config_map_list_serialization(self): + """ + Test serialization/deserialization for ConfigMapList + """ + + # Construct dict forms of any model objects needed in order to build this model. + + config_map_model = {} # ConfigMap + config_map_model['created_at'] = '2022-11-15T21:45:49+01:00' + config_map_model['data'] = {'key1': 'testString'} + config_map_model['entity_tag'] = '2386238209' + config_map_model[ + 'href' + ] = 'https://api.us-east.codeengine.cloud.ibm.com/v2/projects/230828b4-4f15-40a9-b183-1268c6ab88d5/config_maps/my-config-map' + config_map_model['id'] = 'b8376985-d6df-43c5-8feb-194d45390bc8' + config_map_model['name'] = 'my-config-map' + config_map_model['project_id'] = '230828b4-4f15-40a9-b183-1268c6ab88d5' + config_map_model['resource_type'] = 'config_map_v2' + + list_first_metadata_model = {} # ListFirstMetadata + list_first_metadata_model['href'] = 'testString' + + list_next_metadata_model = {} # ListNextMetadata + list_next_metadata_model['href'] = 'testString' + list_next_metadata_model['start'] = 'testString' + + # Construct a json representation of a ConfigMapList model + config_map_list_model_json = {} + config_map_list_model_json['config_maps'] = [config_map_model] + config_map_list_model_json['first'] = list_first_metadata_model + config_map_list_model_json['limit'] = 100 + config_map_list_model_json['next'] = list_next_metadata_model + + # Construct a model instance of ConfigMapList by calling from_dict on the json representation + config_map_list_model = ConfigMapList.from_dict(config_map_list_model_json) + assert config_map_list_model != False + + # Construct a model instance of ConfigMapList by calling from_dict on the json representation + config_map_list_model_dict = ConfigMapList.from_dict(config_map_list_model_json).__dict__ + config_map_list_model2 = ConfigMapList(**config_map_list_model_dict) + + # Verify the model instances are equivalent + assert config_map_list_model == config_map_list_model2 + + # Convert model instance back to dict and verify no loss of data + config_map_list_model_json2 = config_map_list_model.to_dict() + assert config_map_list_model_json2 == config_map_list_model_json + + +class TestModel_EnvVar: + """ + Test Class for EnvVar + """ + + def test_env_var_serialization(self): + """ + Test serialization/deserialization for EnvVar + """ + + # Construct a json representation of a EnvVar model + env_var_model_json = {} + env_var_model_json['key'] = 'MY_VARIABLE' + env_var_model_json['name'] = 'SOME' + env_var_model_json['prefix'] = 'PREFIX_' + env_var_model_json['reference'] = 'my-secret' + env_var_model_json['type'] = 'literal' + env_var_model_json['value'] = 'VALUE' + + # Construct a model instance of EnvVar by calling from_dict on the json representation + env_var_model = EnvVar.from_dict(env_var_model_json) + assert env_var_model != False + + # Construct a model instance of EnvVar by calling from_dict on the json representation + env_var_model_dict = EnvVar.from_dict(env_var_model_json).__dict__ + env_var_model2 = EnvVar(**env_var_model_dict) + + # Verify the model instances are equivalent + assert env_var_model == env_var_model2 + + # Convert model instance back to dict and verify no loss of data + env_var_model_json2 = env_var_model.to_dict() + assert env_var_model_json2 == env_var_model_json + + +class TestModel_EnvVarPrototype: + """ + Test Class for EnvVarPrototype + """ + + def test_env_var_prototype_serialization(self): + """ + Test serialization/deserialization for EnvVarPrototype + """ + + # Construct a json representation of a EnvVarPrototype model + env_var_prototype_model_json = {} + env_var_prototype_model_json['key'] = 'MY_VARIABLE' + env_var_prototype_model_json['name'] = 'SOME' + env_var_prototype_model_json['prefix'] = 'PREFIX_' + env_var_prototype_model_json['reference'] = 'my-secret' + env_var_prototype_model_json['type'] = 'literal' + env_var_prototype_model_json['value'] = 'VALUE' + + # Construct a model instance of EnvVarPrototype by calling from_dict on the json representation + env_var_prototype_model = EnvVarPrototype.from_dict(env_var_prototype_model_json) + assert env_var_prototype_model != False + + # Construct a model instance of EnvVarPrototype by calling from_dict on the json representation + env_var_prototype_model_dict = EnvVarPrototype.from_dict(env_var_prototype_model_json).__dict__ + env_var_prototype_model2 = EnvVarPrototype(**env_var_prototype_model_dict) + + # Verify the model instances are equivalent + assert env_var_prototype_model == env_var_prototype_model2 + + # Convert model instance back to dict and verify no loss of data + env_var_prototype_model_json2 = env_var_prototype_model.to_dict() + assert env_var_prototype_model_json2 == env_var_prototype_model_json + + +class TestModel_Job: + """ + Test Class for Job + """ + + def test_job_serialization(self): + """ + Test serialization/deserialization for Job + """ + + # Construct dict forms of any model objects needed in order to build this model. + + env_var_model = {} # EnvVar + env_var_model['key'] = 'MY_VARIABLE' + env_var_model['name'] = 'SOME' + env_var_model['prefix'] = 'PREFIX_' + env_var_model['reference'] = 'my-secret' + env_var_model['type'] = 'literal' + env_var_model['value'] = 'VALUE' + + volume_mount_model = {} # VolumeMount + volume_mount_model['mount_path'] = '/app' + volume_mount_model['name'] = 'codeengine-mount-b69u90' + volume_mount_model['reference'] = 'my-secret' + volume_mount_model['type'] = 'secret' + + # Construct a json representation of a Job model + job_model_json = {} + job_model_json['created_at'] = '2022-09-13T11:41:35+02:00' + job_model_json['entity_tag'] = '2385407409' + job_model_json[ + 'href' + ] = 'https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/jobs/my-job' + job_model_json['id'] = 'e33b1cv7-7390-4437-a5c2-130d5ccdddc3' + job_model_json['image_reference'] = 'icr.io/codeengine/helloworld' + job_model_json['image_secret'] = 'my-secret' + job_model_json['name'] = 'my-job' + job_model_json['project_id'] = '4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + job_model_json['resource_type'] = 'job_v2' + job_model_json['run_arguments'] = ['testString'] + job_model_json['run_as_user'] = 1001 + job_model_json['run_commands'] = ['testString'] + job_model_json['run_env_variables'] = [env_var_model] + job_model_json['run_mode'] = 'daemon' + job_model_json['run_service_account'] = 'default' + job_model_json['run_volume_mounts'] = [volume_mount_model] + job_model_json['scale_array_spec'] = '1-5,7-8,10' + job_model_json['scale_cpu_limit'] = '1' + job_model_json['scale_ephemeral_storage_limit'] = '4G' + job_model_json['scale_max_execution_time'] = 7200 + job_model_json['scale_memory_limit'] = '4G' + job_model_json['scale_retry_limit'] = 3 + + # Construct a model instance of Job by calling from_dict on the json representation + job_model = Job.from_dict(job_model_json) + assert job_model != False + + # Construct a model instance of Job by calling from_dict on the json representation + job_model_dict = Job.from_dict(job_model_json).__dict__ + job_model2 = Job(**job_model_dict) + + # Verify the model instances are equivalent + assert job_model == job_model2 + + # Convert model instance back to dict and verify no loss of data + job_model_json2 = job_model.to_dict() + assert job_model_json2 == job_model_json + + +class TestModel_JobList: + """ + Test Class for JobList + """ + + def test_job_list_serialization(self): + """ + Test serialization/deserialization for JobList + """ + + # Construct dict forms of any model objects needed in order to build this model. + + list_first_metadata_model = {} # ListFirstMetadata + list_first_metadata_model['href'] = 'testString' + + env_var_model = {} # EnvVar + env_var_model['key'] = 'MY_VARIABLE' + env_var_model['name'] = 'SOME' + env_var_model['prefix'] = 'PREFIX_' + env_var_model['reference'] = 'my-secret' + env_var_model['type'] = 'literal' + env_var_model['value'] = 'VALUE' + + volume_mount_model = {} # VolumeMount + volume_mount_model['mount_path'] = '/app' + volume_mount_model['name'] = 'codeengine-mount-b69u90' + volume_mount_model['reference'] = 'my-secret' + volume_mount_model['type'] = 'secret' + + job_model = {} # Job + job_model['created_at'] = '2022-11-15T21:40:40+01:00' + job_model['entity_tag'] = '2386231540' + job_model[ + 'href' + ] = 'https://api.us-east.codeengine.cloud.ibm.com/v2/projects/230828b4-4f15-40a9-b183-1268c6ab88d5/jobs/my-job' + job_model['id'] = '7e49dd78-09d0-45c7-ad7e-cd968e0e7747' + job_model['image_reference'] = 'icr.io/codeengine/helloworld' + job_model['image_secret'] = 'my-secret' + job_model['name'] = 'my-job' + job_model['project_id'] = '230828b4-4f15-40a9-b183-1268c6ab88d5' + job_model['resource_type'] = 'job_v2' + job_model['run_arguments'] = [] + job_model['run_as_user'] = 1001 + job_model['run_commands'] = [] + job_model['run_env_variables'] = [env_var_model] + job_model['run_mode'] = 'task' + job_model['run_service_account'] = 'default' + job_model['run_volume_mounts'] = [volume_mount_model] + job_model['scale_array_spec'] = '0' + job_model['scale_cpu_limit'] = '1' + job_model['scale_ephemeral_storage_limit'] = '400M' + job_model['scale_max_execution_time'] = 7200 + job_model['scale_memory_limit'] = '4G' + job_model['scale_retry_limit'] = 3 + + list_next_metadata_model = {} # ListNextMetadata + list_next_metadata_model['href'] = 'testString' + list_next_metadata_model['start'] = 'testString' + + # Construct a json representation of a JobList model + job_list_model_json = {} + job_list_model_json['first'] = list_first_metadata_model + job_list_model_json['jobs'] = [job_model] + job_list_model_json['limit'] = 100 + job_list_model_json['next'] = list_next_metadata_model + + # Construct a model instance of JobList by calling from_dict on the json representation + job_list_model = JobList.from_dict(job_list_model_json) + assert job_list_model != False + + # Construct a model instance of JobList by calling from_dict on the json representation + job_list_model_dict = JobList.from_dict(job_list_model_json).__dict__ + job_list_model2 = JobList(**job_list_model_dict) + + # Verify the model instances are equivalent + assert job_list_model == job_list_model2 + + # Convert model instance back to dict and verify no loss of data + job_list_model_json2 = job_list_model.to_dict() + assert job_list_model_json2 == job_list_model_json + + +class TestModel_JobPatch: + """ + Test Class for JobPatch + """ + + def test_job_patch_serialization(self): + """ + Test serialization/deserialization for JobPatch + """ + + # Construct dict forms of any model objects needed in order to build this model. + + env_var_prototype_model = {} # EnvVarPrototype + env_var_prototype_model['key'] = 'MY_VARIABLE' + env_var_prototype_model['name'] = 'MY_PROPERTY' + env_var_prototype_model['prefix'] = 'PREFIX_' + env_var_prototype_model['reference'] = 'my-secret' + env_var_prototype_model['type'] = 'literal' + env_var_prototype_model['value'] = 'OTHER' + + volume_mount_prototype_model = {} # VolumeMountPrototype + volume_mount_prototype_model['mount_path'] = '/app' + volume_mount_prototype_model['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model['reference'] = 'my-secret' + volume_mount_prototype_model['type'] = 'secret' + + # Construct a json representation of a JobPatch model + job_patch_model_json = {} + job_patch_model_json['image_reference'] = 'icr.io/codeengine/helloworld' + job_patch_model_json['image_secret'] = 'my-secret' + job_patch_model_json['run_arguments'] = ['testString'] + job_patch_model_json['run_as_user'] = 1001 + job_patch_model_json['run_commands'] = ['testString'] + job_patch_model_json['run_env_variables'] = [env_var_prototype_model] + job_patch_model_json['run_mode'] = 'daemon' + job_patch_model_json['run_service_account'] = 'default' + job_patch_model_json['run_volume_mounts'] = [volume_mount_prototype_model] + job_patch_model_json['scale_array_spec'] = '1-5,7-8,10' + job_patch_model_json['scale_cpu_limit'] = '1' + job_patch_model_json['scale_ephemeral_storage_limit'] = '4G' + job_patch_model_json['scale_max_execution_time'] = 7200 + job_patch_model_json['scale_memory_limit'] = '4G' + job_patch_model_json['scale_retry_limit'] = 3 + + # Construct a model instance of JobPatch by calling from_dict on the json representation + job_patch_model = JobPatch.from_dict(job_patch_model_json) + assert job_patch_model != False + + # Construct a model instance of JobPatch by calling from_dict on the json representation + job_patch_model_dict = JobPatch.from_dict(job_patch_model_json).__dict__ + job_patch_model2 = JobPatch(**job_patch_model_dict) + + # Verify the model instances are equivalent + assert job_patch_model == job_patch_model2 + + # Convert model instance back to dict and verify no loss of data + job_patch_model_json2 = job_patch_model.to_dict() + assert job_patch_model_json2 == job_patch_model_json + + +class TestModel_JobRun: + """ + Test Class for JobRun + """ + + def test_job_run_serialization(self): + """ + Test serialization/deserialization for JobRun + """ + + # Construct dict forms of any model objects needed in order to build this model. + + env_var_model = {} # EnvVar + env_var_model['key'] = 'MY_VARIABLE' + env_var_model['name'] = 'SOME' + env_var_model['prefix'] = 'PREFIX_' + env_var_model['reference'] = 'my-secret' + env_var_model['type'] = 'literal' + env_var_model['value'] = 'VALUE' + + volume_mount_model = {} # VolumeMount + volume_mount_model['mount_path'] = '/app' + volume_mount_model['name'] = 'codeengine-mount-b69u90' + volume_mount_model['reference'] = 'my-secret' + volume_mount_model['type'] = 'secret' + + job_run_status_model = {} # JobRunStatus + job_run_status_model['completion_time'] = '2022-09-22T17:40:00Z' + job_run_status_model['failed'] = 0 + job_run_status_model['pending'] = 0 + job_run_status_model['requested'] = 0 + job_run_status_model['running'] = 0 + job_run_status_model['start_time'] = '2022-09-22T17:34:00Z' + job_run_status_model['succeeded'] = 1 + job_run_status_model['unknown'] = 0 + + # Construct a json representation of a JobRun model + job_run_model_json = {} + job_run_model_json['created_at'] = '2022-09-13T11:41:35+02:00' + job_run_model_json[ + 'href' + ] = 'https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/job_runs/my-job-run' + job_run_model_json['id'] = 'e33b1cv7-7390-4437-a5c2-130d5ccdddc3' + job_run_model_json['image_reference'] = 'icr.io/codeengine/helloworld' + job_run_model_json['image_secret'] = 'my-secret' + job_run_model_json['job_name'] = 'my-job' + job_run_model_json['name'] = 'my-job-run' + job_run_model_json['project_id'] = '4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + job_run_model_json['resource_type'] = 'job_run_v2' + job_run_model_json['run_arguments'] = ['testString'] + job_run_model_json['run_as_user'] = 1001 + job_run_model_json['run_commands'] = ['testString'] + job_run_model_json['run_env_variables'] = [env_var_model] + job_run_model_json['run_mode'] = 'daemon' + job_run_model_json['run_service_account'] = 'default' + job_run_model_json['run_volume_mounts'] = [volume_mount_model] + job_run_model_json['scale_array_spec'] = '1-5,7-8,10' + job_run_model_json['scale_cpu_limit'] = '1' + job_run_model_json['scale_ephemeral_storage_limit'] = '4G' + job_run_model_json['scale_max_execution_time'] = 7200 + job_run_model_json['scale_memory_limit'] = '4G' + job_run_model_json['scale_retry_limit'] = 3 + job_run_model_json['status'] = 'completed' + job_run_model_json['status_details'] = job_run_status_model + + # Construct a model instance of JobRun by calling from_dict on the json representation + job_run_model = JobRun.from_dict(job_run_model_json) + assert job_run_model != False + + # Construct a model instance of JobRun by calling from_dict on the json representation + job_run_model_dict = JobRun.from_dict(job_run_model_json).__dict__ + job_run_model2 = JobRun(**job_run_model_dict) + + # Verify the model instances are equivalent + assert job_run_model == job_run_model2 + + # Convert model instance back to dict and verify no loss of data + job_run_model_json2 = job_run_model.to_dict() + assert job_run_model_json2 == job_run_model_json + + +class TestModel_JobRunList: + """ + Test Class for JobRunList + """ + + def test_job_run_list_serialization(self): + """ + Test serialization/deserialization for JobRunList + """ + + # Construct dict forms of any model objects needed in order to build this model. + + list_first_metadata_model = {} # ListFirstMetadata + list_first_metadata_model['href'] = 'testString' + + env_var_model = {} # EnvVar + env_var_model['key'] = 'MY_VARIABLE' + env_var_model['name'] = 'SOME' + env_var_model['prefix'] = 'PREFIX_' + env_var_model['reference'] = 'my-secret' + env_var_model['type'] = 'literal' + env_var_model['value'] = 'VALUE' + + volume_mount_model = {} # VolumeMount + volume_mount_model['mount_path'] = '/app' + volume_mount_model['name'] = 'codeengine-mount-b69u90' + volume_mount_model['reference'] = 'my-secret' + volume_mount_model['type'] = 'secret' + + job_run_status_model = {} # JobRunStatus + job_run_status_model['completion_time'] = '2022-09-22T17:40:00Z' + job_run_status_model['failed'] = 0 + job_run_status_model['pending'] = 0 + job_run_status_model['requested'] = 0 + job_run_status_model['running'] = 0 + job_run_status_model['start_time'] = '2022-09-22T17:34:00Z' + job_run_status_model['succeeded'] = 1 + job_run_status_model['unknown'] = 0 + + job_run_model = {} # JobRun + job_run_model['created_at'] = '2022-11-15T22:06:21+01:00' + job_run_model[ + 'href' + ] = 'https://api.us-east.codeengine.cloud.ibm.com/v2/projects/230828b4-4f15-40a9-b183-1268c6ab88d5/jobs/my-job-run-1' + job_run_model['id'] = 'ced5039e-b1d3-4c51-aa29-8dbde3531ace' + job_run_model['image_reference'] = 'icr.io/codeengine/helloworld' + job_run_model['image_secret'] = 'my-secret' + job_run_model['job_name'] = 'my-job' + job_run_model['name'] = 'my-job-run-1' + job_run_model['project_id'] = '230828b4-4f15-40a9-b183-1268c6ab88d5' + job_run_model['resource_type'] = 'job_run_v2' + job_run_model['run_arguments'] = [] + job_run_model['run_as_user'] = 1001 + job_run_model['run_commands'] = [] + job_run_model['run_env_variables'] = [env_var_model] + job_run_model['run_mode'] = 'task' + job_run_model['run_service_account'] = 'default' + job_run_model['run_volume_mounts'] = [volume_mount_model] + job_run_model['scale_array_spec'] = '0' + job_run_model['scale_cpu_limit'] = '1' + job_run_model['scale_ephemeral_storage_limit'] = '400M' + job_run_model['scale_max_execution_time'] = 7200 + job_run_model['scale_memory_limit'] = '4G' + job_run_model['scale_retry_limit'] = 3 + job_run_model['status'] = 'completed' + job_run_model['status_details'] = job_run_status_model + + list_next_metadata_model = {} # ListNextMetadata + list_next_metadata_model['href'] = 'testString' + list_next_metadata_model['start'] = 'testString' + + # Construct a json representation of a JobRunList model + job_run_list_model_json = {} + job_run_list_model_json['first'] = list_first_metadata_model + job_run_list_model_json['job_runs'] = [job_run_model] + job_run_list_model_json['limit'] = 100 + job_run_list_model_json['next'] = list_next_metadata_model + + # Construct a model instance of JobRunList by calling from_dict on the json representation + job_run_list_model = JobRunList.from_dict(job_run_list_model_json) + assert job_run_list_model != False + + # Construct a model instance of JobRunList by calling from_dict on the json representation + job_run_list_model_dict = JobRunList.from_dict(job_run_list_model_json).__dict__ + job_run_list_model2 = JobRunList(**job_run_list_model_dict) + + # Verify the model instances are equivalent + assert job_run_list_model == job_run_list_model2 + + # Convert model instance back to dict and verify no loss of data + job_run_list_model_json2 = job_run_list_model.to_dict() + assert job_run_list_model_json2 == job_run_list_model_json + + +class TestModel_JobRunStatus: + """ + Test Class for JobRunStatus + """ + + def test_job_run_status_serialization(self): + """ + Test serialization/deserialization for JobRunStatus + """ + + # Construct a json representation of a JobRunStatus model + job_run_status_model_json = {} + job_run_status_model_json['completion_time'] = '2022-09-22T17:40:00Z' + job_run_status_model_json['failed'] = 0 + job_run_status_model_json['pending'] = 0 + job_run_status_model_json['requested'] = 0 + job_run_status_model_json['running'] = 0 + job_run_status_model_json['start_time'] = '2022-09-22T17:34:00Z' + job_run_status_model_json['succeeded'] = 1 + job_run_status_model_json['unknown'] = 0 + + # Construct a model instance of JobRunStatus by calling from_dict on the json representation + job_run_status_model = JobRunStatus.from_dict(job_run_status_model_json) + assert job_run_status_model != False + + # Construct a model instance of JobRunStatus by calling from_dict on the json representation + job_run_status_model_dict = JobRunStatus.from_dict(job_run_status_model_json).__dict__ + job_run_status_model2 = JobRunStatus(**job_run_status_model_dict) + + # Verify the model instances are equivalent + assert job_run_status_model == job_run_status_model2 + + # Convert model instance back to dict and verify no loss of data + job_run_status_model_json2 = job_run_status_model.to_dict() + assert job_run_status_model_json2 == job_run_status_model_json + + +class TestModel_ListFirstMetadata: + """ + Test Class for ListFirstMetadata + """ + + def test_list_first_metadata_serialization(self): + """ + Test serialization/deserialization for ListFirstMetadata + """ + + # Construct a json representation of a ListFirstMetadata model + list_first_metadata_model_json = {} + list_first_metadata_model_json['href'] = 'testString' + + # Construct a model instance of ListFirstMetadata by calling from_dict on the json representation + list_first_metadata_model = ListFirstMetadata.from_dict(list_first_metadata_model_json) + assert list_first_metadata_model != False + + # Construct a model instance of ListFirstMetadata by calling from_dict on the json representation + list_first_metadata_model_dict = ListFirstMetadata.from_dict(list_first_metadata_model_json).__dict__ + list_first_metadata_model2 = ListFirstMetadata(**list_first_metadata_model_dict) + + # Verify the model instances are equivalent + assert list_first_metadata_model == list_first_metadata_model2 + + # Convert model instance back to dict and verify no loss of data + list_first_metadata_model_json2 = list_first_metadata_model.to_dict() + assert list_first_metadata_model_json2 == list_first_metadata_model_json + + +class TestModel_ListNextMetadata: + """ + Test Class for ListNextMetadata + """ + + def test_list_next_metadata_serialization(self): + """ + Test serialization/deserialization for ListNextMetadata + """ + + # Construct a json representation of a ListNextMetadata model + list_next_metadata_model_json = {} + list_next_metadata_model_json['href'] = 'testString' + list_next_metadata_model_json['start'] = 'testString' + + # Construct a model instance of ListNextMetadata by calling from_dict on the json representation + list_next_metadata_model = ListNextMetadata.from_dict(list_next_metadata_model_json) + assert list_next_metadata_model != False + + # Construct a model instance of ListNextMetadata by calling from_dict on the json representation + list_next_metadata_model_dict = ListNextMetadata.from_dict(list_next_metadata_model_json).__dict__ + list_next_metadata_model2 = ListNextMetadata(**list_next_metadata_model_dict) + + # Verify the model instances are equivalent + assert list_next_metadata_model == list_next_metadata_model2 + + # Convert model instance back to dict and verify no loss of data + list_next_metadata_model_json2 = list_next_metadata_model.to_dict() + assert list_next_metadata_model_json2 == list_next_metadata_model_json + + +class TestModel_Project: + """ + Test Class for Project + """ + + def test_project_serialization(self): + """ + Test serialization/deserialization for Project + """ + + # Construct a json representation of a Project model + project_model_json = {} + project_model_json['account_id'] = '4329073d16d2f3663f74bfa955259139' + project_model_json['created_at'] = '2021-03-29T12:18:13.992359829Z' + project_model_json[ + 'crn' + ] = 'crn:v1:bluemix:public:codeengine:eu-de:a/4329073d16d2f3663f74bfa955259139:4e49b3e0-27a8-48d2-a784-c7ee48bb863b::' + project_model_json[ + 'href' + ] = 'https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + project_model_json['id'] = '4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + project_model_json['name'] = 'project-name' + project_model_json['region'] = 'us-east' + project_model_json['resource_group_id'] = '5c49eabcf5e85881a37e2d100a33b3df' + project_model_json['resource_type'] = 'project_v2' + project_model_json['status'] = 'active' + + # Construct a model instance of Project by calling from_dict on the json representation + project_model = Project.from_dict(project_model_json) + assert project_model != False + + # Construct a model instance of Project by calling from_dict on the json representation + project_model_dict = Project.from_dict(project_model_json).__dict__ + project_model2 = Project(**project_model_dict) + + # Verify the model instances are equivalent + assert project_model == project_model2 + + # Convert model instance back to dict and verify no loss of data + project_model_json2 = project_model.to_dict() + assert project_model_json2 == project_model_json + + +class TestModel_ProjectList: + """ + Test Class for ProjectList + """ + + def test_project_list_serialization(self): + """ + Test serialization/deserialization for ProjectList + """ + + # Construct dict forms of any model objects needed in order to build this model. + + list_first_metadata_model = {} # ListFirstMetadata + list_first_metadata_model['href'] = 'testString' + + list_next_metadata_model = {} # ListNextMetadata + list_next_metadata_model['href'] = 'testString' + list_next_metadata_model['start'] = 'testString' + + project_model = {} # Project + project_model['account_id'] = 'f9f1030ebf674eda8d57bdbc2b9e536a' + project_model['created_at'] = '2021-03-29T12:18:13.992359829Z' + project_model[ + 'crn' + ] = 'crn:v1:bluemix:public:codeengine:us-east:a/4329073d16d2f3663f74bfa955259139:15314cc3-85b4-4338-903f-c28cdee6d005::' + project_model[ + 'href' + ] = 'https://api.us-east.codeengine.cloud.ibm.com/v2/projects/15314cc3-85b4-4338-903f-c28cdee6d005' + project_model['id'] = '15314cc3-85b4-4338-903f-c28cdee6d005' + project_model['name'] = 'test_project' + project_model['region'] = 'us-east' + project_model['resource_group_id'] = 'b91e849cedb04e7e92bd68c040c672dc' + project_model['resource_type'] = 'project_v2' + project_model['status'] = 'active' + + # Construct a json representation of a ProjectList model + project_list_model_json = {} + project_list_model_json['first'] = list_first_metadata_model + project_list_model_json['limit'] = 100 + project_list_model_json['next'] = list_next_metadata_model + project_list_model_json['projects'] = [project_model] + + # Construct a model instance of ProjectList by calling from_dict on the json representation + project_list_model = ProjectList.from_dict(project_list_model_json) + assert project_list_model != False + + # Construct a model instance of ProjectList by calling from_dict on the json representation + project_list_model_dict = ProjectList.from_dict(project_list_model_json).__dict__ + project_list_model2 = ProjectList(**project_list_model_dict) + + # Verify the model instances are equivalent + assert project_list_model == project_list_model2 + + # Convert model instance back to dict and verify no loss of data + project_list_model_json2 = project_list_model.to_dict() + assert project_list_model_json2 == project_list_model_json + + +class TestModel_Secret: + """ + Test Class for Secret + """ + + def test_secret_serialization(self): + """ + Test serialization/deserialization for Secret + """ + + # Construct a json representation of a Secret model + secret_model_json = {} + secret_model_json['created_at'] = '2022-09-13T11:41:35+02:00' + secret_model_json['data'] = {'key1': 'testString'} + secret_model_json['entity_tag'] = '2385407409' + secret_model_json['format'] = 'generic' + secret_model_json[ + 'href' + ] = 'https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret' + secret_model_json['id'] = 'e33b1cv7-7390-4437-a5c2-130d5ccdddc3' + secret_model_json['name'] = 'my-secret' + secret_model_json['project_id'] = '4e49b3e0-27a8-48d2-a784-c7ee48bb863b' + secret_model_json['resource_type'] = 'testString' + + # Construct a model instance of Secret by calling from_dict on the json representation + secret_model = Secret.from_dict(secret_model_json) + assert secret_model != False + + # Construct a model instance of Secret by calling from_dict on the json representation + secret_model_dict = Secret.from_dict(secret_model_json).__dict__ + secret_model2 = Secret(**secret_model_dict) + + # Verify the model instances are equivalent + assert secret_model == secret_model2 + + # Convert model instance back to dict and verify no loss of data + secret_model_json2 = secret_model.to_dict() + assert secret_model_json2 == secret_model_json + + +class TestModel_SecretList: + """ + Test Class for SecretList + """ + + def test_secret_list_serialization(self): + """ + Test serialization/deserialization for SecretList + """ + + # Construct dict forms of any model objects needed in order to build this model. + + list_first_metadata_model = {} # ListFirstMetadata + list_first_metadata_model['href'] = 'testString' + + list_next_metadata_model = {} # ListNextMetadata + list_next_metadata_model['href'] = 'testString' + list_next_metadata_model['start'] = 'testString' + + secret_model = {} # Secret + secret_model['created_at'] = '2022-11-15T21:59:08+01:00' + secret_model['data'] = {'key1': 'testString'} + secret_model['entity_tag'] = '2386255530' + secret_model['format'] = 'generic' + secret_model[ + 'href' + ] = 'https://api.us-east.codeengine.cloud.ibm.com/v2/projects/230828b4-4f15-40a9-b183-1268c6ab88d5/secrets/my-secret' + secret_model['id'] = '36e3a621-4895-4bd1-b7e8-1163ab49a28f' + secret_model['name'] = 'my-secret' + secret_model['project_id'] = '230828b4-4f15-40a9-b183-1268c6ab88d5' + secret_model['resource_type'] = 'secret_generic_v2' + + # Construct a json representation of a SecretList model + secret_list_model_json = {} + secret_list_model_json['first'] = list_first_metadata_model + secret_list_model_json['limit'] = 100 + secret_list_model_json['next'] = list_next_metadata_model + secret_list_model_json['secrets'] = [secret_model] + + # Construct a model instance of SecretList by calling from_dict on the json representation + secret_list_model = SecretList.from_dict(secret_list_model_json) + assert secret_list_model != False + + # Construct a model instance of SecretList by calling from_dict on the json representation + secret_list_model_dict = SecretList.from_dict(secret_list_model_json).__dict__ + secret_list_model2 = SecretList(**secret_list_model_dict) + + # Verify the model instances are equivalent + assert secret_list_model == secret_list_model2 + + # Convert model instance back to dict and verify no loss of data + secret_list_model_json2 = secret_list_model.to_dict() + assert secret_list_model_json2 == secret_list_model_json + + +class TestModel_VolumeMount: + """ + Test Class for VolumeMount + """ + + def test_volume_mount_serialization(self): + """ + Test serialization/deserialization for VolumeMount + """ + + # Construct a json representation of a VolumeMount model + volume_mount_model_json = {} + volume_mount_model_json['mount_path'] = '/app' + volume_mount_model_json['name'] = 'codeengine-mount-b69u90' + volume_mount_model_json['reference'] = 'my-secret' + volume_mount_model_json['type'] = 'secret' + + # Construct a model instance of VolumeMount by calling from_dict on the json representation + volume_mount_model = VolumeMount.from_dict(volume_mount_model_json) + assert volume_mount_model != False + + # Construct a model instance of VolumeMount by calling from_dict on the json representation + volume_mount_model_dict = VolumeMount.from_dict(volume_mount_model_json).__dict__ + volume_mount_model2 = VolumeMount(**volume_mount_model_dict) + + # Verify the model instances are equivalent + assert volume_mount_model == volume_mount_model2 + + # Convert model instance back to dict and verify no loss of data + volume_mount_model_json2 = volume_mount_model.to_dict() + assert volume_mount_model_json2 == volume_mount_model_json + + +class TestModel_VolumeMountPrototype: + """ + Test Class for VolumeMountPrototype + """ + + def test_volume_mount_prototype_serialization(self): + """ + Test serialization/deserialization for VolumeMountPrototype + """ + + # Construct a json representation of a VolumeMountPrototype model + volume_mount_prototype_model_json = {} + volume_mount_prototype_model_json['mount_path'] = '/app' + volume_mount_prototype_model_json['name'] = 'codeengine-mount-b69u90' + volume_mount_prototype_model_json['reference'] = 'my-secret' + volume_mount_prototype_model_json['type'] = 'secret' + + # Construct a model instance of VolumeMountPrototype by calling from_dict on the json representation + volume_mount_prototype_model = VolumeMountPrototype.from_dict(volume_mount_prototype_model_json) + assert volume_mount_prototype_model != False + + # Construct a model instance of VolumeMountPrototype by calling from_dict on the json representation + volume_mount_prototype_model_dict = VolumeMountPrototype.from_dict(volume_mount_prototype_model_json).__dict__ + volume_mount_prototype_model2 = VolumeMountPrototype(**volume_mount_prototype_model_dict) + + # Verify the model instances are equivalent + assert volume_mount_prototype_model == volume_mount_prototype_model2 + + # Convert model instance back to dict and verify no loss of data + volume_mount_prototype_model_json2 = volume_mount_prototype_model.to_dict() + assert volume_mount_prototype_model_json2 == volume_mount_prototype_model_json + + +# endregion +############################################################################## +# End of Model Tests +############################################################################## diff --git a/test/unit/test_common.py b/test/unit/test_common.py index 1425b13..93ec19b 100644 --- a/test/unit/test_common.py +++ b/test/unit/test_common.py @@ -21,6 +21,7 @@ import unittest from ibm_code_engine_sdk import common + class TestCommon(unittest.TestCase): """ Test methods in the common module @@ -30,7 +31,9 @@ def test_get_sdk_headers(self): """ Test the get_sdk_headers method """ - headers = common.get_sdk_headers(service_name='example_service', service_version='V1', operation_id='operation1') + headers = common.get_sdk_headers( + service_name='example_service', service_version='V1', operation_id='operation1' + ) self.assertIsNotNone(headers) self.assertIsNotNone(headers.get('User-Agent')) self.assertIn('code-engine-python-sdk', headers.get('User-Agent')) diff --git a/test/unit/test_ibm_cloud_code_engine_v1.py b/test/unit/test_ibm_cloud_code_engine_v1.py index 95955ae..1cf8520 100644 --- a/test/unit/test_ibm_cloud_code_engine_v1.py +++ b/test/unit/test_ibm_cloud_code_engine_v1.py @@ -27,9 +27,7 @@ from ibm_code_engine_sdk.ibm_cloud_code_engine_v1 import * -service = IbmCloudCodeEngineV1( - authenticator=NoAuthAuthenticator() - ) +service = IbmCloudCodeEngineV1(authenticator=NoAuthAuthenticator()) base_url = 'https://ibm-cloud-code-engine.cloud.ibm.com/api/v1' service.set_service_url(base_url) @@ -39,7 +37,8 @@ ############################################################################## # region -class TestListKubeconfig(): + +class TestListKubeconfig: """ Test Class for list_kubeconfig """ @@ -61,11 +60,7 @@ def test_list_kubeconfig_all_params(self): # Set up mock url = self.preprocess_url(base_url + '/namespaces/testString/config') mock_response = '"operation_response"' - responses.add(responses.GET, - url, - body=mock_response, - content_type='text/plain', - status=200) + responses.add(responses.GET, url, body=mock_response, content_type='text/plain', status=200) # Set up parameter values refresh_token = 'testString' @@ -73,18 +68,12 @@ def test_list_kubeconfig_all_params(self): accept = 'text/plain' # Invoke method - response = service.list_kubeconfig( - refresh_token, - id, - accept=accept, - headers={} - ) + response = service.list_kubeconfig(refresh_token, id, accept=accept, headers={}) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 - @responses.activate def test_list_kubeconfig_required_params(self): """ @@ -93,28 +82,19 @@ def test_list_kubeconfig_required_params(self): # Set up mock url = self.preprocess_url(base_url + '/namespaces/testString/config') mock_response = '"operation_response"' - responses.add(responses.GET, - url, - body=mock_response, - content_type='text/plain', - status=200) + responses.add(responses.GET, url, body=mock_response, content_type='text/plain', status=200) # Set up parameter values refresh_token = 'testString' id = 'testString' # Invoke method - response = service.list_kubeconfig( - refresh_token, - id, - headers={} - ) + response = service.list_kubeconfig(refresh_token, id, headers={}) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 - @responses.activate def test_list_kubeconfig_value_error(self): """ @@ -123,11 +103,7 @@ def test_list_kubeconfig_value_error(self): # Set up mock url = self.preprocess_url(base_url + '/namespaces/testString/config') mock_response = '"operation_response"' - responses.add(responses.GET, - url, - body=mock_response, - content_type='text/plain', - status=200) + responses.add(responses.GET, url, body=mock_response, content_type='text/plain', status=200) # Set up parameter values refresh_token = 'testString' @@ -139,13 +115,12 @@ def test_list_kubeconfig_value_error(self): "id": id, } for param in req_param_dict.keys(): - req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): service.list_kubeconfig(**req_copy) - -class TestGetKubeconfig(): +class TestGetKubeconfig: """ Test Class for get_kubeconfig """ @@ -167,11 +142,7 @@ def test_get_kubeconfig_all_params(self): # Set up mock url = self.preprocess_url(base_url + '/project/testString/config') mock_response = '"operation_response"' - responses.add(responses.GET, - url, - body=mock_response, - content_type='text/plain', - status=200) + responses.add(responses.GET, url, body=mock_response, content_type='text/plain', status=200) # Set up parameter values x_delegated_refresh_token = 'testString' @@ -179,18 +150,12 @@ def test_get_kubeconfig_all_params(self): accept = 'text/plain' # Invoke method - response = service.get_kubeconfig( - x_delegated_refresh_token, - id, - accept=accept, - headers={} - ) + response = service.get_kubeconfig(x_delegated_refresh_token, id, accept=accept, headers={}) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 - @responses.activate def test_get_kubeconfig_required_params(self): """ @@ -199,28 +164,19 @@ def test_get_kubeconfig_required_params(self): # Set up mock url = self.preprocess_url(base_url + '/project/testString/config') mock_response = '"operation_response"' - responses.add(responses.GET, - url, - body=mock_response, - content_type='text/plain', - status=200) + responses.add(responses.GET, url, body=mock_response, content_type='text/plain', status=200) # Set up parameter values x_delegated_refresh_token = 'testString' id = 'testString' # Invoke method - response = service.get_kubeconfig( - x_delegated_refresh_token, - id, - headers={} - ) + response = service.get_kubeconfig(x_delegated_refresh_token, id, headers={}) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 - @responses.activate def test_get_kubeconfig_value_error(self): """ @@ -229,11 +185,7 @@ def test_get_kubeconfig_value_error(self): # Set up mock url = self.preprocess_url(base_url + '/project/testString/config') mock_response = '"operation_response"' - responses.add(responses.GET, - url, - body=mock_response, - content_type='text/plain', - status=200) + responses.add(responses.GET, url, body=mock_response, content_type='text/plain', status=200) # Set up parameter values x_delegated_refresh_token = 'testString' @@ -245,12 +197,11 @@ def test_get_kubeconfig_value_error(self): "id": id, } for param in req_param_dict.keys(): - req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): service.get_kubeconfig(**req_copy) - # endregion ############################################################################## # End of Service: GetKubeconfig From 1f63e6e2b9830970ab9f3fe7ace2a9639eaadaa9 Mon Sep 17 00:00:00 2001 From: Enrico Regge Date: Sat, 21 Jan 2023 00:00:41 +0100 Subject: [PATCH 04/22] feat(build): added v2 integration tests * feat(test): added v2 integration tests * adjusted python version * fix(build) fixed linter warnings --- .gitignore | 5 +- .travis.yml | 15 +- .travis_public.yml | 51 ++ README.md | 6 +- test/integration/test_v2.py | 1020 +++++++++++++++++++++++++++++++++++ 5 files changed, 1086 insertions(+), 11 deletions(-) create mode 100644 .travis_public.yml create mode 100644 test/integration/test_v2.py diff --git a/.gitignore b/.gitignore index 0420b4f..8c833cb 100644 --- a/.gitignore +++ b/.gitignore @@ -79,4 +79,7 @@ swagger.json # files produced by "npm install" commands during build package-lock.json -node_modules/ \ No newline at end of file +node_modules/ + +# ignore the generated integration test files, as they cannot be used without manual editing +integration/test_code_engine_v2.py \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 549b5cd..e591fde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ dist: bionic language: python +python: + - "3.11" cache: pip @@ -12,12 +14,12 @@ branches: notifications: email: true -matrix: - include: - - python: 3.7 - - python: 3.8 - - python: 3.9 - - python: 3.10 +before_install: +# create an .env file that is pulled in while executing the v2 integration tests +- echo "CODE_ENGINE_URL=https://$CE_API_HOST/v2" > code_engine_v2.env +- echo "CODE_ENGINE_AUTH_TYPE=iam" >> code_engine_v2.env +- echo "CODE_ENGINE_APIKEY=$CE_API_KEY" >> code_engine_v2.env +- echo "CODE_ENGINE_AUTH_URL=$IAM_ENDPOINT" >> code_engine_v2.env install: - sudo apt-get update @@ -28,6 +30,7 @@ install: script: - make ci +- make test-int before_deploy: - nvm install 14 diff --git a/.travis_public.yml b/.travis_public.yml new file mode 100644 index 0000000..549b5cd --- /dev/null +++ b/.travis_public.yml @@ -0,0 +1,51 @@ +dist: bionic + +language: python + +cache: pip + +# Only run on main (still tests PRs) +branches: + only: + - main + +notifications: + email: true + +matrix: + include: + - python: 3.7 + - python: 3.8 + - python: 3.9 + - python: 3.10 + +install: +- sudo apt-get update +- sudo apt-get install pandoc +- pip install pypandoc +- echo -e "machine github.ibm.com\n login $GITHUB_OAUTH_TOKEN" > ~/.netrc +- pip install setuptools=="60.8.2" + +script: +- make ci + +before_deploy: +- nvm install 14 +- npm install +- pip install bump2version + +deploy: +- provider: script + script: npm run semantic-release + skip_cleanup: true + on: + python: '3.7' + branch: main +- provider: pypi + user: __token__ + password: $PYPI_TOKEN + repository: https://upload.pypi.org/legacy + skip_cleanup: true + on: + python: '3.7' + tags: true \ No newline at end of file diff --git a/README.md b/README.md index 40d1989..b46ac0e 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,6 @@ Python client library to interact with the [IBM Cloud Code Engine API](https://cloud.ibm.com/apidocs/codeengine). -Disclaimer: this SDK is being released initially as a **pre-release** version. -Changes might occur which impact applications that use this SDK. - ## Table of Contents -# Python SDK for IBM Cloud Code Engine 0.1.0 +# Python SDK for IBM Cloud Code Engine 1.0.0 Python client library to interact with the [IBM Cloud Code Engine API](https://cloud.ibm.com/apidocs/codeengine). @@ -55,13 +55,13 @@ Service Name | Imported Class Name To install, use `pip` or `easy_install`: ```bash -pip install --upgrade "ibm_code_engine_sdk>=0.1.0" +pip install --upgrade "ibm_code_engine_sdk>=1.0.0" ``` or ```bash -easy_install --upgrade "ibm_code_engine_sdk>=0.1.0" +easy_install --upgrade "ibm_code_engine_sdk>=1.0.0" ``` ## Using the SDK diff --git a/ibm_code_engine_sdk/version.py b/ibm_code_engine_sdk/version.py index fbeddf6..de62c50 100644 --- a/ibm_code_engine_sdk/version.py +++ b/ibm_code_engine_sdk/version.py @@ -17,4 +17,4 @@ """ Version of ibm_code_engine_sdk """ -__version__ = '0.1.0' +__version__ = '1.0.0' diff --git a/setup.py b/setup.py index c73de9b..cc08fd6 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import sys import pkg_resources -__version__ = '0.1.0' +__version__ = '1.0.0' PACKAGE_NAME = 'ibm_code_engine_sdk' PACKAGE_DESC = 'Python SDK for IBM Cloud Code Engine' From 6acb89416e03948fcb92919b0bc1054d04617b76 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sat, 21 Jan 2023 14:34:04 +0000 Subject: [PATCH 09/22] chore(release): 1.0.0 release notes # [1.0.0](https://github.ibm.com/coligo/python-sdk/compare/v0.1.0...v1.0.0) (2023-01-21) ### Features * **build:** release v1 ([#6](https://github.ibm.com/coligo/python-sdk/issues/6)) ([160b7d1](https://github.ibm.com/coligo/python-sdk/commit/160b7d1ac4855a0eb7e6c534c2acb500fa65695f)) ### BREAKING CHANGES * **build:** marks v1.0.0 of this repository --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2e56fc8 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# [1.0.0](https://github.ibm.com/coligo/python-sdk/compare/v0.1.0...v1.0.0) (2023-01-21) + + +### Features + +* **build:** release v1 ([#6](https://github.ibm.com/coligo/python-sdk/issues/6)) ([160b7d1](https://github.ibm.com/coligo/python-sdk/commit/160b7d1ac4855a0eb7e6c534c2acb500fa65695f)) + + +### BREAKING CHANGES + +* **build:** marks v1.0.0 of this repository From b5eea1399e835a3b913add7687e05ed376e87031 Mon Sep 17 00:00:00 2001 From: Enrico Regge Date: Tue, 24 Jan 2023 23:03:22 +0100 Subject: [PATCH 10/22] feat(ci): ready for v2 (#7) BREAKING CHANGE: v2.0.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28fcddd..1861a47 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Service Name | Imported Class Name * An [IBM Cloud][ibm-cloud-onboarding] account. * An IAM API key to allow the SDK to access your account. Create one [here](https://cloud.ibm.com/iam/apikeys). -* Python 3.6 or above. +* Python 3.7 or above. ## Installation From b6b02c1950be60a5a3aef359e70e6c41075b8a31 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 24 Jan 2023 22:06:29 +0000 Subject: [PATCH 11/22] Update version 1.0.0 -> 2.0.0 --- .bumpversion.cfg | 2 +- README.md | 8 ++++---- ibm_code_engine_sdk/version.py | 2 +- setup.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index ddf691a..8987aad 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.0.0 +current_version = 2.0.0 commit = True message = Update version {current_version} -> {new_version} diff --git a/README.md b/README.md index 1861a47..755ee70 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -# Python SDK for IBM Cloud Code Engine 1.0.0 +# Python SDK for IBM Cloud Code Engine 2.0.0 Python client library to interact with the [IBM Cloud Code Engine API](https://cloud.ibm.com/apidocs/codeengine). @@ -40,7 +40,7 @@ IBM Cloud services: Service Name | Imported Class Name --- | --- [IBM Cloud Code Engine V2](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.0) | CodeEngineV2 -[IBM Cloud Code Engine V1](https://cloud.ibm.com/apidocs/codeengine/codeengine-v1.0.0) | IbmCloudCodeEngineV1 +[IBM Cloud Code Engine V1](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.0) | IbmCloudCodeEngineV1 ## Prerequisites @@ -55,13 +55,13 @@ Service Name | Imported Class Name To install, use `pip` or `easy_install`: ```bash -pip install --upgrade "ibm_code_engine_sdk>=1.0.0" +pip install --upgrade "ibm_code_engine_sdk>=2.0.0" ``` or ```bash -easy_install --upgrade "ibm_code_engine_sdk>=1.0.0" +easy_install --upgrade "ibm_code_engine_sdk>=2.0.0" ``` ## Using the SDK diff --git a/ibm_code_engine_sdk/version.py b/ibm_code_engine_sdk/version.py index de62c50..16021b3 100644 --- a/ibm_code_engine_sdk/version.py +++ b/ibm_code_engine_sdk/version.py @@ -17,4 +17,4 @@ """ Version of ibm_code_engine_sdk """ -__version__ = '1.0.0' +__version__ = '2.0.0' diff --git a/setup.py b/setup.py index cc08fd6..86a0a9d 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import sys import pkg_resources -__version__ = '1.0.0' +__version__ = '2.0.0' PACKAGE_NAME = 'ibm_code_engine_sdk' PACKAGE_DESC = 'Python SDK for IBM Cloud Code Engine' From 255db69171d5d4a1b1d7c35cb62c8d22d6b65e13 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 24 Jan 2023 22:06:29 +0000 Subject: [PATCH 12/22] chore(release): 2.0.0 release notes # [2.0.0](https://github.ibm.com/coligo/python-sdk/compare/v1.0.0...v2.0.0) (2023-01-24) ### Features * **ci:** ready for v2 ([#7](https://github.ibm.com/coligo/python-sdk/issues/7)) ([b5eea13](https://github.ibm.com/coligo/python-sdk/commit/b5eea1399e835a3b913add7687e05ed376e87031)) ### BREAKING CHANGES * **ci:** v2.0.0 --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e56fc8..6d4e9aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# [2.0.0](https://github.ibm.com/coligo/python-sdk/compare/v1.0.0...v2.0.0) (2023-01-24) + + +### Features + +* **ci:** ready for v2 ([#7](https://github.ibm.com/coligo/python-sdk/issues/7)) ([b5eea13](https://github.ibm.com/coligo/python-sdk/commit/b5eea1399e835a3b913add7687e05ed376e87031)) + + +### BREAKING CHANGES + +* **ci:** v2.0.0 + # [1.0.0](https://github.ibm.com/coligo/python-sdk/compare/v0.1.0...v1.0.0) (2023-01-21) From 729d82b3fb1bf8e0b550041451d05a3c1d78f80d Mon Sep 17 00:00:00 2001 From: Enrico Regge Date: Wed, 25 Jan 2023 14:39:49 +0100 Subject: [PATCH 13/22] fix(ci): added encrypted pypi deploy key (#8) --- .travis_public.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis_public.yml b/.travis_public.yml index 7a74f8a..2ab02dd 100644 --- a/.travis_public.yml +++ b/.travis_public.yml @@ -32,7 +32,8 @@ script: deploy: - provider: pypi user: __token__ - password: $PYPI_TOKEN + password: + secure: lUZvqL7OY4b6JsZ3w8lbRzx3e1xPGdCaV2eXTZ/fTy+soRWSe8PayK8YkC9oNa9SuNDpJ1n2w24sq24O2KMsjhw7mpJHLPOR9Yj2hVlWL1GSvAT3huI0j4PnBc6LAGXqtFBF2YYr4mIFNV5Zx8WJ0GOT4JNZIaH7M1HrnK224aOkUFNaZXP/a0bwBI9uWFKPLbRoggoYtKU1z7SM18+OINSZOSPzHIyl6ng41pdEWLsdkP+3zt29+LbARMIsocOJ6tLXeM6Dn8G5IxZ9pvJk+royo4MTIKJ1k7QN5s2x19mZoM6SrC/loxSfAFjgypxRDlXK43OWOMRrKnfj7RVl5fW3TIi1RoAq6T6ciC8Yv80ZUr6tIMcBWGkpi7Pbfsc1Z9toYeoGwdc8VSgnl97+Oj8M4WsT03Wc9/Gnlr0MGG1jzUoCH58HjK0ATIP1r5g+KBSHWyJtksonnPXk/JepQQPxDCa6zB2vZz7MnAXTc3hg+6rWpxjy+RpIkmLq2pt5gJZhUnOafLaTsLiCvrD7K6/8wa2FfViK4105y7mVGy6k9Dgnb6HqhWQPdHGkbDiBZMi6NkNYMe3LuJ6Qkd0mKt3VHpJDLU5RRxF1WO9FaX832ER37u9+JCoJnbu4BevMWlkdVNJxqC+vN5yxgNU73/txYMwr52kRJXtcMt1PKMw= repository: https://upload.pypi.org/legacy skip_cleanup: true on: From 5128ded5bdb30effeac9cd64da77f29bb6dd3776 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 25 Jan 2023 13:43:26 +0000 Subject: [PATCH 14/22] Update version 2.0.0 -> 2.0.1 --- .bumpversion.cfg | 2 +- README.md | 10 +++++----- ibm_code_engine_sdk/version.py | 2 +- setup.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 8987aad..817fab5 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.0.0 +current_version = 2.0.1 commit = True message = Update version {current_version} -> {new_version} diff --git a/README.md b/README.md index 755ee70..1ab9d4d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -# Python SDK for IBM Cloud Code Engine 2.0.0 +# Python SDK for IBM Cloud Code Engine 2.0.1 Python client library to interact with the [IBM Cloud Code Engine API](https://cloud.ibm.com/apidocs/codeengine). @@ -39,8 +39,8 @@ IBM Cloud services: Service Name | Imported Class Name --- | --- -[IBM Cloud Code Engine V2](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.0) | CodeEngineV2 -[IBM Cloud Code Engine V1](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.0) | IbmCloudCodeEngineV1 +[IBM Cloud Code Engine V2](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.1) | CodeEngineV2 +[IBM Cloud Code Engine V1](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.1) | IbmCloudCodeEngineV1 ## Prerequisites @@ -55,13 +55,13 @@ Service Name | Imported Class Name To install, use `pip` or `easy_install`: ```bash -pip install --upgrade "ibm_code_engine_sdk>=2.0.0" +pip install --upgrade "ibm_code_engine_sdk>=2.0.1" ``` or ```bash -easy_install --upgrade "ibm_code_engine_sdk>=2.0.0" +easy_install --upgrade "ibm_code_engine_sdk>=2.0.1" ``` ## Using the SDK diff --git a/ibm_code_engine_sdk/version.py b/ibm_code_engine_sdk/version.py index 16021b3..2c48adb 100644 --- a/ibm_code_engine_sdk/version.py +++ b/ibm_code_engine_sdk/version.py @@ -17,4 +17,4 @@ """ Version of ibm_code_engine_sdk """ -__version__ = '2.0.0' +__version__ = '2.0.1' diff --git a/setup.py b/setup.py index 86a0a9d..58ecca3 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import sys import pkg_resources -__version__ = '2.0.0' +__version__ = '2.0.1' PACKAGE_NAME = 'ibm_code_engine_sdk' PACKAGE_DESC = 'Python SDK for IBM Cloud Code Engine' From 320cef29e4a87d673d8619e3963e15d8119f4844 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 25 Jan 2023 13:43:27 +0000 Subject: [PATCH 15/22] chore(release): 2.0.1 release notes ## [2.0.1](https://github.ibm.com/coligo/python-sdk/compare/v2.0.0...v2.0.1) (2023-01-25) ### Bug Fixes * **ci:** added encrypted pypi deploy key ([#8](https://github.ibm.com/coligo/python-sdk/issues/8)) ([729d82b](https://github.ibm.com/coligo/python-sdk/commit/729d82b3fb1bf8e0b550041451d05a3c1d78f80d)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d4e9aa..8885883 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.0.1](https://github.ibm.com/coligo/python-sdk/compare/v2.0.0...v2.0.1) (2023-01-25) + + +### Bug Fixes + +* **ci:** added encrypted pypi deploy key ([#8](https://github.ibm.com/coligo/python-sdk/issues/8)) ([729d82b](https://github.ibm.com/coligo/python-sdk/commit/729d82b3fb1bf8e0b550041451d05a3c1d78f80d)) + # [2.0.0](https://github.ibm.com/coligo/python-sdk/compare/v1.0.0...v2.0.0) (2023-01-24) From dc9e46e2eb4544f2af6e24d607309a422a801a66 Mon Sep 17 00:00:00 2001 From: REGGEENR Date: Wed, 25 Jan 2023 15:15:51 +0100 Subject: [PATCH 16/22] fix(ci): adjusted branch configuration of travis --- .travis_public.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis_public.yml b/.travis_public.yml index 2ab02dd..d7128e6 100644 --- a/.travis_public.yml +++ b/.travis_public.yml @@ -8,6 +8,7 @@ cache: pip branches: only: - main + - /v\d+.\d+.\d+/ notifications: email: true From b887f5306c6e558bdc53726d0a3c50ba55c1c80d Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 25 Jan 2023 14:18:40 +0000 Subject: [PATCH 17/22] Update version 2.0.1 -> 2.0.2 --- .bumpversion.cfg | 2 +- README.md | 10 +++++----- ibm_code_engine_sdk/version.py | 2 +- setup.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 817fab5..f32b74b 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.0.1 +current_version = 2.0.2 commit = True message = Update version {current_version} -> {new_version} diff --git a/README.md b/README.md index 1ab9d4d..9f55561 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -# Python SDK for IBM Cloud Code Engine 2.0.1 +# Python SDK for IBM Cloud Code Engine 2.0.2 Python client library to interact with the [IBM Cloud Code Engine API](https://cloud.ibm.com/apidocs/codeengine). @@ -39,8 +39,8 @@ IBM Cloud services: Service Name | Imported Class Name --- | --- -[IBM Cloud Code Engine V2](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.1) | CodeEngineV2 -[IBM Cloud Code Engine V1](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.1) | IbmCloudCodeEngineV1 +[IBM Cloud Code Engine V2](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.2) | CodeEngineV2 +[IBM Cloud Code Engine V1](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.2) | IbmCloudCodeEngineV1 ## Prerequisites @@ -55,13 +55,13 @@ Service Name | Imported Class Name To install, use `pip` or `easy_install`: ```bash -pip install --upgrade "ibm_code_engine_sdk>=2.0.1" +pip install --upgrade "ibm_code_engine_sdk>=2.0.2" ``` or ```bash -easy_install --upgrade "ibm_code_engine_sdk>=2.0.1" +easy_install --upgrade "ibm_code_engine_sdk>=2.0.2" ``` ## Using the SDK diff --git a/ibm_code_engine_sdk/version.py b/ibm_code_engine_sdk/version.py index 2c48adb..521ee93 100644 --- a/ibm_code_engine_sdk/version.py +++ b/ibm_code_engine_sdk/version.py @@ -17,4 +17,4 @@ """ Version of ibm_code_engine_sdk """ -__version__ = '2.0.1' +__version__ = '2.0.2' diff --git a/setup.py b/setup.py index 58ecca3..cb27e02 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import sys import pkg_resources -__version__ = '2.0.1' +__version__ = '2.0.2' PACKAGE_NAME = 'ibm_code_engine_sdk' PACKAGE_DESC = 'Python SDK for IBM Cloud Code Engine' From f49172fe3df2af657f0dee60787f0b4ab25e6589 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 25 Jan 2023 14:18:40 +0000 Subject: [PATCH 18/22] chore(release): 2.0.2 release notes ## [2.0.2](https://github.ibm.com/coligo/python-sdk/compare/v2.0.1...v2.0.2) (2023-01-25) ### Bug Fixes * **ci:** adjusted branch configuration of travis ([dc9e46e](https://github.ibm.com/coligo/python-sdk/commit/dc9e46e2eb4544f2af6e24d607309a422a801a66)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8885883..57304a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.0.2](https://github.ibm.com/coligo/python-sdk/compare/v2.0.1...v2.0.2) (2023-01-25) + + +### Bug Fixes + +* **ci:** adjusted branch configuration of travis ([dc9e46e](https://github.ibm.com/coligo/python-sdk/commit/dc9e46e2eb4544f2af6e24d607309a422a801a66)) + ## [2.0.1](https://github.ibm.com/coligo/python-sdk/compare/v2.0.0...v2.0.1) (2023-01-25) From ecfc0bad61bb7ae88bbbcfdf2326055715febd2f Mon Sep 17 00:00:00 2001 From: REGGEENR Date: Wed, 25 Jan 2023 17:05:51 +0100 Subject: [PATCH 19/22] fix(ci): updated pypi token --- .travis_public.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis_public.yml b/.travis_public.yml index d7128e6..a2cfab5 100644 --- a/.travis_public.yml +++ b/.travis_public.yml @@ -34,7 +34,7 @@ deploy: - provider: pypi user: __token__ password: - secure: lUZvqL7OY4b6JsZ3w8lbRzx3e1xPGdCaV2eXTZ/fTy+soRWSe8PayK8YkC9oNa9SuNDpJ1n2w24sq24O2KMsjhw7mpJHLPOR9Yj2hVlWL1GSvAT3huI0j4PnBc6LAGXqtFBF2YYr4mIFNV5Zx8WJ0GOT4JNZIaH7M1HrnK224aOkUFNaZXP/a0bwBI9uWFKPLbRoggoYtKU1z7SM18+OINSZOSPzHIyl6ng41pdEWLsdkP+3zt29+LbARMIsocOJ6tLXeM6Dn8G5IxZ9pvJk+royo4MTIKJ1k7QN5s2x19mZoM6SrC/loxSfAFjgypxRDlXK43OWOMRrKnfj7RVl5fW3TIi1RoAq6T6ciC8Yv80ZUr6tIMcBWGkpi7Pbfsc1Z9toYeoGwdc8VSgnl97+Oj8M4WsT03Wc9/Gnlr0MGG1jzUoCH58HjK0ATIP1r5g+KBSHWyJtksonnPXk/JepQQPxDCa6zB2vZz7MnAXTc3hg+6rWpxjy+RpIkmLq2pt5gJZhUnOafLaTsLiCvrD7K6/8wa2FfViK4105y7mVGy6k9Dgnb6HqhWQPdHGkbDiBZMi6NkNYMe3LuJ6Qkd0mKt3VHpJDLU5RRxF1WO9FaX832ER37u9+JCoJnbu4BevMWlkdVNJxqC+vN5yxgNU73/txYMwr52kRJXtcMt1PKMw= + secure: H6pxBCHf26B/9qi/3I6W7NkXnSwbPq04GiD06/z6MfZZkM2QQhbwFvDE55BrLhDskbpSEDNH18JuHMlDKu/ihNjDGw7dVnMTjs1/Uf1QlbrZRRtMhQBp3OuVRmE1mPc1PfYyYZlfqDQZkV6oz7NHI69x6Nz68Ltq6S+FaTT/8C72MoF3E4+ea6i/m8FRrxL6XS4ak7eXP1sKWPg3Sf7uEFwYsAWI/gcpjw2mnrqNCJWXkQmbVwWawo1GbfvIAs7ykhWkyZL+heuagdTmE9XEnnXrInp+U9ean5TcS1RMtDHzfB1TndVDxzZQBPwpXR7CdJcBft/NI2h/qA9xQr2DeC5BVLe5UvlPjIQ8KPK6wy2HOi2XwvXJZ3AVRyXPhujr3eLe8wFW/g9k/RPqs1ptwMYSav62gaPzZQzt3fj4dqLblj+nlZE+pAPS1K4Yr+vDQ6JqPhvK4e3f/kg64BjgDdM5aHPWsAvRaMZ6elS3N1v3I5bDxcS0YkdHtbESJUyI/72BZL8svYFOiUi5kmYGM+/VizBE1Ld2nRFH4MpGAQn0AmoR/Wr0WViEQCNoSRHswZxqidudi/tNuMx/w/P/tx8b34s0A1YG/638jaNnIYyWseBSyY465GzgzLbKe4//qO4G38PCieWqP55aULPNDdddFrW02hzwQ/U/PznI8hg= repository: https://upload.pypi.org/legacy skip_cleanup: true on: From 95d70261e45081c694c46b1ad30a5ab916834c05 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 25 Jan 2023 16:10:09 +0000 Subject: [PATCH 20/22] Update version 2.0.2 -> 2.0.3 --- .bumpversion.cfg | 2 +- README.md | 10 +++++----- ibm_code_engine_sdk/version.py | 2 +- setup.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index f32b74b..0d165dd 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.0.2 +current_version = 2.0.3 commit = True message = Update version {current_version} -> {new_version} diff --git a/README.md b/README.md index 9f55561..1d28e31 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -# Python SDK for IBM Cloud Code Engine 2.0.2 +# Python SDK for IBM Cloud Code Engine 2.0.3 Python client library to interact with the [IBM Cloud Code Engine API](https://cloud.ibm.com/apidocs/codeengine). @@ -39,8 +39,8 @@ IBM Cloud services: Service Name | Imported Class Name --- | --- -[IBM Cloud Code Engine V2](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.2) | CodeEngineV2 -[IBM Cloud Code Engine V1](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.2) | IbmCloudCodeEngineV1 +[IBM Cloud Code Engine V2](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.3) | CodeEngineV2 +[IBM Cloud Code Engine V1](https://cloud.ibm.com/apidocs/codeengine/codeengine-v2.0.3) | IbmCloudCodeEngineV1 ## Prerequisites @@ -55,13 +55,13 @@ Service Name | Imported Class Name To install, use `pip` or `easy_install`: ```bash -pip install --upgrade "ibm_code_engine_sdk>=2.0.2" +pip install --upgrade "ibm_code_engine_sdk>=2.0.3" ``` or ```bash -easy_install --upgrade "ibm_code_engine_sdk>=2.0.2" +easy_install --upgrade "ibm_code_engine_sdk>=2.0.3" ``` ## Using the SDK diff --git a/ibm_code_engine_sdk/version.py b/ibm_code_engine_sdk/version.py index 521ee93..5e0057c 100644 --- a/ibm_code_engine_sdk/version.py +++ b/ibm_code_engine_sdk/version.py @@ -17,4 +17,4 @@ """ Version of ibm_code_engine_sdk """ -__version__ = '2.0.2' +__version__ = '2.0.3' diff --git a/setup.py b/setup.py index cb27e02..0032ea2 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import sys import pkg_resources -__version__ = '2.0.2' +__version__ = '2.0.3' PACKAGE_NAME = 'ibm_code_engine_sdk' PACKAGE_DESC = 'Python SDK for IBM Cloud Code Engine' From e8578434f088a15979281b1ac1436fc8f56696ed Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 25 Jan 2023 16:10:09 +0000 Subject: [PATCH 21/22] chore(release): 2.0.3 release notes ## [2.0.3](https://github.ibm.com/coligo/python-sdk/compare/v2.0.2...v2.0.3) (2023-01-25) ### Bug Fixes * **ci:** updated pypi token ([ecfc0ba](https://github.ibm.com/coligo/python-sdk/commit/ecfc0bad61bb7ae88bbbcfdf2326055715febd2f)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57304a7..61d0819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.0.3](https://github.ibm.com/coligo/python-sdk/compare/v2.0.2...v2.0.3) (2023-01-25) + + +### Bug Fixes + +* **ci:** updated pypi token ([ecfc0ba](https://github.ibm.com/coligo/python-sdk/commit/ecfc0bad61bb7ae88bbbcfdf2326055715febd2f)) + ## [2.0.2](https://github.ibm.com/coligo/python-sdk/compare/v2.0.1...v2.0.2) (2023-01-25) From 4f3a840ce35f8c1feed254214dbabb8e7c710584 Mon Sep 17 00:00:00 2001 From: REGGEENR Date: Wed, 25 Jan 2023 17:21:19 +0100 Subject: [PATCH 22/22] SDK update 20230125-172119 Signed-off-by: REGGEENR --- .bumpversion.cfg | 16 --------- .npmrc | 1 - .releaserc | 23 ------------- .travis.yml | 32 ++++++++--------- .travis_public.yml | 42 ---------------------- CHANGELOG.md | 44 ------------------------ example/README.md | 57 ------------------------------ example/example.py | 65 ----------------------------------- example/example_deprecated.py | 52 ---------------------------- package.json | 15 -------- sdkgen_config.json | 6 ---- test-integration.sh | 29 ---------------- 12 files changed, 14 insertions(+), 368 deletions(-) delete mode 100644 .bumpversion.cfg delete mode 100644 .npmrc delete mode 100644 .releaserc delete mode 100644 .travis_public.yml delete mode 100644 CHANGELOG.md delete mode 100644 example/README.md delete mode 100644 example/example.py delete mode 100644 example/example_deprecated.py delete mode 100644 package.json delete mode 100644 sdkgen_config.json delete mode 100755 test-integration.sh diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index 0d165dd..0000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,16 +0,0 @@ -[bumpversion] -current_version = 2.0.3 -commit = True -message = Update version {current_version} -> {new_version} - -[bumpversion:file:ibm_code_engine_sdk/version.py] -search = __version__ = '{current_version}' -replace = __version__ = '{new_version}' - -[bumpversion:file:setup.py] -search = __version__ = '{current_version}' -replace = __version__ = '{new_version}' - -[bumpversion:file:README.md] -search = {current_version} -replace = {new_version} diff --git a/.npmrc b/.npmrc deleted file mode 100644 index 9cf9495..0000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -package-lock=false \ No newline at end of file diff --git a/.releaserc b/.releaserc deleted file mode 100644 index dcd2868..0000000 --- a/.releaserc +++ /dev/null @@ -1,23 +0,0 @@ -{ - "debug": true, - "branches": [ "main" ], - "plugins": [ - "@semantic-release/commit-analyzer", - "@semantic-release/release-notes-generator", - "@semantic-release/changelog", - [ - "@semantic-release/exec", - { - "prepareCmd": "bump2version --allow-dirty --current-version ${lastRelease.version} --new-version ${nextRelease.version} patch" - } - ], - [ - "@semantic-release/git", - { - "assets" : [ "CHANGELOG.md" ], - "message": "chore(release): ${nextRelease.version} release notes\n\n${nextRelease.notes}" - } - ], - "@semantic-release/github" - ] -} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 4b289b5..a2cfab5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ dist: bionic language: python -python: - - "3.11" cache: pip @@ -10,16 +8,17 @@ cache: pip branches: only: - main + - /v\d+.\d+.\d+/ notifications: email: true -before_install: -# create an .env file that is pulled in while executing the v2 integration tests -- echo "CODE_ENGINE_URL=https://$CE_API_HOST/v2" > code_engine_v2.env -- echo "CODE_ENGINE_AUTH_TYPE=iam" >> code_engine_v2.env -- echo "CODE_ENGINE_APIKEY=$CE_API_KEY" >> code_engine_v2.env -- echo "CODE_ENGINE_AUTH_URL=$IAM_ENDPOINT" >> code_engine_v2.env +matrix: + include: + - python: '3.7' + - python: '3.8' + - python: '3.9' + - python: '3.10' install: - sudo apt-get update @@ -30,17 +29,14 @@ install: script: - make ci -- make test-int - -before_deploy: -- nvm install 14 -- npm install -- pip install bump2version deploy: -# Use semantic release to create a tag and release on each commit to the main branch -- provider: script - script: npm run semantic-release +- provider: pypi + user: __token__ + password: + secure: H6pxBCHf26B/9qi/3I6W7NkXnSwbPq04GiD06/z6MfZZkM2QQhbwFvDE55BrLhDskbpSEDNH18JuHMlDKu/ihNjDGw7dVnMTjs1/Uf1QlbrZRRtMhQBp3OuVRmE1mPc1PfYyYZlfqDQZkV6oz7NHI69x6Nz68Ltq6S+FaTT/8C72MoF3E4+ea6i/m8FRrxL6XS4ak7eXP1sKWPg3Sf7uEFwYsAWI/gcpjw2mnrqNCJWXkQmbVwWawo1GbfvIAs7ykhWkyZL+heuagdTmE9XEnnXrInp+U9ean5TcS1RMtDHzfB1TndVDxzZQBPwpXR7CdJcBft/NI2h/qA9xQr2DeC5BVLe5UvlPjIQ8KPK6wy2HOi2XwvXJZ3AVRyXPhujr3eLe8wFW/g9k/RPqs1ptwMYSav62gaPzZQzt3fj4dqLblj+nlZE+pAPS1K4Yr+vDQ6JqPhvK4e3f/kg64BjgDdM5aHPWsAvRaMZ6elS3N1v3I5bDxcS0YkdHtbESJUyI/72BZL8svYFOiUi5kmYGM+/VizBE1Ld2nRFH4MpGAQn0AmoR/Wr0WViEQCNoSRHswZxqidudi/tNuMx/w/P/tx8b34s0A1YG/638jaNnIYyWseBSyY465GzgzLbKe4//qO4G38PCieWqP55aULPNDdddFrW02hzwQ/U/PznI8hg= + repository: https://upload.pypi.org/legacy skip_cleanup: true on: - branch: main \ No newline at end of file + python: '3.10' + tags: true \ No newline at end of file diff --git a/.travis_public.yml b/.travis_public.yml deleted file mode 100644 index a2cfab5..0000000 --- a/.travis_public.yml +++ /dev/null @@ -1,42 +0,0 @@ -dist: bionic - -language: python - -cache: pip - -# Only run on main (still tests PRs) -branches: - only: - - main - - /v\d+.\d+.\d+/ - -notifications: - email: true - -matrix: - include: - - python: '3.7' - - python: '3.8' - - python: '3.9' - - python: '3.10' - -install: -- sudo apt-get update -- sudo apt-get install pandoc -- pip install pypandoc -- echo -e "machine github.ibm.com\n login $GITHUB_OAUTH_TOKEN" > ~/.netrc -- pip install setuptools=="60.8.2" - -script: -- make ci - -deploy: -- provider: pypi - user: __token__ - password: - secure: H6pxBCHf26B/9qi/3I6W7NkXnSwbPq04GiD06/z6MfZZkM2QQhbwFvDE55BrLhDskbpSEDNH18JuHMlDKu/ihNjDGw7dVnMTjs1/Uf1QlbrZRRtMhQBp3OuVRmE1mPc1PfYyYZlfqDQZkV6oz7NHI69x6Nz68Ltq6S+FaTT/8C72MoF3E4+ea6i/m8FRrxL6XS4ak7eXP1sKWPg3Sf7uEFwYsAWI/gcpjw2mnrqNCJWXkQmbVwWawo1GbfvIAs7ykhWkyZL+heuagdTmE9XEnnXrInp+U9ean5TcS1RMtDHzfB1TndVDxzZQBPwpXR7CdJcBft/NI2h/qA9xQr2DeC5BVLe5UvlPjIQ8KPK6wy2HOi2XwvXJZ3AVRyXPhujr3eLe8wFW/g9k/RPqs1ptwMYSav62gaPzZQzt3fj4dqLblj+nlZE+pAPS1K4Yr+vDQ6JqPhvK4e3f/kg64BjgDdM5aHPWsAvRaMZ6elS3N1v3I5bDxcS0YkdHtbESJUyI/72BZL8svYFOiUi5kmYGM+/VizBE1Ld2nRFH4MpGAQn0AmoR/Wr0WViEQCNoSRHswZxqidudi/tNuMx/w/P/tx8b34s0A1YG/638jaNnIYyWseBSyY465GzgzLbKe4//qO4G38PCieWqP55aULPNDdddFrW02hzwQ/U/PznI8hg= - repository: https://upload.pypi.org/legacy - skip_cleanup: true - on: - python: '3.10' - tags: true \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 61d0819..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,44 +0,0 @@ -## [2.0.3](https://github.ibm.com/coligo/python-sdk/compare/v2.0.2...v2.0.3) (2023-01-25) - - -### Bug Fixes - -* **ci:** updated pypi token ([ecfc0ba](https://github.ibm.com/coligo/python-sdk/commit/ecfc0bad61bb7ae88bbbcfdf2326055715febd2f)) - -## [2.0.2](https://github.ibm.com/coligo/python-sdk/compare/v2.0.1...v2.0.2) (2023-01-25) - - -### Bug Fixes - -* **ci:** adjusted branch configuration of travis ([dc9e46e](https://github.ibm.com/coligo/python-sdk/commit/dc9e46e2eb4544f2af6e24d607309a422a801a66)) - -## [2.0.1](https://github.ibm.com/coligo/python-sdk/compare/v2.0.0...v2.0.1) (2023-01-25) - - -### Bug Fixes - -* **ci:** added encrypted pypi deploy key ([#8](https://github.ibm.com/coligo/python-sdk/issues/8)) ([729d82b](https://github.ibm.com/coligo/python-sdk/commit/729d82b3fb1bf8e0b550041451d05a3c1d78f80d)) - -# [2.0.0](https://github.ibm.com/coligo/python-sdk/compare/v1.0.0...v2.0.0) (2023-01-24) - - -### Features - -* **ci:** ready for v2 ([#7](https://github.ibm.com/coligo/python-sdk/issues/7)) ([b5eea13](https://github.ibm.com/coligo/python-sdk/commit/b5eea1399e835a3b913add7687e05ed376e87031)) - - -### BREAKING CHANGES - -* **ci:** v2.0.0 - -# [1.0.0](https://github.ibm.com/coligo/python-sdk/compare/v0.1.0...v1.0.0) (2023-01-21) - - -### Features - -* **build:** release v1 ([#6](https://github.ibm.com/coligo/python-sdk/issues/6)) ([160b7d1](https://github.ibm.com/coligo/python-sdk/commit/160b7d1ac4855a0eb7e6c534c2acb500fa65695f)) - - -### BREAKING CHANGES - -* **build:** marks v1.0.0 of this repository diff --git a/example/README.md b/example/README.md deleted file mode 100644 index 5c366b9..0000000 --- a/example/README.md +++ /dev/null @@ -1,57 +0,0 @@ -# Code Engine Python SDK Example - -## Running example.py - -To run the example, create a Code Engine project from the Console or Code Engine CLI, and run the following commands from this directory: -1. `pip install kubernetes` -2. `export CE_API_KEY=` -3. `export CE_PROJECT_ID=` -4. `export CE_PROJECT_REGION=` -5. `python example.py` - -Note: Requires Python 3.6 or later. - -## How-to - -### Set up an authenticator -```python -authenticator = IAMAuthenticator( - apikey=os.environ.get('CE_API_KEY'), - client_id='bx', - client_secret='bx', -) -``` - -### Set up a Code Engine client -```python -ce_client = IbmCloudCodeEngineV1(authenticator=authenticator) -ce_client.set_service_url( - 'https://api.' + os.environ.get('CE_PROJECT_REGION') + '.codeengine.cloud.ibm.com/api/v1' -) -``` - -### Use an HTTP library to get a Delegated Refresh Token from IAM -```python -iam_response = requests.post('https://iam.cloud.ibm.com/identity/token', headers={ - 'Content-Type': 'application/x-www-form-urlencoded' -}, data={ - 'grant_type': 'urn:ibm:params:oauth:grant-type:apikey', - 'apikey': os.environ.get('CE_API_KEY'), - 'response_type': 'delegated_refresh_token', - 'receiver_client_ids': 'ce', - 'delegated_refresh_token_expiry': '3600' -}) -delegated_refresh_token = iam_response.json()['delegated_refresh_token'] -``` - -### Use the Code Engine client to get a Kubernetes config -```python -kubeconfig_response = ce_client.get_kubeconfig( - x_delegated_refresh_token=delegated_refresh_token, - id=os.environ.get('CE_PROJECT_ID'), -) -kubeconfig_string = kubeconfig_response.get_result().content -``` - -## Deprecated endpoint -The `/namespaces/{id}/config` endpoint function, `list_kubeconfig()`, is deprecated, and will be removed before Code Engine is out of Beta. Please use the `get_kubeconfig()` function, demonstrated in the example above. diff --git a/example/example.py b/example/example.py deleted file mode 100644 index 168a691..0000000 --- a/example/example.py +++ /dev/null @@ -1,65 +0,0 @@ -""" -Example of IBM Cloud Code Engine SDK usage -""" - -import os -import tempfile -import kubernetes -import requests -import json -from ibm_code_engine_sdk.ibm_cloud_code_engine_v1 import IbmCloudCodeEngineV1 -from ibm_cloud_sdk_core.authenticators import IAMAuthenticator - -if ( - os.environ.get('CE_API_KEY') == None - or os.environ.get('CE_PROJECT_REGION') == None - or os.environ.get('CE_PROJECT_ID') == None -): - print( - 'You must set the envrionment variables CE_API_KEY, CE_PROJECT_REGION and CE_PROJECT_ID ' - + 'before using the example.' - ) - -# Create an IAM authenticator. -authenticator = IAMAuthenticator( - apikey=os.environ.get('CE_API_KEY'), - client_id='bx', - client_secret='bx', -) - -# Construct the Code Engine client. -ce_client = IbmCloudCodeEngineV1(authenticator=authenticator) -ce_client.set_service_url('https://api.' + os.environ.get('CE_PROJECT_REGION') + '.codeengine.cloud.ibm.com/api/v1') - -# Get a Delegated Refresh Token from IAM -iam_response = requests.post( - 'https://iam.cloud.ibm.com/identity/token', - headers={'Content-Type': 'application/x-www-form-urlencoded'}, - data={ - 'grant_type': 'urn:ibm:params:oauth:grant-type:apikey', - 'apikey': os.environ.get('CE_API_KEY'), - 'response_type': 'delegated_refresh_token', - 'receiver_client_ids': 'ce', - 'delegated_refresh_token_expiry': '3600', - }, -) -delegated_refresh_token = iam_response.json()['delegated_refresh_token'] - -# Get Code Engine project config using the Code Engine client. -kubeconfig_response = ce_client.get_kubeconfig( - x_delegated_refresh_token=delegated_refresh_token, - id=os.environ.get('CE_PROJECT_ID'), -) -kubeconfig_string = kubeconfig_response.get_result().content - -# Setup Kubernetes client using project config -kubeconfig_file, kubeconfig_filename = tempfile.mkstemp() -os.write(kubeconfig_file, kubeconfig_string) -kubernetes.config.load_kube_config(config_file=kubeconfig_filename) -kube_client = kubernetes.client.CoreV1Api() - -# Get something from project. -contexts = kubernetes.config.list_kube_config_contexts(config_file=kubeconfig_filename)[0][0] -namespace = contexts.get('context').get('namespace') -configmaps = kube_client.list_namespaced_config_map(namespace) -print('Project ' + os.environ.get('CE_PROJECT_ID') + ' has ' + str(len(configmaps.items)) + ' configmaps.') diff --git a/example/example_deprecated.py b/example/example_deprecated.py deleted file mode 100644 index 36d78ea..0000000 --- a/example/example_deprecated.py +++ /dev/null @@ -1,52 +0,0 @@ -""" -Example of IBM Cloud Code Engine SDK usage -""" - -import os -import tempfile -import kubernetes -from ibm_code_engine_sdk.ibm_cloud_code_engine_v1 import IbmCloudCodeEngineV1 -from ibm_cloud_sdk_core.authenticators import IAMAuthenticator - -if ( - os.environ.get('CE_API_KEY') == None - or os.environ.get('CE_PROJECT_REGION') == None - or os.environ.get('CE_PROJECT_ID') == None -): - print( - 'You must set the envrionment variables CE_API_KEY, CE_PROJECT_REGION and CE_PROJECT_ID ' - + 'before using the example.' - ) - -# Create an IAM authenticator. -authenticator = IAMAuthenticator( - apikey=os.environ.get('CE_API_KEY'), - client_id='bx', - client_secret='bx', -) - -# Construct the Code Engine client. -ce_client = IbmCloudCodeEngineV1(authenticator=authenticator) -ce_client.set_service_url('https://api.' + os.environ.get('CE_PROJECT_REGION') + '.codeengine.cloud.ibm.com/api/v1') - -# Get IAM tokens using the authenticator -refresh_token = authenticator.token_manager.request_token().get('refresh_token') - -# Get Code Engine project config using the Code Engine client. -kubeconfig_response = ce_client.list_kubeconfig( - refresh_token=refresh_token, - id=os.environ.get('CE_PROJECT_ID'), -) -kubeconfig_string = kubeconfig_response.get_result().content - -# Setup Kubernetes client using project config -kubeconfig_file, kubeconfig_filename = tempfile.mkstemp() -os.write(kubeconfig_file, kubeconfig_string) -kubernetes.config.load_kube_config(config_file=kubeconfig_filename) -kube_client = kubernetes.client.CoreV1Api() - -# Get something from project. -contexts = kubernetes.config.list_kube_config_contexts(config_file=kubeconfig_filename)[0][0] -namespace = contexts.get('context').get('namespace') -configmaps = kube_client.list_namespaced_config_map(namespace) -print('Project ' + os.environ.get('CE_PROJECT_ID') + ' has ' + str(len(configmaps.items)) + ' configmaps.') diff --git a/package.json b/package.json deleted file mode 100644 index 86fc6e3..0000000 --- a/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "semantic-release-dependencies", - "version": "0.0.0", - "description": "This package.json is being used to manage semantic-release and its dependencies", - "license": "Apache-2.0", - "devDependencies": { - "semantic-release": "19.0.5", - "@semantic-release/changelog": "6.0.2", - "@semantic-release/exec": "6.0.3", - "@semantic-release/git": "10.0.1" - }, - "scripts": { - "semantic-release": "semantic-release" - } -} diff --git a/sdkgen_config.json b/sdkgen_config.json deleted file mode 100644 index 70dcdd3..0000000 --- a/sdkgen_config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "apiPackage": "ibm_code_engine_sdk", - "serviceClass": "CodeEngineV2", - "unitTestFolder": "test/unit/", - "intTestFolder": "test/integration" -} diff --git a/test-integration.sh b/test-integration.sh deleted file mode 100755 index a636808..0000000 --- a/test-integration.sh +++ /dev/null @@ -1,29 +0,0 @@ -# Code Engine Python SDK Integration tests -# Requires the following env. variables (provdied to TravisCI) -# - CE_API_KEY: IBM Cloud API Key -# - CE_PROJECT_ID: GUID of Code Engine project to target -# - CE_PROJECT_REGION: region for API URL - -echo "Running integration tests..." - -# Install dependencies -pip install kubernetes - -# Run example, get exit code -exampleoutput=$(python example/example.py) -exampleexit=$? -if [ $exampleexit -ne 0 ]; then - echo "Integration tests failed with exit code $exampleexit" - echo $exampleoutput - exit $exampleexit -fi - -# Check if output is expected -outputcheck="2 configmaps" -if [[ $exampleoutput != *$outputcheck* ]]; then - echo "Intergration test output is incorrect:" - echo "Expected '$exampleoutput' to contain '$outputcheck'" - exit 1 -fi - -echo "Success!" \ No newline at end of file