devices.modelsΒΆ

This modules contains all models specific to the device abstractions.

ClassesΒΆ

DeviceModel

The DeviceModel.

IssuedCredentialModel

Model for all credentials and certificates that have been issued or requested by the Trustpoint.

RemoteDeviceCredentialDownloadModel

Model to associate a credential model with an OTP and token for unauthenticated remoted download.

Module ContentsΒΆ

class devices.models.DeviceModel(*args, **kwargs)[source]ΒΆ

Bases: util.db.CustomDeleteActionModel

The DeviceModel.

common_name[source]ΒΆ
serial_number[source]ΒΆ
ip_address[source]ΒΆ
opc_server_port[source]ΒΆ
domain[source]ΒΆ
onboarding_config[source]ΒΆ
no_onboarding_config[source]ΒΆ
class DeviceType(*args, **kwds)[source]ΒΆ

Bases: django.db.models.IntegerChoices

Enum for device type.

GENERIC_DEVICE[source]ΒΆ
OPC_UA_GDS[source]ΒΆ
OPC_UA_GDS_PUSH[source]ΒΆ
device_type[source]ΒΆ
created_at[source]ΒΆ
__str__()[source]ΒΆ

Returns a human-readable string representation.

Return type:

str

pre_delete()[source]ΒΆ

Delete all issued credentials for this device before deleting the device itself.

Return type:

None

property est_username: str[source]ΒΆ

Gets the EST username.

Return type:

str

clean()[source]ΒΆ

Validation before saving the model.

Return type:

None

class devices.models.IssuedCredentialModel(*args, **kwargs)[source]ΒΆ

Bases: util.db.CustomDeleteActionModel

Model for all credentials and certificates that have been issued or requested by the Trustpoint.

class IssuedCredentialType(*args, **kwds)[source]ΒΆ

Bases: django.db.models.IntegerChoices

The type of the credential.

DOMAIN_CREDENTIAL[source]ΒΆ
APPLICATION_CREDENTIAL[source]ΒΆ
id[source]ΒΆ
common_name[source]ΒΆ
issued_credential_type[source]ΒΆ
issued_using_cert_profile[source]ΒΆ
credential[source]ΒΆ
device[source]ΒΆ
domain[source]ΒΆ
created_at[source]ΒΆ
class Meta[source]ΒΆ

Bases: django_stubs_ext.db.models.TypedModelMeta

Meta class configuration.

__str__()[source]ΒΆ

Returns a human-readable string representation.

Return type:

str

revoke()[source]ΒΆ

Revokes all active certificates associated with this credential.

Return type:

None

pre_delete()[source]ΒΆ

Revoke all active certificates and delete the credential.

Return type:

None

is_valid_domain_credential()[source]ΒΆ

Determines if this issued credential is valid for enrolling new application credentials.

This method performs the following checks:
  1. The IssuedCredentialModel type must be of type DOMAIN_CREDENTIAL.

  2. The credential must be of type ISSUED_CREDENTIAL.

  3. A primary certificate must exist.

  4. The certificate’s status must be β€˜OK’.

Returns:

A tuple where:
  • The first value is True if the credential meets all criteria, False otherwise.

  • The second value is a reason string explaining why the credential is invalid.

Return type:

tuple[bool, str]

static get_credential_for_certificate(cert)[source]ΒΆ

Retrieve an IssuedCredentialModel instance for the given certificate.

Parameters:

cert (cryptography.x509.Certificate) – x509.Certificate to search for.

Returns:

The corresponding IssuedCredentialModel instance.

Raises:

ClientCertificateAuthenticationError – if no matching issued credential is found.

Return type:

IssuedCredentialModel

class devices.models.RemoteDeviceCredentialDownloadModel(*args, **kwargs)[source]ΒΆ

Bases: django.db.models.Model

Model to associate a credential model with an OTP and token for unauthenticated remoted download.

BROWSER_MAX_OTP_ATTEMPTS = 3[source]ΒΆ
TOKEN_VALIDITY[source]ΒΆ
issued_credential_model[source]ΒΆ
otp[source]ΒΆ
device[source]ΒΆ
attempts[source]ΒΆ
download_token[source]ΒΆ
token_created_at[source]ΒΆ
class Meta[source]ΒΆ

Bases: django_stubs_ext.db.models.TypedModelMeta

Meta class configuration.

__str__()[source]ΒΆ

Return a string representation of the model.

Return type:

str

save(*args, **kwargs)[source]ΒΆ

Generates a new random OTP on initial save of the model.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

None

get_otp_display()[source]ΒΆ

Return the OTP in the format β€˜credential_id.otp’ for display within the admin view.

Returns:

The str to display.

Return type:

str

check_otp(otp)[source]ΒΆ

Check if the provided OTP matches the stored OTP.

Parameters:

otp (str) – The OTP to check.

Returns:

True if the OTP is valid, False otherwise.

Return type:

bool

check_token(token)[source]ΒΆ

Check if the provided token matches the stored token and whether it is still valid.

Parameters:

token (str) – The token to check.

Returns:

True if the token is valid, false otherwise.

Return type:

bool