Class HubDefinitionFile
HUB-DESIGN.md section 4.2: UTF-8, unix-style ini, a byte-order mark ignored, LF or CRLF, # or ; comments, case-insensitive section names, the sections [hub], [members] and [origins], each at most once. The lexical rules are those of PUSH-CREDENTIALS.md section 3 with one addition the design's own example needs: a comment may also follow a value on the same line, starting at a # or ; preceded by whitespace. The shape of this class is PushCredentialsFile's, copied and not extracted (ruling H-9).[hub]: name (required: the key of the hub's rows in HUB.*, at most 64 characters of letters, digits, - and _), policy (sticky, the default, or priority; ruling H-2), lease (15 s), margin (10 s; both H-3), grace (900 s; H-11), hold (60 s; T-4) and key, the path of the interim cluster key file (H-8), kept as written. The four durations are whole seconds, lease at least 1 and none above 86400; an empty value is an absent key and the default applies; a key set twice uses the later value with a WARNING; an unknown key is a WARNING and ignored.
[members]: memberID = URL [principal], one member per line, in priority order. A member ID is at least one and at most 64 characters of letters, digits, - and _; the URL is the member's public base URL, absolute, http or https, with a host and without a query or fragment; the only flag is principal, marking an eligible member. A member ID that appears twice (in any letter case) is refused on both lines.
[origins]: allow = origins, separated by spaces or commas, each scheme://host[:port] with http or https and an optional leading *. wildcard label; several allow lines are their union; an invalid origin is refused alone, the rest of its line applies.
Pure. No I/O and no logging: parse(byte[],String) answers a HubDefinitionFile.Parsed that carries the values and a HubDefinitionFile.Diagnostic per refusal or warning, which the loader logs. A diagnostic names the file and the line number and never a line's content or a value: a section name, a key name or a flag name is quoted where the operator needs it to act, a value never is.
What is refused, and how: a malformed section header, a section that appears twice, a line outside any section, a missing or invalid name, a policy that is neither value, a duration that is not a whole number or is out of range, a member line without =, an invalid member ID, a missing or invalid URL, an unknown flag, a duplicate member ID and an invalid origin. Every refusal is SEVERE and the line (or the value) is ignored; the valid lines still apply. An unknown section and an unknown key are WARNINGs and are ignored. A file without a usable name is not usable at all (HubDefinitionFile.Parsed.isUsable()).
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA refusal or a warning of the parser: theILoglevel, the line (0 for a whole-file message) and the message, which never carries a line's content or a value.static final recordA member of the[members]section.static final classThe result of a parse: the values, the defaults where the file sets nothing, and the diagnostics.static enumThe election policy of section 4.4 (ruling H-2).Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default fail-open grace in seconds (H-11).static final intThe default hold in seconds (T-4).static final intThe default lease in seconds (H-3).static final intThe default margin in seconds (H-3).static final HubDefinitionFile.PolicyThe default policy (H-2).static final StringThe member flag marking an eligible member.static final StringThe[origins]key.static final StringThe[hub]keys.static final StringThe[hub]keys.static final StringThe[hub]keys.static final StringThe[hub]keys.static final StringThe[hub]keys.static final StringThe[hub]keys.static final StringThe[hub]keys.static final intThe longest member ID:HUB.MEMBERS.member_idisVARCHAR(64).static final intThe longest hub name:HUB.CLUSTER.hub_nameisVARCHAR(64).static final intThe largest duration accepted, in seconds: one day.static final intThe longest member URL:HUB.MEMBERS.urlisVARCHAR(254).static final StringThe section names.static final StringThe section names.static final StringThe section names.Method Summary
Modifier and TypeMethodDescriptionstatic booleanisValidHubName(String name) Validates a hub name: the rule of a member ID, at most 64 characters.static booleanValidates a member ID, section 4.2: at least one and at most 64 characters of letters, digits,-and_.static booleanisValidMemberURL(String url) Validates a member URL: absolute,httporhttps, a host, no query or fragment, at most 254 characters.static StringnormalizeOrigin(String origin) Normalises an origin of the[origins]section:scheme://host[:port],httporhttps, the host optionally starting with*., no path, query or fragment; answered in lower case.static HubDefinitionFile.ParsedParses the bytes of a file: UTF-8, a byte-order mark ignored.static HubDefinitionFile.ParsedParses the text of a file.
Field Details
SECTION_HUB
SECTION_MEMBERS
SECTION_ORIGINS
KEY_NAME
KEY_POLICY
KEY_LEASE
KEY_MARGIN
KEY_GRACE
KEY_HOLD
KEY_KEY
KEY_ALLOW
FLAG_PRINCIPAL
DEFAULT_POLICY
The default policy (H-2).DEFAULT_LEASE
public static final int DEFAULT_LEASEThe default lease in seconds (H-3).- See Also:
DEFAULT_MARGIN
public static final int DEFAULT_MARGINThe default margin in seconds (H-3).- See Also:
DEFAULT_GRACE
public static final int DEFAULT_GRACEThe default fail-open grace in seconds (H-11).- See Also:
DEFAULT_HOLD
public static final int DEFAULT_HOLDThe default hold in seconds (T-4).- See Also:
MAX_SECONDS
public static final int MAX_SECONDSThe largest duration accepted, in seconds: one day. A larger value is a typo, not a policy.- See Also:
MAX_NAME_LENGTH
public static final int MAX_NAME_LENGTHThe longest hub name:HUB.CLUSTER.hub_nameisVARCHAR(64).- See Also:
MAX_MEMBER_ID_LENGTH
public static final int MAX_MEMBER_ID_LENGTHThe longest member ID:HUB.MEMBERS.member_idisVARCHAR(64).- See Also:
MAX_URL_LENGTH
public static final int MAX_URL_LENGTHThe longest member URL:HUB.MEMBERS.urlisVARCHAR(254).- See Also:
Method Details
parse
Parses the bytes of a file: UTF-8, a byte-order mark ignored.- Parameters:
bytes- The file content.fileName- The file name, for the diagnostics.- Returns:
- The result, never null.
parse
Parses the text of a file.- Parameters:
text- The file content, LF or CRLF line endings.fileName- The file name, for the diagnostics.- Returns:
- The result, never null.
isValidMemberID
isValidHubName
normalizeOrigin
Normalises an origin of the[origins]section:scheme://host[:port],httporhttps, the host optionally starting with*., no path, query or fragment; answered in lower case.- Parameters:
origin- The origin as written.- Returns:
- The normalised origin, or null when invalid.
isValidMemberURL