#!/usr/bin/env ruby # frozen_string_literal: true require "pathname" require "secretmgr" arg = ARGV cmd = arg[0] if cmd == "setup_data" # p "setup_data 0" arg.shift secret_dir = arg.shift plain_setting_file = arg.shift plain_secret_file = arg.shift secret_dir_pn = Pathname.new(secret_dir) plain_setting_file_pn = Pathname.new(plain_setting_file) plain_secret_file_pn = Pathname.new(plain_secret_file) exit 10 unless secret_dir_pn.exist? # p "setup_data 11" exit 11 unless secret_dir_pn.directory? # p "setup_data 12" exit 12 unless plain_setting_file_pn.exist? # p "setup_data 13" exit 13 unless plain_setting_file_pn.file? # p "setup_data 14" exit 14 unless plain_secret_file_pn.exist? # p "setup_data 15" exit 15 unless plain_secret_file_pn.file? # p "setup_data 100" else setting_txt_file = arg.shift secret_txt_file = arg.shift # p "setting_txt_file=#{setting_txt_file}" if (arg[0] == "--template-dir") || (arg[0] == "-d") template_dir = arg[1] arg.shift arg.shift end # p "template_dir=#{template_dir}" if (arg[0] == "--target") || (arg[0] == "-t") target = arg[1] sub_target = arg[2] arg.shift arg.shift arg.shift end # p "target=#{target}" # p "sub_target=#{sub_target}" setting_pn = Pathname.new(setting_txt_file) exit 10 unless setting_pn.exist? exit 10 unless setting_pn.file? secret_dir_pn = setting_pn.parent secret_pn = Pathname.new(secret_txt_file) exit 10 unless secret_pn.exist? exit 10 unless secret_pn.file? # secret_txt_file end case cmd when "setup_data" inst = Secretmgr::Secretmgr.create(secret_dir_pn, plain_setting_file_pn, plain_secret_file_pn) inst.setup else sm = Secretmgr::Secretmgr.new(secret_dir_pn) sm.set_setting_for_query(target, sub_target) sm.load p sm.make(template_dir, target, sub_target) end