Skip to content

Commit

Permalink
please mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
johanlundberg committed Nov 30, 2023
1 parent f6b7769 commit 5875279
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
15 changes: 8 additions & 7 deletions src/auth_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,22 @@ class AuthServerConfig(BaseSettings):
auth_flows: List[str] = Field(default_factory=list)
mdq_server: Optional[str] = Field(default=None)
tls_fed_metadata: List[TLSFEDMetadata] = Field(default_factory=list)
tls_fed_metadata_max_age: timedelta = Field(default="PT1H")
keystore_path: Path = Field(default="keystore.jwks")
tls_fed_metadata_max_age: timedelta = Field(default=timedelta(hours=1))
keystore_path: Path = Field(default=Path("keystore.jwks"))
signing_key_id: str = Field(default="default")
auth_token_issuer: str
auth_token_audience: Optional[str] = Field(default=None)
auth_token_expires_in: timedelta = Field(default="PT10H")
proof_jws_max_age: timedelta = Field(default="PT5M")
auth_token_expires_in: timedelta = Field(default=timedelta(hours=10))
proof_jws_max_age: timedelta = Field(default=timedelta(minutes=5))
client_keys: Dict[str, ClientKey] = Field(default_factory=dict)
mongo_uri: Optional[str] = None
transaction_state_expires_in: timedelta = Field(default="PT10M")
transaction_state_expires_in: timedelta = Field(default=timedelta(minutes=10))
pysaml2_config_path: Optional[Path] = Field(default=None)
pysaml2_config_name: str = "SAML_CONFIG"
saml2_discovery_service_url: Optional[AnyUrl] = None
saml2_single_idp: Optional[str] = None
ca_certs_path: Optional[Path] = None # all files ending with .crt will be loaded recursively. PEM and DER supported
ca_certs_path: Optional[Path] = None # all files ending with .c* will be loaded recursively. PEM and DER supported
ca_certs_mandatory_org_id: bool = False # fail grant requests where no org id is found in the certificate

@field_validator("application_root")
@classmethod
Expand Down Expand Up @@ -113,7 +114,7 @@ def load_config() -> AuthServerConfig:
config = AuthServerConfig.parse_obj(data)
else:
# config will be instantiated with env vars if there is no config file
config = AuthServerConfig() # type: ignore[call-arg]
config = AuthServerConfig()
# Save config to a file in /dev/shm for introspection
fd_int = os.open(f"/dev/shm/{config.app_name}_config.yaml", os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
with open(fd_int, "w") as fd:
Expand Down
2 changes: 1 addition & 1 deletion src/auth_server/models/tls_fed_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SAMLScopeExtension(BaseModel):
class Extensions(BaseModel):
model_config = ConfigDict(extra="allow", populate_by_name=True)

saml_scope: Optional[SAMLScopeExtension] = Field(default=None, alias=RegisteredExtensions.SAML_SCOPE.value) # type: ignore[literal-required]
saml_scope: Optional[SAMLScopeExtension] = Field(default=None, alias=RegisteredExtensions.SAML_SCOPE.value)


class CertIssuers(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion src/auth_server/proof/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def load_config_key(client_key: ClientKey) -> Key:
elif client_key.cert_S256:
logger.info("Loading cert_S256 from config")
logger.debug(f"client_key.cert_S256: {client_key.cert_S256}")
return Key(proof=client_key.proof, cert_S256=client_key.cert_S256) # type: ignore[call-arg]
return Key(proof=client_key.proof, cert_S256=client_key.cert_S256)

raise ConfigurationError(f"malformed client key in config")

Expand Down
2 changes: 1 addition & 1 deletion src/auth_server/routers/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def transaction(
# init a new transaction state
state = TransactionState(
flow_name=auth_flow_name,
grant_request=grant_req.copy(deep=True), # let every flow have their own copy of the grant request,
grant_request=grant_req.model_copy(deep=True), # let every flow have their own copy of the grant request,
)

flow = auth_flow(request=request, config=config, signing_key=signing_key, state=state.to_dict())
Expand Down
2 changes: 1 addition & 1 deletion src/auth_server/saml2.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def from_pysaml2(cls, ava: Dict[str, List[str]]) -> SAMLAttributes:
result.update(ava)
result.update(single_values)
# what's up with pydantic typing, hopefully an upgrade to 2 will solve this
return cls(**result) # type: ignore[arg-type]
return cls(**result)


class SessionInfo(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion src/auth_server/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _fake_saml_authentication(self, transaction_id: str):
"https://refeds.org/assurance/IAP/medium",
],
entitlement=["some-entitlement"],
) # type: ignore[call-arg]
)
name_id = NameID(
format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
sp_name_qualifier="http://test.localhost/saml2-metadata",
Expand Down
2 changes: 1 addition & 1 deletion src/auth_server/tests/test_saml_sp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def setUp(self) -> None:
sp_provided_id=None,
id="1f87035b4c1325b296a53d92097e6b3fa36d7e30ee82e3fcb0680d60243c1f03",
),
attributes=SAMLAttributes( # type: ignore[call-arg]
attributes=SAMLAttributes(
assurance=[
"http://www.swamid.se/policy/assurance/al1",
"http://www.swamid.se/policy/assurance/al2",
Expand Down

0 comments on commit 5875279

Please sign in to comment.