def decorator( # lgtm[py/similar-function] fn: callbacks.DaemonFn, ) -> callbacks.DaemonFn: _warn_conflicting_values(field, value) _verify_filters(labels, annotations) real_registry = registry if registry is not None else registries.get_default_registry() real_field = dicts.parse_field(field) or None # to not store tuple() as a no-field case. real_id = registries.generate_id(fn=fn, id=id, suffix=".".join(real_field or [])) selector = references.Selector( __group_or_groupversion_or_name, __version_or_name, __name, group=group, version=version, kind=kind, plural=plural, singular=singular, shortcut=shortcut, category=category, ) handler = handlers.DaemonHandler( fn=fn, id=real_id, param=param, errors=errors, timeout=timeout, retries=retries, backoff=backoff, selector=selector, labels=labels, annotations=annotations, when=when, field=real_field, value=value, initial_delay=initial_delay, requires_finalizer=True, cancellation_backoff=cancellation_backoff, cancellation_timeout=cancellation_timeout, cancellation_polling=cancellation_polling, ) real_registry._spawning.append(handler) return fn
def decorator( # lgtm[py/similar-function] fn: callbacks.ChangingFn, ) -> callbacks.ChangingFn: _warn_conflicting_values(field, value) _verify_filters(labels, annotations) real_registry = registry if registry is not None else registries.get_default_registry( ) real_field = dicts.parse_field( field) or None # to not store tuple() as a no-field case. real_id = registries.generate_id(fn=fn, id=id, suffix=".".join(real_field or [])) selector = references.Selector( __group_or_groupversion_or_name, __version_or_name, __name, group=group, version=version, kind=kind, plural=plural, singular=singular, shortcut=shortcut, category=category, ) handler = handlers.ChangingHandler( fn=fn, id=real_id, param=param, errors=errors, timeout=timeout, retries=retries, backoff=backoff, selector=selector, labels=labels, annotations=annotations, when=when, field=real_field, value=value, old=None, new=None, field_needs_change=False, initial=None, deleted=None, requires_finalizer=bool(not optional), reason=causes.Reason.DELETE, ) real_registry._changing.append(handler) return fn
def decorator( # lgtm[py/similar-function] fn: callbacks.WebhookFn, ) -> callbacks.WebhookFn: _warn_conflicting_values(field, value) _verify_filters(labels, annotations) real_registry = registry if registry is not None else registries.get_default_registry( ) real_field = dicts.parse_field( field) or None # to not store tuple() as a no-field case. real_id = registries.generate_id(fn=fn, id=id, suffix=".".join(real_field or [])) selector = references.Selector( __group_or_groupversion_or_name, __version_or_name, __name, group=group, version=version, kind=kind, plural=plural, singular=singular, shortcut=shortcut, category=category, ) handler = handlers.WebhookHandler( fn=fn, id=real_id, param=param, errors=None, timeout=None, retries=None, backoff=None, # TODO: add some meaning later selector=selector, labels=labels, annotations=annotations, when=when, field=real_field, value=value, reason=causes.WebhookType.MUTATING, operation=operation, persistent=persistent, side_effects=side_effects, ignore_failures=ignore_failures, ) real_registry._webhooks.append(handler) return fn
def decorator( # lgtm[py/similar-function] fn: callbacks.IndexingFn, ) -> callbacks.IndexingFn: _warn_conflicting_values(field, value) _verify_filters(labels, annotations) real_registry = registry if registry is not None else registries.get_default_registry() real_field = dicts.parse_field(field) or None # to not store tuple() as a no-field case. real_id = registries.generate_id(fn=fn, id=id) selector = references.Selector( __group_or_groupversion_or_name, __version_or_name, __name, group=group, version=version, kind=kind, plural=plural, singular=singular, shortcut=shortcut, category=category, ) handler = handlers.IndexingHandler( fn=fn, id=real_id, param=param, errors=errors, timeout=timeout, retries=retries, backoff=backoff, selector=selector, labels=labels, annotations=annotations, when=when, field=real_field, value=value, ) real_registry._indexing.append(handler) return fn
def find_resource( *, request: reviews.Request, insights: references.Insights, ) -> references.Resource: """ Identify the requested resource by its meta-information (as discovered). """ # NB: Absent keys in the request are not acceptable, they must be provided. request_payload: reviews.RequestPayload = request['request'] request_resource: reviews.RequestResource = request_payload['resource'] group = request_resource['group'] version = request_resource['version'] plural = request_resource['resource'] selector = references.Selector(group=group, version=version, plural=plural) resources = selector.select(insights.webhook_resources) if not resources: raise UnknownResourceError(f"The specified resource has no handlers: {request_resource}") elif len(resources) > 1: raise AmbiguousResourceError(f"The specified resource is ambiguous: {request_resource}") else: return list(resources)[0]