async def validate(self, data, schema_name): verrors = ValidationErrors() if data.get('protocol') == 'httphttps' and data.get('tcpport') == data.get('tcpportssl'): verrors.add( f"{schema_name}.tcpportssl", 'The HTTP and HTTPS ports cannot be the same!' ) cert_ssl = data.get('certssl') or 0 if data.get('protocol') != 'http': if not cert_ssl: verrors.add( f"{schema_name}.certssl", 'WebDAV SSL protocol specified without choosing a certificate' ) else: verrors.extend((await self.middleware.call( 'certificate.cert_services_validation', cert_ssl, f'{schema_name}.certssl', False ))) if verrors: raise verrors return data
async def do_create(self, job, data): """ `catalog_create.preferred_trains` specifies trains which will be displayed in the UI directly for a user. """ verrors = ValidationErrors() # We normalize the label data['label'] = data['label'].upper() if await self.query([['id', '=', data['label']]]): verrors.add('catalog_create.label', 'A catalog with specified label already exists', errno=errno.EEXIST) if await self.query([['repository', '=', data['repository']], ['branch', '=', data['branch']]]): for k in ('repository', 'branch'): verrors.add( f'catalog_create.{k}', 'A catalog with same repository/branch already exists', errno=errno.EEXIST ) verrors.check() if not data['preferred_trains']: data['preferred_trains'] = ['stable'] if not data.pop('force'): job.set_progress(40, f'Validating {data["label"]!r} catalog') # We will validate the catalog now to ensure it's valid wrt contents / format path = os.path.join( TMP_IX_APPS_DIR, 'validate_catalogs', convert_repository_to_path(data['repository'], data['branch']) ) try: await self.middleware.call('catalog.update_git_repository', {**data, 'location': path}) await self.middleware.call('catalog.validate_catalog_from_path', path) await self.common_validation( {'trains': await self.middleware.call('catalog.retrieve_train_names', path)}, 'catalog_create', data ) except ValidationErrors as ve: verrors.extend(ve) except CallError as e: verrors.add('catalog_create.label', f'Failed to validate catalog: {e}') finally: await self.middleware.run_in_thread(shutil.rmtree, path, ignore_errors=True) else: job.set_progress(50, 'Skipping validation of catalog') verrors.check() job.set_progress(60, 'Completed Validation') await self.middleware.call('datastore.insert', self._config.datastore, data) job.set_progress(70, f'Successfully added {data["label"]!r} catalog') job.set_progress(80, f'Syncing {data["label"]} catalog') sync_job = await self.middleware.call('catalog.sync', data['label']) await sync_job.wait() if sync_job.error: raise CallError(f'Catalog was added successfully but failed to sync: {sync_job.error}') job.set_progress(100, f'Successfully synced {data["label"]!r} catalog') return await self.get_instance(data['label'])