tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

write-dummy-secret.py (1042B)


      1 #!/usr/bin/env python3
      2 
      3 # This Source Code Form is subject to the terms of the Mozilla Public
      4 # License, v. 2.0. If a copy of the MPL was not distributed with this
      5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      6 
      7 
      8 import argparse
      9 import errno
     10 import os
     11 
     12 
     13 def write_secret_to_file(path, secret):
     14    path = os.path.abspath(os.path.join(os.getcwd(), path))
     15    try:
     16        os.makedirs(os.path.dirname(path))
     17    except OSError as error:
     18        if error.errno != errno.EEXIST:
     19            raise
     20 
     21    print(f"Outputting secret to: {path}")
     22 
     23    with open(path, "w") as f:
     24        f.write(secret)
     25 
     26 
     27 def main():
     28    parser = argparse.ArgumentParser(description="Store a dummy secret to a file")
     29 
     30    parser.add_argument(
     31        "-c", dest="content", action="store", help="content of the secret"
     32    )
     33    parser.add_argument(
     34        "-f", dest="path", action="store", help="file to save secret to"
     35    )
     36 
     37    result = parser.parse_args()
     38 
     39    write_secret_to_file(result.path, result.content)
     40 
     41 
     42 if __name__ == "__main__":
     43    main()