ovh_shinken.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:sauna 作者: NicolasLM 项目源码 文件源码
def request_ovh_client(consumer_key=None):
    try:
        import requests
        import requests.exceptions
    except ImportError:
        print('The requests library is needed to perform this command:')
        print('    pip install requests')
        print('    apt-get install python3-requests')
        exit(1)
    client = Client(
        endpoint='ovh-eu',
        application_key='yVPsINnSdHOLTGHf',
        application_secret='5mVDkHaJw6rp5GYiYBUlgDv1vruRejkl',
        consumer_key=consumer_key
    )
    if not consumer_key:
        response = client.request_consumerkey(
            access_rules=[
                {'method': 'GET', 'path': '/paas/monitoring'},
                {'method': 'GET', 'path': '/paas/monitoring/*'},
                {'method': 'POST', 'path': '/paas/monitoring/*'},
                {'method': 'PUT', 'path': '/paas/monitoring/*'},
                {'method': 'DELETE', 'path': '/paas/monitoring/*'}
            ]
        )
        response = response.json()
        print('New consumer key:', response['consumerKey'])
        print('Validate it at', response['validationUrl'])
        input('When you are ready, press Enter')
    try:
        client.get('/paas/monitoring')
    except requests.exceptions.HTTPError as e:
        if not e.response.status_code == 403:
            raise
        return request_ovh_client()

    return client
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号