Esempio n. 1
0
def TemporaryHmacSecretFile( secret ):
  """Helper function for passing the hmac secret when starting a JediHTTP server

    with TemporaryHmacSecretFile( 'mysecret' ) as hmac_file:
      jedihttp = subprocess.Popen( ['python',
                                    'jedihttp',
                                    '--hmac-file-secret', hmac_file.name ] )

    The JediHTTP Server as soon as it reads the hmac secret will remove the file
  """
  hmac_file = tempfile.NamedTemporaryFile( 'w', delete = False )
  encoded_secret = decode_string( b64encode( encode_string( secret ) ) )
  json.dump( { 'hmac_secret': encoded_secret }, hmac_file )
  return hmac_file
def teardown_jedihttp(jedihttp):
    try:
        requests.post('http://127.0.0.1:{0}/shutdown'.format(PORT),
                      auth=HmacAuth(SECRET))
    except requests.exceptions.ConnectionError:
        pass

    try:
        wait_process_shutdown(jedihttp)
    except RuntimeError:
        jedihttp.terminate()

    stdout, _ = jedihttp.communicate()
    sys.stdout.write(decode_string(stdout))
Esempio n. 3
0
def TemporaryHmacSecretFile(secret):
    """Helper function for passing the hmac secret when starting a JediHTTP server

    with TemporaryHmacSecretFile( 'mysecret' ) as hmac_file:
      jedihttp = subprocess.Popen( ['python',
                                    'jedihttp',
                                    '--hmac-file-secret', hmac_file.name ] )

    The JediHTTP Server as soon as it reads the hmac secret will remove the file
  """
    hmac_file = tempfile.NamedTemporaryFile('w', delete=False)
    encoded_secret = decode_string(b64encode(encode_string(secret)))
    json.dump({'hmac_secret': encoded_secret}, hmac_file)
    return hmac_file
Esempio n. 4
0
 def _set_hmac_header(self, headers, hmac):
     headers[_HMAC_HEADER] = decode_string(b64encode(hmac))
Esempio n. 5
0
 def _SetHmacHeader( self, headers, hmac ):
   headers[ _HMAC_HEADER ] = decode_string( b64encode( hmac ) )
Esempio n. 6
0
 def _SetHmacHeader(self, headers, hmac):
     headers[_HMAC_HEADER] = decode_string(b64encode(hmac))
Esempio n. 7
0
 def _set_hmac_header(self, headers, hmac):
     headers[_HMAC_HEADER] = decode_string(b64encode(hmac))