diff options
| author | ruki <[email protected]> | 2022-05-01 13:45:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-01 13:45:18 +0800 |
| commit | 91d3f55bf5400ecf07c094c5fa3f05e910c5f51c (patch) | |
| tree | 055ff77c9c974b4cd721fe0e32c764145ee1e0f4 /xmake/modules/private/service/remote_build/client.lua | |
| parent | 2d3313ba1a2aa40350be90d52082f2e0f2cfedb4 (diff) | |
add token mode
Diffstat (limited to 'xmake/modules/private/service/remote_build/client.lua')
| -rw-r--r-- | xmake/modules/private/service/remote_build/client.lua | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index a53e265df..f5672d2a4 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -79,8 +79,8 @@ function remote_build_client:connect() end -- we need user authorization? - local auth - if self:user() then + local token = config.get("remote_build.client.token") + if not token and self:user() then -- get user password cprint("Please input user ${bright}%s${clear} password:", self:user()) @@ -89,8 +89,8 @@ function remote_build_client:connect() assert(pass ~= "", "password is empty!") -- compute user authorization - auth = base64.encode(self:user() .. ":" .. pass) - auth = hash.md5(bytes(auth)) + token = base64.encode(self:user() .. ":" .. pass) + token = hash.md5(bytes(token)) end -- do connect @@ -103,7 +103,7 @@ function remote_build_client:connect() print("%s: connect %s:%d ..", self, addr, port) if sock then local stream = socket_stream(sock) - if stream:send_msg(message.new_connect(session_id, {auth = auth})) and stream:flush() then + if stream:send_msg(message.new_connect(session_id, {token = token})) and stream:flush() then local msg = stream:recv_msg() if msg then vprint(msg:body()) @@ -125,7 +125,7 @@ function remote_build_client:connect() local status = self:status() status.addr = addr status.port = port - status.auth = auth + status.token = token status.connected = ok status.session_id = session_id self:status_save() @@ -151,7 +151,7 @@ function remote_build_client:disconnect() print("%s: disconnect %s:%d ..", self, addr, port) if sock then local stream = socket_stream(sock) - if stream:send_msg(message.new_disconnect(session_id, {auth = self:auth()})) and stream:flush() then + if stream:send_msg(message.new_disconnect(session_id, {token = self:token()})) and stream:flush() then local msg = stream:recv_msg() if msg then vprint(msg:body()) @@ -175,7 +175,7 @@ function remote_build_client:disconnect() -- update status local status = self:status() - status.auth = nil + status.token = nil status.connected = not ok self:status_save() end @@ -215,7 +215,7 @@ function remote_build_client:sync() -- do sync cprint("Uploading files with ${bright}%d${clear} bytes ..", os.filesize(archive_diff_file)) local send_ok = false - if stream:send_msg(message.new_sync(session_id, diff_files, {auth = self:auth()})) and stream:flush() then + if stream:send_msg(message.new_sync(session_id, diff_files, {token = self:token()})) and stream:flush() then if stream:send_file(archive_diff_file) and stream:flush() then send_ok = true end @@ -256,7 +256,7 @@ function remote_build_client:clean() local ok = false print("%s: clean files in %s:%d ..", self, addr, port) local stream = socket_stream(sock) - if stream:send_msg(message.new_clean(session_id, {auth = self:auth()})) and stream:flush() then + if stream:send_msg(message.new_clean(session_id, {token = self:token()})) and stream:flush() then local msg = stream:recv_msg() if msg then vprint(msg:body()) @@ -288,7 +288,7 @@ function remote_build_client:runcmd(program, argv) local leftstr = "" cprint("%s: run ${bright}%s${clear} in %s:%d ..", self, command, addr, port) local stream = socket_stream(sock) - if stream:send_msg(message.new_runcmd(session_id, program, argv, {auth = self:auth()})) and stream:flush() then + if stream:send_msg(message.new_runcmd(session_id, program, argv, {token = self:token()})) and stream:flush() then local stdin_opt = {stop = false} scheduler.co_start(self._read_stdin, self, stream, stdin_opt) while true do @@ -371,9 +371,9 @@ function remote_build_client:workdir() return self._WORKDIR end --- get user auth -function remote_build_client:auth() - return self:status().auth +-- get user token +function remote_build_client:token() + return self:status().token end -- get the session id, only for unique project @@ -396,7 +396,7 @@ function remote_build_client:_diff_files(stream) local count = 0 local result, errors cprint("Comparing ${bright}%d${clear} files ..", filecount) - if stream:send_msg(message.new_diff(session_id, manifest, {auth = self:auth()})) and stream:flush() then + if stream:send_msg(message.new_diff(session_id, manifest, {token = self:token()})) and stream:flush() then local msg = stream:recv_msg() if msg and msg:success() then result = msg:body().manifest @@ -460,7 +460,7 @@ function remote_build_client:_read_stdin(stream, opt) if line and #line > 0 then local ok = false local data = bytes(line) - if stream:send_msg(message.new_data(0, data:size(), {auth = self:auth()})) then + if stream:send_msg(message.new_data(0, data:size(), {token = self:token()})) then if stream:send(data) and stream:flush() then ok = true end |
