Skip to content

Commit

Permalink
[ISSUE-533]Fix demo admin user creation (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuyuanmao authored Aug 29, 2023
1 parent 03caad3 commit 790cbcb
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,4 @@ src/dashboard/lambda/mock/index.js
.config.old

# Cello local storage
/opt/cello
/**/opt/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ If environment is prepared, then we can start cello service.
* Set local storage environment variable, e.g. Use current path as storage path

```bash
$ export CELLO_PATH=$(pwd)/opt/cello
$ export CELLO_STORAGE_PATH=$(pwd)/cello
```


Expand Down
7 changes: 4 additions & 3 deletions bootup/docker-compose-files/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
ports:
- "5432:5432"
volumes:
- /opt/cello/pgdata:/var/lib/postgresql/data
- ${CELLO_STORAGE_PATH:-/opt/cello}/pgdata:/var/lib/postgresql/data
networks:
- cello-net

Expand All @@ -54,10 +54,11 @@ services:
- DEBUG=True
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- FABRIC_LOGGING_SPEC=INFO
- [email protected]
ports:
- "8080:8080"
volumes:
- /opt/cello:/opt/cello
- ${CELLO_STORAGE_PATH:-/opt/cello}:/opt/cello
networks:
- cello-net

Expand All @@ -74,7 +75,7 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- DOCKER_URL=unix://var/run/docker.sock
- STORAGE_PATH=/opt/hyperledger
- STORAGE_PATH=${CELLO_STORAGE_PATH:-/opt/cello}/hyperledger
networks:
- cello-net

Expand Down
8 changes: 4 additions & 4 deletions build_image/docker/common/api-engine/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ holdup -t 120 tcp://${DB_HOST}:${DB_PORT};
if [[ "$RUN_MODE" == "server" ]]; then
python manage.py makemigrations && python manage.py migrate;
python manage.py create_user \
--username ${ADMIN_USERNAME:-admin} \
--password ${ADMIN_PASSWORD:-pass} \
--email ${ADMIN_EMAIL:-admin@cello} \
--username ${API_ENGINE_ADMIN_USERNAME:-admin} \
--password ${API_ENGINE_ADMIN_PASSWORD:-pass} \
--email ${API_ENGINE_ADMIN_EMAIL:-admin@cello.com} \
--is_superuser \
--role operator
--role admin
if [[ "$DEBUG" == "True" ]]; then # For dev, use pure Django directly
python manage.py runserver 0.0.0.0:8080;
else # For production, use uwsgi in front
Expand Down
8 changes: 4 additions & 4 deletions build_image/dockerhub/latest/common/api-engine/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ holdup -t 120 tcp://${DB_HOST}:${DB_PORT};
if [[ "$RUN_MODE" == "server" ]]; then
python manage.py makemigrations && python manage.py migrate;
python manage.py create_user \
--username ${ADMIN_USERNAME:-admin} \
--password ${ADMIN_PASSWORD:-pass} \
--email ${ADMIN_EMAIL:-admin@cello} \
--username ${API_ENGINE_ADMIN_USERNAME:-admin} \
--password ${API_ENGINE_ADMIN_PASSWORD:-pass} \
--email ${API_ENGINE_ADMIN_EMAIL:-admin@cello.com} \
--is_superuser \
--role operator
--role admin
if [[ "$DEBUG" == "True" ]]; then # For dev, use pure Django directly
python manage.py runserver 0.0.0.0:8080;
else # For production, use uwsgi in front
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/configuration/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ all related configuration variable is written in ==.makerc/api-engine==.

**default**: `[email protected]`

**description**: {>>Default operator email of api engine, who have the maximum rights.<<}
**description**: {>>Default admin email of api engine, who have the maximum rights.<<}

**usage**:
```bash
Expand Down
56 changes: 29 additions & 27 deletions src/api-engine/api/lib/peer/chaincode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import os
import json
import subprocess
from api.lib.peer.basicEnv import BasicEnv
from api.lib.peer.command import Command
from api.config import FABRIC_TOOL, FABRIC_CFG


class ChainCode(BasicEnv):
class ChainCode(Command):
def __init__(self, version="2.2.0", peer=FABRIC_TOOL, **kwargs):
self.peer = peer + "/peer"
super(ChainCode, self).__init__(version, **kwargs)
Expand Down Expand Up @@ -39,7 +39,8 @@ def lifecycle_install(self, cc_targz):
:return: 0 means success.
"""
try:
res = os.system("{} lifecycle chaincode install {}".format(self.peer, cc_targz))
res = os.system(
"{} lifecycle chaincode install {}".format(self.peer, cc_targz))
res = res >> 8
except Exception as e:
err_msg = "install chaincode failed for {}!".format(e)
Expand Down Expand Up @@ -158,7 +159,8 @@ def lifecycle_query_approved(self, channel_name, cc_name):

try:
res = subprocess.Popen("{} lifecycle chaincode queryapproved --output json --channelID {}"
" --name {}".format(self.peer, channel_name, cc_name),
" --name {}".format(self.peer,
channel_name, cc_name),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = res.communicate()
return_code = res.returncode
Expand Down Expand Up @@ -220,7 +222,8 @@ def lifecycle_check_commit_readiness(self, orderer_url, orderer_tls_rootcert, ch
stderr = str(stderr, encoding="utf-8")
return return_code, stderr
except Exception as e:
err_msg = "lifecycle_check_commit_readiness failed for {}!".format(e)
err_msg = "lifecycle_check_commit_readiness failed for {}!".format(
e)
raise Exception(err_msg)

def lifecycle_commit(self, orderer_url, orderer_tls_rootcert, channel_name, cc_name, chaincode_version,
Expand Down Expand Up @@ -279,7 +282,8 @@ def lifecycle_query_committed(self, channel_name, cc_name):
"""
try:
res = subprocess.Popen("{} lifecycle chaincode querycommitted --channelID {} "
"--output json --name {}".format(self.peer, channel_name, cc_name),
"--output json --name {}".format(
self.peer, channel_name, cc_name),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = res.communicate()
return_code = res.returncode
Expand Down Expand Up @@ -315,28 +319,26 @@ def invoke(self, orderer_url, orderer_tls_rootcert, channel_name, cc_name, args,
invoke_command_tls = "{} chaincode invoke -o {} --tls --cafile {} --channelID {} --name {} -c '{}'"

if os.getenv("CORE_PEER_TLS_ENABLED") == "false" or os.getenv("CORE_PEER_TLS_ENABLED") is None:
if self.version in BasicEnv.binary_versions_v2:
res = subprocess.Popen(invoke_command.format(self.peer, orderer_url, channel_name, cc_name, args),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = res.communicate()
return_code = res.returncode
if return_code == 0:
return return_code, ''
else:
stderr = str(stderr, encoding="utf-8")
return return_code, stderr
res = subprocess.Popen(invoke_command.format(self.peer, orderer_url, channel_name, cc_name, args),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
_, stderr = res.communicate()
return_code = res.returncode
if return_code == 0:
return return_code, ''
else:
stderr = str(stderr, encoding="utf-8")
return return_code, stderr
else:
if self.version in BasicEnv.binary_versions_v2:
res = subprocess.Popen(invoke_command_tls.format(self.peer, orderer_url, orderer_tls_rootcert,
channel_name, cc_name, args),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = res.communicate()
return_code = res.returncode
if return_code == 0:
return return_code, ''
else:
stderr = str(stderr, encoding="utf-8")
return return_code, stderr
res = subprocess.Popen(invoke_command_tls.format(self.peer, orderer_url, orderer_tls_rootcert,
channel_name, cc_name, args),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
_, stderr = res.communicate()
return_code = res.returncode
if return_code == 0:
return return_code, ''
else:
stderr = str(stderr, encoding="utf-8")
return return_code, stderr
except Exception as e:
err_msg = "invoke failed for {}!".format(e)
raise Exception(err_msg)
Expand Down
6 changes: 3 additions & 3 deletions src/api-engine/api/lib/peer/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import os
import json
import subprocess
from api.lib.peer.basicEnv import BasicEnv
from api.lib.peer.command import Command
from api.config import FABRIC_TOOL


class Channel(BasicEnv):
class Channel(Command):
"""Call CMD to perform channel create, join and other related operations"""

def __init__(self, version="2.2.0", peer=FABRIC_TOOL, **kwargs):
Expand Down 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from api.config import FABRIC_CFG


class BasicEnv:
# Command class reads local environment variables by given their names
class Command:
def __init__(self, version, **kwargs):
self.version = version
# Setting environment variables according to user input. Recommended main settings: CORE_PEER_LOCALMSPID、
Expand Down

0 comments on commit 790cbcb

Please sign in to comment.