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

feat: 云 API 权限批量申请 API #1587

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apiserver/paasng/paasng/accessories/cloudapi/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class PermissionActionEnum(StructuredEnum):


class PermissionApplyExpireDaysEnum(StructuredEnum):
PERMANENT = EnumField(0, label="永久")
SIX_MONTH = EnumField(180, label="6个月")
TWELVE_MONTH = EnumField(360, label="12个月")

Expand Down
21 changes: 21 additions & 0 deletions apiserver/paasng/paasng/accessories/cloudapi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ class APIGWPermissionApplySLZ(serializers.Serializer):
gateway_name = serializers.CharField(help_text="网关名称,用于记录操作记录")


class GatewayResourceIDsSLZ(serializers.Serializer):
gateway_id = serializers.IntegerField(required=True, help_text="网关 ID")
resource_ids = serializers.ListField(
max_length=100,
child=serializers.IntegerField(),
allow_empty=True,
required=False,
help_text="如果不传则为网关维度申请",
)


class APIGWPermissionBatchApplySLZ(serializers.Serializer):
"""批量申请网关/ API 权限"""

reason = serializers.CharField(max_length=512, allow_blank=True, required=False, default="")
expire_days = serializers.ChoiceField(
jamesgetx marked this conversation as resolved.
Show resolved Hide resolved
choices=constants.PermissionApplyExpireDaysEnum.get_django_choices(),
)
gateway_resource_ids = serializers.ListField(child=GatewayResourceIDsSLZ(), max_length=100)


class APIGWPermissionRenewSLZ(serializers.Serializer):
resource_ids = serializers.ListField(
child=serializers.IntegerField(),
Expand Down
5 changes: 5 additions & 0 deletions apiserver/paasng/paasng/accessories/cloudapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
views.CloudAPIViewSet.as_view({"post": "apply"}),
name="api.cloudapi.v1.apply_resource_permissions",
),
path(
"api/cloudapi/apps/<slug:app_code>/apis/permissions/apply/",
views.CloudAPIViewSet.as_view({"post": "batch_apply"}),
name="api.cloudapi.v1.batch_apply_resource_permissions",
),
path(
"api/cloudapi/apps/<slug:app_code>/apis/permissions/renew/",
views.CloudAPIViewSet.as_view({"post": "renew"}),
Expand Down
13 changes: 13 additions & 0 deletions apiserver/paasng/paasng/accessories/cloudapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ def apply(self, request, *args, **kwargs):
apigw_url = self._trans_request_path_to_apigw_url(request.path, app.code)
return self._post(request, apigw_url, operation_type, app)

@swagger_auto_schema(
request_body=serializers.APIGWPermissionBatchApplySLZ,
tags=["CloudAPI"],
)
def batch_apply(self, request, *args, **kwargs):
slz = serializers.APIGWPermissionBatchApplySLZ(data=request.data)
slz.is_valid(raise_exception=True)

app = self.get_application()
operation_type = OperationEnum.APPLY
apigw_url = self._trans_request_path_to_apigw_url(request.path, app.code)
return self._post(request, apigw_url, operation_type, app)

@swagger_auto_schema(
request_body=serializers.APIGWPermissionRenewSLZ,
tags=["CloudAPI"],
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions apiserver/paasng/tests/paasng/accessories/cloudapi/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ def test_post(self, request_factory, mocker, app_code, operation_type, path, moc
"/api/v1/apis/",
False,
),
# 批量申请 API
(
"/api/cloudapi/apps/test/apis/permissions/apply/",
"test",
"/api/v1/apis/permissions/apply/",
False,
),
# 按单个网关申请 API
(
"/api/cloudapi/apps/test/apis/1/permissions/apply/",
"test",
"/api/v1/apis/1/permissions/apply/",
False,
),
(
"/api/apps/test/apis/",
"test",
Expand Down