Skip to content

Commit

Permalink
Format python files with black
Browse files Browse the repository at this point in the history
  • Loading branch information
dseomn committed May 26, 2024
1 parent b9f8996 commit 3654f10
Show file tree
Hide file tree
Showing 16 changed files with 783 additions and 592 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
python -m pip install --upgrade pip
pip install \
absl-py \
black \
freezegun \
mypy \
passlib \
Expand All @@ -38,6 +39,9 @@ jobs:
python-dateutil \
types-passlib \
types-python-dateutil
- name: Check formatting
run: |
black --check --diff .
- name: Run mypy
run: |
mypy
Expand Down
4 changes: 2 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import pytest


@pytest.fixture(scope='session', autouse=True)
@pytest.fixture(scope="session", autouse=True)
def _parse_absl_flags():
# absltest doesn't work well without absl flags being parsed, which pytest
# doesn't do. This fixture works around that.
flags.FLAGS(('pytest',))
flags.FLAGS(("pytest",))
49 changes: 25 additions & 24 deletions salt/file/accounts/generate_lemonldap_ng_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@

def _args():
parser = argparse.ArgumentParser(
description='Generate dynamic parts of lemonldap-ng.ini.')
description="Generate dynamic parts of lemonldap-ng.ini."
)
parser.add_argument(
'--input',
"--input",
type=pathlib.Path,
required=True,
help='Path to the static lemonldap-ng.ini to read.',
help="Path to the static lemonldap-ng.ini to read.",
)
parser.add_argument(
'--output',
"--output",
type=pathlib.Path,
required=True,
help='Path to the dynamic lemonldap-ng.ini to replace.',
help="Path to the dynamic lemonldap-ng.ini to replace.",
)
return parser.parse_args()

Expand All @@ -52,12 +53,12 @@ def _portal_lines() -> Sequence[str]:
# algorithms in the static part of the config file to match.
private_key = subprocess.run(
(
'openssl',
'genpkey',
'-algorithm',
'RSA',
'-pkeyopt',
'rsa_keygen_bits:3072',
"openssl",
"genpkey",
"-algorithm",
"RSA",
"-pkeyopt",
"rsa_keygen_bits:3072",
),
stdout=subprocess.PIPE,
# See https://github.com/openssl/openssl/issues/13177
Expand All @@ -66,34 +67,34 @@ def _portal_lines() -> Sequence[str]:
text=True,
).stdout
public_key = subprocess.run(
('openssl', 'pkey', '-pubout'),
("openssl", "pkey", "-pubout"),
input=private_key,
stdout=subprocess.PIPE,
check=True,
text=True,
).stdout
key_id = str(uuid.uuid4())
return (
'oidcServicePrivateKeySig = <<EOF\n',
"oidcServicePrivateKeySig = <<EOF\n",
private_key,
'EOF\n',
'oidcServicePublicKeySig = <<EOF\n',
"EOF\n",
"oidcServicePublicKeySig = <<EOF\n",
public_key,
'EOF\n',
f'oidcServiceKeyIdSig = {key_id}\n',
"EOF\n",
f"oidcServiceKeyIdSig = {key_id}\n",
)


def main() -> None:
args = _args()
with args.input.open('rt') as input_file:
with args.input.open("rt") as input_file:
config = list(input_file)
portal_index = config.index('[portal]\n')
config[portal_index + 1:portal_index + 1] = _portal_lines()
portal_index = config.index("[portal]\n")
config[portal_index + 1 : portal_index + 1] = _portal_lines()
with tempfile.NamedTemporaryFile(
mode='wt',
dir=args.output.parent,
delete=False,
mode="wt",
dir=args.output.parent,
delete=False,
) as output_tempfile:
output_tempfile.writelines(config)
input_stat = args.input.stat()
Expand All @@ -102,5 +103,5 @@ def main() -> None:
os.replace(output_tempfile.name, args.output)


if __name__ == '__main__':
if __name__ == "__main__":
main()
36 changes: 19 additions & 17 deletions salt/file/backup/repo/borg_require_recent_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,26 @@

def _args():
parser = argparse.ArgumentParser(
description='Print a message if the latest archive is too old.')
description="Print a message if the latest archive is too old."
)
parser.add_argument(
'--repository',
"--repository",
type=str,
required=True,
help='Repository to check.',
help="Repository to check.",
)
parser.add_argument(
'--max-age',
"--max-age",
default=datetime.timedelta(days=2, hours=12),
type=lambda arg: datetime.timedelta(seconds=float(arg)),
help='How old to warn about, in seconds.',
help="How old to warn about, in seconds.",
)
parser.add_argument(
'borg_option',
nargs='*',
"borg_option",
nargs="*",
default=[],
type=str,
help='Borg common options.',
help="Borg common options.",
)
return parser.parse_args()

Expand All @@ -51,29 +52,30 @@ def main() -> None:
args = _args()
repository_list_raw = subprocess.run(
(
'borg',
"borg",
*args.borg_option,
'list',
'--json',
'--last=5',
"list",
"--json",
"--last=5",
args.repository,
),
stdout=subprocess.PIPE,
check=True,
).stdout
now = datetime.datetime.now(tz=datetime.timezone.utc)
repository_list = json.loads(repository_list_raw)
archives = repository_list['archives']
archives = repository_list["archives"]
if not archives:
print('No archives.')
print("No archives.")
return
last_archive_time = datetime.datetime.fromisoformat(
archives[-1]['start']).astimezone(datetime.timezone.utc)
archives[-1]["start"]
).astimezone(datetime.timezone.utc)
if last_archive_time < now - args.max_age:
print(f'Latest archive is older than {args.max_age}. Recent archives:')
print(f"Latest archive is older than {args.max_age}. Recent archives:")
pprint.pprint(archives)
return


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading

0 comments on commit 3654f10

Please sign in to comment.