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

Iamv3 framework #1580

Merged
merged 5 commits into from
Oct 12, 2021
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
2 changes: 1 addition & 1 deletion bcs-app/backend/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
include("backend.templatesets.open_apis.template_urls"),
),
# 提供给iam拉取资源实例的url(已注册到iam后台)
url(r"^iam/", include("backend.bcs_web.iam.open_apis.urls")),
url(r"^iam/", include("backend.iam.open_apis.urls")),
# web_console API
url(
r"^projects/(?P<project_id_or_code>[\w\-]+)/clusters/(?P<cluster_id>[\w\-]+)/web_console/sessions/",
Expand Down
1 change: 0 additions & 1 deletion bcs-app/backend/bcs_web/iam/bcs_iam_migration/__init__.py

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion bcs-app/backend/bcs_web/iam/open_apis/__init__.py

This file was deleted.

This file was deleted.

49 changes: 0 additions & 49 deletions bcs-app/backend/bcs_web/iam/open_apis/resources/project.py

This file was deleted.

64 changes: 0 additions & 64 deletions bcs-app/backend/bcs_web/iam/open_apis/resources/provider.py

This file was deleted.

1 change: 0 additions & 1 deletion bcs-app/backend/bcs_web/iam/open_apis/v1/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion bcs-app/backend/bcs_web/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

from backend.accounts import bcs_perm
from backend.bcs_web.audit_log.audit.context import AuditContext
from backend.bcs_web.iam import permissions
from backend.components.base import ComponentAuth
from backend.components.paas_cc import PaaSCCClient
from backend.container_service.clusters.base.models import CtxCluster
from backend.container_service.projects.base.models import CtxProject
from backend.iam import legacy_perms as permissions
from backend.utils import FancyDict
from backend.utils.cache import region

Expand Down
2 changes: 1 addition & 1 deletion bcs-app/backend/components/paas_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""
import logging

from backend.bcs_web.iam import permissions
from backend.iam import legacy_perms as permissions

from .ssm import get_client_access_token

Expand Down
9 changes: 8 additions & 1 deletion bcs-app/backend/components/paas_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from backend.bcs_web.iam import permissions
from backend.components.base import BaseHttpClient, BkApiClient, ComponentAuth, response_handler
from backend.components.utils import http_delete, http_get, http_patch, http_post, http_put
from backend.container_service.clusters.models import CommonStatus
from backend.iam import legacy_perms as permissions
from backend.utils.basic import getitems
from backend.utils.decorators import parse_response_data
from backend.utils.errcodes import ErrorCode
Expand Down Expand Up @@ -523,6 +523,7 @@ def __init__(self, host: str):

# PaaSCC 系统接口地址
self.get_cluster_url = f"{host}/projects/{{project_id}}/clusters/{{cluster_id}}"
self.get_cluster_by_id_url = f"{host}/clusters/{{cluster_id}}/"
self.get_project_url = f"{host}/projects/{{project_id}}/"
self.update_cluster_url = f"{host}/projects/{{project_id}}/clusters/{{cluster_id}}/"
self.delete_cluster_url = f"{host}/projects/{{project_id}}/clusters/{{cluster_id}}/"
Expand Down Expand Up @@ -552,6 +553,12 @@ def get_cluster(self, project_id: str, cluster_id: str) -> Dict:
url = self._config.get_cluster_url.format(project_id=project_id, cluster_id=cluster_id)
return self._client.request_json('GET', url)

@response_handler()
def get_cluster_by_id(self, cluster_id: str) -> Dict:
"""根据集群ID获取集群信息"""
url = self._config.get_cluster_by_id_url.format(cluster_id=cluster_id)
return self._client.request_json('GET', url)

@parse_response_data()
def get_project(self, project_id: str) -> Dict:
"""获取项目信息"""
Expand Down
2 changes: 1 addition & 1 deletion bcs-app/backend/container_service/projects/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def query_projects(access_token, query_params=None):
return paas_cc.get_projects(access_token, query_params)


def filter_projects(access_token, query_params=None):
def list_projects(access_token, query_params=None):
data = query_projects(access_token, query_params)
projects = data.get("results") or []
# 为了兼容导航的参数要求, 增加了project_code字段
Expand Down
4 changes: 2 additions & 2 deletions bcs-app/backend/container_service/projects/open_apis/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from backend.bcs_web.apis.authentication import JWTAuthentication
from backend.bcs_web.apis.permissions import AccessTokenPermission
from backend.container_service.projects.base import filter_projects
from backend.container_service.projects.base import list_projects
from backend.container_service.projects.views import NavProjectPermissionViewSet
from backend.utils.renderers import BKAPIRenderer

Expand All @@ -27,5 +27,5 @@ class ProjectsViewSet(NavProjectPermissionViewSet):
permission_classes = (AccessTokenPermission,)

def list_projects(self, request):
projects = filter_projects(request.user.token.access_token)
projects = list_projects(request.user.token.access_token)
return Response(projects)
2 changes: 1 addition & 1 deletion bcs-app/backend/container_service/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"""
from rest_framework import serializers

from backend.bcs_web.iam.permissions import ProjectActions
from backend.container_service.projects.base.constants import ProjectKindID
from backend.iam.legacy_perms import ProjectActions


class UpdateProjectNewSLZ(serializers.Serializer):
Expand Down
8 changes: 4 additions & 4 deletions bcs-app/backend/container_service/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

from backend.bcs_web.audit_log import client
from backend.bcs_web.constants import bcs_project_cache_key
from backend.bcs_web.iam.permissions import ProjectPermission
from backend.bcs_web.viewsets import SystemViewSet
from backend.components import cc, paas_cc
from backend.container_service.projects import base as Project
from backend.container_service.projects.utils import fetch_has_maintain_perm_apps, update_bcs_service_for_project
from backend.iam.legacy_perms import ProjectPermission
from backend.utils.basic import normalize_datetime
from backend.utils.cache import region
from backend.utils.errcodes import ErrorCode
Expand Down Expand Up @@ -229,11 +229,11 @@ def filter_projects(self, request):
access_token = request.user.token.access_token

if project_code:
projects = Project.filter_projects(access_token, {"english_names": project_code})
projects = Project.list_projects(access_token, {"english_names": project_code})
elif project_name:
projects = Project.filter_projects(access_token, {"project_names": project_name})
projects = Project.list_projects(access_token, {"project_names": project_name})
else:
projects = Project.filter_projects(access_token)
projects = Project.list_projects(access_token)

if not projects:
return Response(projects)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@
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 ..views import ResourceAPIView


class ProjectAPIView(ResourceAPIView):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@
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 django.conf.urls import url

from . import views

urlpatterns = [url(r"^projects/", views.ProjectAPIView.as_view())]
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@


class BcsIamMigrationConfig(AppConfig):
name = "backend.bcs_web.iam.bcs_iam_migration"
name = "backend.iam.bcs_iam_migration"
label = "bcs_iam_migration"
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ class Migration(migrations.Migration):

dependencies = []

operations = [
migrations.RunPython(forward_func)
]
operations = [migrations.RunPython(forward_func)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://opensource.org/licenses/MIT

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 codecs
import json
import os

from django.conf import settings
from django.db import migrations
from iam.contrib.iam_migration.migrator import IAMMigrator


def forward_func(apps, schema_editor):

migrator = IAMMigrator(Migration.migration_json)
migrator.migrate()


class Migration(migrations.Migration):
migration_json = "0002_project_extra.json"

dependencies = [('bcs_iam_migration', '0001_initial')]

operations = [migrations.RunPython(forward_func)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://opensource.org/licenses/MIT

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 codecs
import json
import os

from django.conf import settings
from django.db import migrations
from iam.contrib.iam_migration.migrator import IAMMigrator


def forward_func(apps, schema_editor):

migrator = IAMMigrator(Migration.migration_json)
migrator.migrate()


class Migration(migrations.Migration):
migration_json = "0003_cluster.json"

dependencies = [('bcs_iam_migration', '0002_bk_bcs_app_202108181450')]

operations = [migrations.RunPython(forward_func)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://opensource.org/licenses/MIT

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 codecs
import json
import os

from django.conf import settings
from django.db import migrations
from iam.contrib.iam_migration.migrator import IAMMigrator


def forward_func(apps, schema_editor):

migrator = IAMMigrator(Migration.migration_json)
migrator.migrate()


class Migration(migrations.Migration):
migration_json = "0004_namespace.json"

dependencies = [('bcs_iam_migration', '0003_bk_bcs_app_202108181523')]

operations = [migrations.RunPython(forward_func)]
Loading