Unverified Commit f6da011b authored by Tamika Tannis's avatar Tamika Tannis Committed by GitHub

docs: Add Dashboard Preview Doc (#496)

* Add doc; Nest dashboard preview code into same directory

* Some edits

* Lint fix
parent 1588241e
......@@ -2,7 +2,7 @@ import logging
from abc import ABCMeta, abstractmethod
from amundsen_application.base.base_preview import BasePreview
from amundsen_application.dashboard_preview.mode_preview import ModePreview
from amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview import ModePreview
LOGGER = logging.getLogger(__name__)
......
......@@ -5,8 +5,8 @@ from http import HTTPStatus
from flask import send_file, jsonify, make_response, Response, current_app as app
from flask.blueprints import Blueprint
from amundsen_application.dashboard_preview.preview_factory_method import DefaultPreviewMethodFactory, \
BasePreviewMethodFactory
from amundsen_application.api.preview.dashboard.dashboard_preview.preview_factory_method import \
DefaultPreviewMethodFactory, BasePreviewMethodFactory
LOGGER = logging.getLogger(__name__)
PREVIEW_FACTORY: BasePreviewMethodFactory = None # type: ignore
......
......@@ -15,6 +15,29 @@ def init_custom_routes(app: Flask) -> None:
def custom_route():
pass
```
## Dashboard Preview
This service provides an API to download preview image of dashboard resources, which currently only supports [Mode](https://app.mode.com/).
The dashboard preview image is cached in user's browser up to a day. In order to adjust this you can change the value of `DASHBOARD_PREVIEW_IMAGE_CACHE_MAX_AGE_SECONDS`
### How to configure Mode dashboard preview
Add the following environment variables:
```bash
CREDENTIALS_MODE_ADMIN_TOKEN
CREDENTIALS_MODE_ADMIN_PASSWORD
MODE_ORGANIZATION
```
#### How to enable authorization on Mode dashboard
By default, Amundsen does not do any authorization on showing preview. By registering name of the Mode preview class in configuration, you can enable authorization.
```bash
ACL_ENABLED_DASHBOARD_PREVIEW = {'ModePreview'}
```
Amundsen ingests Mode dashboards only from the shared space, which all registered Mode users are able to view. Therefore our authorization first validates if the current user is registered in Mode. This feature is dependent on Amundsen also ingesting Mode user information via the [ModeDashboardUserExtractor](https://github.com/lyft/amundsendatabuilder/blob/master/README.md#modedashboarduserextractor) and the metadata service version must be at least [v2.5.2](https://github.com/lyft/amundsenmetadatalibrary/releases/tag/v2.5.2).
### How to support preview of different product?
You can add preview support for different products by adding its preview class to [DefaultPreviewMethodFactory](https://github.com/lyft/amundsenfrontendlibrary/blob/master/amundsen_application/api/preview/dashboard/dashboard_preview/preview_factory_method.py#L27)
In order to develop new preview class, you need to implement the class that inherits [BasePreview](https://github.com/lyft/amundsenfrontendlibrary/blob/master/amundsen_application/base/base_preview.py#L4) class and [ModePreview](https://github.com/lyft/amundsenfrontendlibrary/blob/master/amundsen_application/api/preview/dashboard/dashboard_preview/mode_preview.py#L28) would be a great example.
## Mail Client Features
Amundsen has two features that leverage the custom mail client -- the feedback tool and notifications. For these features a custom implementation of [base_mail_client](https://github.com/lyft/amundsenfrontendlibrary/blob/master/amundsen_application/base/base_mail_client.py) must be mapped to the `MAIL_CLIENT` configuration variable.
......
......@@ -7,7 +7,7 @@ from requests.auth import HTTPBasicAuth
from unittest.mock import MagicMock
from amundsen_application import create_app
from amundsen_application.dashboard_preview.mode_preview import ModePreview, DEFAULT_REPORT_URL_TEMPLATE
from amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview import ModePreview, DEFAULT_REPORT_URL_TEMPLATE
from amundsen_application.api.utils import request_utils
ACCESS_TOKEN = 'token'
......@@ -92,7 +92,7 @@ class TestModePreview(unittest.TestCase):
self.app.config['ACL_ENABLED_DASHBOARD_PREVIEW'] = {'ModePreview'}
self.app.config['AUTH_USER_METHOD'] = MagicMock()
with patch('amundsen_application.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
with patch('amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
mock_request_metadata.return_value.json.return_value = {
'employee_type': 'teamMember',
'full_name': 'test_full_name',
......@@ -112,7 +112,7 @@ class TestModePreview(unittest.TestCase):
preview._authorize_access(user_id='test_email')
with patch('amundsen_application.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
with patch('amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
mock_request_metadata.return_value.json.return_value = {
'employee_type': 'teamMember',
'full_name': 'test_full_name',
......@@ -131,7 +131,7 @@ class TestModePreview(unittest.TestCase):
preview = ModePreview(access_token='token', password='password', organization='foo')
self.assertRaises(PermissionError, preview._authorize_access, user_id='test_email')
with patch('amundsen_application.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
with patch('amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
mock_request_metadata.return_value.json.return_value = {
'employee_type': 'teamMember',
'full_name': 'test_full_name',
......@@ -148,7 +148,7 @@ class TestModePreview(unittest.TestCase):
preview = ModePreview(access_token='token', password='password', organization='foo')
self.assertRaises(PermissionError, preview._authorize_access, user_id='test_email')
with patch('amundsen_application.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
with patch('amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
mock_request_metadata.return_value.json.return_value = {
'employee_type': 'teamMember',
'full_name': 'test_full_name',
......@@ -167,7 +167,7 @@ class TestModePreview(unittest.TestCase):
preview = ModePreview(access_token='token', password='password', organization='foo')
self.assertRaises(PermissionError, preview._authorize_access, user_id='test_email')
with patch('amundsen_application.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
with patch('amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
mock_request_metadata.return_value.json.return_value = {
'employee_type': 'teamMember',
'full_name': 'test_full_name',
......@@ -184,7 +184,7 @@ class TestModePreview(unittest.TestCase):
preview = ModePreview(access_token='token', password='password', organization='foo')
self.assertRaises(PermissionError, preview._authorize_access, user_id='test_email')
with patch('amundsen_application.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
with patch('amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata') as mock_request_metadata:
mock_request_metadata.return_value.json.return_value = {
'employee_type': 'teamMember',
'full_name': 'test_full_name',
......
......@@ -4,8 +4,8 @@ import unittest
from flask import current_app
from amundsen_application import create_app
from amundsen_application.dashboard_preview.mode_preview import ModePreview
from amundsen_application.dashboard_preview.preview_factory_method import DefaultPreviewMethodFactory
from amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview import ModePreview
from amundsen_application.api.preview.dashboard.dashboard_preview.preview_factory_method import DefaultPreviewMethodFactory
class TestDefaultPreviewFactory(unittest.TestCase):
......
......@@ -7,8 +7,8 @@ from http import HTTPStatus
from amundsen_application import create_app
from amundsen_application.api.preview.dashboard import v0
from amundsen_application.base.base_preview import BasePreview
from amundsen_application.dashboard_preview.preview_factory_method import DefaultPreviewMethodFactory,\
BasePreviewMethodFactory
from amundsen_application.api.preview.dashboard.dashboard_preview.preview_factory_method import \
DefaultPreviewMethodFactory, BasePreviewMethodFactory
from unittest.mock import MagicMock
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment