-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plugins endpoint to the REST API (#14280)
* add plugins endpoint * include access menu permission to plugin endpoint * apply suggestions from code review * fixup! apply suggestions from code review * refactor get plugins info * fixup! refactor get plugins info * fixup! fixup! refactor get plugins info * fixup! fixup! fixup! refactor get plugins info * added plugin in summary of changes * Remove menu access permission * remove menu_links and admin_views and add limit and offset to endpoint * fixup! remove menu_links and admin_views and add limit and offset to endpoint
- Loading branch information
1 parent
e05ba51
commit 31acf95
Showing
7 changed files
with
490 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 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. | ||
from airflow.api_connexion import security | ||
from airflow.api_connexion.parameters import check_limit, format_parameters | ||
from airflow.api_connexion.schemas.plugin_schema import PluginCollection, plugin_collection_schema | ||
from airflow.plugins_manager import get_plugin_info | ||
from airflow.security import permissions | ||
|
||
|
||
@security.requires_access([(permissions.ACTION_CAN_READ, permissions.RESOURCE_PLUGIN)]) | ||
@format_parameters({'limit': check_limit}) | ||
def get_plugins(limit, offset=0): | ||
"""Get plugins endpoint""" | ||
plugins_info = get_plugin_info() | ||
total_entries = len(plugins_info) | ||
plugins_info = plugins_info[offset:] | ||
plugins_info = plugins_info[:limit] | ||
return plugin_collection_schema.dump(PluginCollection(plugins=plugins_info, total_entries=total_entries)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# 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. | ||
|
||
from typing import List, NamedTuple | ||
|
||
from marshmallow import Schema, fields | ||
|
||
|
||
class PluginSchema(Schema): | ||
"""Plugin schema""" | ||
|
||
number = fields.Int() | ||
name = fields.String() | ||
hooks = fields.List(fields.String()) | ||
executors = fields.List(fields.String()) | ||
macros = fields.List(fields.String()) | ||
flask_blueprints = fields.List(fields.String()) | ||
appbuilder_views = fields.List(fields.String()) | ||
appbuilder_menu_items = fields.List(fields.Dict()) | ||
global_operator_extra_links = fields.List(fields.String()) | ||
operator_extra_links = fields.List(fields.String()) | ||
source = fields.String() | ||
|
||
|
||
class PluginCollection(NamedTuple): | ||
"""Plugin List""" | ||
|
||
plugins: List | ||
total_entries: int | ||
|
||
|
||
class PluginCollectionSchema(Schema): | ||
"""Plugin Collection List""" | ||
|
||
plugins = fields.List(fields.Nested(PluginSchema)) | ||
total_entries = fields.Int() | ||
|
||
|
||
plugin_schema = PluginSchema() | ||
plugin_collection_schema = PluginCollectionSchema() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.