Object Management

Note

Refer to Authentication for ways to authenticate to the TPP WebSDK.

Getting & Validating Config Objects

Note

Most features have their own get() method. Using features.objects.get() is simply another way of getting the Config Object of an object’s Distinguished Name (DN).

Getting Config Objects By DN

from pytpp import Authenticate, Features

api = Authenticate(...)
features = Features(api)

#### GET AN OBJECT ####
certificate = features.objects.get(object_dn=r'\VED\Policy\Certificates\Awesome Team\awesome_cert.com')
print(certificate.dn)

Handling Objects That May Not Exist

from pytpp import Authenticate, Features
from pytpp.features.definitions.exceptions import ObjectDoesNotExist

api = Authenticate(...)
features = Features(api)

credential_dn = r'\VED\Policy\Administration\Credentials\Awesome Credential'

#### VALIDATE EXISTENCE WITH TRY/EXCEPT ####
try:
    credential = features.objects.get(object_dn=credential_dn)
except ObjectDoesNotExist:
    print(f'Cannot find {credential_dn}.')

#### VALIDATE EXISTENCE USING DN PROPERTY ####
credential = features.objects.get(
    object_dn=credential_dn,
    raise_error_if_not_exists=False  # The default is True
)
if not credential.dn:
    print(f'Cannot find {credential_dn}.')

#### VALIDATE EXISTENCE USING EXISTS() ####
if not features.objects.exists(object_dn=credential_dn):
    print(f'Cannot find {credential_dn}.')

Reading Attributes

Note

To read policy attributes for a particular class use Reading Policy Attributes.

from pytpp import Authenticate, Features, Attributes

api = Authenticate(...)
features = Features(api)

#### READ A SINGLE ATTRIBUTE ####
certiifcate_authority = features.objects.read(
    obj=r'\VED\Policy\Certificates\Awesome Team\awesome_cert.com',
    attribute_name=Attributes.certificate.certificate_authority,
    include_policy_values=True  # If False, only the explicit attribute on this object is read.
)

#### READ ALL ATTRIBUTES ####
attributes = features.objects.read_all(obj=r'\VED\Policy\Certificates\Awesome Team\awesome_cert.com')
certificate_authority = [attr.values[0] for attr in attributes if attr.name == Attributes.certificate.certificate_authority]

Writing Attributes

Note

To write policy attributes for a particular class use Writing Policy Attributes.

Warning

Writing attributes will override the existing value(s) for that particular attribute. To append to a list of attributes that may already exist, first read those values and then append the new values.

from pytpp import Authenticate, Features, Attributes, AttributeValues

api = Authenticate(...)
features = Features(api)

features.objects.write(
    obj=r'\VED\Policy\Certificates\Awesome Team\awesome_cert.com',
    attributes={
        Attributes.certificate.consumers: [r'\VED\Policy\Installations\Awesome Devices\awesome_device.com\Awesome App'],
        Attributes.certificate.management_type: AttributeValues.Certificate.ManagementType.provisioning
    }
)

Waiting For Attribute Values

Note

Sometimes an operation is occurring that will create or update an attribute value on an object. For example, renewing a certificate will cause the Stage and Status attributes to populate. This is useful when you are expecting a value to be assigned to an attribute in some interval of time.

from pytpp import Authenticate, Features, Attributes

api = Authenticate(...)
features = Features(api)

# Do some operation here.

# Well, there is a certificate feature for this, but this is how it does it!
features.objects.wait_for(
    obj=r'\VED\Policy\Certificates\Awesome Team\awesome_cert.com',
    attribute_name=Attributes.certificate.stage,
    attribute_value='500'
)

Renaming Objects

from pytpp import Authenticate, Features, Attributes

api = Authenticate(...)
features = Features(api)

# This is used for renaming and/or moving objects.
features.objects.rename(
    obj=r'\VED\Policy\Certificates\Awesome Team\awesome_cert.com',
    new_object_dn=obj=r'\VED\Policy\Certificates\Awesome Team\Awesome Folder\awesome_cert.com',
)