How to call a method returning a value from a main function

prasanth kotagiri prasanthktgr at gmail.com
Wed Sep 28 02:47:25 EDT 2016


#!/sur/bin/env python

import sys
import jwt
import argparse
from calendar import timegm
from datetime import datetime
import uuid

class TokenGenerator:
    def __init__(self, args):
        self.macKey = args.authzSystemMacKey
        self.authzSystemId = args.authzSystemId
        self.permissions = args.permissions
        self.configurationId = args.configurationId
        self.tokenExpiry = args.tokenExpiryInSeconds

    def generate(self):
        payload = {
            'iss': self.authzSystemId,
            'aud': 'qed:' + self.configurationId,
            'sub': 'admin:tokengen.py',
            'qedp': self.permissions,
            'exp': timegm(datetime.utcnow().utctimetuple()) + self.tokenExpiry
        }
        if self.tokenExpiry <= 300: # less than 5minutes
            payload['jti'] = str(uuid.uuid1())
        return jwt.encode(payload, self.macKey, algorithm='HS256')

class JWTParms:
     pass



def GenAccessToken(mackey,authid,configid,tokenexp,*perm):
    args=JWTParms()
    args.configurationId=configid
    args.authzSystemMacKey=mackey
    args.authzSystemId=authid
    args.tokenExpiryInSeconds=tokenexp
    args.permissions=perm
    tokenGen=TokenGenerator(args)
    tok=tokenGen.generate()
    return tok

if __name__ == '__main__':
      GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", "default", "default", 60000,
           "g,m,a,s,c,p,d")

when i am calling the above method it is not returning any value but when i use print it is printing the value. Is there any wrong in returning the value from above method. Please help me ASAP



More information about the Python-list mailing list