pkgcore.bugzilla.apikey module

Locating a bugs.gentoo.org api key, and wiring it into an argparser.

find_api_key() consults four sources in order, stopping at the first one holding a non-empty value:

  1. an explicit key, normally from --api-key. Convenient, but visible to anyone able to read ps.

  2. the BUGZ_API_KEY environment variable. The only source usable from CI without writing a secret to disk.

  3. ~/.bugzrc, an INI file whose name and layout come from pybugz. The sections default, gentoo and Gentoo are tried in that order:

    [default]
    key = AbCdEf0123456789AbCdEf0123456789AbCdEf01
    

    Only the key option is read, so an existing pybugz config works as is.

  4. ~/.bugz_token, holding nothing but the key:

    AbCdEf0123456789AbCdEf0123456789AbCdEf01
    

Either file being group or world readable is warned about, but still used.

Finding no key at all is not an error. The client then runs anonymously, which is read only, and which Bugzilla further degrades by truncating every email address it returns at the @.

class pkgcore.bugzilla.apikey.BugzillaApiKey[source]

Bases: object

Adds --api-key, defaulting through find_api_key()

classmethod mangle_argparser(parser: Any) None[source]
class pkgcore.bugzilla.apikey.BugzillaClientArgs[source]

Bases: BugzillaApiKey

As BugzillaApiKey, plus --bugzilla-url and a ready client.

The client lands on namespace.bugzilla; its delayed default runs after the key’s, so the key is resolved by the time it is built.

classmethod mangle_argparser(parser: Any) None[source]
pkgcore.bugzilla.apikey.find_api_key(explicit: str | None = None, *, allow_env: bool = True, home: Path | None = None) str | None[source]

Locate an api key, per the precedence documented for this module.

Parameters:
  • explicit – a key supplied directly, normally from --api-key; blank or whitespace-only is treated as absent

  • allow_env – whether $BUGZ_API_KEY may be consulted

  • home – directory to look the dotfiles up in, defaulting to the user’s home

Returns:

the key, or None to run anonymously

Raises:

BugzillaUsageError – if ~/.bugzrc exists but can’t be parsed