Beispiel #1
0
    def __init__(self, session_id=None):
        self.sf_session = None
        self.sf_session_id = None

        if session_id is not None: #remote initialization
            try:
                self.__create_session__(session_id)
            except Exception as e:
                print "Unable to Create Session with passed token: %s" % session_id
                print e
        else: #local initialization
            session = GusSession()
            try:
                self.__create_session__(session.load_session_id())
            except Exception as e:
                if sys.stdin.isatty():
                    login = Factory().get_login('CLI', 'Looks like we need to login to Gus...')
                else:
                    login = Factory().get_login('GUI', 'Looks like we need to login to Gus...')
                    
                login.add_prompt('user', 'GUS UserName', 'TEXT', session.load_user_name())
                login.add_prompt('password', 'GUS Password', 'PASSWORD')
                login.add_prompt('token', 'GUS Security Token', 'TEXT', session.load_gus_token())

                counter = 0
                while self.sf_session_id is None and counter < 3:
                    login.display()
                    user = login.get_value('user')
                    passwd = login.get_value('password')
                    token = login.get_value('token')
                        
                    self.__create_session__(session.login(user, passwd, token))
                    
                if self.sf_session_id is None:
                    raise Exception('Not Logged into GUS')
Beispiel #2
0
 def get_current_user_id(self):
     '''
     Determines the ID of the currently logged in user
     '''
     session = GusSession()
     username = session.load_user_name()
     result = self.sf_session.query("select Id from User where Username='******'" % username)
     return result['records'][0]['Id']