# What Linear API keys the library redacts, and what it leaves alone.
#
# Every key here is built from the ordered run
# 0123456789abcdefghijklmnopqrstuvwxyz, which no real credential is. That run is
# thirty-six characters, so a body carries it and four characters more — the
# shortest body the pattern reads, since the count is a floor. It is spelled in
# lowercase where the case does not matter and in uppercase where the case is
# what a case is about: base62 holds the letters of both, so either spelling is
# a body.

patterns: linear-api-key

# The one prefix Linear has issued a personal API key with. There is a single
# kind of string here rather than a table of them, as the GitLab and Slack files
# have: a key carries the permissions of whoever created it and may be narrowed
# to reading alone or to a single team, so nothing in the value says what it is
# allowed to do, and the cases below are that one shape in the places a key is
# written.

case:     a key in an environment assignment
in:       LINEAR_API_KEY=lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123
out:      LINEAR_API_KEY=«linear-api-key»

case:     a key in the authorization header, which Linear asks for without a Bearer
in:       Authorization: lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123
out:      Authorization: «linear-api-key»

case:     a key in json
in:       {"apiKey":"lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123"}
out:      {"apiKey":"«linear-api-key»"}

case:     a key on a command line
in:       curl -H "Authorization: lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123" https://api.linear.app/graphql
out:      curl -H "Authorization: «linear-api-key»" https://api.linear.app/graphql

case:     a key in a configuration environment block
in:       "env": {"LINEAR_API_KEY": "lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123"}
out:      "env": {"LINEAR_API_KEY": "«linear-api-key»"}

# The alphabet the forty characters are written in. It is base62 — the letters
# of both cases and the digits — which is what both rulesets stating a shape
# admit behind the prefix. The two characters base64url adds, the hyphen and the
# underscore, are not admitted, and either of them ends a body.

case:     a body written in capitals
in:       lin_api_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123
out:      «linear-api-key»

case:     a body carrying a hyphen
in:       lin_api_0123456789abcdefghij-lmnopqrstuvwxyz0123
out:      lin_api_0123456789abcdefghij-lmnopqrstuvwxyz0123

case:     a body carrying an underscore
in:       lin_api_0123456789abcdefghij_lmnopqrstuvwxyz0123
out:      lin_api_0123456789abcdefghij_lmnopqrstuvwxyz0123

# The lengths either side of forty. Linear states no length for a key, and no
# alphabet and no checksum either; forty is the count both rulesets stating a
# shape read off the keys they were shown. Like the GitHub, Stripe, PyPI and npm
# bodies and unlike the AWS access key ID, the GitLab token, the Google API key
# and the SendGrid key, it is read as a floor rather than a count: thirty-nine
# characters are not a key, and forty-one are one key to the end of its run
# rather than a key and a character left over. What the floor costs is the
# middle case below — a key cut short of forty keeps every random character
# written in front of the cut, and none of them is redacted.

case:     a body of forty characters is a key
in:       lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123
out:      «linear-api-key»

case:     a body of thirty-nine characters is not
in:       lin_api_0123456789abcdefghijklmnopqrstuvwxyz012
out:      lin_api_0123456789abcdefghijklmnopqrstuvwxyz012

case:     an alphabet run longer than the floor is a key to the end of it
in:       lin_api_0123456789abcdefghijklmnopqrstuvwxyz01234
out:      «linear-api-key»

# What a key may be written against. There is no boundary on either side of the
# prefix, so a key keeps its span whatever word character it abuts — and where
# the run of its alphabet carries on past the floor, what carries it on is
# redacted with the key. A hyphen and an underscore end the run instead, which
# is what tells this pattern apart from the OpenAI and Anthropic ones: their
# bodies are base64url and would draw a hyphenated word in.

case:     a key after an underscore
in:       LINEAR_API_KEY_lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123
out:      LINEAR_API_KEY_«linear-api-key»

case:     a key after a letter
in:       xlin_api_0123456789abcdefghijklmnopqrstuvwxyz0123
out:      x«linear-api-key»

case:     a word written against a key
in:       lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123suffix
out:      «linear-api-key»

case:     a hyphenated word written against a key
in:       lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123-suffix
out:      «linear-api-key»-suffix

case:     an underscored word written against a key
in:       lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123_suffix
out:      «linear-api-key»_suffix

case:     a key at the end of a sentence
in:       the key is lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123.
out:      the key is «linear-api-key».

# Two keys written together. The three letters the prefix opens with belong to
# the alphabet a body is written in, so a body may close with lin and the
# underscore of the next key stand directly behind it; the second key begins
# three characters before the first one ends, the two spans overlap and are
# redacted as one. Written with nothing at all between them the first body
# reaches three characters into the second prefix and stops at the underscore
# behind them, so those two overlap as well. Written with a space between them
# the two are separate values, and both go.

case:     a key beginning inside the key before it
in:       lin_api_0123456789abcdefghijklmnopqrstuvwxyz0lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123
out:      «linear-api-key»

case:     two keys with nothing between them
in:       lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123lin_api_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123
out:      «linear-api-key»

case:     two keys separated by a space
in:       lin_api_0123456789abcdefghijklmnopqrstuvwxyz0123 lin_api_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123
out:      «linear-api-key» «linear-api-key»

# A word closing on the three letters the prefix opens with. berlin, dublin,
# merlin, muslin, kaolin, insulin, gremlin, violin and javelin each end on lin,
# so a snake_case name built from one of them carries a whole prefix — and where
# forty unbroken characters of the alphabet stand behind it, everything from the
# lin onward is redacted and only the syllable in front of it stays. The
# tightening that would rule that out is the demand the Slack and Stripe
# patterns make, that no letter and no digit stand in front of a prefix; it is
# declined, because the key written inside another has the last letter of a body
# in front of its own prefix and the demand would leave that key in the text
# with its body whole. What holds the ordinary name away instead is the floor,
# which the next underscore of such a name ends long before.

