Skip to content

Commit

Permalink
Merge pull request #446 from zhuyuanmao/clean-code
Browse files Browse the repository at this point in the history
Clean api-engine and agent code
  • Loading branch information
yeasy authored May 19, 2022
2 parents 0e57291 + c4102fe commit cac0001
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 98 deletions.
20 changes: 1 addition & 19 deletions src/agent/docker-rest-agent/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
aniso8601==8.0.0
certifi==2020.6.20
chardet==3.0.4
click==7.1.2
docker==4.3.1
Flask==1.1.2
Flask-RESTful==0.3.8
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
pytz==2020.1
requests==2.24.0
six==1.15.0
urllib3==1.25.11
websocket-client==0.57.0
Werkzeug==1.0.1
gevent==20.9.0
greenlet==0.4.17
gunicorn==20.0.4
zope.event==4.5.0
zope.interface==5.1.2
gevent==1.4
2 changes: 1 addition & 1 deletion src/api-engine/api/lib/agent/docker/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
#
import logging
from requests import put, get, post
from requests import get, post
import json

from api.lib.agent.base import AgentBase
Expand Down
1 change: 0 additions & 1 deletion src/api-engine/api/lib/agent/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
#
import logging
import os

from django.conf import settings

Expand Down
1 change: 0 additions & 1 deletion src/api-engine/api/lib/agent/kubernetes/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os

from django.conf import settings
from kubernetes import client, config
Expand Down
11 changes: 3 additions & 8 deletions src/api-engine/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import shutil
import tarfile
from zipfile import ZipFile
from pathlib import Path

from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.contrib.postgres.fields import JSONField
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
Expand All @@ -19,7 +17,6 @@

