Skip to content

Commit

Permalink
Merge pull request #27 from maykinmedia/feature/ci-cd-configure-auth
Browse files Browse the repository at this point in the history
✨ Add natural keys to allow loading of auth config dumps
  • Loading branch information
annashamray authored May 28, 2024
2 parents a0f5174 + 686c00f commit 53e9051
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions vng_api_common/authorizations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class Meta:
verbose_name = _("Autorisatiecomponentconfiguratie")


class ApplicatieManager(models.Manager):
def get_by_natural_key(self, uuid):
return self.get(uuid=uuid)


class Applicatie(APIMixin, models.Model):
"""
Client level of authorization
Expand Down Expand Up @@ -52,10 +57,20 @@ class Applicatie(APIMixin, models.Model):
),
)

objects = ApplicatieManager()

def natural_key(self):
return (str(self.uuid),)

def __str__(self):
return f"Applicatie ({self.label})"


class AutorisatieManager(models.Manager):
def get_by_natural_key(self, applicatie, component, scopes):
return self.get(applicatie=applicatie, component=component, scopes=scopes)


class Autorisatie(APIMixin, models.Model):
applicatie = models.ForeignKey(
"Applicatie",
Expand Down Expand Up @@ -109,6 +124,15 @@ class Autorisatie(APIMixin, models.Model):
blank=True,
)

objects = AutorisatieManager()

def natural_key(self):
return (
self.applicatie,
self.component,
self.scopes,
)

def satisfy_vertrouwelijkheid(self, vertrouwelijkheidaanduiding: str) -> bool:
max_confid_level = VertrouwelijkheidsAanduiding.get_choice(
self.max_vertrouwelijkheidaanduiding
Expand Down
10 changes: 10 additions & 0 deletions vng_api_common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def get_absolute_api_url(self, request=None, **kwargs) -> str:
return url


class JWTSecretManager(models.Manager):
def get_by_natural_key(self, identifier):
return self.get(identifier=identifier)


class JWTSecret(models.Model):
"""
Store credentials of clients that want to access our API.
Expand All @@ -53,6 +58,11 @@ class JWTSecret(models.Model):
_("secret"), max_length=255, help_text=_("Secret belonging to the client ID.")
)

objects = JWTSecretManager()

def natural_key(self):
return (self.identifier,)

class Meta:
verbose_name = _("client credential")
verbose_name_plural = _("client credentials")
Expand Down

0 comments on commit 53e9051

Please sign in to comment.