Skip to main content

Managing Secrets

Secrets play a crucial role in Covalent Cloud by enabling secure and efficient environment setup. You can now manage a suite of up to 100 secrets to use inside electron tasks and while building environments. View your secrets with ease in the UI’s environment/secrets page.

The example below demonstrates how to store, list, and delete secrets.

import covalent_cloud as cc

# cc.save_api_key("your-api-key")

# Store secrets
cc.store_secret(name="USERNAME", value="my_username")
cc.store_secret(name="MY_URL", value="https://catfact.ninja/fact")
cc.store_secret(name="KEY", value="fact")

# Retrieve a list of all stored secrets
print(cc.list_secrets())

# Optionally, delete a secret if no longer needed
# cc.delete_secret(name="MY_SECRET_NAME")

Using Secrets for Environment Building

Secrets also come in handy when creating environments. For example, secrets can be used to install Python packages from private repositories:

# Use secrets within the environment creation process
cc.create_env(
name="my_custom_env",
pip=[
"git+https://username:{covalent.secrets.USERNAME}@github.com/user/project.git@main"
]
)

Substrings like "{covalent.secrets.USERNAME}" are substituted with the matching value inside any string parameter passed to create_env.

Secrets inside Electrons

Secrets also available inside electron functions as environment variables. This enables secure access to e.g. private data buckets, API keys, and tokens directly within your compute tasks.

For example, the workflow below accesses the secrets MY_URL and KEY, which we defined above.

import json
import os
import requests

import covalent as ct

@ct.electron(executor=cc.CloudExecutor())
def my_task(num: int = 1):

url = os.getenv("MY_URL")
key = os.getenv("KEY")

facts = []
for _ in range(num):
output = json.loads(requests.get(url).text)
facts.append(output[key])

return "\n".join(facts)

@ct.lattice(executor=cloud_executor, workflow_executor=cloud_executor)
def workflow(num: int):
return my_task(num)

dispatch_id = cc.dispatch(workflow)(5)
res = cc.get_result(dispatch_id, wait=True)
res.result.load()
print(res.result.value)

Dispatching this workflow produces an output that contains five responses from MY_URL (i.e. "https://catfact.ninja/fact").

Cats often overract to unexpected stimuli because of their extremely sensitive nervous system.
Grown cats have 30 teeth. Kittens have about 26 temporary teeth, which they lose when they are about 6 months old.
Unlike other cats, lions have a tuft of hair at the end of their tails.
The average cat can jump 8 feet in a single bound, nearly six times its body length!
An adult lion's roar can be heard up to five miles (eight kilometers) away.