#2 Generalize User Agent for rpm-ostree
Merged 3 years ago by smooge. Opened 3 years ago by siosm.
siosm/mirrors-countme master  into  master

file modified
+10 -8
@@ -21,7 +21,7 @@ 

  

  __all__ = (

      'compile_log_regex',

-     'LOG_RE', 'LIBDNF_USER_AGENT_RE',

+     'LOG_RE', 'LIBDNF_USER_AGENT_RE', 'COUNTME_USER_AGENT_RE',

      'MIRRORS_LOG_RE', 'COUNTME_LOG_RE', 'LOG_DATE_RE',

  )

  
@@ -83,15 +83,16 @@ 

      'user_agent': '.+?',

  }

  

- # A regex for libdnf user-agent strings.

+ # A regex for libdnf/rpm-ostree user-agent strings.

  # Examples:

  #   "libdnf/0.35.5 (Fedora 32; workstation; Linux.x86_64)"

  #   "libdnf (Fedora 32; generic; Linux.x86_64)"

+ #   "rpm-ostree (Fedora 33; coreos; Linux.x86_64)"

  #

  # The format, according to libdnf/utils/os-release.cpp:getUserAgent():

  #   f"{USER_AGENT} ({os_name} {os_version}; {os_variant}; {os_canon}.{os_arch})"

  # where:

- #   USER_AGENT = "libdnf" or "libdnf/{LIBDNF_VERSION}"

+ #   USER_AGENT = "libdnf" or "libdnf/{LIBDNF_VERSION}" or "rpm-ostree"

  #   os_name    = os-release NAME

  #   os_version = os-release VERSION_ID

  #   os_variant = os-release VARIANT_ID
@@ -103,8 +104,8 @@ 

  #

  # For more info on the User-Agent header, see RFC7231, Section 5.5.3:

  #   https://tools.ietf.org/html/rfc7231#section-5.5.3)

- LIBDNF_USER_AGENT_PATTERN = (

-     r'(?P<product>libdnf(?:/(?P<product_version>\S+))?)\s+'

+ COUNTME_USER_AGENT_PATTERN = (

+     r'(?P<product>(libdnf(?:/(?P<product_version>\S+)))|rpm-ostree?)\s+'

      r'\('

        r'(?P<os_name>.*)\s'

        r'(?P<os_version>[0-9a-z._-]*?);\s'
@@ -113,7 +114,8 @@ 

        r'(?P<os_arch>\w+)'

      r'\)'

  )

- LIBDNF_USER_AGENT_RE = re.compile(LIBDNF_USER_AGENT_PATTERN)

+ COUNTME_USER_AGENT_RE = re.compile(COUNTME_USER_AGENT_PATTERN)

+ LIBDNF_USER_AGENT_RE = re.compile(COUNTME_USER_AGENT_PATTERN)

  

  # Helper function for making compiled log-matching regexes.

  def compile_log_regex(flags=0, ascii=True, query_present=None, **kwargs):
@@ -160,12 +162,12 @@ 

  #   * that have a query string containing "&countme=\d+",

  #   * with libdnf's User-Agent string (see above).

  COUNTME_LOG_RE = compile_log_regex(

-     method        = "GET",

+     method        = "GET|HEAD",

      query_present = True,

      path          = r'/metalink|/mirrorlist',

      query         = r'\S+&countme=\d+\S*',

      status        = r'200|302',

-     user_agent    = LIBDNF_USER_AGENT_PATTERN,

+     user_agent    = COUNTME_USER_AGENT_PATTERN,

  )

  

  # Regex for pulling the date out of a log line

WIP PR as this might be a breaking change as it changes imports names and I'm not sure which kind of RE is used here.

rebased onto a087583d870562b179fb0066c5c3568f0715de3f

3 years ago

rebased onto 2872a82

3 years ago

Updated this PR to:

  • keep the existing exports to avoid an api/interface change
  • fix the regular expression for rpm-ostree user agent

@wwoods can you merge this? we are go for adding this to the program.

Gentle ping here as we need review / merge on this one.

Will is out for a while (and I failed to realize that til just now). I am looking to see how to get access to merge.

Pull-Request has been merged by smooge

3 years ago

merged. thank you for your patience.

Thanks! Let me know how I can help for the next steps to get counting results per variant.

Metadata