Hello, here! I'm working with a TLS private key that get passed as a dagger.Secret through the CLI.
s.with_mounted_secret(mounted_tls_key_path, tls_key)
Now, technically I could also fetch this file from the src directory that gets passed as an argument, and I would like that to be the default behaviour (i.e. tls_key is an optional argument). My solution was to set tls_key to None by default and then do:
if tls_key is None:
tls_key = src.file(TLS_KEY_PATH_IN_SRC)
Here's where the conundrum arises. The tls_key can now either be dagger.File or dagger.Secret. I could not find an easy way to convert a dagger.File to dagger.Secret, so during mounting I did a conditional like:
s = (
s.with_mounted_file(mounted_tls_key_path, tls_key)
if isinstance(tls_key, dagger.File)
else s.with_mounted_secret(mounted_tls_key_path, tls_key)
)
Frankly, this looks pretty hacky and I believe there must be a better way to do this. I dislike how in this case I treat the tls_key as either a File or a Secret when mounting it into the container, when I want it to be a Secret. Better ideas would be much appreciated!