当前位置: 首页>>代码示例>>Python>>正文


Python Configuration.get_credentials方法代码示例

本文整理汇总了Python中config.Configuration.get_credentials方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get_credentials方法的具体用法?Python Configuration.get_credentials怎么用?Python Configuration.get_credentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在config.Configuration的用法示例。


在下文中一共展示了Configuration.get_credentials方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get_credentials [as 别名]
def main():
    config = Configuration()
    credentials = config.get_credentials()

    # Create an httplib2.Http object to handle our HTTP requests and authorize it
    # with our good Credentials.
    http = httplib2.Http()
    http = credentials.authorize(http)

    # Construct the service object for the interacting with the Admin Reports API.
    service = discovery.build('admin', 'reports_v1', http=http)
    activities = service.activities()

    settings = config.settings
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    try:
        login_list = activities.list(userKey='all', applicationName='login', maxResults=1000).execute()
        DBSession.query(LoginItem).first()

        print("Success!")
    except client.AccessTokenRefreshError:
        print("Failure. Access token is invalid. Please re-run the tool to get a new access token.")
    except OperationalError:
        print("Database has not been initialised. Please run acctwatch_initdb.")
    except:
        print("Some other unknown error occured")
开发者ID:GuardedRisk,项目名称:Google-Apps-Auditing,代码行数:30,代码来源:configcheck.py

示例2: main

# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import get_credentials [as 别名]
def main():
    config = Configuration()
    credentials = config.get_credentials()

    # Create an httplib2.Http object to handle our HTTP requests and authorize it
    # with our good Credentials.
    http = httplib2.Http()
    http = credentials.authorize(http)

    # Construct the service object for the interacting with the Admin Reports API.
    service = discovery.build('admin', 'reports_v1', http=http)
    activities = service.activities()

    settings = config.settings
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    geoip_reader = geoipdb.Reader(settings['geoip_db'])

    print ("Started watching for new logins")

    while 1:
        try:
            all_new = True

            request = activities.list(userKey='all', applicationName='login', maxResults=1000)
            response = None

            while all_new:
                response = request.execute()

                for login_item in response['items']:
                    login_id = login_item['id']

                    exists = DBSession.query(LoginItem).filter(LoginItem.guid == login_id['uniqueQualifier']).first()

                    if exists:
                        all_new = False
                        continue



                    litem = LoginItem(guid=login_id['uniqueQualifier'], time=datetime.datetime.strptime(login_id['time'], '%Y-%m-%dT%H:%M:%S.%fZ'), ip=login_item['ipAddress'])
                    lactor = DBSession.query(Actor).filter(Actor.id == login_item['actor']['profileId']).first()

                    if lactor:
                        litem.actor = lactor
                    else:
                        litem.actor = Actor(id=login_item['actor']['profileId'], email=login_item['actor']['email'])


                    try:
                        geoip = geoip_reader.city(login_item['ipAddress'])
                        geoip_results = '{}, {}, {}'.format(geoip.city.name, geoip.subdivisions.most_specific.name, geoip.country.name)

                        llocation = DBSession.query(Location).filter(Location.location == geoip_results).first()

                        if llocation:
                            litem.location = llocation
                        else:
                            litem.location = Location(location=geoip_results)

                        print ("New login found for \"{}\" at \"{}\", from \"{}\" ({})".format(login_item['actor']['email'], login_id['time'], geoip_results, login_item['ipAddress']))
                    except AddressNotFoundError:
                        print ("New login found for \"{}\" at \"{}\", from \"unknown\" ({})".format(login_item['actor']['email'], login_id['time'], login_item['ipAddress']))

                    login_event = login_item['events']
                    for event in login_event:
                        if event['type'] == 'login':
                            if event['name'] == 'login_success':
                                litem.success = True
                            if event['name'] == 'login_failure':
                                litem.success = False
                                failed_params = event['parameters']

                                litem.failure = ''
                                for fail_param in failed_params:
                                    if fail_param['name'] == 'login_type':
                                        litem.failure = '{}{}'.format(fail_param['value'], litem.failure)
                                    if fail_param['name'] == 'login_failure_type':
                                        litem.failure = '{} - {}'.format(litem.failure, fail_param['value'])

                    DBSession.add(litem)
                    DBSession.commit()

                if all_new == True:
                    old_request = request
                    request = activities.list_next(old_request, response)

                    if request is None:
                        all_new = False
                        break

        except client.AccessTokenRefreshError:
            print ("The credentials have been revoked or expired, please re-run"
                    "the application to re-authorize")
        except apiclient.errors.HttpError as e:
            print ("Google returned us an error. {}".format(e))
        except KeyboardInterrupt:
            print ("Received the signal to quit")
#.........这里部分代码省略.........
开发者ID:GuardedRisk,项目名称:Google-Apps-Auditing,代码行数:103,代码来源:acctwatch.py


注:本文中的config.Configuration.get_credentials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。