From 45d8f4cb1b57ab946e861c31f00bea16fe616303 Mon Sep 17 00:00:00 2001 From: Carlos Konstanski Date: Wed, 25 Oct 2017 15:03:17 -0600 Subject: Don't depend on pre-existing JARS in webdav Closes-Bug: IS-23 --- bootstrap/http_client.rb | 90 ---------------------------------------------- bootstrap/pillar_config.rb | 51 ++++++++++---------------- 2 files changed, 19 insertions(+), 122 deletions(-) delete mode 100644 bootstrap/http_client.rb diff --git a/bootstrap/http_client.rb b/bootstrap/http_client.rb deleted file mode 100644 index 58eea23..0000000 --- a/bootstrap/http_client.rb +++ /dev/null @@ -1,90 +0,0 @@ -require 'json' -require 'net/http' -require 'net/https' -require 'uri' -require 'openssl' - -class HttpClient - attr_accessor :uri - attr_accessor :header - attr_accessor :cookies - attr_accessor :body - attr_accessor :response - attr_accessor :response_code - - @@req_xml = < - - - -EOF - - def initialize(url: nil, username: nil, password: nil, headers: Hash.new, cookies: Hash.new, body: nil) - @uri = URI.parse(url) - @username = username - @password = password - @headers = headers - @cookies = cookies - @body = body - end - - def do_http(method: :get, do_cookies_p: false, read_timeout: 600, extra_headers: Hash.new) - resp = nil - http = Net::HTTP.new(@uri.host, @uri.port) - if uri.scheme == 'https' - http.use_ssl = true - http.verify_mode = OpenSSL::SSL::VERIFY_NONE - end - http.read_timeout = read_timeout - req = case method - when :get - Net::HTTP::Get.new(uri.request_uri, @headers.merge(extra_headers)) - when :delete - Net::HTTP::Delete.new(uri.request_uri, @headers.merge(extra_headers)) - when :post - Net::HTTP::Post.new(uri.request_uri, @headers.merge(extra_headers)) - when :put - Net::HTTP::Put.new(uri.request_uri, @headers.merge(extra_headers)) - when :propfind - Net::HTTP::Propfind.new(uri.request_uri, {"Depth" => "1"}) - end - req.basic_auth(@username, @password) if @username and @password - if method == :propfind - req.body = @@req_xml - else - req.body = @body if @body - end - resp = http.request(req) - @response = resp.body - @response_code = resp.class - get_cookies(resp) if do_cookies_p - end - - # Below is a pair of example Set-Cookie headers after - # Net::HttpClient turns them into a concatenated string. Note the - # bad use of a comma to separate the cookies. It's bad because a - # comma already appears in the date. We deal with that by eating - # the date with gsub() before splitting. - # - # csrftoken=urvsX10TfzWIK1fgctZ2HjHuNQZDr3E7; expires=Wed, 16-Nov-2016 16:57:20 GMT; Max-Age=31449600; Path=/, sessionid=e0t7304jn44ssc7gw412abup4aasehgb; expires=Wed, 18-Nov-2015 17:57:20 GMT; httponly; Max-Age=3600; Path=/ - # - # rememberMe=deleteMe; Path=/Openbook; Max-Age=0; Expires=Wed, 16-Dec-2015 22:53:58 GMT - def get_cookies(resp) - if resp.response['Set-Cookie'] - rawstring = resp.response['Set-Cookie'].gsub(/expires.*?Path=/, '') - rawstring.chomp.split(",").each do |entry| - entryparts = entry.split(";") - if entryparts.length >= 1 - cookieparts = entryparts[0].split("=") - name = cookieparts[0].strip - value = cookieparts[1].strip - @cookies[name] = value - end - end - end - end - - def create_cookie(name, value) - "#{name}=#{value}; Path=/" - end -end diff --git a/bootstrap/pillar_config.rb b/bootstrap/pillar_config.rb index 56bdb3d..6d9d3fb 100755 --- a/bootstrap/pillar_config.rb +++ b/bootstrap/pillar_config.rb @@ -1,6 +1,5 @@ #!/usr/bin/ruby -require_relative 'http_client' require 'digest' require 'getoptlong' require "json" @@ -28,40 +27,20 @@ def get_ip_address() end end -def get_jar_versions(yml, branch) - ret = Hash.new - begin - http_client = HttpClient.new(url: yml["jars"]["url"], - username: yml["jars"]["username"], - password: yml["jars"]["password"]) - http_client.do_http(method: :propfind) - http_client.response.each_line do |line| - if line =~ /D:href.*#{branch}.*\.jar/ - jar_name = line.chomp.split(/[<>]/)[2] - jarparts = jar_name.split(/\//) - name, *version_parts, junk1 = jarparts[jarparts.length - 1].split(".") - ret["#{name.gsub("-", "_").gsub("_#{branch}", "")}"] = { - "jar_name" => jarparts[jarparts.length - 1], - "jar_version" => version_parts.join("."), - "image_name" => "openbook_#{name.gsub("-", "_")}", - "container_name" => "#{name.gsub("-", "_")}", - "build_dir" => "/root/openbook_build/#{name.gsub("-", "_").gsub("_#{branch}", "")}" - } - end - end - rescue Exception => e - STDERR.puts "Error while contacting webdav endpoint: #{e.message}" - exit(1) - end - ret -end - -def process_yaml() +def process_yaml(branch) env_yaml_path = "#{File.dirname($0)}/config.yaml" if ! File.file?(env_yaml_path) STDERR.puts "Unable to find config.yaml. Exiting." exit(1) end + components = [ + "admin-api-server", + "customer-api-server", + "admin-web-ui", + "customer-web-ui", + "job-scheduler-server", + "workflow-server" + ] yml = YAML.load_file(env_yaml_path) yml["database"] = {} yml["database"]["image_name"] = "openbook_database" @@ -69,6 +48,14 @@ def process_yaml() yml["database"]["build_dir"] = "/root/openbook_build/database" yml["ansible"] = Hash.new yml["ansible"]["build_dir"] = "/root/openbook_build/ansible" + components.each do |component| + yml["#{component.gsub("-", "_")}"] = { + "jar_name" => "#{component}-#{branch}", + "image_name" => "openbook_#{component.gsub("-", "_")}_#{branch}", + "container_name" => "#{component.gsub("-", "_")}_#{branch}", + "build_dir" => "/root/openbook_build/#{component.gsub("-", "_")}" + } + end yml end @@ -83,8 +70,8 @@ def main() end end - yml = process_yaml() - puts yml.merge(get_jar_versions(yml, branch)).to_json + yml = process_yaml(branch) + puts yml.to_json end main() -- cgit v1.3