~allanlesage/qakit/practitest-reporting

« back to all changes in this revision

Viewing changes to qakit/practitest/auth.py

  • Committer: Allan LeSage
  • Date: 2015-06-24 20:30:44 UTC
  • mfrom: (5.8.2 upload_result_logs)
  • Revision ID: allan.lesage@canonical.com-20150624203044-9he2uqfmj2ns2lew
MergeĀ upload_result_logs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import time
20
20
 
21
21
 
22
 
def compose_headers(api_key, api_secret_key):
 
22
def compose_headers(api_key, api_secret_key, content_type='application/json'):
23
23
    """Return auth headers incorporating give api key details."""
24
24
    ts = str(int(time.time()))
25
25
    signature = hashlib.md5(
26
26
        (api_key+api_secret_key+ts).encode()).hexdigest()
27
 
    return {
 
27
    auth_header = {
28
28
        'Authorization':
29
29
            'custom api_key={}, signature={}, ts={}'.format(
30
 
                api_key, signature, ts),
31
 
        'Content-Type': 'application/json'
 
30
                api_key, signature, ts)
32
31
    }
 
32
    if content_type is not None:
 
33
        auth_header['Content-Type'] = content_type
 
34
    return auth_header