Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insights report #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rest-service/manager_rest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def __init__(self):
self.max_results = 1000
self.min_available_memory_mb = None

self.insights_report_url = None

self.security_hash_salt = None
self.security_secret_key = None
self.security_encoding_alphabet = None
Expand Down
7 changes: 7 additions & 0 deletions rest-service/manager_rest/flask_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def get_postgres_conf(manager_ip='localhost'):
)


def get_insights_report_url():
"""Return the URL used to fetch the Insights report"""
manager_config.load_configuration()
url = manager_config.insights_report_url or 'https://mist.io/'
return url.strip('/') + '/api/v1/report'


def set_flask_security_config(app, hash_salt=None, secret_key=None):
"""Set all necessary Flask-Security configurations

Expand Down
3 changes: 2 additions & 1 deletion rest-service/manager_rest/rest/endpoint_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def setup_resources(api):
'FileServerAuth': 'file-server-auth',
'LdapAuthentication': 'ldap',
'Secrets': 'secrets',
'SecretsKey': 'secrets/<string:key>'
'SecretsKey': 'secrets/<string:key>',
'InsightsReport': 'report',
}

# Set version endpoint as a non versioned endpoint
Expand Down
2 changes: 2 additions & 0 deletions rest-service/manager_rest/rest/resources_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@
from .status import Status # noqa
from .tokens import Tokens # noqa
from .version import Version # noqa

from .report import InsightsReport
54 changes: 54 additions & 0 deletions rest-service/manager_rest/rest/resources_v1/report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#########
# Copyright (c) 2017 GigaSpaces Technologies Ltd. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
#
import requests

from flask import request

from manager_rest.storage import models
from manager_rest.storage import get_storage_manager

from manager_rest.security import SecuredResource

from manager_rest.flask_utils import get_insights_report_url

from manager_rest.manager_exceptions import NotFoundError
from manager_rest.manager_exceptions import ManagerException
from manager_rest.manager_exceptions import UnauthorizedError
from manager_rest.manager_exceptions import BadParametersError

from manager_rest.rest.rest_decorators import exceptions_handled


class InsightsReport(SecuredResource):

@exceptions_handled
def get(self):
"""
Get the Insights report
"""
token = get_storage_manager().get(models.Secret, 'insights_token')
report = requests.get(get_insights_report_url(),
params=request.args,
headers={'Authorization': token.value})
if not report.ok:
if report.status_code == 400:
raise BadParametersError()
if report.status_code == 401:
raise UnauthorizedError()
if report.status_code == 404:
raise NotFoundError()
raise ManagerException(report.status_code, 'insights_report_error')
return report.json()