Exemple #1
0
from flask import jsonify, request

from .embeds_helper import EmbedsHelper, InvalidEmbedToken
from meltano.api.api_blueprint import APIBlueprint
from meltano.api.models import db

embedsBP = APIBlueprint("embeds", __name__)


@embedsBP.errorhandler(InvalidEmbedToken)
def _handle(ex):
    return (
        jsonify({
            "error":
            True,
            "code":
            f"No matching resource found or this resource is no longer public.",
        }),
        400,
    )


@embedsBP.route("/embed/<token>", methods=["GET"])
def get_embed(token):
    today = request.args.get("today", None)

    embeds_helper = EmbedsHelper()
    response_data = embeds_helper.get_embed_from_token(db.session,
                                                       token,
                                                       today=today)
Exemple #2
0
from flask import request, jsonify, g

from meltano.core.error import PluginInstallError
from meltano.core.plugin_discovery_service import (
    PluginDiscoveryService,
    PluginNotFoundError,
)
from meltano.core.plugin import PluginType
from meltano.core.project import Project
from meltano.core.project_add_service import ProjectAddService
from meltano.core.config_service import ConfigService
from meltano.core.plugin_install_service import PluginInstallService
from flask_security import roles_required
from meltano.api.api_blueprint import APIBlueprint

pluginsBP = APIBlueprint("plugins", __name__)


@pluginsBP.errorhandler(PluginInstallError)
def _handle(ex):
    return (jsonify({"error": True, "code": str(ex)}), 502)


@pluginsBP.route("/all", methods=["GET"])
def all():
    project = Project.find()
    discovery = PluginDiscoveryService(project)
    ordered_plugins = {}

    for type, plugins in groupby(discovery.plugins(), key=lambda p: p.type):
        canonical_plugins = []
Exemple #3
0
from flask import jsonify, request
from flask_principal import Need, Permission
from flask_restful import Api, Resource, fields, marshal, marshal_with
from flask_security import roles_required
from meltano.api.api_blueprint import APIBlueprint
from meltano.api.models.security import Role, RolePermissions, RolesUsers, User, db
from meltano.api.security import users
from meltano.api.security.auth import block_if_readonly
from sqlalchemy.orm import joinedload
from werkzeug.exceptions import Forbidden

from .settings_helper import SettingsHelper

settingsBP = APIBlueprint("settings", __name__)
settingsApi = Api(settingsBP)


@settingsBP.route("/", methods=["GET"])
@roles_required("admin")
def index():
    settings_helper = SettingsHelper()
    return jsonify(settings_helper.get_connections())


@settingsBP.route("/save", methods=["POST"])
@roles_required("admin")
@block_if_readonly
def save():
    settings_helper = SettingsHelper()
    connection = request.get_json()
    settings = settings_helper.save_connection(connection)
Exemple #4
0
from meltano.api.security.resource_filter import NameFilterMixin, ResourceFilter
from meltano.core.compiler.project_compiler import ProjectCompiler
from meltano.core.m5o.m5o_collection_parser import (
    M5oCollectionParser,
    M5oCollectionParserTypes,
)
from meltano.core.m5o.m5o_file_parser import (
    MeltanoAnalysisFileParser,
    MeltanoAnalysisFileParserError,
    MeltanoAnalysisMissingTopicFilesError,
)
from meltano.core.project import Project

from .repos_helper import ReposHelper

reposBP = APIBlueprint("repos", __name__)


class ReportIndexFilter(NameFilterMixin, ResourceFilter):
    def __init__(self, *args):
        super().__init__(*args)

        self.needs(self.design_need)

    def design_need(self, permission_type, report):
        return Need("view:design", report["design"])


