FAQ | This is a LIVE service | Changelog

Commit 4925203a authored by Robin Goodall's avatar Robin Goodall 💬
Browse files

Add dry-run / really-do-this argument + typing

parent 54b69ff0
......@@ -6,7 +6,7 @@ Usage:
lookupsync student-inst-members --gateway-client-id=CLIENT_ID --lookup-username=USERNAME
( --gateway-client-secret=CLIENT_SECRET | --gateway-client-secret-from=PATH )
( --lookup-password=PASSWORD | --lookup-password-from=PATH )
[--quiet] [--debug]
[--quiet] [--debug] [--really-do-this]
Options:
-h, --help Show a brief usage summary.
......@@ -28,6 +28,9 @@ Options:
Leading and trailing whitespace is trimmed. This is preferable
to passing secrets on the command line.
--really-do-this Actually attempt to update lookup group memberships, otherwise
just output what would have been changed.
Operations:
The student-inst-members operation will synchronise membership of institutions from CamSIS'
affiliation records.
......@@ -36,7 +39,7 @@ import datetime
import logging
import os
import sys
import typing
from typing import List, Optional, Generator
import urllib.parse
import docopt
......@@ -66,14 +69,18 @@ def main(argv=None):
logging.WARN if opts["--quiet"] else logging.INFO
)
dry_run = not opts['--really-do-this']
if dry_run:
LOG.warn('Operating in dry-run mode - no changes will be made')
if opts['student-inst-members']:
_student_inst_members(opts)
_student_inst_members(opts, dry_run)
# OPERATIONS
def _student_inst_members(opts):
def _student_inst_members(opts: dict, dry_run: bool):
"""
Synchronise institutional memberships for students.
......@@ -176,9 +183,9 @@ class StudentAffiliation(pydantic.BaseModel):
Affiliation resource from Student API.
"""
end: typing.Optional[datetime.date]
end: Optional[datetime.date]
scheme: str
start: typing.Optional[datetime.date]
start: Optional[datetime.date]
status: str
value: str
......@@ -188,14 +195,14 @@ class Student(pydantic.BaseModel):
Student resource from Student API.
"""
affiliations: typing.List[StudentAffiliation]
affiliations: List[StudentAffiliation]
forenames: str
identifiers: typing.List[StudentIdentifier]
identifiers: List[StudentIdentifier]
namePrefixes: str
surname: str
def _create_api_gateway_session(opts):
def _create_api_gateway_session(opts: dict) -> requests_oauthlib.OAuth2Session:
"""
Create a requests session object authenticated to use the API Gateway via the credentials
passed in lookup_sync_client_credentials.
......@@ -215,7 +222,8 @@ def _create_api_gateway_session(opts):
return oauth
def _fetch_all_students(session):
def _fetch_all_students(
session: requests_oauthlib.OAuth2Session) -> Generator[List[Student], None, None]:
"""
Fetch all students from the students API. *Generates* a list of Student resources.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment