Skip to content

Commit

Permalink
Fix a gh-action issue in hyperledger-cello#472
Browse files Browse the repository at this point in the history
In hyperledger-cello#472, the tox github action plugin was not configued correctly.

That results some missing code format problems in the following
PRs.

This PR adds the correct configuration to tox.ini file and fixs
the missed code format problems.

Signed-off-by: Xichen Pan <xichen.pan@gmail.com>
  • Loading branch information
xichen1 committed Sep 9, 2022
1 parent 0ed95e2 commit 8a3bbb9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.7'
python-version: '3.5'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
python -m pip install tox tox-gh-actions
- name: Check code
run: make check
14 changes: 7 additions & 7 deletions src/api-engine/api/lib/configtxlator/configtxlator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def proto_encode(self, input, type, output):
output: A file to write the output to.
"""
try:
res = call([self.configtxlator,
call([self.configtxlator,
"proto_encode",
"--input={}".format(input),
"--type={}".format(type),
"--output={}".format(output),
])
])
except Exception as e:
err_msg = "configtxlator proto decode fail! "
raise Exception(err_msg + str(e))
Expand All @@ -45,11 +45,11 @@ def proto_decode(self, input, type):
"""
try:
res = run([self.configtxlator,
"proto_decode",
"--type={}".format(type),
"--input={}".format(input),
],
capture_output= True)
"proto_decode",
"--type={}".format(type),
"--input={}".format(input),
],
capture_output=True)
if res.returncode == 0 :
return res.stdout
else:
Expand Down
2 changes: 1 addition & 1 deletion src/api-engine/api/lib/peer/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def fetch(self, option, channel):
"{}".format(option),
"-c",
channel
])
])
except Exception as e:
err_msg = "fetch a specified block failed {}!".format(e)
raise Exception(err_msg)
Expand Down
2 changes: 1 addition & 1 deletion src/api-engine/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ class Channel(models.Model):
)

def get_channel_config_path(self):
return "/var/www/server/" + self.name +"_config.block"
return "/var/www/server/" + self.name + "_config.block"
# class ChainCode(models.Model):
# id = models.UUIDField(
# primary_key=True,
Expand Down
16 changes: 9 additions & 7 deletions src/api-engine/api/routes/channel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,35 +194,37 @@ def update(self, request, pk=None):
return Response(status=status.HTTP_202_ACCEPTED)
except ObjectDoesNotExist:
raise ResourceNotFound

@swagger_auto_schema(
responses=with_common_response({status.HTTP_200_OK: "Accepted"}),
)
@action(
methods=["get"],
methods=["get"],
detail=True,
url_path="config"
url_path="config"
)
def get_channel_org_config(self, request, pk=None):
try:
org = request.user.organization
channel = Channel.objects.get(id=pk)
path = channel.get_channel_config_path()
node = Node.objects.filter(
organization=org,
type=FabricNodeType.Peer.name.lower(),
organization=org,
type=FabricNodeType.Peer.name.lower(),
status=NodeStatus.Running.name.lower()
).first()
dir_node = "{}/{}/crypto-config/peerOrganizations".format(
CELLO_HOME, org.name)
CELLO_HOME, org.name)
env = {
"FABRIC_CFG_PATH": "{}/{}/peers/{}/".format(dir_node, org.name, node.name + "." + org.name),
}
peer_channel_cli = PeerChannel("v2.2.0", **env)
peer_channel_cli.fetch(option="config", channel=channel.name)
config = ConfigTxLator().proto_decode(input=path,type="common.Block")
config = ConfigTxLator().proto_decode(input=path, type="common.Block")
except ObjectDoesNotExist:
raise ResourceNotFound
return Response(data=to_dict(config, org.name.split(".")[0].capitalize()),status=status.HTTP_200_OK)
return Response(data=to_dict(config, org.name.split(".")[0].capitalize()), status=status.HTTP_200_OK)


def init_env_vars(node, org):
"""
Expand Down
2 changes: 2 additions & 0 deletions src/api-engine/api/routes/node/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class Meta:
"created_at": {"required": True, "read_only": False},
}


class NodeStatusSerializer(NodeIDSerializer, serializers.ModelSerializer):
class Meta:
model = Node
Expand Down Expand Up @@ -325,6 +326,7 @@ class NodeOperationSerializer(serializers.Serializer):
choices=Operation.to_choices(True),
)


class NodeConfigFileSerializer(serializers.ModelSerializer):
files = serializers.FileField()

Expand Down
9 changes: 5 additions & 4 deletions src/api-engine/api/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,21 @@ def zip_file(dirpath, outFullName):
zfile.write(dirpath, dirpath.rsplit("/", 1)[1])
zfile.close()


def to_dict(data, org_name):
"""
Parse org config from channel config block.
:param data: channel config block in json format.
:param org_name: the organization prefix name
:return organization config
"""
config = loads(data)
if config.get("data") != None:
if config.get("data") is not None:
payloads = config["data"]["data"]
for p in payloads:
groups = p["payload"]["data"]["config"]["channel_group"]["groups"]["Application"]["groups"]
res = groups.get(org_name, None)
if res != None:
res = groups.get(org_name, None)
if res is not None:
return res
return {"error": "can't find channel config"}
4 changes: 4 additions & 0 deletions src/api-engine/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ basepython = python3
skip_install = true
deps = flake8
commands = flake8 {toxinidir}

[gh-actions]
python =
3.5: py35, flake8

0 comments on commit 8a3bbb9

Please sign in to comment.