case:     a word closing on the prefix with a body behind it
in:       berlin_api_0123456789abcdefghijklmnopqrstuvwxyz0123
out:      ber«linear-api-key»

case:     a word closing on the prefix with a short segment behind it
in:       berlin_api_key=1 dublin_api_host=localhost
out:      berlin_api_key=1 dublin_api_host=localhost

# What this pattern redacts that nobody issued. The prefix carries two
# underscores, which standard base64 writes nowhere, so only a base64url
# encoding can hold one — and there eight characters of an alphabet of sixty-
# four stand where the prefix stands about once in two hundred and eighty
# million million characters. Where forty base62 characters follow, the run from
# the prefix to the end of them is redacted whether or not Linear issued it.
# That is the answer rather than a fault in it, because such a run is a key's
# format exactly and nothing in the text tells the two apart: sparing these
# would spare a real key written the same way. What is taken is a stretch of a
# value that was already opaque to a reader.

case:     the prefix inside a longer run of base64url
in:       payload=zzzzlin_api_0123456789abcdefghijklmnopqrstuvwxyz0123zzzz
out:      payload=zzzz«linear-api-key»

case:     the prefix where a signature stands
in:       eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhYmMifQ.zzzzlin_api_0123456789abcdefghijklmnopqrstuvwxyz0123zzzz
out:      eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhYmMifQ.zzzz«linear-api-key»

# A digest written behind the prefix, which is the one over-match here that
# takes a value a reader had a use for. Hexadecimal digits are base62 and a
# digest carries nothing that ends a run, so lin_api_ and the forty characters
# of a SHA-1 are a key's format exactly, as lin_api_ and the sixty-four of a
# SHA-256 are. Both are redacted. Declining them would mean declining every key
# Linear happened to write in the digits alone, which is a whole credential
# against a cache key. What holds either side of it is the floor and the prefix:
# an MD5 is thirty-two characters, eight short of a body, and a hyphen is no
# character the prefix carries.

case:     a sha1 behind the prefix
in:       lin_api_0123456789abcdef0123456789abcdef01234567
out:      «linear-api-key»

case:     a sha256 in a cache key
in:       key: lin_api_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
out:      key: «linear-api-key»

case:     an md5 behind the prefix, eight characters short of a body
in:       lin_api_0123456789abcdef0123456789abcdef
out:      lin_api_0123456789abcdef0123456789abcdef

case:     a sha1 behind hyphens rather than the prefix
in:       lin-api-0123456789abcdef0123456789abcdef01234567
out:      lin-api-0123456789abcdef0123456789abcdef01234567

# And what this pattern leaves alone. The first four are the prefix, read in the
# case Linear writes it, in both of the underscores it carries and in the word
# between them — the middle segment is read literally rather than as any
# lowercase word, which is what the Stripe pattern decided about its own mode
# segment and for the same reason: three letters and two underscores are not an
# anchor. The two after them are the alphabet and the anchor: a body a space has
# broken, and a run of the right length with no prefix in front of it. The last
# two hold no underscore where the prefix wants one, so neither holds a position
# to be found at however long it runs.

case:     an uppercase prefix
in:       LIN_API_0123456789abcdefghijklmnopqrstuvwxyz0123
out:      LIN_API_0123456789abcdefghijklmnopqrstuvwxyz0123

case:     hyphens where the prefix carries underscores
in:       lin-api-0123456789abcdefghijklmnopqrstuvwxyz0123
out:      lin-api-0123456789abcdefghijklmnopqrstuvwxyz0123

case:     the prefix without its closing underscore
in:       lin_api0123456789abcdefghijklmnopqrstuvwxyz0123
out:      lin_api0123456789abcdefghijklmnopqrstuvwxyz0123

case:     another word where the prefix carries api
in:       lin_key_0123456789abcdefghijklmnopqrstuvwxyz0123
out:      lin_key_0123456789abcdefghijklmnopqrstuvwxyz0123

case:     a body broken by a space
in:       lin_api_0123456789abcdefghij lmnopqrstuvwxyz0123
out:      lin_api_0123456789abcdefghij lmnopqrstuvwxyz0123

case:     a run of the right length opening with no prefix
in:       0123456789abcdefghijklmnopqrstuvwxyz0123
out:      0123456789abcdefghijklmnopqrstuvwxyz0123

case:     a hexadecimal digest
in:       sha1=0123456789abcdef0123456789abcdef01234567
out:      sha1=0123456789abcdef0123456789abcdef01234567

case:     prose
in:       there is no credential in this sentence
out:      there is no credential in this sentence

# The prefix this pattern does not read. Linear's changelog names lin_oauth_
# beside lin_api_ and names nothing else about it — no ruleset carries a rule
# for it, no example of such a token has been published, and Linear's own OAuth
# page still prints an access token of sixty-four hexadecimal characters with
# no prefix at all. So an OAuth access token is left in the text whole, and the
# cases below are here to move with the scan: a body invented for the second
# prefix would start locating them.

case:     an oauth access token
in:       lin_oauth_0123456789abcdefghijklmnopqrstuvwxyz0123
out:      lin_oauth_0123456789abcdefghijklmnopqrstuvwxyz0123

case:     an oauth access token in an environment assignment
in:       LINEAR_OAUTH_TOKEN=lin_oauth_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
out:      LINEAR_OAUTH_TOKEN=lin_oauth_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