class M5ocFilter(ResourceFilter):
    def filter_designs(self, designs):
        return (
Exemple #5
0
from flask import jsonify, request

from .errors import InvalidFileNameError

from meltano.core.project import Project
from meltano.core.m5o.reports_service import (
    ReportAlreadyExistsError,
    ReportDoesNotExistError,
    ReportsService,
)

from meltano.api.api_blueprint import APIBlueprint
from meltano.api.security.resource_filter import ResourceFilter, NameFilterMixin, Need
from flask_security import roles_required

reportsBP = APIBlueprint("reports", __name__)


def reports_service():
    project = Project.find()
    return ReportsService(project)


class ReportFilter(NameFilterMixin, ResourceFilter):
    def __init__(self, *args):
        super().__init__(*args)

        self.needs(self.design_need)

    def design_need(self, permission_type, report):
        if permission_type == "view:reports":
Exemple #6
0

@root.route("/bootstrap")
@redirect_to_login_if_auth_required
def bootstrap():
    return redirect(current_app.config["MELTANO_UI_URL"])


@root.route("/echo", methods=["POST"])
def echo():
    payload = request.get_json()
    print(payload)
    return jsonify(payload)


api_root = APIBlueprint("api_root", __name__, url_prefix="/api/v1/")


@api_root.route("/identity")
def identity():
    if current_user.is_anonymous:
        return jsonify({
            "username":
            "******",
            "anonymous":
            True,
            "can_sign_in":
            current_app.config["MELTANO_AUTHENTICATION"],
        })

    return jsonify({
Exemple #7
0
        if not str(resolved_file_path).startswith(
                str(uploads_directory) + "/"):
            logging.warning(
                "Cannot set a file configuration to a path outside the project directory"
            )
            return False

    old_value, metadata = settings.get_with_metadata(name, session=db.session)
    if not metadata["overwritable"]:
        logging.warning("Cannot overwrite this setting.")
        return False

    return True


orchestrationsBP = APIBlueprint("orchestrations", __name__)
orchestrationsAPI = Api(
    orchestrationsBP,
    errors={
        "UnprocessableEntity": {
            "error": True,
            "code": "The subscription could not be created.",
            "status": UnprocessableEntity.code,
        },
        "Conflict": {
            "error": True,
            "code": "A subscription already exists for this address.",
            "status": Conflict.code,
        },
    },
)
Exemple #8
0
from flask import jsonify, request
from meltano.api.api_blueprint import APIBlueprint
from meltano.api.models import db
from meltano.api.security import block_if_api_auth_required

from .embeds_helper import EmbedsHelper, InvalidEmbedToken

embedsBP = APIBlueprint("embeds", __name__, require_authentication=False)


@embedsBP.errorhandler(InvalidEmbedToken)
def _handle(ex):
    return (
        jsonify(
            {
                "error": True,
                "code": f"No matching resource found or this resource is no longer public.",
            }
        ),
        400,
    )


@embedsBP.route("/embed/<token>", methods=["GET"])
def get_embed(token):
    today = request.args.get("today", None)

    embeds_helper = EmbedsHelper()
    response_data = embeds_helper.get_embed_from_token(db.session, token, today=today)

    return jsonify(response_data)
Exemple #9
0
from flask import jsonify, request
from .dashboards_helper import DashboardsHelper
from meltano.core.project import Project
from meltano.core.m5o.dashboards_service import (
    DashboardAlreadyExistsError,
    DashboardDoesNotExistError,
    DashboardsService,
)
from meltano.core.schedule_service import ScheduleNotFoundError
from .errors import InvalidFileNameError
from meltano.api.api_blueprint import APIBlueprint
from flask_security import roles_required

dashboardsBP = APIBlueprint("dashboards", __name__)


def dashboards_service():
    project = Project.find()
    return DashboardsService(project)


@dashboardsBP.errorhandler(DashboardAlreadyExistsError)
def _handle(ex):
    dashboard_name = ex.dashboard["name"]
    return (
        jsonify({
            "error":
            True,
            "code":
            f"A dashboard with the name '{dashboard_name}' already exists. Try renaming the dashboard.",
        }),
Exemple #10
0
import sqlalchemy

from datetime import date, datetime
from decimal import Decimal
from flask import jsonify, request

from .settings_helper import SettingsHelper
from .sql_helper import SqlHelper, ConnectionNotFound, UnsupportedConnectionDialect
from meltano.api.api_blueprint import APIBlueprint
from meltano.core.project import Project
from meltano.core.schedule_service import ScheduleService, ScheduleNotFoundError
from meltano.core.utils import find_named, NotFound
from meltano.core.sql.filter import FilterOptions
from meltano.core.sql.base import ParseError, EmptyQuery

sqlBP = APIBlueprint("sql", __name__)


@sqlBP.errorhandler(ConnectionNotFound)
def _handle(ex):
    return (
        jsonify({
            "error":
            True,
            "code":
            f"Missing connection details to '{ex.connection_name}'. Create a connection to '{ex.connection_name}' in the settings.",
        }),
        500,
    )