Hi all, I’m not sure how i am supposed to leverage...
# ask-community
l
Hi all, I’m not sure how i am supposed to leverage secret string from a customised block. I’m trying to run a shell where i pass a password.
Copy code
@flow()
def obtain_kerberos_ticket(kerberos_block: KerberosCredentials) -> None:
   logger = get_run_logger()
   shell_run_command(
        command='echo "${PASSWORD}" | kinit USERNAME; klist',
        env={
            'USERNAME': kerberos_block.username,
            'PASSWORD': kerberos_block.password,
        },
        return_all=True)
    <http://logger.info|logger.info>("a kerberos tickets has been obtained")
TypeError: expected str, bytes or os.PathLike object, not SecretStr
thanks for any help
m
Hey Luca I think after you load the block you also need to call .get() to return the value for the secret str. Something Like this assuming your loading the block earlier
Copy code
@flow()
def obtain_kerberos_ticket(kerberos_block: KerberosCredentials) -> None:
   logger = get_run_logger()
   shell_run_command(
        command='echo "${PASSWORD}" | kinit USERNAME; klist',
        env={
            'USERNAME': kerberos_block.get("username"),
            'PASSWORD': kerberos_block.get("password"),
        },
        return_all=True)
    <http://logger.info|logger.info>("a kerberos tickets has been obtained")
l
@Mason Menges it doesnt seem to be this.
Copy code
'USERNAME': kerberos_block.get('username'),
AttributeError: 'KerberosCredentials' object has no attribute 'get'
This is how I defined the block:
Copy code
from pydantic import SecretStr
from prefect.blocks.core import Block

class KerberosCredentials(Block):
   username: str
    password: SecretStr