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
Signed-off-by: Wu Zhende wuzhende666@163.com --- src/lib/job.cr | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 4bef329..05c5462 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,10 @@ class Job return if @hash["id"] == "#{id}" end
+ @es = Elasticsearch::Client.new @hash["id"] = JSON::Any.new("#{id}") check_required_keys() + check_account_info() set_defaults() end
@@ -271,6 +274,9 @@ class Job id suite testbox + my_email + my_uuid + my_name ]
private def check_required_keys @@ -281,6 +287,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"]) + + 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 +319,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 +460,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"
On Sat, Nov 21, 2020 at 06:22:08PM +0800, Wu Zhende wrote:
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
Signed-off-by: Wu Zhende wuzhende666@163.com
src/lib/job.cr | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 4bef329..05c5462 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,10 @@ class Job return if @hash["id"] == "#{id}" end
- @es = Elasticsearch::Client.new @hash["id"] = JSON::Any.new("#{id}") check_required_keys()
- check_account_info() set_defaults() end
@@ -271,6 +274,9 @@ class Job id suite testbox
my_email
my_uuid
my_name ]
private def check_required_keys
@@ -281,6 +287,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"])
- 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"]
it seems that account_info["my_name"] and account_info["my_uuid"] are same data type, both add .to_s, or both cancel it
Thanks, Luan Shengde
- @hash.delete("my_uuid")
- end
- private def initialized? initialized_keys = [] of String
@@ -302,6 +319,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 +460,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