Skip to content
This repository was archived by the owner on Dec 14, 2025. It is now read-only.

Commit d905e73

Browse files
committed
1 parent 6baccaa commit d905e73

3 files changed

Lines changed: 49 additions & 13 deletions

File tree

Dockerfile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ FROM debian:12-slim
33
ENV PYTHONUNBUFFERED=1
44

55
RUN set -ex; \
6-
apt update; \
7-
apt install \
8-
--no-install-recommends \
9-
-y \
10-
seafile-cli \
11-
oathtool \
12-
ca-certificates \
13-
gnupg;
6+
apt update; \
7+
apt install \
8+
--no-install-recommends \
9+
-y \
10+
seafile-cli \
11+
oathtool \
12+
ca-certificates \
13+
gnupg; \
14+
apt-get clean; \
15+
rm -rf /var/lib/apt/lists/*
1416

1517
COPY --chmod=755 src/entrypoint.py /entrypoint.py
1618

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ Possible issues
6666

6767
try `docker exec -it seaf-cli /bin/bash` and make sure the command (e.q. `seaf-cli list-remote ...`) works
6868

69+
## Dev memo
70+
71+
```bash
72+
# test
73+
docker build -t seaf-cli . --no-cache
74+
75+
# run
76+
docker run --rm -it --net=host -v /root/seafile-client:/seafile-client seaf-cli
77+
78+
# debug
79+
docker run --rm -it --net=host -v /root/seafile-client:/seafile-client --entrypoint=/bin/bash seaf-cli
80+
# in container
81+
apt update
82+
apt install -y nano procps ntpdate
83+
nano /bin/seaf-cli
84+
/entrypoint.sh
85+
```
86+
6987
## TODO
7088

7189
- hard link log files to stdout: `ln -sf /proc/self/fd/1 /var/log/myapp.log`

src/entrypoint.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import time
1010
import traceback
1111
import types
12-
13-
import seafile
12+
import urllib.error
1413

1514
def load_as_module(path: str):
1615
module = types.ModuleType("dynamic_module")
@@ -127,7 +126,7 @@ def __run(self, cmd: list, **kwargs):
127126
logging.debug(f'run `{ subprocess.list2cmdline(cmd) }`')
128127
return subprocess.run(cmd, **kwargs)
129128

130-
def __run_tfa(self, totp_secret: str):
129+
def __run_tfa(self):
131130
cmd = ['oathtool', '--base32', '--totp', self.totp_secret]
132131
mask_cmd = self.__mask_cmd(cmd, ['--totp'])
133132
logging.debug(f'run `{ subprocess.list2cmdline(mask_cmd) }`')
@@ -178,10 +177,27 @@ def __get_rpc_client(self):
178177
def __get_cached_token(self):
179178
if self.__cached_token is None:
180179
seafcli.seafile_datadir = str(self.seafile_data_dir)
181-
tfa = self.__run_tfa(self.totp_secret)
182-
self.__cached_token = seafcli.get_token(self.server_url, self.username, self.password, tfa, seafcli.DEFAULT_CONF_DIR)
180+
tfa = self.__run_tfa()
181+
# https://github.com/haiwen/seahub/blob/master/seahub/api2/serializers.py#L137
182+
# https://github.com/haiwen/seahub/blob/master/seahub/two_factor/views/login.py#L212
183+
# if otp failed, could check log file: `/shared/logs/seahub.log`
184+
self.__cached_token = self.__debug_seafile_error(
185+
lambda: seafcli.get_token(self.server_url, self.username, self.password, tfa, seafcli.DEFAULT_CONF_DIR)
186+
)
183187
return self.__cached_token
184188

189+
def __debug_seafile_error(self, fn):
190+
try:
191+
return fn()
192+
except Exception as e:
193+
if isinstance(e, urllib.error.HTTPError):
194+
try:
195+
body = e.read().decode('utf-8')
196+
except Exception:
197+
body = None
198+
logging.error(f'HTTPError: {e.code} {body}')
199+
raise
200+
185201
def init(self):
186202
logging.info(f'Initializing...')
187203
if not self.seafile_ini.exists():

0 commit comments

Comments
 (0)