On Tue, Nov 24, 2020 at 10:17:36AM +0800, Wu Zhende wrote:
[Why] When a job submit, check it's account info. Must key:my_email, my_name, my_uuid Check whether the information is the same as that stored in the ES database Also need update pub_key.
[Why comment code] Because now many people don't have an account. If the verification is mandatory, many users can't use the service. Therefore, use a gentle approach to promote accounts first.
Signed-off-by: Wu Zhende wuzhende666@163.com
src/lib/job.cr | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 4bef329..cfd52d7 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -9,6 +9,7 @@ require "scheduler/constants.cr" require "scheduler/jobfile_operate.cr" require "scheduler/kernel_params.cr" require "scheduler/pp_params.cr" +require "../scheduler/elasticsearch_client"
struct JSON::Any def []=(key : String, value : String) @@ -58,8 +59,11 @@ class Job return if @hash["id"] == "#{id}" end
- @es = Elasticsearch::Client.new @hash["id"] = JSON::Any.new("#{id}")
- @account_info = Hash(String, JSON::Any).new check_required_keys()
- check_account_info() set_defaults() end
@@ -152,7 +156,7 @@ class Job set_kernel_append_root() set_kernel_params() set_lkp_server()
- set_sshr_port()
- set_sshr_info() set_queue() end
@@ -183,12 +187,35 @@ class Job end end
- private def set_sshr_port
private def set_sshr_info return unless self["sshd"]?
self["sshr_port"] = ENV["SSHR_PORT"] self["sshr_port_base"] = ENV["SSHR_PORT_BASE"] self["sshr_port_len"] = ENV["SSHR_PORT_LEN"]
return if @account_info["found"]? == false
sshd = update_my_pub_key
@hash["sshd"] = JSON.parse(sshd.to_json)
end
private def update_my_pub_key
You set sshd pub_key by account_info["my_ssh_pubkey"] and return sshd, update_sshd_pub_key will be more clear?
Thanks, Xueliang
sshd = @hash["sshd"].as_h? || Hash(String, JSON::Any).new()
pub_key = sshd["pub_key"]?.to_s
my_ssh_pubkey = @account_info["my_ssh_pubkey"].as_a
if pub_key.empty? || my_ssh_pubkey.includes?(pub_key)
sshd["pub_key"] = @account_info["my_ssh_pubkey"]
return sshd
end
my_ssh_pubkey << JSON::Any.new(pub_key)
@account_info["my_ssh_pubkey"] = JSON.parse(my_ssh_pubkey.to_json)
@es.update_account(JSON.parse(@account_info.to_json), self["my_email"].to_s)
sshd["pub_key"] = @account_info["my_ssh_pubkey"]
return sshd end
private def set_os_dir
@@ -281,6 +308,17 @@ class Job end end
- private def check_account_info
- # error_msg = "Failed to verify the account. Please check your configuration"
- @account_info = @es.get_account(self["my_email"]).as_h
- # raise error_msg if @account_info["found"]? == false
- # raise error_msg unless self["my_name"] == @account_info["my_name"].to_s
- # raise error_msg unless self["my_uuid"] == @account_info["my_uuid"]
- @hash.delete("my_uuid")
- end
- private def initialized? initialized_keys = [] of String
@@ -302,6 +340,8 @@ class Job "SCHED_HOST", "SCHED_PORT"]
- initialized_keys -= ["my_uuid"]
- initialized_keys.each do |key| return false unless @hash.has_key?(key) end
@@ -441,7 +481,7 @@ class Job else program_version = "latest" end
deps_dest_file = "#{SRV_INITRD}/deps/#{mount_type}/#{os_dir}/#{program}/#{program}.cgz" pkg_dest_file = "#{SRV_INITRD}/pkg/#{mount_type}/#{os_dir}/#{program}/#{program_version}.cgz"
-- 2.23.0