-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamp systemd credential syntax to be more consistent with constants…
… (#966).
- Loading branch information
Showing
28 changed files
with
295 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import functools | ||
import re | ||
|
||
import borgmatic.hooks.dispatch | ||
|
||
IS_A_HOOK = False | ||
|
||
|
||
CREDENTIAL_PATTERN = re.compile( | ||
r'\{credential +(?P<hook_name>[A-Za-z0-9_]+) +(?P<credential_name>[A-Za-z0-9_]+)\}' | ||
) | ||
|
||
GENERAL_CREDENTIAL_PATTERN = re.compile(r'\{credential( +[^}]*)?\}') | ||
|
||
|
||
@functools.cache | ||
def resolve_credential(value): | ||
''' | ||
Given a configuration value containing a string like "{credential hookname credentialname}", resolve it by | ||
calling the relevant hook to get the actual credential value. If the given value does not | ||
actually contain a credential tag, then return it unchanged. | ||
Cache the value so repeated calls to this function don't need to load the credential repeatedly. | ||
Raise ValueError if the config could not be parsed or the credential could not be loaded. | ||
''' | ||
if value is None: | ||
return value | ||
|
||
result = CREDENTIAL_PATTERN.sub( | ||
lambda matcher: borgmatic.hooks.dispatch.call_hook( | ||
'load_credential', {}, matcher.group('hook_name'), matcher.group('credential_name') | ||
), | ||
value, | ||
) | ||
|
||
# If we've tried to parse the credential, but the parsed result still looks kind of like a | ||
# credential, it means it's invalid syntax. | ||
if GENERAL_CREDENTIAL_PATTERN.match(result): | ||
raise ValueError(f'Cannot load credential with invalid syntax "{value}"') | ||
|
||
return result |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.