From 66a332ba4adbc84000b01d7beb834971586e0283 Mon Sep 17 00:00:00 2001 From: Sergey Klyuykov Date: Sat, 30 Nov 2019 17:33:47 +1000 Subject: [PATCH 1/7] Fix pypi publishing --- .gitlab-ci.yml | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0e102bc5..599f45d4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -184,23 +184,24 @@ release_pypi: TOX_ARGS: "" script: - make test ENVS=build + - make twine allow_failure: true artifacts: - name: "release-rpm-${CI_BUILD_REF_NAME}.${CI_BUILD_ID}" + name: "release-packages-${CI_BUILD_REF_NAME}.${CI_BUILD_ID}" paths: - dist/ -publish_pypi: - stage: publish - image: onegreyonewhite/tox:tox - only: - refs: - - tags - variables: - - $PYPI_UPLOAD_PASSWORD - - $PYPI_UPLOAD_NAME - script: - - make twine +#publish_pypi: +# stage: publish +# image: onegreyonewhite/tox:tox +# only: +# refs: +# - tags +# variables: +# - $PYPI_UPLOAD_PASSWORD +# - $PYPI_UPLOAD_NAME +# script: +# - make twine publish_release: From 99bedbf6777e7ce71c7b1b53070af0184fa52f27 Mon Sep 17 00:00:00 2001 From: Sergey Klyuykov Date: Sat, 30 Nov 2019 18:19:06 +1000 Subject: [PATCH 2/7] Update schema for docs --- doc/api_schema.yaml | 80 ++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 56 deletions(-) diff --git a/doc/api_schema.yaml b/doc/api_schema.yaml index d0244c3a..cf9b7b27 100755 --- a/doc/api_schema.yaml +++ b/doc/api_schema.yaml @@ -19,9 +19,9 @@ info: url: https://gitlab.com/vstconsulting/polemarch.git Request: - name: Question - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Ask&issue%5Btitle%5D=Ask%20about%20version%201.4.4 + url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Ask&issue%5Btitle%5D=Ask%20about%20version%201.5.1 - name: Bug report - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Bug&issue%5Btitle%5D=Bug%20in%20version%201.4.4 + url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Bug&issue%5Btitle%5D=Bug%20in%20version%201.5.1 - name: Feature request url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Feature%20request&issue%5Btitle%5D= x-menu: @@ -54,11 +54,11 @@ info: span_class: fa fa-plug url: /hook x-versions: - application: 1.4.4 - library: 1.4.4 - vstutils: 2.6.6 - django: 2.2.4 - ansible: 2.8.4 + application: 1.5.1 + library: 1.5.1 + vstutils: 2.11.0 + django: 2.2.7 + ansible: 2.8.7 version: v2 host: localhost:8080 schemes: @@ -8060,6 +8060,11 @@ paths: description: Full path to module. required: false type: string + - name: name + in: query + description: Name of module. + required: false + type: string - name: path__not in: query description: Full path to module. @@ -8763,6 +8768,11 @@ paths: description: Playbook filename. required: false type: string + - name: pb_filter + in: query + description: Playbook filename - filter for prefetch. + required: false + type: string - name: id__not in: query description: A unique integer value (or comma separated list) identifying @@ -11426,9 +11436,8 @@ definitions: default: false become_method: title: Become method - description: 'privilege escalation method to use (default=sudo), valid choices: - [ sudo | su | pbrun | pfexec | doas | dzdo | ksu | runas | pmrun | enable - | machinectl ]' + description: privilege escalation method to use (default=%default), use `ansible-doc + -t become -l` to list valid choices. type: string become_user: title: Become user @@ -11486,8 +11495,7 @@ definitions: default: false module_path: title: Module path - description: prepend colon-separated path(s) to module library (default=[u'/home/grey/.ansible/plugins/modules', - u'/usr/share/ansible/plugins/modules']) + description: prepend colon-separated path(s) to module library (default=~/.ansible/plugins/modules:/usr/share/ansible/plugins/modules) type: string one_line: title: One line @@ -11496,7 +11504,7 @@ definitions: default: false playbook_dir: title: Playbook dir - description: Since this tool does not use playbooks, use this as a subsitute + description: Since this tool does not use playbooks, use this as a substitute playbook directory.This sets the relative path for many features including roles/ group_vars/ etc. type: string @@ -11525,25 +11533,6 @@ definitions: title: Ssh extra args description: specify extra arguments to pass to ssh only (e.g. -R) type: string - su: - title: Su - description: run operations with su (deprecated, use become) - type: boolean - default: false - su_user: - title: Su user - description: run operations with su as this user (default=None) (deprecated, - use become) - type: string - sudo: - title: Sudo - description: run operations with sudo (nopasswd) (deprecated, use become) - type: boolean - default: false - sudo_user: - title: Sudo user - description: desired sudo user (default=root) (deprecated, use become) - type: string syntax_check: title: Syntax check description: perform a syntax check on the playbook, but do not execute it @@ -11620,9 +11609,8 @@ definitions: default: false become_method: title: Become method - description: 'privilege escalation method to use (default=sudo), valid choices: - [ sudo | su | pbrun | pfexec | doas | dzdo | ksu | runas | pmrun | enable - | machinectl ]' + description: privilege escalation method to use (default=%default), use `ansible-doc + -t become -l` to list valid choices. type: string become_user: title: Become user @@ -11700,8 +11688,7 @@ definitions: default: false module_path: title: Module path - description: prepend colon-separated path(s) to module library (default=[u'/home/grey/.ansible/plugins/modules', - u'/usr/share/ansible/plugins/modules']) + description: prepend colon-separated path(s) to module library (default=~/.ansible/plugins/modules:/usr/share/ansible/plugins/modules) type: string private_key: title: Private key @@ -11737,25 +11724,6 @@ definitions: description: 'one-step-at-a-time: confirm each task before running' type: boolean default: false - su: - title: Su - description: run operations with su (deprecated, use become) - type: boolean - default: false - su_user: - title: Su user - description: run operations with su as this user (default=None) (deprecated, - use become) - type: string - sudo: - title: Sudo - description: run operations with sudo (nopasswd) (deprecated, use become) - type: boolean - default: false - sudo_user: - title: Sudo user - description: desired sudo user (default=root) (deprecated, use become) - type: string syntax_check: title: Syntax check description: perform a syntax check on the playbook, but do not execute it From c2da0765a5b49634855b8a6fe01c4c032e3abde4 Mon Sep 17 00:00:00 2001 From: Kirill Bychkov Date: Mon, 9 Dec 2019 07:03:43 +0000 Subject: [PATCH 3/7] Recreate openapi test --- doc/api_schema.yaml | 96 +- polemarch/main/tests/openapi.py | 2271 +------------------------------ 2 files changed, 61 insertions(+), 2306 deletions(-) diff --git a/doc/api_schema.yaml b/doc/api_schema.yaml index cf9b7b27..3788e44a 100755 --- a/doc/api_schema.yaml +++ b/doc/api_schema.yaml @@ -11,52 +11,52 @@ info: has_docs: true docs_url: /docs/ x-links: + Request: + - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Ask&issue%5Btitle%5D=Ask%20about%20version%201.5.1 + name: Question + - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Bug&issue%5Btitle%5D=Bug%20in%20version%201.5.1 + name: Bug report + - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Feature%20request&issue%5Btitle%5D= + name: Feature request Documentation: - name: Official documentation url: http://polemarch.readthedocs.io/ + name: Official documentation Repository: - name: Official repository url: https://gitlab.com/vstconsulting/polemarch.git - Request: - - name: Question - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Ask&issue%5Btitle%5D=Ask%20about%20version%201.5.1 - - name: Bug report - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Bug&issue%5Btitle%5D=Bug%20in%20version%201.5.1 - - name: Feature request - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Feature%20request&issue%5Btitle%5D= + name: Official repository x-menu: - name: Projects - span_class: fa fa-fort-awesome url: /project + span_class: fa fa-fort-awesome - name: Community - span_class: fa fa-cloud url: /community_template + span_class: fa fa-cloud - name: Inventories + url: /inventory span_class: fa fa-folder sublinks: - name: Groups - span_class: fa fa-tasks url: /group + span_class: fa fa-tasks - name: Hosts - span_class: fa fa-codepen url: /host - url: /inventory + span_class: fa fa-codepen - name: History - span_class: fa fa-calendar url: /history + span_class: fa fa-calendar - name: System span_class: fa fa-cog sublinks: - name: Users - span_class: fa fa-user url: /user + span_class: fa fa-user - name: Hooks - span_class: fa fa-plug url: /hook + span_class: fa fa-plug x-versions: application: 1.5.1 library: 1.5.1 - vstutils: 2.11.0 + vstutils: 2.11.1 django: 2.2.7 ansible: 2.8.7 version: v2 @@ -10953,14 +10953,14 @@ definitions: type: string format: dynamic additionalProperties: - choices: {} field: key + choices: {} types: - ansible_become: boolean - ansible_become_pass: password - ansible_port: integer ansible_ssh_pass: password ansible_ssh_private_key_file: secretfile + ansible_become: boolean + ansible_port: integer + ansible_become_pass: password Host: type: object properties: @@ -11325,15 +11325,15 @@ definitions: format: dynamic default: NONE additionalProperties: + field: type choices: GIT: - NONE - KEY - PASSWORD - field: type types: - GIT: string MANUAL: hidden + GIT: string TAR: hidden auth_data: title: Repo auth data @@ -11341,22 +11341,22 @@ definitions: format: dynamic default: '' additionalProperties: - choices: {} field: repo_auth + choices: {} types: KEY: secretfile - NONE: hidden PASSWORD: password + NONE: hidden branch: title: Branch for GIT(branch/tag/SHA) or TAR(subdir) type: string format: dynamic additionalProperties: - choices: {} field: type + choices: {} types: - GIT: string MANUAL: hidden + GIT: string TAR: string x-nullable: true OneProject: @@ -11885,22 +11885,22 @@ definitions: type: string format: dynamic additionalProperties: - choices: {} field: kind + choices: {} types: - MODULE: fk_autocomplete PLAYBOOK: fk_autocomplete + MODULE: fk_autocomplete TEMPLATE: hidden inventory: title: Inventory type: string format: dynamic additionalProperties: - choices: {} field: kind + choices: {} types: - MODULE: fk_autocomplete PLAYBOOK: fk_autocomplete + MODULE: fk_autocomplete TEMPLATE: hidden save_result: title: Save result @@ -11914,11 +11914,11 @@ definitions: type: string format: dynamic additionalProperties: - choices: {} field: kind + choices: {} types: - MODULE: hidden PLAYBOOK: hidden + MODULE: hidden TEMPLATE: autocomplete enabled: title: Enabled @@ -11935,8 +11935,8 @@ definitions: type: string format: dynamic additionalProperties: - choices: {} field: type + choices: {} types: CRONTAB: crontab INTERVAL: integer @@ -11967,22 +11967,22 @@ definitions: type: string format: dynamic additionalProperties: - choices: {} field: kind + choices: {} types: - MODULE: fk_autocomplete PLAYBOOK: fk_autocomplete + MODULE: fk_autocomplete TEMPLATE: hidden inventory: title: Inventory type: string format: dynamic additionalProperties: - choices: {} field: kind + choices: {} types: - MODULE: fk_autocomplete PLAYBOOK: fk_autocomplete + MODULE: fk_autocomplete TEMPLATE: hidden save_result: title: Save result @@ -11996,11 +11996,11 @@ definitions: type: string format: dynamic additionalProperties: - choices: {} field: kind + choices: {} types: - MODULE: hidden PLAYBOOK: hidden + MODULE: hidden TEMPLATE: autocomplete enabled: title: Enabled @@ -12017,8 +12017,8 @@ definitions: type: string format: dynamic additionalProperties: - choices: {} field: type + choices: {} types: CRONTAB: crontab INTERVAL: integer @@ -12182,20 +12182,20 @@ definitions: type: string format: dynamic additionalProperties: + field: key choices: - repo_sync_on_run: - - true - - false repo_type: - MANUAL - GIT - TAR - field: key + repo_sync_on_run: + - true + - false types: - ci_template: fk - repo_key: secretfile repo_password: password + repo_key: secretfile repo_sync_on_run_timeout: uptime + ci_template: fk Team: required: - name diff --git a/polemarch/main/tests/openapi.py b/polemarch/main/tests/openapi.py index 0d1e4d61..e8aa67ef 100644 --- a/polemarch/main/tests/openapi.py +++ b/polemarch/main/tests/openapi.py @@ -1,2270 +1,25 @@ -import six +from pathlib import Path from unittest import skipUnless -from django.conf import settings +import yaml from ._base import BaseTestCase -from ... import __version__ -import re -skip_it = (settings.VST_PROJECT == 'polemarch' or six.PY2) +openapi_schema_yaml = Path(__file__).parent.parent.parent.parent / 'doc' / 'api_schema.yaml' -class OApiTestCase(BaseTestCase): - re_path = re.compile(r"(?<={).+?(?=})") - pm_filters = [ - dict(name='id', description=True, required=False, type='string'), - dict(name='id__not', description=True, required=False, type='string'), - ] - pm_name_filter = [ - dict(name='name', description=True, required=False, type='string'), - dict(name='name__not', description=True, required=False, type='string'), - ] - default_filters = [ - dict(name='ordering', description=True, required=False, type='string'), - dict(name='limit', description=True, required=False, type='integer'), - dict(name='offset', description=True, required=False, type='integer'), - ] +class OApiTestCase(BaseTestCase): - @skipUnless(skip_it, 'Check only on CE.') + @skipUnless(openapi_schema_yaml.is_file(), "OpenApi schema file doesn't exist") def test_openapi_schema(self): - api_version = self._settings('VST_API_VERSION') - api_path = self._settings('API_URL') schema = self.get_result('get', '/api/openapi/?format=openapi') - # Test base info - self.assertEqual(schema.get('swagger', None), '2.0') - self.assertEqual(schema['info']['title'], 'Polemarch') - self.assertEqual(schema['info']['x-versions']['application'], __version__) - self.assertEqual(schema['info']['version'], api_version) - self.assertEqual(schema['basePath'], '/{}/{}'.format(api_path, api_version)) - - definitions = schema['definitions'] - id_value = dict(type='integer', readOnly=True) - name_value = dict(type='string', maxLength=512, minLength=1) - notes_value = dict(type='string', format='textarea') - # Test definitions - group = definitions['Group'] - objName = 'Group' - - self.check_fields(objName, group['properties']['id'], **id_value) - - self.check_fields(objName, group['properties']['name'], **name_value) - - self.check_fields( - objName, group['properties']['children'], type='boolean', readOnly=True - ) - del group - - error = definitions['Error'] - objName = 'Error' - - self.check_fields(objName, error['required'], 'detail') - self.check_fields( - objName, error['properties']['detail'], **dict(type='string', minLength=1) - ) - del error - - user = definitions['User'] - objName = 'User' - - self.check_fields(objName, user['required'], 'username') - self.check_fields(objName, user['properties']['id'], **id_value) - self.check_fields( - objName, user['properties']['username'], type='string', pattern='^[\w.@+-]+$', - maxLength=150, minLength=1, description=True - ) - self.check_fields( - objName, user['properties']['is_active'], type='boolean', default=True - ) - del user - - groupCreateMaster = definitions['GroupCreateMaster'] - objName = 'GroupCreateMaster' - ref = '#/definitions/User' - - self.check_fields(objName, groupCreateMaster['properties']['id'], **id_value) - self.check_fields(objName, groupCreateMaster['properties']['name'], **name_value) - self.check_fields( - objName, groupCreateMaster['properties']['notes'], **notes_value - ) - self.check_fields( - objName, groupCreateMaster['properties']['children'], - type='boolean', default=False - ) - self.check_fields( - objName, groupCreateMaster['properties']['owner'], **{'$ref': ref} - ) - self.check_ref(schema, ref) - del groupCreateMaster - - oneGroup = definitions['OneGroup'] - objName = 'OneGroup' - - self.check_fields(objName, oneGroup['properties']['id'], **id_value) - self.check_fields(objName, oneGroup['properties']['name'], **name_value) - self.check_fields(objName, oneGroup['properties']['notes'], **notes_value) - self.check_fields( - objName, oneGroup['properties']['children'], type='boolean', readOnly=True - ) - self.check_fields(objName, oneGroup['properties']['owner'], **{'$ref': ref}) - self.check_ref(schema, ref) - del oneGroup - - setOwner = definitions['SetOwner'] - objName = 'SetOwner' - - self.check_fields(objName, setOwner['required'], 'user_id') - self.check_fields( - objName, setOwner['properties']['user_id'], - type='integer', format='fk', - additionalProperties=dict( - value_field='id', view_field='username', model={'$ref': ref} - ) - ) - del setOwner - - inventoryVariable = definitions['InventoryVariable'] - objName = 'InventoryVariable' - enum = [ - 'ansible_host', 'ansible_port', 'ansible_user', 'ansible_connection', - 'ansible_ssh_pass', 'ansible_ssh_private_key_file', 'ansible_ssh_common_args', - 'ansible_sftp_extra_args', 'ansible_scp_extra_args', 'ansible_ssh_extra_args', - 'ansible_ssh_executable', 'ansible_ssh_pipelining', 'ansible_become', - 'ansible_become_method', 'ansible_become_user', 'ansible_become_pass', - 'ansible_become_exe', 'ansible_become_flags', 'ansible_shell_type', - 'ansible_python_interpreter', 'ansible_ruby_interpreter', - 'ansible_perl_interpreter', 'ansible_shell_executable' - ] - additional_properties = dict( - field='key', choices={}, - types=dict( - ansible_become='boolean', - ansible_ssh_private_key_file='secretfile', - ansible_ssh_pass='password', - ansible_port='integer', - ansible_become_pass='password', - ) - ) - - self.check_fields(objName, inventoryVariable['required'], 'key', 'value') - self.check_fields(objName, inventoryVariable['properties']['id'], **id_value) - self.check_fields( - objName, inventoryVariable['properties']['value'], - type='string', format='dynamic', additionalProperties=additional_properties - ) - self.check_fields( - objName, inventoryVariable['properties']['key'], - type='string', format='autocomplete', enum=enum - ) - del inventoryVariable - - host = definitions['Host'] - objName = 'Host' - - self.check_fields(objName, host['properties']['id'], **id_value) - self.check_fields(objName, host['properties']['name'], **name_value) - self.check_fields( - objName, host['properties']['type'], - type='string', default='HOST', enum=['HOST', 'RANGE'] - ) - del host - - oneHost = definitions['OneHost'] - objName = 'OneHost' - - self.check_fields(objName, oneHost['properties']['id'], **id_value) - self.check_fields(objName, oneHost['properties']['name'], **name_value) - self.check_fields(objName, oneHost['properties']['notes'], **notes_value) - self.check_fields( - objName, oneHost['properties']['type'], - type='string', default='HOST', enum=['HOST', 'RANGE'] - ) - self.check_fields(objName, oneHost['properties']['owner'], **{'$ref': ref}) - self.check_ref(schema, ref) - del oneHost - - history = definitions['History'] - objName = 'History' - - self.check_fields(objName, history['required'], 'mode') - self.check_fields(objName, history['properties']['id'], **id_value) - self.check_fields( - objName, history['properties']['status'], - type='string', enum=self.get_model_class('History').statuses - ) - self.check_fields(objName, history['properties']['executor'], type='integer') - self.check_fields(objName, history['properties']['project'], type='integer') - self.check_fields( - objName, history['properties']['kind'], - type='string', maxLength=50, minLength=1 - ) - self.check_fields( - objName, history['properties']['mode'], - type='string', maxLength=256, minLength=1 - ) - self.check_fields(objName, history['properties']['inventory'], type='integer') - self.check_fields( - objName, history['properties']['start_time'], - type='string', format='date-time' - ) - self.check_fields( - objName, history['properties']['stop_time'], type='string', format='date-time' - ) - self.check_fields(objName, history['properties']['initiator'], type='integer') - self.check_fields( - objName, history['properties']['initiator_type'], - type='string', maxLength=50, minLength=1 - ) - self.check_fields( - objName, history['properties']['options'], type='string', readOnly=True - ) - - oneHistory = definitions['OneHistory'] - objName = 'OneHistory' - - self.check_fields( - objName, oneHistory['required'], 'mode', 'execution_time' - ) - self.check_fields(objName, oneHistory['properties']['id'], **id_value) - self.check_fields( - objName, oneHistory['properties']['status'], - type='string', enum=self.get_model_class('History').statuses - ) - self.check_fields(objName, oneHistory['properties']['executor'], type='integer') - self.check_fields(objName, oneHistory['properties']['project'], type='integer') - self.check_fields( - objName, oneHistory['properties']['revision'], type='string', maxLength=256 - ) - self.check_fields(objName, oneHistory['properties']['inventory'], type='integer') - self.check_fields( - objName, oneHistory['properties']['kind'], - type='string', maxLength=50, minLength=1 - ) - self.check_fields( - objName, oneHistory['properties']['mode'], - type='string', maxLength=256, minLength=1 - ) - self.check_fields( - objName, oneHistory['properties']['execute_args'], - type='string', readOnly=True - ) - self.check_fields( - objName, oneHistory['properties']['execution_time'], - type='integer', format='uptime' - ) - self.check_fields( - objName, oneHistory['properties']['start_time'], - type='string', format='date-time' - ) - self.check_fields( - objName, oneHistory['properties']['stop_time'], - type='string', format='date-time' - ) - self.check_fields(objName, oneHistory['properties']['initiator'], type='integer') - self.check_fields( - objName, oneHistory['properties']['initiator_type'], - type='string', maxLength=50, minLength=1 - ) - self.check_fields( - objName, oneHistory['properties']['options'], type='string', readOnly=True - ) - self.check_fields( - objName, oneHistory['properties']['raw_args'], type='string', minLength=1 - ) - self.check_fields( - objName, oneHistory['properties']['raw_stdout'], type='string', readOnly=True - ) - self.check_fields( - objName, oneHistory['properties']['raw_inventory'], type='string', minLength=1 - ) - del oneHistory - - empty = definitions['Empty'] - self.assertTrue(not empty['properties']) - del empty - - actionResponse = definitions['ActionResponse'] - objName = 'ActionResponse' - - self.check_fields(objName, actionResponse['required'], 'detail') - self.check_fields( - objName, actionResponse['properties']['detail'], type='string', minLength=1 - ) - del actionResponse - - data = definitions['Data'] - self.assertTrue(not data['properties']) - del data - - hook = definitions['Hook'] - objName = 'Hook' - enum = [ - 'on_execution', 'after_execution', 'on_user_add', 'on_user_upd', - 'on_user_del', 'on_object_add', 'on_object_upd', 'on_object_del' - ] - - self.check_fields(objName, hook['required'], 'type', 'recipients') - self.check_fields(objName, hook['properties']['id'], **id_value) - self.check_fields(objName, hook['properties']['name'], **name_value) - self.check_fields( - objName, hook['properties']['type'], type='string', enum=['HTTP', 'SCRIPT'] - ) - self.check_fields(objName, hook['properties']['when'], type='string', enum=enum) - self.check_fields(objName, hook['properties']['enable'], type='boolean') - self.check_fields( - objName, hook['properties']['recipients'], - type='string', minLength=1 - ) - del hook - - inventory = definitions['Inventory'] - objName = 'Inventory' - - self.check_fields(objName, inventory['properties']['id'], **id_value) - self.check_fields(objName, inventory['properties']['name'], **name_value) - del inventory - - oneInventory = definitions['OneInventory'] - objName = 'OneInventory' - - self.check_fields(objName, oneInventory['properties']['id'], **id_value) - self.check_fields(objName, oneInventory['properties']['name'], **name_value) - self.check_fields(objName, oneInventory['properties']['notes'], **notes_value) - self.check_fields(objName, oneInventory['properties']['owner'], **{'$ref': ref}) - self.check_ref(schema, ref) - del oneInventory - - project = definitions['Project'] - objName = 'Project' - - self.check_fields(objName, project['properties']['id'], **id_value) - self.check_fields(objName, project['properties']['name'], **name_value) - self.check_fields( - objName, project['properties']['type'], - type='string', readOnly=True, minLength=1 - ) - self.check_fields( - objName, project['properties']['status'], - type='string', readOnly=True, enum=self.get_model_class('Project').STATUSES - ) - del project - - projectCreateMaster = definitions['ProjectCreateMaster'] - objName = 'ProjectCreateMaster' - - self.check_fields(objName, projectCreateMaster['required'], 'name') - self.check_fields(objName, projectCreateMaster['properties']['id'], **id_value) - self.check_fields( - objName, projectCreateMaster['properties']['name'], **name_value - ) - self.check_fields( - objName, projectCreateMaster['properties']['status'], - type='string', readOnly=True, minLength=1 - ) - self.check_fields( - objName, projectCreateMaster['properties']['type'], - type='string', default='MANUAL', enum=['MANUAL', 'GIT', 'TAR'] - ) - self.check_fields( - objName, projectCreateMaster['properties']['repository'], - type='string', default='MANUAL', minLength=1 - ) - self.check_fields( - objName, projectCreateMaster['properties']['repo_auth'], - type='string', format='dynamic', default='NONE', - additionalProperties={} - ) - additional_properties = dict( - field='repo_auth', choices={}, - types=dict(KEY='secretfile', PASSWORD='password', NONE='hidden') - ) - - self.check_fields( - objName, projectCreateMaster['properties']['auth_data'], - type='string', format='dynamic', default='', - additionalProperties=additional_properties - ) - del projectCreateMaster - - oneProject = definitions['OneProject'] - objName = 'OneProject' - - self.check_fields(objName, oneProject['properties']['id'], **id_value) - self.check_fields(objName, oneProject['properties']['name'], **name_value) - self.check_fields( - objName, oneProject['properties']['repository'], - type='string', default='MANUAL', minLength=1 - ) - self.check_fields( - objName, oneProject['properties']['status'], - type='string', readOnly=True, enum=self.get_model_class('Project').STATUSES - ) - self.check_fields( - objName, oneProject['properties']['revision'], - type='string', readOnly=True - ) - self.check_fields( - objName, oneProject['properties']['branch'], - type='string', readOnly=True - ) - self.check_fields(objName, oneProject['properties']['owner'], **{'$ref': ref}) - self.check_ref(schema, ref) - self.check_fields(objName, oneProject['properties']['notes'], **notes_value) - self.check_fields( - objName, oneProject['properties']['readme_content'], - type='string', format='html', readOnly=True - ) - del oneProject - - ansibleModule = definitions['AnsibleModule'] - objName = 'AnsibleModule' - ref = '#/definitions/Module' - additional_properties = dict( - value_field='name', view_field='path', model={'$ref': ref} - ) - - self.check_fields(objName, ansibleModule['required'], 'module') - self.check_fields( - objName, ansibleModule['properties']['module'], - type='string', format='autocomplete', - additionalProperties=additional_properties - ) - self.check_fields( - objName, ansibleModule['properties']['args'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['background'], - type='integer', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['become'], - type='boolean', description=True, default=False - ) - self.check_fields( - objName, ansibleModule['properties']['become_method'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['become_user'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['check'], - type='boolean', description=True, default=False - ) - self.check_fields( - objName, ansibleModule['properties']['connection'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['diff'], - type='boolean', description=True, default=False - ) - self.check_fields( - objName, ansibleModule['properties']['extra_vars'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['forks'], - type='integer', description=True - ) - - ref = '#/definitions/Inventory' - additional_properties = dict( - value_field='id', view_field='name', model={'$ref': ref} - ) - - self.check_fields( - objName, ansibleModule['properties']['inventory'], - type='string', - format='autocomplete', - description=True, - additionalProperties=additional_properties - ) - self.check_fields( - objName, ansibleModule['properties']['key_file'], - type='string', format='secretfile', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['limit'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['list_hosts'], - type='boolean', default=False, description=True - ) - self.check_fields( - objName, ansibleModule['properties']['module_path'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['one_line'], - type='boolean', default=False, description=True - ) - self.check_fields( - objName, ansibleModule['properties']['playbook_dir'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['poll'], - type='integer', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['private_key'], - type='string', format='secretfile', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['scp_extra_args'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['sftp_extra_args'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['ssh_common_args'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['ssh_extra_args'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['syntax_check'], - type='boolean', default=False, description=True - ) - self.check_fields( - objName, ansibleModule['properties']['timeout'], - type='integer', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['tree'], type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['user'], type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['vault_id'], - type='string', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['vault_password_file'], - type='string', format='secretfile', description=True - ) - self.check_fields( - objName, ansibleModule['properties']['verbose'], - type='integer', default=0, maximum=4, description=True - ) - self.check_fields( - objName, ansibleModule['properties']['group'], type='string', default='all' - ) - del ansibleModule - - executeResponse = definitions['ExecuteResponse'] - objName = 'ExecuteResponse' - - self.check_fields(objName, executeResponse['required'], 'detail') - self.check_fields( - objName, executeResponse['properties']['detail'], type='string', minLength=1 - ) - self.check_fields( - objName, executeResponse['properties']['executor'], type='integer' - ) - self.check_fields( - objName, executeResponse['properties']['history_id'], - type='integer', additionalProperties=dict(redirect=True) - ) - del executeResponse - - ansiblePlaybook = definitions['AnsiblePlaybook'] - objName = 'AnsiblePlaybook' - ref = '#/definitions/Playbook' - - self.check_fields(objName, ansiblePlaybook['required'], 'playbook') - - additional_properties = dict( - value_field='playbook', view_field='name', model={'$ref': ref}) - - self.check_fields( - objName, ansiblePlaybook['properties']['playbook'], - type='string', format='autocomplete', - additionalProperties=additional_properties - ) - self.check_fields( - objName, ansiblePlaybook['properties']['become'], - type='boolean', description=True, default=False - ) - self.check_fields( - objName, ansiblePlaybook['properties']['become_method'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['become_user'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['check'], - type='boolean', description=True, default=False - ) - self.check_fields( - objName, ansiblePlaybook['properties']['connection'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['diff'], - type='boolean', description=True, default=False - ) - self.check_fields( - objName, ansiblePlaybook['properties']['extra_vars'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['flush_cache'], - type='boolean', description=True, default=False - ) - self.check_fields( - objName, ansiblePlaybook['properties']['force_handlers'], - type='boolean', description=True, default=False - ) - self.check_fields( - objName, ansiblePlaybook['properties']['forks'], - type='integer', description=True - ) - - ref = '#/definitions/Inventory' - additional_properties = dict( - value_field='id', view_field='name', model={'$ref': ref} - ) - - self.check_fields( - objName, ansiblePlaybook['properties']['inventory'], - type='string', format='autocomplete', description=True, - additionalProperties=additional_properties - ) - self.check_fields( - objName, ansiblePlaybook['properties']['key_file'], - type='string', format='secretfile', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['limit'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['list_hosts'], - type='boolean', default=False, description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['list_tags'], - type='boolean', default=False, description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['list_tasks'], - type='boolean', default=False, description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['module_path'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['private_key'], - type='string', format='secretfile', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['scp_extra_args'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['sftp_extra_args'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['skip_tags'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['ssh_common_args'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['ssh_extra_args'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['start_at_task'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['step'], - type='boolean', default=False, description=True - ) - # self.check_fields( - # objName, ansiblePlaybook['properties']['su'], - # type='boolean', default=False, description=True - # ) - # self.check_fields( - # objName, ansiblePlaybook['properties']['su_user'], - # type='string', description=True - # ) - # self.check_fields( - # objName, ansiblePlaybook['properties']['sudo'], - # type='boolean', default=False, description=True - # ) - # self.check_fields( - # objName, ansiblePlaybook['properties']['sudo_user'], - # type='string', description=True - # ) - self.check_fields( - objName, ansiblePlaybook['properties']['syntax_check'], - type='boolean', default=False, description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['tags'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['timeout'], - type='integer', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['user'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['vault_id'], - type='string', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['vault_password_file'], - type='string', format='secretfile', description=True - ) - self.check_fields( - objName, ansiblePlaybook['properties']['verbose'], - type='integer', default=0, maximum=4, description=True - ) - del ansiblePlaybook - - projectHistory = definitions['ProjectHistory'] - objName = 'ProjectHistory' - - self.check_fields(objName, projectHistory['required'], 'mode') - self.check_fields(objName, projectHistory['properties']['id'], **id_value) - self.check_fields( - objName, projectHistory['properties']['status'], - type='string', enum=self.get_model_class('History').statuses - ) - self.check_fields( - objName, projectHistory['properties']['revision'], - type='string', maxLength=256 - ) - self.check_fields( - objName, projectHistory['properties']['executor'], type='integer' - ) - self.check_fields( - objName, projectHistory['properties']['kind'], type='string', - maxLength=50, minLength=1 - ) - self.check_fields( - objName, projectHistory['properties']['mode'], - type='string', maxLength=256, minLength=1 - ) - self.check_fields( - objName, projectHistory['properties']['inventory'], type='integer' - ) - self.check_fields( - objName, projectHistory['properties']['start_time'], - type='string', format='date-time' - ) - self.check_fields( - objName, projectHistory['properties']['stop_time'], - type='string', format='date-time' - ) - self.check_fields( - objName, projectHistory['properties']['initiator'], type='integer' - ) - self.check_fields( - objName, projectHistory['properties']['initiator_type'], - type='string', minLength=1, maxLength=50 - ) - self.check_fields( - objName, projectHistory['properties']['options'], type='string', readOnly=True - ) - del projectHistory - - module = definitions['Module'] - objName = 'Module' - - self.check_fields(objName, module['required'], 'path') - self.check_fields(objName, module['properties']['id'], **id_value) - self.check_fields( - objName, module['properties']['path'], - type='string', minLength=1, maxLength=1024 - ) - self.check_fields( - objName, module['properties']['name'], type='string', readOnly=True - ) - del module - - oneModule = definitions['OneModule'] - objName = 'OneModule' - ref = '#/definitions/Data' - - self.check_fields(objName, oneModule['required'], 'path', 'data') - self.check_fields(objName, oneModule['properties']['id'], **id_value) - self.check_fields( - objName, oneModule['properties']['name'], type='string', readOnly=True - ) - self.check_fields( - objName, oneModule['properties']['path'], - type='string', minLength=1, maxLength=1024 - ) - self.check_fields(objName, oneModule['properties']['data'], **{'$ref': ref}) - del oneModule - - periodicTask = definitions['Periodictask'] - objName = 'Periodictask' - - self.check_fields(objName, periodicTask['required'], 'schedule') - self.check_fields(objName, periodicTask['properties']['id'], **id_value) - self.check_fields(objName, periodicTask['properties']['name'], **name_value) - self.check_fields( - objName, periodicTask['properties']['type'], - type='string', default='CRONTAB', enum=['CRONTAB', 'INTERVAL'] - ) - - additional_properties = dict( - field='type', choices={}, types=dict(CRONTAB='crontab', INTERVAL='integer') - ) - self.check_fields( - objName, periodicTask['properties']['schedule'], - type='string', format='dynamic', additionalProperties=additional_properties - ) - - additional_properties = dict( - field='kind', choices={}, - types=dict(PLAYBOOK='fk_autocomplete', MODULE='fk_autocomplete', TEMPLATE='hidden') - ) - self.check_fields( - objName, periodicTask['properties']['mode'], - type='string', format='dynamic', additionalProperties=additional_properties - ) - - self.check_fields( - objName, periodicTask['properties']['kind'], - type='string', default='PLAYBOOK', enum=['PLAYBOOK', 'MODULE', 'TEMPLATE'] - ) - - additional_properties = dict( - field='kind', choices={}, - types=dict(PLAYBOOK='fk_autocomplete', MODULE='fk_autocomplete', TEMPLATE='hidden') - ) - self.check_fields( - objName, periodicTask['properties']['inventory'], - type='string', format='dynamic', additionalProperties=additional_properties - ) - - self.check_fields( - objName, periodicTask['properties']['save_result'], type='boolean' - ) - self.check_fields( - objName, periodicTask['properties']['template'], type='integer' - ) - - additional_properties = dict( - field='kind', choices={}, - types=dict(PLAYBOOK='hidden', MODULE='hidden', TEMPLATE='autocomplete') - ) - self.check_fields( - objName, periodicTask['properties']['template_opt'], - type='string', format='dynamic', additionalProperties=additional_properties - ) - self.check_fields(objName, periodicTask['properties']['enabled'], type='boolean') - del periodicTask - - onePeriodicTask = definitions['OnePeriodictask'] - objName = 'OnePeriodictask' - - self.check_fields(objName, onePeriodicTask['required'], 'schedule') - self.check_fields(objName, onePeriodicTask['properties']['id'], **id_value) - self.check_fields(objName, onePeriodicTask['properties']['name'], **name_value) - self.check_fields(objName, onePeriodicTask['properties']['notes'], **notes_value) - self.check_fields( - objName, onePeriodicTask['properties']['type'], - type='string', default='CRONTAB', enum=['CRONTAB', 'INTERVAL'] - ) - - additional_properties = dict( - field='type', choices={}, types=dict(CRONTAB='crontab', INTERVAL='integer') - ) - self.check_fields( - objName, onePeriodicTask['properties']['schedule'], - type='string', format='dynamic', additionalProperties=additional_properties - ) - - additional_properties = dict( - field='kind', choices={}, - types=dict( - PLAYBOOK='fk_autocomplete', MODULE='fk_autocomplete', TEMPLATE='hidden' - ) - ) - self.check_fields( - objName, onePeriodicTask['properties']['mode'], - type='string', format='dynamic', additionalProperties=additional_properties - ) - - self.check_fields( - objName, onePeriodicTask['properties']['kind'], - type='string', default='PLAYBOOK', enum=['PLAYBOOK', 'MODULE', 'TEMPLATE'] - ) - - additional_properties = dict( - field='kind', choices={}, - types=dict( - PLAYBOOK='fk_autocomplete', MODULE='fk_autocomplete', TEMPLATE='hidden' - ) - ) - self.check_fields( - objName, onePeriodicTask['properties']['inventory'], - type='string', format='dynamic', additionalProperties=additional_properties - ) - self.check_fields( - objName, onePeriodicTask['properties']['save_result'], type='boolean' - ) - self.check_fields( - objName, onePeriodicTask['properties']['template'], type='integer' - ) - - additional_properties = dict( - field='kind', choices={}, - types=dict(PLAYBOOK='hidden', MODULE='hidden', TEMPLATE='autocomplete') - ) - self.check_fields( - objName, onePeriodicTask['properties']['template_opt'], - type='string', format='dynamic', additionalProperties=additional_properties - ) - self.check_fields( - objName, onePeriodicTask['properties']['enabled'], type='boolean' - ) - del onePeriodicTask - - periodicTaskVariable = definitions['PeriodicTaskVariable'] - objName = 'PeriodicTaskVariable' - - self.check_fields(objName, periodicTaskVariable['required'], 'key') - self.check_fields(objName, periodicTaskVariable['properties']['id'], **id_value) - self.check_fields( - objName, periodicTaskVariable['properties']['key'], - type='string', minLength=1, maxLength=512 - ) - self.check_fields( - objName, periodicTaskVariable['properties']['value'], - type='string', default='' - ) - del periodicTaskVariable - - playbook = definitions['Playbook'] - objName = 'Playbook' - - self.check_fields(objName, playbook['required'], 'playbook') - self.check_fields(objName, playbook['properties']['id'], **id_value) - self.check_fields( - objName, playbook['properties']['name'], - type='string', maxLength=251, minLength=1 - ) - self.check_fields( - objName, playbook['properties']['playbook'], - type='string', minLength=1, maxLength=256 - ) - del playbook - - onePlaybook = definitions['OnePlaybook'] - objName = 'OnePlaybook' - - self.check_fields(objName, onePlaybook['properties']['id'], **id_value) - self.check_fields( - objName, onePlaybook['properties']['name'], - type='string', maxLength=251, minLength=1 - ) - self.check_fields( - objName, onePlaybook['properties']['playbook'], - type='string', readOnly=True, minLength=1 - ) - del onePlaybook - - template = definitions['Template'] - objName = 'Template' - ref = '#/definitions/Data' - - self.check_fields(objName, template['required'], 'name', 'data', 'options') - self.check_fields(objName, template['properties']['id'], **id_value) - self.check_fields(objName, template['properties']['name'], **name_value) - self.check_fields( - objName, template['properties']['kind'], - type='string', default='Task', enum=['Task', 'Module'] - ) - self.check_fields(objName, template['properties']['data'], *{'$ref': ref}) - self.check_fields(objName, template['properties']['options'], **{'$ref': ref}) - self.check_fields( - objName, template['properties']['options_list'], - type='array', readOnly=True, items=dict(type='string') - ) - del template - - oneTemplate = definitions['OneTemplate'] - objName = 'OneTemplate' - - self.check_fields(objName, oneTemplate['required'], 'name', 'data') - self.check_fields(objName, oneTemplate['properties']['id'], **id_value) - self.check_fields(objName, oneTemplate['properties']['name'], **name_value) - self.check_fields(objName, oneTemplate['properties']['notes'], **notes_value) - self.check_fields( - objName, oneTemplate['properties']['kind'], - type='string', default='Task', enum=['Task', 'Module'] - ) - self.check_fields(objName, oneTemplate['properties']['data'], **{'$ref': ref}) - self.check_fields(objName, oneTemplate['properties']['options'], **{'$ref': ref}) - self.check_fields( - objName, oneTemplate['properties']['options_list'], - type='array', readOnly=True, items=dict(type='string') - ) - del oneTemplate - - templateExec = definitions['TemplateExec'] - objName = 'TemplateExec' - - self.check_fields( - objName, templateExec['properties']['option'], - type='string', minLength=0, description=True - ) - del templateExec - - projectVariable = definitions['ProjectVariable'] - objName = 'ProjectVariable' - - self.check_fields(objName, projectVariable['required'], 'key', 'value') - self.check_fields(objName, projectVariable['properties']['id'], **id_value) - - key_list = [ - 'repo_type', 'repo_sync_on_run', 'repo_sync_on_run_timeout', - 'repo_branch', 'repo_password', 'repo_key', 'ci_template' - ] - self.check_fields( - objName, projectVariable['properties']['key'], - type='string', format='autocomplete', enum=key_list - ) - additional_properties = dict( - field='key', - types=dict( - repo_password='password', - repo_key='secretfile', - repo_sync_on_run_timeout='uptime', - ci_template='fk' - ), - choices=dict( - repo_type=['MANUAL', 'GIT', 'TAR'], - repo_sync_on_run=[True, False] - ) - ) - - self.check_fields( - objName, projectVariable['properties']['value'], - type='string', format='dynamic', additionalProperties=additional_properties - ) - del projectVariable - - team = definitions['Team'] - objName = 'Team' - - self.check_fields(objName, team['required'], 'name') - self.check_fields(objName, team['properties']['id'], **id_value) - self.check_fields( - objName, team['properties']['name'], - type='string', maxLength=150, minLength=1 - ) - del team - - oneTeam = definitions['OneTeam'] - objName = 'OneTeam' - - self.check_fields(objName, oneTeam['required'], 'name') - self.check_fields(objName, oneTeam['properties']['id'], **id_value) - self.check_fields( - objName, oneTeam['properties']['name'], - type='string', minLength=1, maxLength=150 - ) - self.check_fields(objName, oneTeam['properties']['notes'], **notes_value) - ref = '#/definitions/User' - self.check_fields(objName, oneTeam['properties']['owner'], **{'$ref': ref}) - del oneTeam - - createUser = definitions['CreateUser'] - objName = 'CreateUser' - - self.check_fields( - objName, createUser['required'], 'username', 'password', 'password2' - ) - self.check_fields(objName, createUser['properties']['id'], **id_value) - self.check_fields( - objName, createUser['properties']['username'], - description=True, type='string', pattern='^[\w.@+-]+$', - maxLength=150, minLength=1 - ) - self.check_fields( - objName, createUser['properties']['is_active'], type='boolean', default=True - ) - self.check_fields( - objName, createUser['properties']['first_name'], type='string', maxLength=30 - ) - self.check_fields( - objName, createUser['properties']['last_name'], type='string', maxLength=150 - ) - self.check_fields( - objName, createUser['properties']['email'], - type='string', format='email', minLength=1 - ) - self.check_fields( - objName, createUser['properties']['password'], type='string', minLength=1 - ) - self.check_fields( - objName, createUser['properties']['password2'], type='string', minLength=1 - ) - del createUser - - oneUser = definitions['OneUser'] - objName = 'OneUser' - - self.check_fields(objName, oneUser['required'], 'username') - self.check_fields(objName, oneUser['properties']['id'], **id_value) - self.check_fields( - objName, oneUser['properties']['username'], - type='string', - description=True, - maxLength=150, - minLength=1, - pattern='^[\w.@+-]+$' - ) - self.check_fields( - objName, oneUser['properties']['is_active'], type='boolean', default=True - ) - self.check_fields( - objName, oneUser['properties']['first_name'], type='string', maxLength=30 - ) - self.check_fields( - objName, oneUser['properties']['last_name'], type='string', maxLength=150 - ) - self.check_fields( - objName, oneUser['properties']['email'], - type='string', format='email', minLength=1 - ) - del oneUser - - changePassword = definitions['ChangePassword'] - objName = 'ChangePassword' - self.check_fields( - objName, changePassword['required'], 'old_password', 'password', 'password2' - ) - self.check_fields( - objName, changePassword['properties']['old_password'], - type='string', minLength=1 - ) - self.check_fields( - objName, changePassword['properties']['password'], - type='string', minLength=1 - ) - self.check_fields( - objName, changePassword['properties']['password2'], - type='string', minLength=1 - ) - del changePassword - - chartLineSetting = definitions['ChartLineSetting'] - objName = 'ChartLineSetting' - - self.check_fields( - objName, chartLineSetting['properties']['active'], - type='boolean', default=True - ) - del chartLineSetting - - chartLineSettings = definitions['ChartLineSettings'] - objName = 'ChartLineSettings' - ref = '#/definitions/ChartLineSetting' - chart_line_list = ['all_tasks', 'delay', 'ok', 'error', 'interrupted', 'offline'] - - self.check_fields(objName, chartLineSettings['required'], *chart_line_list) - - self.check_fields( - objName, chartLineSettings['properties']['all_tasks'], **{'$ref': ref} - ) - self.check_fields( - objName, chartLineSettings['properties']['delay'], **{'$ref': ref} - ) - self.check_fields( - objName, chartLineSettings['properties']['ok'], **{'$ref': ref} - ) - self.check_fields( - objName, chartLineSettings['properties']['error'], **{'$ref': ref} - ) - self.check_fields( - objName, chartLineSettings['properties']['interrupted'], **{'$ref': ref} - ) - self.check_fields( - objName, chartLineSettings['properties']['offline'], **{'$ref': ref} - ) - - del chartLineSettings - - counterWidgetSetting = definitions['CounterWidgetSetting'] - objName = 'CounterWidgetSetting' - - self.check_fields( - objName, counterWidgetSetting['properties']['active'], - type='boolean', default=True - ) - self.check_fields( - objName, counterWidgetSetting['properties']['collapse'], - type='boolean', default=False, readOnly=True - ) - self.check_fields( - objName, counterWidgetSetting['properties']['sort'], type='integer', default=0 - ) - del counterWidgetSetting - - widgetSetting = definitions['WidgetSetting'] - objName = 'WidgetSetting' - - self.check_fields( - objName, widgetSetting['properties']['active'], type='boolean', default=True - ) - self.check_fields( - objName, widgetSetting['properties']['collapse'], - type='boolean', default=False - ) - self.check_fields( - objName, widgetSetting['properties']['sort'], type='integer', default=0 - ) - del widgetSetting - - widgetSettings = definitions['WidgetSettings'] - objName = 'WidgetSettings' - - widgetList = ['pmwUsersCounter', 'pmwProjectsCounter', 'pmwTemplatesCounter', - 'pmwInventoriesCounter', 'pmwGroupsCounter', 'pmwHostsCounter', - 'pmwChartWidget'] - self.check_fields(objName, widgetSettings['required'], *widgetList) - ref = '#/definitions/CounterWidgetSetting' - self.check_fields( - objName, widgetSettings['properties']['pmwUsersCounter'], **{'$ref': ref} - ) - self.check_fields( - objName, widgetSettings['properties']['pmwProjectsCounter'], **{'$ref': ref} - ) - self.check_fields( - objName, widgetSettings['properties']['pmwInventoriesCounter'], - **{'$ref': ref} - ) - self.check_fields( - objName, widgetSettings['properties']['pmwGroupsCounter'], **{'$ref': ref} - ) - self.check_fields( - objName, widgetSettings['properties']['pmwHostsCounter'], **{'$ref': ref} - ) - ref = '#/definitions/WidgetSetting' - self.check_fields( - objName, widgetSettings['properties']['pmwChartWidget'], **{'$ref': ref} - ) - del widgetSettings - - userSettings = definitions['UserSettings'] - objName = 'UserSettings' - - self.check_fields( - objName, userSettings['required'], 'chartLineSettings', 'widgetSettings' - ) - - ref = '#/definitions/ChartLineSettings' - self.check_fields( - objName, userSettings['properties']['chartLineSettings'], **{'$ref': ref} - ) - ref = '#/definitions/WidgetSettings' - self.check_fields( - objName, userSettings['properties']['widgetSettings'], **{'$ref': ref} - ) - del userSettings - - for path in schema['paths']: - p = path.split('/') - p = list(filter(bool, p)) - keys = [ - 'host', 'inventory', 'group', 'variables', 'project', - 'all_hosts', 'all_groups', 'history', 'playbook', - 'module', 'team', 'periodic_task', 'hook', 'user', - 'template' - ] - if '{' in p[-1]: - name = p[-2] - parent = p[-4] if len(p) > 4 else p[0] - type = '_detail' - else: - name = p[-1] - parent = p[-3] if len(p) > 3 else p[0] - type = '_list' - if name in keys: - if name == 'variables' and parent == 'project': - ref = '#/definitions/ProjectVariable' - getattr(self, 'check_path_' + name + type)(schema, path, ref=ref) - elif parent == 'periodic_task': - ref = '#/definitions/PeriodicTaskVariable' - getattr(self, 'check_path_' + name + type)(schema, path, ref=ref) - else: - getattr(self, 'check_path_' + name + type)( - schema, path, parent=parent - ) - else: - getattr( - self, 'check_path_' + name, self.check_path_default - )(schema, path, parent=parent) - - def check_path_default(self, schema, path, *args, **kwargs): # nocv - self.models.logger.warning( - "There are no checks for this path [{}]".format(path) - ) - - def check_fields(self, objname, obj, *args, **kwargs): - if args: - self.assertTrue( - all(val in args for val in obj), - 'input_data doesn\'t have enough keys\nargs={}\nobj={}'.format(args, obj) - ) - msg = '{} doesn\'t have enough keys'.format(objname) - self.assertTrue( - all(val in obj for val in args), msg - ) - if kwargs: - - objKeys = list(obj.keys()) - objName = objname + ':' + obj.pop('title', '') - exclude_fields = ['title', 'x-nullable'] - if 'minimum' not in kwargs.keys(): - exclude_fields.append('minimum') - if 'maximum' not in kwargs.keys(): - exclude_fields.append('maximum') - for key in exclude_fields: - objKeys.remove(key) if key in objKeys else None - - keys_in_kwargs = all(key in kwargs for key in objKeys) - keys_in_obj = all(key in obj for key in kwargs.keys()) - err_kw = ( - 'kwargs doesn\'t have enough keys\nobj={}\nkwargs={}\nobjKeys={}' - ).format(obj, kwargs.keys(), objKeys) - err_obj = ( - 'object doesn\'t have enough keys\nobj={}\nkwargs={}\nobjKeys={}' - ).format(obj, kwargs.keys(), objKeys) - self.assertTrue(keys_in_kwargs, err_kw) - self.assertTrue(keys_in_obj, err_obj) - - if keys_in_kwargs and keys_in_obj: - for key in objKeys: - if key == 'description': - self.assertTrue( - obj[key], 'Description is empty. [{}]'.format(objName) - ) - continue - elif key == 'additionalProperties' or isinstance(obj[key], dict): - self.check_fields(objName, obj[key], **kwargs[key]) - elif key == 'enum' or isinstance(obj[key], list): - self.check_fields(objName, obj[key], *kwargs[key]) - else: - msg = 'input_data[{key}]:{in_val} != {obj}[{key}]:{obj_val}' - msg = msg.format( - key=key, in_val=kwargs[key], obj=objName, obj_val=obj[key] - ) - self.assertEqual(obj[key], kwargs[key], msg) - - def check_ref(self, schema, ref, *args, **kwargs): - path = ref[2:].split('/') - obj = schema - for val in path: - try: - obj = obj[val] - except: # nocv - raise Exception('Definition \'#/' + '/'.join(path) + '\' doesn\'t exist') - - def get_params_checked_value_by_name(self, name, checked_value, *args, **kwargs): - for index in range(len(checked_value)): - if checked_value[index]['name'] == name: - return checked_value[index] - - def check_parameters(self, object_parameters, *arg, **kwargs): - checked_values = kwargs.pop('params', None) - in_values = kwargs.pop('params_in_values', None) - path = kwargs.pop('path', None) - for index in range(len(object_parameters)): - param_obj = object_parameters[index] - if object_parameters[index]: - self.assertEqual(param_obj['in'], in_values) - del param_obj['in'] - param_checked_value = self.get_params_checked_value_by_name( - param_obj['name'], checked_values - ) - self.check_fields(path, param_obj, **param_checked_value) - - def check_request(self, obj, *args, **kwargs): - response_code = kwargs.pop('response_code', '200') - request_value = kwargs.pop('request_value', None) - path = kwargs.pop('name', None) - self.assertTrue(request_value, '{} doesn\'t have data for check'.format(obj)) - schema = kwargs.pop('schema', None) - self.assertTrue(schema) - - # Check parameters - params = request_value.pop('params', None) - params_in_values = kwargs.pop('in_values', None) - self.check_parameters( - obj['parameters'], - params=params, params_in_values=params_in_values, path=path - ) - - # Check responses - responses = request_value.pop('responses', None) - - self.check_fields(path, obj['responses'][response_code], **responses) - if response_code != '204': - if responses['schema'].get('$ref', None): - ref = responses['schema']['$ref'] - else: - ref = responses['schema']['properties']['results']['items']['$ref'] - self.check_ref(schema, ref) - - def check_path(self, schema, path, requests=None, *args, **kwargs): - path_parameters = self.re_path.findall(path) - # If detail: `requests`={'GET', 'PUT', 'PATCH', 'DELETE'} - # else this list: `requests`={'GET', 'POST'} - if not requests: - if path_parameters and path.split(path_parameters[-1])[-1] == '}/': - requests = dict(get='query', put='body', patch='body', delete='') - else: - requests = dict(get='query', post='body') - - for request in requests.keys(): - request_value = kwargs.pop(request+'_value', None) - response_code = request_value.pop('response_code', '200') - self.check_request( - schema['paths'][path][request], - schema=schema, name=path, response_code=response_code, - request_value=request_value, in_values=requests[request] - ) - - parameters = schema['paths'][path]['parameters'] - for parameter in parameters: - if parameter['name'] in path_parameters: - path_parameters.remove(parameter['name']) - else: # nocv - msg = 'In \'{path}\'[parameters], have key \'{key}\' ' \ - 'doesn\'t exist in {path}' - self.logging(msg, path=path, key=parameter['name']) - msg = 'In `{path}`[parameters], not enough keys for path'.format(path=path) - self.assertEqual(len(path_parameters), 0, msg) - - def logging(self, msg, *args, **kwargs): # nocv - output_msg = msg.format(*args, **kwargs) - print(output_msg) - - def check_path_variables_list(self, schema, path, ref=None, *arg, **kwargs): - if not ref: - ref = '#/definitions/InventoryVariable' - # Get data - get_params = [ - dict(name='key', description=True, required=False, type='string'), - dict(name='value', description=True, required=False, type='string'), - ] + self.pm_filters + self.default_filters - get_schema = dict( - required=['count', 'results'], - properties=dict( - count=dict(type='integer'), next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ), - type='object' - ) - get_responses = dict(description=True, schema=get_schema) - get_value = dict( - responses=get_responses, params=get_params, response_code='200' - ) - - # Post data - post_params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - post_response = dict( - description=True, schema={'$ref': ref} - ) - post_value = dict( - responses=post_response, params=post_params, response_code='201' - ) - self.check_path(schema, path, post_value=post_value, get_value=get_value) - - def check_path_variables_detail(self, schema, path, ref=None, *arg, **kwargs): - if not ref: - ref = '#/definitions/InventoryVariable' - # Get data - params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - responses = dict(description=True, schema={'$ref': ref}) - get_value = dict(responses=responses, params=[], response_code='200') - put_value = dict(responses=responses, params=params, response_code='200') - patch_value = dict(responses=responses, params=params, response_code='200') - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) - self.check_path( - schema, path, get_value=get_value, put_value=put_value, - patch_value=patch_value, delete_value=delete_value - ) - - def check_path_host_list(self, schema, path, *args, **kwargs): - get_params = [ - dict(name='type', description=True, required=False, type='string'), - dict(name='variables', description=True, required=False, type='string'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - get_schema = dict( - required=['count', 'results'], - properties=dict( - count=dict(type='integer'), next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': '#/definitions/Host'}) - ), - type='object' - ) - get_responses = dict(description=True, schema=get_schema) - get_value = dict( - responses=get_responses, params=get_params, response_code='200' - ) - - ref = '#/definitions/OneHost' - post_params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - post_response = dict( - description=True, schema={'$ref': ref} - ) - post_value = dict( - responses=post_response, params=post_params, response_code='201' - ) - self.check_path(schema, path, post_value=post_value, get_value=get_value) - - def check_path_host_detail(self, schema, path, *args, **kwargs): - ref = '#/definitions/OneHost' - # Get data - params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - responses = dict(description=True, schema={'$ref': ref}) - - get_value = dict(responses=responses, params=[], response_code='200') - put_value = dict(responses=responses, params=params, response_code='200') - patch_value = dict(responses=responses, params=params, response_code='200') - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) - - self.check_path( - schema, path, get_value=get_value, put_value=put_value, - patch_value=patch_value, delete_value=delete_value - ) - - def check_path_group_list(self, schema, path, *arg, **kwargs): - get_params = [ - dict(name='variables', description=True, required=False, type='string'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - get_schema = dict( - required=['count', 'results'], - properties=dict( - count=dict(type='integer'), next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': '#/definitions/Group'}) - ), - type='object' - ) - get_responses = dict(description=True, schema=get_schema) - get_value = dict( - responses=get_responses, params=get_params, response_code='200' - ) - - ref = '#/definitions/GroupCreateMaster' - post_params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - post_response = dict( - description=True, schema={'$ref': ref} - ) - post_value = dict( - responses=post_response, params=post_params, response_code='201' - ) - self.check_path(schema, path, post_value=post_value, get_value=get_value) - - def check_path_group_detail(self, schema, path, *arg, **kwargs): - ref = '#/definitions/OneGroup' - # Get data - params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - responses = dict(description=True, schema={'$ref': ref}) - - get_value = dict(responses=responses, params=[], response_code='200') - put_value = dict(responses=responses, params=params, response_code='200') - patch_value = dict(responses=responses, params=params, response_code='200') - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) - - self.check_path( - schema, path, get_value=get_value, put_value=put_value, - patch_value=patch_value, delete_value=delete_value - ) - - def check_path_inventory_list(self, schema, path, *arg, **kwargs): - get_params = [ - dict(name='variables', description=True, required=False, type='string'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - get_schema = dict( - required=['count', 'results'], - properties=dict( - count=dict(type='integer'), next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': '#/definitions/Inventory'}) - ), - type='object' - ) - get_responses = dict(description=True, schema=get_schema) - get_value = dict( - responses=get_responses, params=get_params, response_code='200' - ) - - ref = '#/definitions/OneInventory' - post_params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - post_response = dict( - description=True, schema={'$ref': ref} - ) - post_value = dict( - responses=post_response, params=post_params, response_code='201' - ) - self.check_path(schema, path, post_value=post_value, get_value=get_value) - - def check_path_inventory_detail(self, schema, path, *arg, **kwargs): - ref = '#/definitions/OneInventory' - # Get data - params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - responses = dict(description=True, schema={'$ref': ref}) - - get_value = dict(responses=responses, params=[], response_code='200') - put_value = dict(responses=responses, params=params, response_code='200') - patch_value = dict(responses=responses, params=params, response_code='200') - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) - - self.check_path( - schema, path, get_value=get_value, put_value=put_value, - patch_value=patch_value, delete_value=delete_value - ) - - def check_path_project_list(self, schema, path, *arg, **kwargs): - get_params = [ - dict(name='status', description=True, required=False, type='string'), - dict(name='variables', description=True, required=False, type='string'), - dict(name='status__not', description=True, required=False, type='string'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - get_schema = dict( - required=['count', 'results'], - properties=dict( - count=dict(type='integer'), next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': '#/definitions/Project'}) - ), - type='object' - ) - get_responses = dict(description=True, schema=get_schema) - get_value = dict( - responses=get_responses, params=get_params, response_code='200' - ) - - ref = '#/definitions/ProjectCreateMaster' - post_params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - post_response = dict( - description=True, schema={'$ref': ref} - ) - post_value = dict( - responses=post_response, params=post_params, response_code='201' - ) - self.check_path(schema, path, post_value=post_value, get_value=get_value) - - def check_path_project_detail(self, schema, path, *arg, **kwargs): - ref = '#/definitions/OneProject' - # Get data - params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - responses = dict(description=True, schema={'$ref': ref}) - - get_value = dict(responses=responses, params=[], response_code='200') - put_value = dict(responses=responses, params=params, response_code='200') - patch_value = dict(responses=responses, params=params, response_code='200') - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) - - self.check_path( - schema, path, get_value=get_value, put_value=put_value, - patch_value=patch_value, delete_value=delete_value - ) - - def check_path_copy(self, schema, path, *args, **kwargs): - parent = kwargs.pop('parent', None) - ref = '#/definitions/' + parent.capitalize() - params = [ - dict(name='data', required=True, schema={'$ref': ref}) - ] - responses = dict(description=True, schema={'$ref': ref}) - post_value = dict(responses=responses, params=params, response_code='201') - - self.check_path(schema, path, requests=dict(post='body'), post_value=post_value) - - def check_path_set_owner(self, schema, path, *args, **kwargs): - ref = '#/definitions/SetOwner' - - params = [dict(name='data', required=True, schema={'$ref': ref})] - responses = dict(description=True, schema={'$ref': ref}) - post_value = dict(responses=responses, params=params, response_code='201') - - self.check_path(schema, path, requests=dict(post='body'), post_value=post_value) - - def check_path_all_hosts_list(self, schema, path, *args, **kwargs): - ref = '#/definitions/Host' - - params = [ - dict(name='type', description=True, required=False, type='string'), - dict(name='variables', description=True, required=False, type='string'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - responses = dict( - description=True, - schema=dict( - required=['count', 'results'], type='object', - properties=dict( - count=dict(type='integer'), - next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ) - ) - ) - get_value = dict(responses=responses, params=params, response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_all_hosts_detail(self, schema, path, *args, **kwargs): - ref = '#/definitions/OneHost' - - responses = dict(description=True, schema={'$ref': ref}) - get_value = dict(responses=responses, params=[], response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_all_groups_list(self, schema, path, *args, **kwargs): - ref = '#/definitions/Group' - - params = [ - dict(name='variables', description=True, required=False, type='string'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - responses = dict( - description=True, - schema=dict( - required=['count', 'results'], type='object', - properties=dict( - count=dict(type='integer'), - next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ) - ) - ) - get_value = dict(responses=responses, params=params, response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_all_groups_detail(self, schema, path, *args, **kwargs): - ref = '#/definitions/OneGroup' - - responses = dict(description=True, schema={'$ref': ref}) - get_value = dict(responses=responses, params=[], response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_execute_playbook(self, schema, path, *args, **kwargs): - ref = '#/definitions/AnsiblePlaybook' - - params = [dict(name='data', required=True, schema={'$ref': ref})] - - ref = '#/definitions/ExecuteResponse' - responses = dict(description=True, schema={'$ref': ref}) - post_value = dict(responses=responses, params=params, response_code='201') - self.check_path(schema, path, requests=dict(post='body'), post_value=post_value) - - def check_path_history_list(self, schema, path, *args, **kwargs): - parent = kwargs.pop('parent', None) - if parent == 'history': - ref = '#/definitions/History' - else: - ref = '#/definitions/{}History'.format(parent.capitalize()) - - params = [ - dict(name='mode', description=True, required=False, type='string'), - dict(name='kind', description=True, required=False, type='string'), - dict(name='status', description=True, required=False, type='string'), - dict(name='older', description=True, required=False, type='string'), - dict(name='newer', description=True, required=False, type='string'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - responses = dict( - description=True, - schema=dict( - required=['count', 'results'], type='object', - properties=dict( - count=dict(type='integer'), next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ) - ) - ) - get_value = dict(params=params, responses=responses, response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_history_detail(self, schema, path, *args, **kwargs): - ref = '#/definitions/OneHistory' - responses = dict(description=True, schema={'$ref': ref}) - - get_value = dict(params=[], responses=responses, response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_settings(self, schema, path, *args, **kwargs): - ref = '#/definitions/UserSettings' - - get_responses = dict(description=True, schema={'$ref': ref}) - get_value = dict(params=[], responses=get_responses, response_code='200') - - post_params = [ - dict(name='data', required=True, schema={'$ref': ref}) - ] - post_responses = dict(description=True, schema={'$ref': ref}) - post_value = dict( - params=post_params, responses=post_responses, response_code='201' - ) - self.check_path( - schema, path, requests=dict(get='query', post='body'), - get_value=get_value, post_value=post_value - ) - - def check_path_playbook_list(self, schema, path, *args, **kwargs): - ref = '#/definitions/Playbook' - - params = [ - dict(name='playbook', description=True, required=False, type='string'), - dict(name='playbook__not', description=True, required=False, type='string'), - dict(name='pb_filter', description=True, required=False, type='string'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - responses = dict( - description=True, - schema=dict( - required=['count', 'results'], type='object', - properties=dict( - count=dict(type='integer'), next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ) - ) - ) - get_value = dict(responses=responses, params=params, response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_playbook_detail(self, schema, path, *args, **kwargs): - ref = '#/definitions/OnePlaybook' - - responses = dict(description=True, schema={'$ref': ref}) - get_value = dict(params=[], responses=responses, response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_sync(self, schema, path, *args, **kwargs): - ref = '#/definitions/Empty' - params = [dict(name='data', required=True, schema={'$ref': ref})] - ref = '#/definitions/ActionResponse' - responses = dict(description=True, schema={'$ref': ref}) - - post_value = dict(responses=responses, params=params, response_code='200') - self.check_path(schema, path, requests=dict(post='body'), post_value=post_value) - - def check_path_hook_list(self, schema, path, *args, **kwars): - ref = '#/definitions/Hook' - - get_params = [ - dict(name='type', description=True, required=False, type='string'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - get_responses = dict( - description=True, - schema=dict( - required=['count', 'results'], type='object', - properties=dict( - count=dict(type='integer'), next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ) - ) - ) - get_value = dict(responses=get_responses, params=get_params, response_code='200') - - post_params = [ - dict(name='data', required=True, schema={'$ref': ref}) - ] - post_responses = dict(description=True, schema={'$ref': ref}) - post_value = dict( - responses=post_responses, params=post_params, response_code='201' - ) - self.check_path( - schema, path, requests=dict(get='query', post='body'), post_value=post_value, - get_value=get_value - ) - - def check_path_hook_detail(self, schema, path, *arg, **kwargs): - ref = '#/definitions/Hook' - # Get data - params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - responses = dict(description=True, schema={'$ref': ref}) - - get_value = dict(responses=responses, params=[], response_code='200') - put_value = dict(responses=responses, params=params, response_code='200') - patch_value = dict(responses=responses, params=params, response_code='200') - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) - - self.check_path( - schema, path, get_value=get_value, put_value=put_value, - patch_value=patch_value, delete_value=delete_value - ) - - def check_path_execute_module(self, schema, path, *args, **kwargs): - ref = '#/definitions/AnsibleModule' - - params = [ - dict(name='data', required=True, schema={'$ref': ref}) - ] - ref = '#/definitions/ExecuteResponse' - responses = dict(description=True, schema={'$ref': ref}) - post_value = dict(responses=responses, params=params, response_code='201') - self.check_path(schema, path, requests=dict(post='body'), post_value=post_value) - - def check_path_module_list(self, schema, path, *args, **kwargs): - ref = '#/definitions/Module' - - params = [ - dict(name='path', description=True, required=False, type='string'), - dict(name='path__not', description=True, required=False, type='string'), - dict(name='name', description=True, required=False, type='string'), - ] + self.default_filters - responses = dict( - description=True, - schema=dict( - required=['count', 'results'], type='object', - properties=dict( - count=dict(type='integer'), - next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ) - ) - ) - get_value = dict(params=params, responses=responses, response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_module_detail(self, schema, path, *args, **kwargs): - ref = '#/definitions/OneModule' - - responses = dict(description=True, schema={'$ref': ref}) - get_value = dict(params=[], responses=responses, response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_cancel(self, schema, path, *arg, **kwargs): - ref = '#/definitions/ActionResponse' - - params = [ - dict(name='data', required=True, schema={'$ref': '#/definitions/Empty'}) - ] - responses = dict(description=True, schema={'$ref': ref}) - post_value = dict(responses=responses, params=params, response_code='200') - self.check_path(schema, path, requests=dict(post='body'), post_value=post_value) - - def check_path_change_password(self, schema, path, *args, **kwargs): - ref = '#/definitions/ChangePassword' - - params = [ - dict(name='data', required=True, schema={'$ref': ref}) - ] - responses = dict(description=True, schema={'$ref': ref}) - - post_value = dict(responses=responses, params=params, response_code='201') - self.check_path(schema, path, requests=dict(post='body'), post_value=post_value) - - def check_path_user_list(self, schema, path, *args, **kwargs): - ref = '#/definitions/User' - - get_params = [ - dict(name='username', description=True, required=False, type='string'), - dict(name='is_active', description=True, required=False, type='string'), - dict(name='first_name', description=True, required=False, type='string'), - dict(name='last_name', description=True, required=False, type='string'), - dict(name='email', description=True, required=False, type='string'), - dict(name='username__not', description=True, required=False, type='string'), - ] + self.pm_filters + self.default_filters - get_responses = dict( - description=True, - schema=dict( - required=['count', 'results'], type='object', - properties=dict( - count=dict(type='integer'), - next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ) - ) - ) - get_value = dict(responses=get_responses, params=get_params, response_code='200') - - ref = '#/definitions/CreateUser' - post_params = [ - dict(name='data', required=True, schema={'$ref': ref}) - ] - post_responses = dict(description=True, schema={'$ref': ref}) - post_value = dict( - responses=post_responses, params=post_params, response_code='201' - ) - - self.check_path( - schema, path, requests=dict(get='query', post='body'), - post_value=post_value, get_value=get_value - ) - - def check_path_user_detail(self, schema, path, *args, **kwargs): - ref = '#/definitions/OneUser' - # Get data - params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - responses = dict(description=True, schema={'$ref': ref}) - - get_value = dict(responses=responses, params=[], response_code='200') - put_value = dict(responses=responses, params=params, response_code='200') - patch_value = dict(responses=responses, params=params, response_code='200') - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) - - self.check_path( - schema, path, get_value=get_value, put_value=put_value, - patch_value=patch_value, delete_value=delete_value - ) - - def check_path_execute(self, schema, path, *args, **kwargs): - parent = kwargs.pop('parent', None) - if parent == 'template': - ref = '#/definitions/TemplateExec' - else: - ref = '#/definitions/Empty' - - params = [ - dict(name='data', required=True, schema={'$ref': ref}) - ] - - ref = '#/definitions/ExecuteResponse' - responses = dict(description=True, schema={'$ref': ref}) - post_value = dict(responses=responses, params=params, response_code='201') - self.check_path(schema, path, requests=dict(post='body'), post_value=post_value) - - def check_path_team_list(self, schema, path, *args, **kwargs): - ref = '#/definitions/Team' - - get_params = [] + self.pm_filters + self.pm_name_filter + self.default_filters - get_responses = dict( - description=True, - schema=dict( - required=['count', 'results'], type='object', - properties=dict( - count=dict(type='integer'), - next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ) - ) - ) - get_value = dict(params=get_params, responses=get_responses, response_code='200') - - ref = '#/definitions/OneTeam' - post_params = [ - dict(name='data', required=True, schema={'$ref': ref}) - ] - post_responses = dict(description=True, schema={'$ref': ref}) - post_value = dict( - params=post_params, responses=post_responses, response_code='201' - ) - - self.check_path( - schema, path, requests=dict(get='query', post='body'), - post_value=post_value, get_value=get_value - ) - - def check_path_team_detail(self, schema, path, *args, **kwargs): - ref = '#/definitions/OneTeam' - # Get data - params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - responses = dict(description=True, schema={'$ref': ref}) - - get_value = dict(responses=responses, params=[], response_code='200') - put_value = dict(responses=responses, params=params, response_code='200') - patch_value = dict(responses=responses, params=params, response_code='200') - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) - - self.check_path( - schema, path, get_value=get_value, put_value=put_value, - patch_value=patch_value, delete_value=delete_value - ) - - def check_path_facts(self, schema, path, *args, **kwargs): - ref = '#/definitions/Data' - - responses = dict(description=True, schema={'$ref': ref}) - get_value = dict(responses=responses, params=[], response_code='200') - self.check_path(schema, path, requests=dict(get='query'), get_value=get_value) - - def check_path_periodic_task_list(self, schema, path, *args, **kwargs): - ref = '#/definitions/Periodictask' - - get_params = [ - dict(name='mode', description=True, required=False, type='string'), - dict(name='kind', description=True, required=False, type='string'), - dict(name='type', description=True, required=False, type='string'), - dict(name='template', description=True, required=False, type='number'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - get_responses = dict( - description=True, - schema=dict( - required=['count', 'results'], type='object', - properties=dict( - count=dict(type='integer'), - next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ) - ) - ) - - get_value = dict(responses=get_responses, params=get_params, response_code='200') - - ref = '#/definitions/OnePeriodictask' - post_params = [ - dict(name='data', required=True, schema={'$ref': ref}) - ] - post_responses = dict(description=True, schema={'$ref': ref}) - post_value = dict( - responses=post_responses, params=post_params, response_code='201' - ) - self.check_path( - schema, path, requests=dict(get='query', post='body'), - post_value=post_value, get_value=get_value - ) - - def check_path_periodic_task_detail(self, schema, path, *args, **kwargs): - ref = '#/definitions/OnePeriodictask' - # Get data - params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - responses = dict(description=True, schema={'$ref': ref}) - - get_value = dict(responses=responses, params=[], response_code='200') - put_value = dict(responses=responses, params=params, response_code='200') - patch_value = dict(responses=responses, params=params, response_code='200') - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) - - self.check_path( - schema, path, get_value=get_value, put_value=put_value, - patch_value=patch_value, delete_value=delete_value - ) - - def check_path_clear(self, schema, path, *args, **kwargs): - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) - self.check_path(schema, path, requests=dict(delete=''), delete_value=delete_value) - - def check_path_template_list(self, schema, path, *args, **kwargs): - ref = '#/definitions/Template' - - get_params = [ - dict(name='kind', description=True, required=False, type='string'), - dict(name='inventory', description=True, required=False, type='string'), - ] + self.pm_filters + self.pm_name_filter + self.default_filters - get_responses = dict( - description=True, - schema=dict( - required=['count', 'results'], type='object', - properties=dict( - count=dict(type='integer'), - next=dict(type='string', format='uri'), - previous=dict(type='string', format='uri'), - results=dict(type='array', items={'$ref': ref}) - ) - ) - ) - - get_value = dict(responses=get_responses, params=get_params, response_code='200') - - ref = '#/definitions/OneTemplate' - post_params = [ - dict(name='data', required=True, schema={'$ref': ref}) - ] - post_responses = dict(description=True, schema={'$ref': ref}) - post_value = dict( - responses=post_responses, params=post_params, response_code='201' - ) - self.check_path( - schema, path, requests=dict(get='query', post='body'), - post_value=post_value, get_value=get_value - ) - - def check_path_template_detail(self, schema, path, *args, **kwargs): - ref = '#/definitions/OneTemplate' - # Get data - params = [dict( - name='data', required=True, schema={'$ref': ref} - )] - responses = dict(description=True, schema={'$ref': ref}) + with openapi_schema_yaml.open('r') as fin: + openapi_schema_yml = yaml.load(fin, Loader=yaml.SafeLoader) - get_value = dict(responses=responses, params=[], response_code='200') - put_value = dict(responses=responses, params=params, response_code='200') - patch_value = dict(responses=responses, params=params, response_code='200') - delete_value = dict( - responses=dict(description=True), params=[], response_code='204' - ) + openapi_schema_yml['host'] = self.server_name + openapi_schema_yml['schemes'][0] = 'https' + openapi_schema_yml['info']['contact'] = schema['info']['contact'] + openapi_schema_yml['info']['x-versions']['vstutils'] = schema['info']['x-versions']['vstutils'] + openapi_schema_yml['info']['x-versions']['ansible'] = schema['info']['x-versions']['ansible'] - self.check_path( - schema, path, get_value=get_value, put_value=put_value, - patch_value=patch_value, delete_value=delete_value - ) + self.assertDictEqual(openapi_schema_yml, schema) From 78ae4d8a5b534d82d6608f485cd31fa34029416c Mon Sep 17 00:00:00 2001 From: Sergey Klyuykov Date: Mon, 9 Dec 2019 17:20:32 +1000 Subject: [PATCH 4/7] Fix for openapi diff output --- .gitlab-ci.yml | 1 - polemarch/main/tests/openapi.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 599f45d4..a2715494 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -86,7 +86,6 @@ py37-coverage: <<: *branch_tests variables: TOX_ENVS: "$CI_BUILD_NAME" - allow_failure: true py36-install: <<: *branch_tests diff --git a/polemarch/main/tests/openapi.py b/polemarch/main/tests/openapi.py index e8aa67ef..b1810bd6 100644 --- a/polemarch/main/tests/openapi.py +++ b/polemarch/main/tests/openapi.py @@ -8,6 +8,7 @@ class OApiTestCase(BaseTestCase): + maxDiff = None @skipUnless(openapi_schema_yaml.is_file(), "OpenApi schema file doesn't exist") def test_openapi_schema(self): @@ -19,7 +20,6 @@ def test_openapi_schema(self): openapi_schema_yml['host'] = self.server_name openapi_schema_yml['schemes'][0] = 'https' openapi_schema_yml['info']['contact'] = schema['info']['contact'] - openapi_schema_yml['info']['x-versions']['vstutils'] = schema['info']['x-versions']['vstutils'] - openapi_schema_yml['info']['x-versions']['ansible'] = schema['info']['x-versions']['ansible'] + openapi_schema_yml['info']['x-versions'] = schema['info']['x-versions'] self.assertDictEqual(openapi_schema_yml, schema) From 7ec2829faefd603ce3d9798b78dfd040f152db62 Mon Sep 17 00:00:00 2001 From: Akhmadullin Roman Date: Mon, 9 Dec 2019 07:53:58 +0000 Subject: [PATCH 5/7] Fix bug with several enum fields in .polemarch.yaml form. polemarch/ce#240 --- polemarch/static/js/pmProjects.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/polemarch/static/js/pmProjects.js b/polemarch/static/js/pmProjects.js index 6e98b547..9dab6b63 100644 --- a/polemarch/static/js/pmProjects.js +++ b/polemarch/static/js/pmProjects.js @@ -312,8 +312,7 @@ const gui_project_page_additional = Vue.component('gui_project_page_additional', * @param {object} value New form value. */ formOnChangeHandler(prop, value) { - this[prop] = value; - this[prop] = { ...this[prop] }; + this[prop] = { ...this[prop], ...value }; }, }, }); From 1bc9ed1384901f48e9854d53c7ec4a524f5c3a97 Mon Sep 17 00:00:00 2001 From: Sergey Klyuykov Date: Mon, 9 Dec 2019 18:23:59 +1000 Subject: [PATCH 6/7] Update min vstutils version --- requirements-doc.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-doc.txt b/requirements-doc.txt index 1aceaecb..2b830631 100644 --- a/requirements-doc.txt +++ b/requirements-doc.txt @@ -1,2 +1,2 @@ # Docs -vstutils[doc]~=2.11.0 +vstutils[doc]~=2.11.2 diff --git a/requirements.txt b/requirements.txt index 6c704587..515d669b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Main -vstutils[rpc,ldap,doc,prod]~=2.11.0 +vstutils[rpc,ldap,doc,prod]~=2.11.2 docutils==0.15.2 markdown2==2.3.8 From 88bfc3309f2bbd4a8ba43fd9e1e3a2718cbb1005 Mon Sep 17 00:00:00 2001 From: Sergey Klyuykov Date: Tue, 10 Dec 2019 13:40:57 +1000 Subject: [PATCH 7/7] Update min vstutils version --- doc/api_schema.yaml | 100 +++++++++++++++--------------- polemarch/__init__.py | 2 +- polemarch/main/models/__init__.py | 3 +- polemarch/main/models/base.py | 4 +- polemarch/main/models/tasks.py | 3 +- polemarch/main/models/users.py | 3 +- polemarch/main/models/vars.py | 1 + polemarch/main/tests/api.py | 7 +-- polemarch/main/tests/openapi.py | 4 +- tox.ini | 3 +- 10 files changed, 64 insertions(+), 66 deletions(-) diff --git a/doc/api_schema.yaml b/doc/api_schema.yaml index 3788e44a..81d52caf 100755 --- a/doc/api_schema.yaml +++ b/doc/api_schema.yaml @@ -11,52 +11,52 @@ info: has_docs: true docs_url: /docs/ x-links: - Request: - - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Ask&issue%5Btitle%5D=Ask%20about%20version%201.5.1 - name: Question - - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Bug&issue%5Btitle%5D=Bug%20in%20version%201.5.1 - name: Bug report - - url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Feature%20request&issue%5Btitle%5D= - name: Feature request Documentation: - url: http://polemarch.readthedocs.io/ name: Official documentation + url: http://polemarch.readthedocs.io/ Repository: - url: https://gitlab.com/vstconsulting/polemarch.git name: Official repository + url: https://gitlab.com/vstconsulting/polemarch.git + Request: + - name: Question + url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Ask&issue%5Btitle%5D=Ask%20about%20version%201.5.2 + - name: Bug report + url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Bug&issue%5Btitle%5D=Bug%20in%20version%201.5.2 + - name: Feature request + url: https://gitlab.com/vstconsulting/polemarch/issues/new?issuable_template%5D=Feature%20request&issue%5Btitle%5D= x-menu: - name: Projects - url: /project span_class: fa fa-fort-awesome + url: /project - name: Community - url: /community_template span_class: fa fa-cloud + url: /community_template - name: Inventories - url: /inventory span_class: fa fa-folder sublinks: - name: Groups - url: /group span_class: fa fa-tasks + url: /group - name: Hosts - url: /host span_class: fa fa-codepen + url: /host + url: /inventory - name: History - url: /history span_class: fa fa-calendar + url: /history - name: System span_class: fa fa-cog sublinks: - name: Users - url: /user span_class: fa fa-user + url: /user - name: Hooks - url: /hook span_class: fa fa-plug + url: /hook x-versions: - application: 1.5.1 - library: 1.5.1 - vstutils: 2.11.1 + application: 1.5.2 + library: 1.5.2 + vstutils: 2.11.2 django: 2.2.7 ansible: 2.8.7 version: v2 @@ -10953,14 +10953,14 @@ definitions: type: string format: dynamic additionalProperties: - field: key choices: {} + field: key types: - ansible_ssh_pass: password - ansible_ssh_private_key_file: secretfile ansible_become: boolean - ansible_port: integer ansible_become_pass: password + ansible_port: integer + ansible_ssh_pass: password + ansible_ssh_private_key_file: secretfile Host: type: object properties: @@ -11325,15 +11325,15 @@ definitions: format: dynamic default: NONE additionalProperties: - field: type choices: GIT: - NONE - KEY - PASSWORD + field: type types: - MANUAL: hidden GIT: string + MANUAL: hidden TAR: hidden auth_data: title: Repo auth data @@ -11341,22 +11341,22 @@ definitions: format: dynamic default: '' additionalProperties: - field: repo_auth choices: {} + field: repo_auth types: KEY: secretfile - PASSWORD: password NONE: hidden + PASSWORD: password branch: title: Branch for GIT(branch/tag/SHA) or TAR(subdir) type: string format: dynamic additionalProperties: - field: type choices: {} + field: type types: - MANUAL: hidden GIT: string + MANUAL: hidden TAR: string x-nullable: true OneProject: @@ -11885,22 +11885,22 @@ definitions: type: string format: dynamic additionalProperties: - field: kind choices: {} + field: kind types: - PLAYBOOK: fk_autocomplete MODULE: fk_autocomplete + PLAYBOOK: fk_autocomplete TEMPLATE: hidden inventory: title: Inventory type: string format: dynamic additionalProperties: - field: kind choices: {} + field: kind types: - PLAYBOOK: fk_autocomplete MODULE: fk_autocomplete + PLAYBOOK: fk_autocomplete TEMPLATE: hidden save_result: title: Save result @@ -11914,11 +11914,11 @@ definitions: type: string format: dynamic additionalProperties: - field: kind choices: {} + field: kind types: - PLAYBOOK: hidden MODULE: hidden + PLAYBOOK: hidden TEMPLATE: autocomplete enabled: title: Enabled @@ -11935,8 +11935,8 @@ definitions: type: string format: dynamic additionalProperties: - field: type choices: {} + field: type types: CRONTAB: crontab INTERVAL: integer @@ -11967,22 +11967,22 @@ definitions: type: string format: dynamic additionalProperties: - field: kind choices: {} + field: kind types: - PLAYBOOK: fk_autocomplete MODULE: fk_autocomplete + PLAYBOOK: fk_autocomplete TEMPLATE: hidden inventory: title: Inventory type: string format: dynamic additionalProperties: - field: kind choices: {} + field: kind types: - PLAYBOOK: fk_autocomplete MODULE: fk_autocomplete + PLAYBOOK: fk_autocomplete TEMPLATE: hidden save_result: title: Save result @@ -11996,11 +11996,11 @@ definitions: type: string format: dynamic additionalProperties: - field: kind choices: {} + field: kind types: - PLAYBOOK: hidden MODULE: hidden + PLAYBOOK: hidden TEMPLATE: autocomplete enabled: title: Enabled @@ -12017,8 +12017,8 @@ definitions: type: string format: dynamic additionalProperties: - field: type choices: {} + field: type types: CRONTAB: crontab INTERVAL: integer @@ -12182,20 +12182,20 @@ definitions: type: string format: dynamic additionalProperties: - field: key choices: + repo_sync_on_run: + - true + - false repo_type: - MANUAL - GIT - TAR - repo_sync_on_run: - - true - - false + field: key types: - repo_password: password + ci_template: fk repo_key: secretfile + repo_password: password repo_sync_on_run_timeout: uptime - ci_template: fk Team: required: - name diff --git a/polemarch/__init__.py b/polemarch/__init__.py index c6b30fb0..cc1a699e 100644 --- a/polemarch/__init__.py +++ b/polemarch/__init__.py @@ -31,6 +31,6 @@ "VST_ROOT_URLCONF": os.getenv("VST_ROOT_URLCONF", 'vstutils.urls'), } -__version__ = "1.5.1" +__version__ = "1.5.2" prepare_environment(**default_settings) diff --git a/polemarch/main/models/__init__.py b/polemarch/main/models/__init__.py index 47670ee7..0da73504 100644 --- a/polemarch/main/models/__init__.py +++ b/polemarch/main/models/__init__.py @@ -17,7 +17,7 @@ from .vars import Variable from .hosts import Host, Group, Inventory from .projects import Project, Task, Module, ProjectTemplate, list_to_choices -from .users import BaseUser, UserGroup, ACLPermission, UserSettings +from .users import get_user_model, UserGroup, ACLPermission, UserSettings from .tasks import PeriodicTask, History, HistoryLines, Template from .hooks import Hook from ..validators import RegexValidator, validate_hostname @@ -26,6 +26,7 @@ logger = logging.getLogger('polemarch') +BaseUser = get_user_model() ##################################### diff --git a/polemarch/main/models/base.py b/polemarch/main/models/base.py index 5f258ef4..5bdfa793 100644 --- a/polemarch/main/models/base.py +++ b/polemarch/main/models/base.py @@ -3,14 +3,14 @@ from typing import Callable, Any from django.db import models from django.conf import settings -from django.contrib.auth.models import User as BaseUser +from django.contrib.auth import get_user_model from django.utils.module_loading import import_string from vstutils.utils import classproperty from vstutils.models import BQuerySet as _BQSet, BaseModel as _BM, Manager as _BManager def first_staff_user() -> int: - return BaseUser.objects.filter(is_staff=True).first().id + return get_user_model().objects.filter(is_staff=True).first().id class BQuerySet(_BQSet): diff --git a/polemarch/main/models/tasks.py b/polemarch/main/models/tasks.py index f8fbc497..87557686 100644 --- a/polemarch/main/models/tasks.py +++ b/polemarch/main/models/tasks.py @@ -14,7 +14,7 @@ from django.db import transaction from django.db.models import Q from django.utils import timezone -from django.contrib.auth.models import User +from django.contrib.auth import get_user_model from django.db.models import functions as dbfunc, Count from django.utils.timezone import now from django.test import Client @@ -30,6 +30,7 @@ logger = logging.getLogger("polemarch") InvOrString = TypeVar('InvOrString', str, int, Inventory, None) +User = get_user_model() # Block of real models diff --git a/polemarch/main/models/users.py b/polemarch/main/models/users.py index d490dafc..a2dc0879 100644 --- a/polemarch/main/models/users.py +++ b/polemarch/main/models/users.py @@ -5,7 +5,6 @@ import json from django.contrib.auth.models import Group as BaseGroup -from django.contrib.auth.models import User as BaseUser from django.contrib.auth import get_user_model from .base import models, BModel, ACLModel, BQuerySet @@ -50,7 +49,7 @@ class UserGroup(BaseGroup, ACLModel): class UserSettings(BModel): settings = models.TextField(default="{}") - user = models.OneToOneField(BaseUser, on_delete=models.CASCADE, + user = models.OneToOneField(get_user_model(), on_delete=models.CASCADE, related_query_name="settings", related_name="settings") diff --git a/polemarch/main/models/vars.py b/polemarch/main/models/vars.py index bf498897..8f9388f2 100644 --- a/polemarch/main/models/vars.py +++ b/polemarch/main/models/vars.py @@ -110,6 +110,7 @@ class Meta: 'ansible_ssh_pass', 'ansible_ssh_private_key_file', 'ansible_become_pass', + 'ansible_become_password', 'ansible_password' ] diff --git a/polemarch/main/tests/api.py b/polemarch/main/tests/api.py index 4c102f1b..875cfcab 100644 --- a/polemarch/main/tests/api.py +++ b/polemarch/main/tests/api.py @@ -3,12 +3,7 @@ from django.test import Client from django.contrib.auth.hashers import make_password from django.utils.timezone import now - -try: - from mock import patch -except ImportError: # nocv - from unittest.mock import patch - +from unittest.mock import patch from vstutils.utils import redirect_stdany from ._base import BaseTestCase, json from .hosts import InventoriesTestCase, InvBaseTestCase # noqa: F401 diff --git a/polemarch/main/tests/openapi.py b/polemarch/main/tests/openapi.py index b1810bd6..c8a5cd54 100644 --- a/polemarch/main/tests/openapi.py +++ b/polemarch/main/tests/openapi.py @@ -4,7 +4,9 @@ from ._base import BaseTestCase -openapi_schema_yaml = Path(__file__).parent.parent.parent.parent / 'doc' / 'api_schema.yaml' +openapi_schema_yaml = Path.cwd().parent.parent / 'doc' / 'api_schema.yaml' +if not openapi_schema_yaml.exists(): + openapi_schema_yaml = Path(__file__).parent.parent.parent.parent / 'doc' / 'api_schema.yaml' class OApiTestCase(BaseTestCase): diff --git a/tox.ini b/tox.ini index 5dd9e99e..4ff9fde4 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{27,35,36,37}-{django111}-{coverage,install},flake,pylint +envlist = py{35,36,37}-{coverage,install},flake,pylint skipsdist = True setenv = PIP_CONFIG_FILE=.pip.conf whitelist_externals = @@ -34,7 +34,6 @@ commands = deps = coverage: -rrequirements.txt install: cython>=0.29.2 - py27-install: multiprocessing -rrequirements-doc.txt -rrequirements-git.txt -rrequirements-test.txt