Secrets

In the realm of software development, safeguarding sensitive information is crucial. Whether you’re dealing with API keys, authentication tokens, or other confidential data, secrets play a vital role in maintaining application security. This document will guide you on how to add and manage secrets.

Understanding Secrets

Secrets are encrypted variables that you can store in Thread to ensure the safety of sensitive information. They allow you to securely pass authentication credentials to APIs, databases, or other external services without exposing them directly in your code.

To create, edit, and manage your secrets, open the Secrets window in the Thread CDE Tools.

The Secrets set will be shared across all threads in this project, but will not be committed to your version control.

Adding Secrets

Click the ’+ New Secret’ button to add a new secret. You can specify the desired Secret Key and Value, then select Add Secret.

secrets

Editing Secrets

There are two ways to modify secrets in the Secrets window:

  • Using the ellipsis: Click the three dots next to the key you want to change. Then, select Edit to update the key or value.

secrets

  • JSON Editing: Click the Edit as JSON button to modify multiple secrets at once. After making your changes, click Save.

secrets

Accessing Secrets

You can access secrets in your code through environment variables. Below are examples in several popular programming languages:

console.log(process.env.MY_SECRET);
package main

import (
    "fmt"
    "os"
)

func main() {
    secret := os.Getenv("MY_SECRET")
    fmt.Println(secret)
}
import os
print(os.getenv("MY_SECRET"))
puts ENV['MY_SECRET']