Skip to content

Commit

Permalink
dont cache a global mutable object
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo committed Jan 17, 2025
1 parent f4bc31a commit fd0358e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from middlewared.api.base import BaseModel

__all__ = ("CAProfilesArgs", "CAProfilesResults", "CAPROFILES")
__all__ = ("CAProfilesArgs", "CAProfilesModel", "CAProfilesResults")

# Defines the default lifetime of a certificate
# (https://support.apple.com/en-us/HT211025)
Expand Down Expand Up @@ -39,7 +39,7 @@ class CertExtensionsModel(BaseModel):


@final
class CAModel(BaseModel):
class CAProfilesModel(BaseModel):
key_length: int = 2048
key_type: str = "RSA"
lifetime: int = DEFAULT_LIFETIME_DAYS
Expand All @@ -52,7 +52,4 @@ class CAProfilesArgs(BaseModel):


class CAProfilesResults(BaseModel):
result: CAModel = CAModel()


CAPROFILES = CAModel().model_dump(by_alias=True)
result: CAProfilesModel = CAProfilesModel()
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

__all__ = (
"CertProfilesArgs",
"CertProfilesModel",
"CertProfilesResult",
"CSRProfilesArgs",
"CSRProfilesModel",
"CSRProfilesResult",
"CERTPROFILES",
"CSRPROFILES",
)


Expand Down Expand Up @@ -174,7 +174,3 @@ class CSRProfilesArgs(BaseModel):
@final
class CSRProfilesResult(BaseModel):
result: CSRProfilesModel = CSRProfilesModel()


CERTPROFILES = CertProfilesModel().model_dump(by_alias=True)
CSRPROFILES = CSRProfilesModel().model_dump(by_alias=True)
4 changes: 2 additions & 2 deletions src/middlewared/middlewared/plugins/crypto_/ca_profiles.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from middlewared.api import api_method
from middlewared.api.current import (
CAPROFILES,
CAProfilesArgs,
CAProfilesModel,
CAProfilesResults,
)
from middlewared.service import Service
Expand All @@ -17,4 +17,4 @@ async def profiles(self):
Returns a dictionary of predefined options for
creating certificate authority requests.
"""
return CAPROFILES
return CAProfilesModel().model_dump(by_alias=True)
8 changes: 4 additions & 4 deletions src/middlewared/middlewared/plugins/crypto_/cert_profiles.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from middlewared.api import api_method
from middlewared.api.current import (
CERTPROFILES,
CertProfilesArgs,
CertProfilesModel,
CertProfilesResult,
CSRProfilesArgs,
CSRProfilesModel,
CSRProfilesResult,
CSRPROFILES,
)
from middlewared.service import Service

Expand All @@ -17,12 +17,12 @@ async def profiles(self):
Returns a dictionary of predefined configuration
options for creating certificates.
"""
return CERTPROFILES
return CertProfilesModel().model_dump(by_alias=True)

@api_method(CSRProfilesArgs, CSRProfilesResult, roles=["CERTIFICATE_READ"])
async def certificate_signing_requests_profiles(self):
"""
Returns a dictionary of predefined configuration
options for creating certificate signing requests.
"""
return CSRPROFILES
return CSRProfilesModel().model_dump(by_alias=True)
12 changes: 6 additions & 6 deletions src/middlewared/middlewared/plugins/webui/crypto.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from middlewared.api import api_method
from middlewared.api.current import (
CAPROFILES,
CAProfilesArgs,
CAProfilesModel,
CAProfilesResult,
CERTPROFILES,
CertProfilesArgs,
CertProfilesModel,
CertProfilesResult,
CSRProfilesArgs,
CSRProfilesModel,
CSRProfilesResult,
CSRPROFILES,
)
from middlewared.schema import accepts, Int
from middlewared.service import Service
Expand All @@ -27,15 +27,15 @@ class Config:
roles=['READONLY_ADMIN']
)
async def certificate_profiles(self):
return CERTPROFILES
return CertProfilesModel().model_dump(by_alias=True)

@api_method(
CAProfilesArgs,
CAProfilesResult,
roles=['READONLY_ADMIN']
)
async def certificateauthority_profiles(self):
return CAPROFILES
return CAProfilesModel().model_dump(by_alias=True)

@accepts(Int('cert_id'), roles=['READONLY_ADMIN'])
async def get_certificate_domain_names(self, cert_id):
Expand All @@ -47,4 +47,4 @@ async def get_certificate_domain_names(self, cert_id):
roles=['READONLY_ADMIN']
)
async def csr_profiles(self):
return CSRPROFILES
return CSRProfilesModel().model_dump(by_alias=True)

0 comments on commit fd0358e

Please sign in to comment.