Capture tokens and secret id from Hashicorp Vault and assign it to Windows Env Variables: Combining regex and Select-String cmdlet

usecase

  • The concern is documenting capturing the token from hashicorp vault and passing it to the Windows Environment Variables
  • that I need to re-issue every 12 hours in order to work with the stack.
  • The aim is to get both consul and nomad CLI to work properly and to use the same keys for the WEBUI
  • nomad output:

1. cmdlet: Select-String

  • I can use Select-String aka sls to grab the line

2. regex: lookaheads and lookbehinds

  • concepts to define patterns that only match they they
  • are / are not followed by a certain pattern → lookahead (positive / negative)
  • are / are not preceded by a certain pattern → lookbehind (positive / negative)
Image for post
Image for post
  • if I want to capture a name that is after mr + an empty string (whitespace \s)
  • I need to use lookbehind syntax

4. final regex with vault

Image for post
Image for post

5. assign the binding to the env var

6. CODE

7. sources

Written by

today I learnt… | as a support eng of the wonderful Snowplow Analytics, expect everything around modern (postmodern?) business intelligence

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store