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

Add 'Show record' option for variables #21342

Merged
merged 12 commits into from
Feb 28, 2022
4 changes: 4 additions & 0 deletions airflow/www/templates/airflow/variable_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@
<div class="clearfix"></div>
{% endif %}
{{ super() }}
<style>
td { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; max-width:1px;}
th { resize: horizontal; overflow: auto;}
</style>
{% endblock %}
28 changes: 28 additions & 0 deletions airflow/www/templates/airflow/variable_show.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{#
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
#}

{% extends 'appbuilder/general/model/show.html' %}

{% block tail %}
{{ super() }}
<style>
#val { font-family: monospace; white-space: pre-wrap;}
table { table-layout: fixed; word-wrap: break-word;}
</style>
{% endblock %}
70 changes: 70 additions & 0 deletions airflow/www/templates/airflow/variable_show_widget.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{#
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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 'appbuilder/general/lib.html' as lib %}
{% include 'appbuilder/general/confirm.html' %}
{% include 'appbuilder/general/alert.html' %}

{% block columns %}

{% if fieldsets %}

{% for fieldset_item in fieldsets %}
{% if fieldset_item[1].get('expanded') == None %}
{% set expanded = True %}
{% else %}
{% set expanded = fieldset_item[1].get('expanded') %}
{% endif %}
{% call lib.accordion_tag(loop.index,fieldset_item[0], expanded) %}
<div class="table-responsive">
<table class="table table-bordered">
{% for item in fieldset_item[1].get('fields') %}
<tr>
<th class="col-lg-2 col-md-2 col-sm-2">{{label_columns.get(item)}}</th>
<td><span id="{{item}}">{{value_columns[include_columns.index(item)]}}</span></td>
</tr>
{% endfor %}
</table></div>
{% endcall %}
{% endfor %}

{% else %}
<div class="table-responsive">
<table class="table table-bordered">

{% for item in include_columns %}
<tr>
<th class="col-lg-2 col-md-2 col-sm-2">{{label_columns.get(item)}}</th>
<td>
<span id="{{item}}">{{value_columns[loop.index-1]}}</span>
</td>
</tr>
{% endfor %}
</table></div>
{% endif %}

{% endblock columns %}


{% block actions %}
<div class="well well-sm">
{{ lib.render_action_links(actions, pk, modelview_name) }}
{{ lib.lnk_back() }}
</div>
{% endblock actions %}
28 changes: 27 additions & 1 deletion airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
UserStatsChartView,
ViewMenuModelView,
)
from flask_appbuilder.urltools import get_order_args, get_page_args, get_page_size_args
from flask_appbuilder.widgets import FormWidget
from flask_babel import lazy_gettext
from jinja2.utils import htmlsafe_json_dumps, pformat # type: ignore
Expand Down Expand Up @@ -129,7 +130,7 @@
DateTimeWithNumRunsWithDagRunsForm,
TaskInstanceEditForm,
)
from airflow.www.widgets import AirflowModelListWidget
from airflow.www.widgets import AirflowModelListWidget, AirflowVariableShowWidget

PAGE_SIZE = conf.getint('webserver', 'page_size')
FILTER_TAGS_COOKIE = 'tags_filter'
Expand Down Expand Up @@ -4068,6 +4069,9 @@ class VariableModelView(AirflowModelView):

list_template = 'airflow/variable_list.html'
edit_template = 'airflow/variable_edit.html'
show_template = 'airflow/variable_show.html'
aa3pankaj marked this conversation as resolved.
Show resolved Hide resolved

show_widget = AirflowVariableShowWidget

datamodel = AirflowModelView.CustomSQLAInterface(models.Variable) # type: ignore

Expand All @@ -4076,6 +4080,7 @@ class VariableModelView(AirflowModelView):
'add': 'create',
'list': 'read',
'edit': 'edit',
'show': 'read',
'delete': 'delete',
'action_muldelete': 'delete',
'action_varexport': 'read',
Expand All @@ -4091,6 +4096,7 @@ class VariableModelView(AirflowModelView):
list_columns = ['key', 'val', 'description', 'is_encrypted']
add_columns = ['key', 'val', 'description']
edit_columns = ['key', 'val', 'description']
show_columns = ['key', 'val', 'description']
search_columns = ['key', 'val']

base_order = ('key', 'asc')
Expand All @@ -4116,6 +4122,26 @@ def prefill_form(self, form, request_id):
if secrets_masker.should_hide_value_for_key(form.key.data):
form.val.data = '*' * 8

def prefill_show(self, item):
if secrets_masker.should_hide_value_for_key(item.key):
item.val = '*' * 8

def _show(self, pk):
pages = get_page_args()
page_sizes = get_page_size_args()
orders = get_order_args()

item = self.datamodel.get(pk, self._base_filters)
if not item:
abort(404)
self.prefill_show(item)
widgets = self._get_show_widget(pk, item)
self.update_redirect()

return self._get_related_views_widgets(
item, orders=orders, pages=pages, page_sizes=page_sizes, widgets=widgets
)

extra_args = {"can_create_variable": _can_create_variable}

@action('muldelete', 'Delete', 'Are you sure you want to delete selected records?', single=False)
Expand Down
6 changes: 6 additions & 0 deletions airflow/www/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ class BS3TextAreaROWidget(BS3TextAreaFieldWidget):
def __call__(self, field, **kwargs):
kwargs['readonly'] = 'true'
return super().__call__(field, **kwargs)


class AirflowVariableShowWidget(RenderTemplateWidget):
"""Airflow variable show widget"""

template = 'airflow/variable_show_widget.html'