from api.common.enums import (
HostStatus,
LogLevel,
HostType,
K8SCredentialType,
separate_upper_class,
Expand Down Expand Up @@ -262,7 +259,7 @@ class KubernetesConfig(models.Model):
max_length=256,
blank=True,
)
parameters = JSONField(
parameters = models.JSONField(
help_text="Extra parameters for kubernetes",
default=dict,
null=True,
Expand Down Expand Up @@ -379,7 +376,7 @@ class FabricCA(models.Model):
default="adminpw",
max_length=32,
)
hosts = JSONField(
hosts = models.JSONField(
help_text="Hosts for ca", null=True, blank=True, default=list
)
type = models.CharField(
Expand Down Expand Up @@ -486,7 +483,7 @@ class Node(models.Model):
% (FabricNodeType.names()),
max_length=64,
)
urls = JSONField(
urls = models.JSONField(
help_text="URL configurations for node",
null=True,
blank=True,
Expand Down Expand Up @@ -739,7 +736,6 @@ class Channel(models.Model):
organizations = models.ManyToManyField(
to="Organization",
help_text="the organization of the channel",
null=True,
related_name="channels",
# on_delete=models.SET_NULL
)
Expand All @@ -752,7 +748,6 @@ class Channel(models.Model):
orderers = models.ManyToManyField(
to="Node",
help_text="Orderer list in the channel",
null=True,
)

# class ChainCode(models.Model):
Expand Down
3 changes: 0 additions & 3 deletions src/api-engine/api/routes/agent/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import logging

from django.core.validators import (
URLValidator,
RegexValidator,
FileExtensionValidator,
)
from rest_framework import serializers

from api.common.enums import (
NetworkStatus,
LogLevel,
HostType,
K8SCredentialType,
separate_upper_class,
)
Expand Down
3 changes: 3 additions & 0 deletions src/api-engine/api/routes/chaincode/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#
# SPDX-License-Identifier: Apache-2.0
#
from rest_framework import serializers
from api.config import FABRIC_CHAINCODE_STORE

Expand Down
3 changes: 3 additions & 0 deletions src/api-engine/api/routes/chaincode/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import zipfile

from drf_yasg.utils import swagger_auto_schema
#
# SPDX-License-Identifier: Apache-2.0
#
from api.config import FABRIC_CHAINCODE_STORE
from api.config import CELLO_HOME
from api.models import (
Expand Down
6 changes: 4 additions & 2 deletions src/api-engine/api/routes/channel/serializers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#
# SPDX-License-Identifier: Apache-2.0
#
from rest_framework import serializers

from api.models import Channel, Organization
from api.models import Channel
from api.common.serializers import ListResponseSerializer


class ChannelCreateBody(serializers.Serializer):
#organization = serializers.UUIDField(help_text="ID of Organization")
name = serializers.CharField(max_length=128, required=True)
peers = serializers.ListField(
child=serializers.UUIDField(help_text="ID of Peer Nodes")
Expand Down
5 changes: 3 additions & 2 deletions src/api-engine/api/routes/channel/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#
# SPDX-License-Identifier: Apache-2.0
#
from rest_framework import viewsets, status
from rest_framework.response import Response
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
Expand All @@ -13,14 +16,12 @@
from api.auth import TokenAuth
from api.lib.configtxgen import ConfigTX, ConfigTxGen
from api.lib.peer.channel import Channel as PeerChannel
from api.lib.configtxlator.configtxlator import ConfigTxLator
from api.exceptions import (
ResourceNotFound,
)
from api.models import (
Channel,
Node,
Port
)
from api.routes.channel.serializers import (
ChannelCreateBody,
Expand Down
2 changes: 0 additions & 2 deletions src/api-engine/api/routes/general/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#
# SPDX-License-Identifier: Apache-2.0
#
from abc import ABC

from rest_framework import serializers


Expand Down
5 changes: 2 additions & 3 deletions src/api-engine/api/routes/general/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
from api.models import UserProfile, Organization
from api.routes.general.serializers import (
RegisterBody,
RegisterIDSerializer,
RegisterResponse,
LoginBody,

)
from api.lib.pki import CryptoGen, CryptoConfig
from api.utils import zip_dir, zip_file
from api.utils import zip_dir
from api.common import ok, err
from api.config import CELLO_HOME
from api.utils.jwt import jwt_response_payload_handler
Expand Down
1 change: 0 additions & 1 deletion src/api-engine/api/routes/network/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
NetworkOperation,
ChannelType,
FabricNodeType,
NetworkCreateType,
)
from api.models import Network

Expand Down
7 changes: 1 addition & 6 deletions src/api-engine/api/routes/network/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@
from api.routes.network.serializers import (
NetworkQuery,
NetworkListResponse,
NetworkOperationBody,
ChannelBody,
ChannelID,
ChannelCreateBody,
NetworkMemberResponse,
NetworkCreateBody,
NetworkIDSerializer,
)
from api.utils.common import with_common_response
from api.common.enums import NodeStatus
from api.lib.configtxgen import ConfigTX, ConfigTxGen
from api.models import Network, Node, Port
from api.config import CELLO_HOME
from api.utils import zip_dir, zip_file
from api.utils import zip_file
from api.auth import TokenAuth
from api.lib.agent import AgentHandler
from api.common import ok, err
Expand Down
7 changes: 0 additions & 7 deletions src/api-engine/api/routes/node/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@
#
import logging

from django.core.validators import FileExtensionValidator
from rest_framework import serializers
from api.common.enums import (
Operation,
NetworkType,
FabricNodeType,
FabricVersions,
HostType,
)
from api.common.serializers import PageQuerySerializer
from api.models import (
Node,
Port,
FabricCA,
validate_file,
NodeUser,
FabricPeer,
PeerCa,
PeerCaUser,
)
from api.utils.common import to_form_paras

LOG = logging.getLogger(__name__)

Expand Down
13 changes: 2 additions & 11 deletions src/api-engine/api/routes/node/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,20 @@
import threading

from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import PermissionDenied
from django.core.paginator import Paginator
from django.db.models import Count, F
from django.urls import reverse
from drf_yasg.utils import swagger_auto_schema
from rest_framework import viewsets, status
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework_jwt.authentication import JSONWebTokenAuthentication

from api.auth import IsOperatorAuthenticated
from api.common.enums import NodeStatus, AgentOperation, Operation
from api.common.enums import AgentOperation
from api.exceptions import CustomError, NoResource, ResourceExists, ResourceInUse
from api.exceptions import ResourceNotFound
from api.models import (
Agent,
Node,
Organization,
Port,
FabricCA,
FabricNodeType,
FabricCAServerType,
NodeUser,
FabricPeer,
Expand All @@ -41,7 +33,6 @@
NodeQuery,
NodeCreateBody,
NodeIDSerializer,
NodeCIDSerializer,
NodeListSerializer,
NodeUpdateBody,
# NodeFileCreateSerializer,
Expand All @@ -54,7 +45,7 @@
)
from api.tasks import operate_node
from api.utils.common import with_common_response
from api.auth import CustomAuthenticate, TokenAuth
from api.auth import TokenAuth
from api.lib.pki import CryptoGen, CryptoConfig
from api.utils import zip_dir, zip_file
from api.config import (
Expand Down
20 changes: 5 additions & 15 deletions src/api-engine/api/routes/organization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,16 @@

from rest_framework import viewsets, status
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from drf_yasg.utils import swagger_auto_schema
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import Paginator
from rest_framework_jwt.authentication import JSONWebTokenAuthentication

from api.auth import IsOperatorAuthenticated
from api.utils.common import with_common_response
from api.exceptions import ResourceExists, ResourceNotFound, ResourceInUse
from api.models import (
Agent,
Node,
Organization,
Port,
FabricCA,
FabricNodeType,
FabricCAServerType,
NodeUser,
FabricPeer,
PeerCa,
PeerCaUser,
)
from api.routes.organization.serializers import (
OrganizationQuery,
Expand All @@ -40,15 +28,17 @@
OrganizationUpdateBody,
)
from api.routes.user.serializers import UserIDSerializer
from api.models import UserProfile, Organization, Network
from api.models import UserProfile, Organization
from api.routes.user.serializers import UserListSerializer, UserQuerySerializer
from api.lib.pki import CryptoGen, CryptoConfig
from api.utils import zip_dir, zip_file
from api.config import CELLO_HOME
from api.auth import TokenAuth
from api.utils.node_config import NodeConfig

from api.common import ok, err
from api.common import (
ok,
#err
)

LOG = logging.getLogger(__name__)

Expand Down
5 changes: 0 additions & 5 deletions src/api-engine/api/routes/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
from drf_yasg.utils import swagger_auto_schema
from rest_framework import viewsets, status
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework_jwt.authentication import JSONWebTokenAuthentication

from api.auth import IsAdminAuthenticated, IsOperatorAuthenticated
from api.exceptions import ResourceExists, CustomError
from api.models import UserProfile
from api.routes.user.serializers import (
Expand All @@ -22,9 +19,7 @@
UserQuerySerializer,
UserListSerializer,
)
from api.utils.common import any_of
from api.utils.common import with_common_response
from api.auth import TokenAuth

LOG = logging.getLogger(__name__)

Expand Down
Loading

0 comments on commit cac0001

Please sign in to comment.