Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds documentation on usage for new Secret fields env_var and file #1017

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions examples/containerization/containerization/use_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,42 @@ def my_secret_workflow() -> Tuple[str, str, str, str, str]:
f, s = secret_file_task()
return x, y, z, f, s

# %% [markdown]
# By default, Secrets injected as environment variables get the name `_FSEC_{GROUP}_{KEY}`.
# Secrets mounted as files are located by default at `/etc/flyte/secrets/{group}/{key}`.
# The `env_var` and `file` fields allow you to specify an override. In that case, you do
# not need to specify `mount_requirement`:

# %%

from flytekit import task, workflow, Secret
import flytekit
import os

@task(
secret_requests=[
Secret(
group="user-info",
key="user_secret",
env_var=Secret.MountEnvVar(name="foo"),
),
Secret(
group="user-info",
key="user_secret",
file=Secret.MountFile(path="/foo"),
),
]
)
def secret_task() -> None:
context = flytekit.current_context()

# retrieve env_var
print(context.secrets.get(env_name="foo"))

# retrieve file
with open('/foo/user_secret', 'r') as infile:
print(infile.readlines())


# %% [markdown]
# ### Testing with Mock Secrets
Expand Down