Match wildcard certificates

Write codeEasy14 min

Your task

An edge proxy checks whether it already holds a certificate for an arriving request. patterns lists the hostnames the installed certificates cover, and hosts lists the hostnames requests came in on. A hostname is one or more labels joined by dots, and every label is a non empty run of lowercase letters, digits or hyphens. The leftmost label of a pattern may be exactly one asterisk. No other label of a pattern is an asterisk, and no host carries one. A pattern with no asterisk covers a host only when the two read identically. A wildcard pattern covers a host when the host has the same number of labels and every label after the leftmost is identical, so "*.example.com" covers "api.example.com" but covers neither "example.com" nor "eu.api.example.com". Return one boolean per host, in the order given, true when at least one pattern covers that host.

Examples

cert_host_coverage(patterns: list[str], hosts: list[str]) -> list[bool]
Example 1
Inputcert_host_coverage(["*.example.com", "example.com"], ["api.example.com", "example.com", "eu.api.example.com", "example.org"])
Output[True, True, False, False]
Example 2
Inputcert_host_coverage(["cdn-1.assets.net", "*.assets.net"], ["cdn-1.assets.net", "cdn-2.assets.net", "assets.net"])
Output[True, True, False]