# Secret Tasks


Secret Tasks are a special kind of Prefect Task used to represent the retrieval of sensitive data.

The base implementation uses Prefect Cloud secrets, but users are encouraged to subclass the Secret task class for interacting with other secret providers. Secrets always use a special kind of result handler that prevents the persistence of sensitive information.

# SecretBase

class

prefect.tasks.secrets.base.SecretBase

(**kwargs)[source]

Base Secrets Task. This task does not perform any action but rather serves as the base task class which should be inherited from when writing new Secret Tasks.

Users should subclass this Task and override its run method for plugging into other Secret stores, as it is handled differently during execution to ensure the underlying secret value is not accidentally persisted in a non-safe location.

Args:

  • **kwargs (Any, optional): additional keyword arguments to pass to the Task constructor
Raises:
  • ValueError: if a result keyword is passed



# PrefectSecret

class

prefect.tasks.secrets.base.PrefectSecret

(name=None, **kwargs)[source]

Prefect Secrets Task. This task retrieves the underlying secret through the Prefect Secrets API (which has the ability to toggle between local vs. Cloud secrets).

Args:

  • name (str, optional): The name of the underlying secret
  • **kwargs (Any, optional): additional keyword arguments to pass to the Task constructor
Raises:
  • ValueError: if a result keyword is passed

methods:                                                                                                                                                       

prefect.tasks.secrets.base.PrefectSecret.run

(name=None)[source]

The run method for Secret Tasks. This method actually retrieves and returns the underlying secret value using the Secret.get() method. Note that this method first checks context for the secret value, and if not found either raises an error or queries Prefect Cloud, depending on whether config.cloud.use_local_secrets is True or False.

Args:

  • name (str, optional): the name of the underlying Secret to retrieve. Defaults to the name provided at initialization.
Returns:
  • Any: the underlying value of the Prefect Secret



# EnvVarSecret

class

prefect.tasks.secrets.env_var.EnvVarSecret

(name=None, cast=None, raise_if_missing=False, **kwargs)[source]

A Secret task that retrieves a value from an environment variable.

Args:

  • name (str, optional): the environment variable that contains the secret value
  • cast (Callable[[Any], Any]): A function that will be called on the Parameter value to coerce it to a type.
  • raise_if_missing (bool): if True, an error will be raised if the env var is not found.
  • **kwargs (Any, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.secrets.env_var.EnvVarSecret.run

(name=None)[source]

Returns the value of an environment variable after applying an optional cast function.

Args:

  • name (str, optional): the name of the underlying environment variable to retrieve. Defaults to the name provided at initialization.
Returns:
  • Any: the (optionally type-cast) value of the environment variable
Raises:
  • ValueError: if raise_is_missing is True and the environment variable was not found



This documentation was auto-generated from commit ffa9a6c
on February 1, 2023 at 18:44 UTC