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

Support token helper #639

Open
JasonCust opened this issue Oct 27, 2020 · 0 comments
Open

Support token helper #639

JasonCust opened this issue Oct 27, 2020 · 0 comments

Comments

@JasonCust
Copy link

JasonCust commented Oct 27, 2020

In order to support Vault's token helper on reads, I came up with this little hack but it would be nice to fully support the helper within hvac (on logins, reads, etc).

def getToken():
    '''Gets the token from a Vault token helper file.

    Since the hvac package doesn't yet respect token helpers, we can
    do it outselves.
    '''

    tokenHelperFilePath = os.path.expanduser('~/.vault')

    if os.path.exists(tokenHelperFilePath):
      with open(tokenHelperFilePath, 'r') as fIn:
        tokenHelperPath = fIn.read().split('=')[1].strip().replace('"', '')
        
        if os.path.exists(tokenHelperPath):
          process = subprocess.run(
            [tokenHelperPath, 'get'], 
            stdout = subprocess.PIPE, 
            universal_newlines = True
          )

          return process.stdout


client = hvac.Client(token = getToken())

Any thoughts on if this is something that can be internally supported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant