Skip to content

Instantly share code, notes, and snippets.

@dontlaugh
Last active October 18, 2021 23:13
Show Gist options
  • Save dontlaugh/62bbd5ba3242ec02632d52fc1dceb07e to your computer and use it in GitHub Desktop.
Save dontlaugh/62bbd5ba3242ec02632d52fc1dceb07e to your computer and use it in GitHub Desktop.
Parse a markdown table in Raku
| Name | Type | Default | Example | Description |
| :--- | :--- | :--- | :--- | :--- |
| rules | array | n/a | | A list of rules to compare to the incoming request. Rules are checked in order of appearance in the list. |
| rules.key | string | n/a | "Authorization" | The key to check in the incoming request |
| rules.location | enum\[header, cookie, queryString, metadata\] | header | cookie | The location to check for the specified key/value pair |
| rules.location | enum\[header, cookie, queryString, metadata\] | header | cookie | The locati
on to check for the specified key/value pair |
| rules.metadataFilter | string | "" | "gm.oidc-authentication" | The name of the filter to read dynamic metadata from. Required if rules.location=metadata |
| rules.enforce | bool | false | true | Whether to completely reject the request if a rule doesn't match |
| rules.enforceResponseCode | string | 403 | 500 | The status code to send back if a rule does not match and `enforce` is true. |
| rules.removeOriginal | bool | false | true | Whether to remove the original matching key/value pair from the request. |
| rules.value.matchType | enum\[exact, prefix, suffix, regex\] | exact | regex | The type of comparison between the key/value pair and the incoming request |
| rules.value.matchString | string | n/a | Bearer\s+\(\S+\).\* | The string to match against the incoming request |
| rules.value.copyTo | array | n/a | | A list of locations where the matched variable may be copied \(optional\) |
| rules.value.copyTo.location | enum\[header, cookie, queryString, metadata\] | header | cookie | Location to copy the matched variable to |
| rules.value.copyTo.key | string | n/a | "access\_token" | Name of the key where the value will be stored |
| rules.value.copyTo.direction | enum\[default, request, response, both\] | default | response | Whether to copy the variable to the request, response, or both. Default will be request or response depending on the `location`. |
| rules.value.copyTo.cookieOptions.httpOnly | bool | false | true | Whether the cookie being created should be [httpOnly](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies). |
| rules.value.copyTo.cookieOptions.secure | bool | false | true | Whether the cookie being created should only be sent to the server over HTTPS. |
| rules.value.copyTo.cookieOptions.maxAge | string | session | 12h | The `Max-Age` of the new cookie. The value is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "s", "m", "h" \("ns", "us"/"µs", and "ms" are also valid but the value gets rounded to the nearest second as `Max-Age` is defined as "number of seconds until the cookie expires"\). If `maxAge` is not set, the cookie will have `Expires/Max-Age` of `Session`. |
| rules.value.copyTo.cookieOptions.path | string | "" | /ping | Path indicates a URL path that must exist in the requested URL in order to send the Cookie header. The %x2F \("/"\) character is considered a directory separator, and subdirectories will match as well. |
| rules.value.copyTo.cookieOptions.domain | string | "" | localhost | Domain specifies allowed hosts to receive the cookie. If unspecified, it defaults to the host of the current document location, excluding subdomains. If Domain is specified, then subdomains are always included. |
#!/usr/bin/env raku
class ConfigAttr {
has Str $.name;
has Str $.type;
has Str $.desc;
has Str $.default;
method render(--> Str) {
"* **$!name** ($!type, default: $!default) - $!desc"
}
}
grammar Row {
token TOP { <sep> <item> <sep> <item> <sep> <item> <sep> <item> <sep> <item> <sep> }
token sep { '|' }
regex item { (\s* | \w+)+ }
}
sub MAIN(Str $path) {
for $path.IO.lines -> $line {
my $parsed = Row.parse($line);
say $parsed;
# TODO: make ConfigAttr instance, render it in our new bulleted list style
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment