예제 #1
0
def add_connector():
    """
    Adds a new connector
    """
    form = ConnectorForm()
    if form.validate_on_submit():
        connector_type = ConnectorType.query.get(
            form.connector_type.raw_data[0])
        connector = ConnectorManager.get_connector(connector_type.name)

        if not connector.validate(
                server=form.server.data,
                login=form.login.data,
                api_token=form.api_token.data,
        ):
            flash(
                "Connector is not valid. Check spelling or correctness of fields and try again",
                "error")
            return redirect(url_for("app_routes.add_connector"))

        Connector.create(name=form.name.data,
                         server=form.server.data,
                         login=form.login.data,
                         password=form.password.data,
                         api_token=form.api_token.data,
                         connector_type_id=form.connector_type.raw_data[0],
                         user_id=current_user.get_id())

        return redirect(url_for("app_routes.get_connectors"))

    return render_template("forms/connector.html",
                           headline='Add a new connector',
                           action="/connector/add",
                           form=form)
예제 #2
0
 def is_valid(self):
     connector = ConnectorManager.get_connector(self.connector_type.name)
     return connector.validate(
         server=self.server,
         login=self.login,
         api_token=self.api_token,
     )
예제 #3
0
def get_connector_type_fields(connector_type_id):
    connector_type = ConnectorType.query.get(connector_type_id)

    if connector_type:
        connector = ConnectorManager.get_connector(connector_type.name)
        return jsonify({'fields': connector.FORM_FIELDS})

    raise Exception(
        'Connector type with id {} does not exist.'.format(connector_type_id))