refChannelPattern

fun refChannelPattern(pattern: String, projection: String? = null): String

Builds the PAM channel regex matching the ref-channels of every DataSync resource whose id matches pattern, as seen through projection (resolved like refChannel).

The result is always anchored at the start and wraps pattern in a non-capturing group, so a top-level | stays behind the prefix:

  • ("capy-.*", null) → ^(?:capy-.*). The anchor keeps it from also matching the projection mirrors (__admin__capy-1), which PAM's unanchored matching of a bare capy-.* would.

  • ("capy-.*", "admin") → ^__admin__(?:capy-.*).

  • A leading ^ in pattern is moved to the front: ("^capy-.*", "admin") → ^__admin__(?:capy-.*).

Only the leading ^ is moved. A pattern that anchors several alternatives (^a|^b) is not rewritten, so its inner ^ can never match after the prefix: write it as a|b instead.

pattern must be a valid regex on its own. Otherwise the wrapper could be closed early: a)|.* would become ^(?:a)|.*, whose unanchored .* branch matches every channel, projection mirrors included.

Throws

if pattern is blank or only ^ (either would match every channel), if it is not a valid regex, or if projection is blank.