idcfcloud 0.2.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +12 -0
  3. data/.rubocop.yml +12 -2
  4. data/README.md +30 -12
  5. data/idcfcloud.gemspec +12 -12
  6. data/lib/idcf/cli/command/morio.rb +4 -4
  7. data/lib/idcf/cli/conf/conf.yml +0 -6
  8. data/lib/idcf/cli/conf/const.rb +32 -29
  9. data/lib/idcf/cli/controller/base.rb +50 -23
  10. data/lib/idcf/cli/controller/compute.rb +15 -2
  11. data/lib/idcf/cli/controller/extend/command.rb +25 -2
  12. data/lib/idcf/cli/controller/extend/search_module.rb +0 -10
  13. data/lib/idcf/cli/controller/extend/util.rb +12 -0
  14. data/lib/idcf/cli/controller/include/client.rb +1 -1
  15. data/lib/idcf/cli/controller/include/command.rb +1 -1
  16. data/lib/idcf/cli/controller/include/util.rb +3 -5
  17. data/lib/idcf/cli/controller/include/validate.rb +1 -1
  18. data/lib/idcf/cli/extend/configure.rb +2 -4
  19. data/lib/idcf/cli/extend/update.rb +21 -21
  20. data/lib/idcf/cli/extend/update_file.rb +21 -10
  21. data/lib/idcf/cli/gem_ext/idcf/json_hyper_schema/expands/link_info_base_extension.rb +25 -9
  22. data/lib/idcf/cli/gem_ext/thor/init_util.rb +6 -3
  23. data/lib/idcf/cli/index.rb +17 -5
  24. data/lib/idcf/cli/lib/api.rb +5 -4
  25. data/lib/idcf/cli/lib/configure.rb +2 -2
  26. data/lib/idcf/cli/lib/convert/filter/field_filter.rb +9 -12
  27. data/lib/idcf/cli/lib/convert/filter/json_path_filter.rb +1 -1
  28. data/lib/idcf/cli/lib/convert/formatter/base.rb +1 -2
  29. data/lib/idcf/cli/lib/convert/formatter/csv_format.rb +15 -32
  30. data/lib/idcf/cli/lib/convert/formatter/json_format.rb +1 -1
  31. data/lib/idcf/cli/lib/convert/formatter/table_format.rb +2 -2
  32. data/lib/idcf/cli/lib/convert/formatter/xml_format.rb +1 -1
  33. data/lib/idcf/cli/lib/convert/helper.rb +16 -5
  34. data/lib/idcf/cli/lib/document.rb +45 -0
  35. data/lib/idcf/cli/lib/util/cli_file.rb +1 -1
  36. data/lib/idcf/cli/lib/util/cli_logger.rb +3 -3
  37. data/lib/idcf/cli/lib/util/ini_conf.rb +2 -2
  38. data/lib/idcf/cli/lib/util/input.rb +40 -5
  39. data/lib/idcf/cli/lib/util/yml_conf.rb +1 -1
  40. data/lib/idcf/cli/service/base.rb +6 -6
  41. data/lib/idcf/cli/service/ilb/base_server_for_protocol.rb +22 -18
  42. data/lib/idcf/cli/validate/custom/month_check_validator.rb +1 -1
  43. data/lib/idcf/cli/validate/custom/require_relation_validator.rb +2 -2
  44. data/lib/idcf/cli/validate/define/base.rb +3 -2
  45. data/lib/idcf/cli/version.rb +1 -1
  46. metadata +55 -68
  47. data/lib/idcf/cli/controller/cdn.rb +0 -37
@@ -28,12 +28,24 @@ module Idcf
28
28
  # @param arg [Hash] options
29
29
  def init(arg)
30
30
  map COMMAND_MAPS
31
+ add_classify_rule
31
32
  sub_command_regist('controller', File.dirname(__FILE__), arg)
32
33
  rescue Idcf::Cli::Error::CliError => e
33
34
  error_exit(e)
34
- rescue => e
35
+ rescue StandardError => e
35
36
  error_exit(Idcf::Cli::Error::CliError.new(e.message))
36
37
  end
38
+
39
+ protected
40
+
41
+ # add classify rule
42
+ def add_classify_rule
43
+ Idcf::Cli::Conf::Const::CLASSIFY_RULE.each do |rule|
44
+ ActiveSupport::Inflector.inflections do |inflect|
45
+ inflect.irregular(*rule)
46
+ end
47
+ end
48
+ end
37
49
  end
38
50
 
39
51
  def initialize(*args)
@@ -48,7 +60,7 @@ module Idcf
48
60
  def init
49
61
  configure
50
62
  update
51
- rescue => e
63
+ rescue StandardError => e
52
64
  self.class.error_exit(e)
53
65
  end
54
66
 
@@ -56,7 +68,7 @@ module Idcf
56
68
 
57
69
  def update
58
70
  do_update(options)
59
- rescue => e
71
+ rescue StandardError => e
60
72
  self.class.error_exit(e)
61
73
  end
62
74
 
@@ -67,7 +79,7 @@ module Idcf
67
79
  def configure
68
80
  init_f = ARGV[0] == 'init'
69
81
  do_configure(options, init_f)
70
- rescue => e
82
+ rescue StandardError => e
71
83
  self.class.error_exit(e)
72
84
  end
73
85
 
@@ -75,7 +87,7 @@ module Idcf
75
87
 
76
88
  def version
77
89
  puts Idcf::Cli::Conf::Const::VERSION_STR
78
- rescue => e
90
+ rescue StandardError => e
79
91
  self.class.error_exit(e)
80
92
  end
81
93
  end
@@ -1,4 +1,5 @@
1
1
  require 'idcf/cli/lib/util/cli_logger'
2
+ require 'idcf/cli/lib/document'
2
3
  module Idcf
3
4
  module Cli
4
5
  module Lib
@@ -113,16 +114,16 @@ module Idcf
113
114
  min = link.url_param_names.size + offset
114
115
  max = between_max(min, link)
115
116
 
116
- msg = format('Argument: %s', self.class.command_param_str(link))
117
+ msg = format('Argument: %<arg>s', arg: self.class.command_param_str(link))
118
+ msg = "#{msg}\n#{Idcf::Cli::Lib::Document.make_document_desc(link)}"
117
119
  cli_error msg unless args.size.between?(min, max)
118
120
  end
119
121
 
120
122
  def between_max(min, link)
121
123
  offset = 0
122
124
  required_f = self.class.param_required?(link)
123
- if !required_f && (link.properties.present? || link.query_param_names.present?)
124
- offset = 1
125
- end
125
+ offset = 1 if !required_f && (link.properties.present? || link.query_param_names.present?)
126
+
126
127
  min + offset
127
128
  end
128
129
 
@@ -40,7 +40,7 @@ module Idcf
40
40
  profile = get_profile(o)
41
41
 
42
42
  return get_user_conf(path, profile)
43
- rescue
43
+ rescue StandardError => _e
44
44
  return code_config.find(path) if code_config
45
45
  f_path = Idcf::Cli::Conf::Const::CODE_CONF_PATH
46
46
  @code_config = Idcf::Cli::Lib::Util::YmlConf.new(f_path)
@@ -65,7 +65,7 @@ module Idcf
65
65
  region = ''
66
66
  region = get_user_conf('region', get_profile(o)) if read_conf
67
67
  region.empty? ? 'default' : region
68
- rescue
68
+ rescue StandardError => _e
69
69
  'default'
70
70
  end
71
71
 
@@ -6,7 +6,7 @@ module Idcf
6
6
  module Filter
7
7
  # filter fields
8
8
  class FieldFilter < Base
9
- MSG_NO_TARGETS = '[fields][%s] is not found.'.freeze
9
+ MSG_NO_TARGETS = '[fields][%<field>s] is not found.'.freeze
10
10
 
11
11
  # filter
12
12
  #
@@ -41,18 +41,15 @@ module Idcf
41
41
 
42
42
  def extraction(data, condition)
43
43
  check_extraction(data, condition)
44
- {}.tap do |result|
45
- condition.split(',').each do |key|
46
- next if key.empty?
44
+ result = {}
45
+ condition.split(',').each do |key|
46
+ next if key.blank?
47
47
 
48
- val = data[key]
49
- if @options[:table_flag]
50
- result[key] = [Array, Hash].include?(val.class) ? val.to_s : val
51
- next
52
- end
53
- result[key] = val
54
- end
48
+ val = data[key]
49
+ flg = @options[:table_flag] && [Array, Hash].include?(val.class)
50
+ result[key] = flg ? val.to_s : val
55
51
  end
52
+ result
56
53
  end
57
54
 
58
55
  def check_extraction(data, condition)
@@ -63,7 +60,7 @@ module Idcf
63
60
  end
64
61
 
65
62
  return nil if no_targets.empty?
66
- cli_error(MSG_NO_TARGETS % no_targets.join(','))
63
+ cli_error(format(MSG_NO_TARGETS, field: no_targets.join(',')))
67
64
  end
68
65
  end
69
66
  end
@@ -19,7 +19,7 @@ module Idcf
19
19
  end
20
20
  path = JsonPath.new(condition)
21
21
  path.on(data.to_json)
22
- rescue => e
22
+ rescue StandardError => e
23
23
  cli_error("[json-path]#{e.message}")
24
24
  end
25
25
  end
@@ -8,9 +8,8 @@ module Idcf
8
8
  # format
9
9
  #
10
10
  # @param _data [Hash]
11
- # @param _err_f [Boolean]
12
11
  # @return String
13
- def format(_data, _err_f)
12
+ def format(_data)
14
13
  raise Idcf::Cli::Error::CliError, 'override'
15
14
  end
16
15
  end
@@ -8,9 +8,9 @@ module Idcf
8
8
  module Formatter
9
9
  # csv formatter
10
10
  class CsvFormat < Base
11
- def format(data, err_f)
12
- result = CSV.generate do |csv|
13
- scrape_line(data, err_f).each do |v|
11
+ def format(data)
12
+ result = CSV.generate(force_quotes: true) do |csv|
13
+ scrape_line(data).each do |v|
14
14
  csv << v
15
15
  end
16
16
  end
@@ -20,11 +20,11 @@ module Idcf
20
20
 
21
21
  protected
22
22
 
23
- def scrape_line(data, err_f)
24
- list = scrape(data, err_f)
23
+ def scrape_line(data)
24
+ list = scrape(data)
25
25
  return [] if list.size.zero?
26
26
 
27
- result = []
27
+ result = []
28
28
  headers = make_header(list.first)
29
29
  result << headers
30
30
  push_list(list, headers, result)
@@ -33,7 +33,7 @@ module Idcf
33
33
  def make_header(first_list)
34
34
  result = []
35
35
  if first_list.class == Hash
36
- first_list.each do |k, _v|
36
+ first_list.each_key do |k|
37
37
  result << k
38
38
  end
39
39
  else
@@ -56,10 +56,8 @@ module Idcf
56
56
 
57
57
  # scrape
58
58
  # @param data [Hash]
59
- # @param err_f [Boolean]
60
59
  # @return Array in Hash
61
- def scrape(data, err_f)
62
- return [flat_hash(data)] if err_f
60
+ def scrape(data)
63
61
  return [flat_hash(data)] if data.class == Hash
64
62
  return [[data]] unless data.class == Array
65
63
 
@@ -83,29 +81,14 @@ module Idcf
83
81
  end
84
82
 
85
83
  def flat_hash(data)
86
- {}.tap do |result|
87
- return {} unless data.class == Hash
88
- data.each do |k, v|
89
- value = v
90
- arr_f = v.class == Array || v.class == Hash
91
- next if k != :message && arr_f
92
- value = flat(value) if arr_f
93
- result[k.to_sym] = value
94
- end
84
+ result = {}
85
+ return result unless data.class == Hash
86
+ data.each do |k, v|
87
+ value = v
88
+ value = JSON.generate(value) if v.class == Array || v.class == Hash
89
+ result[k.to_sym] = value
95
90
  end
96
- end
97
-
98
- def flat(list)
99
- result = []
100
- list.each do |k, v|
101
- if list.class == Hash
102
- result << "#{k}:#{v.join('/')}"
103
- next
104
- end
105
- result << (v.nil? ? k : v)
106
- end
107
-
108
- result.join("\n")
91
+ result
109
92
  end
110
93
  end
111
94
  end
@@ -8,7 +8,7 @@ module Idcf
8
8
  module Formatter
9
9
  # json formatter
10
10
  class JsonFormat < Base
11
- def format(data, _err_f)
11
+ def format(data)
12
12
  JSON.pretty_generate(data)
13
13
  end
14
14
  end
@@ -7,9 +7,9 @@ module Idcf
7
7
  module Formatter
8
8
  # table formatter
9
9
  class TableFormat < CsvFormat
10
- def format(data, err_f)
10
+ def format(data)
11
11
  require 'kosi'
12
- Kosi::Table.new.render(scrape_line(data, err_f))
12
+ Kosi::Table.new.render(scrape_line(data))
13
13
  end
14
14
  end
15
15
  end
@@ -10,7 +10,7 @@ module Idcf
10
10
  module Formatter
11
11
  # xml formatter
12
12
  class XmlFormat < Base
13
- def format(data, _err_f)
13
+ def format(data)
14
14
  data.to_xml(dasherize: false)
15
15
  end
16
16
  end
@@ -9,16 +9,15 @@ module Idcf
9
9
  module Convert
10
10
  # format helper
11
11
  class Helper
12
- FILTER_OPTION = [:json_path, :fields].freeze
12
+ FILTER_OPTION = %i[json_path fields].freeze
13
13
 
14
14
  # data convert
15
15
  #
16
16
  # @param data [Hash]
17
- # @param err_f [Boolean]
18
17
  # @param f [String] format
19
18
  # @return String
20
- def format(data, err_f, f)
21
- cls_load("Formatter::#{f.classify}Format").new.format(data, err_f)
19
+ def format(data, f)
20
+ cls_load("Formatter::#{f.classify}Format").new.format(data)
22
21
  end
23
22
 
24
23
  # is filter target
@@ -31,6 +30,19 @@ module Idcf
31
30
  false
32
31
  end
33
32
 
33
+ # only filter
34
+ #
35
+ # @param o [Hash]
36
+ # @return Boolean
37
+ def only_filter_fields?(o)
38
+ return false if o[:fields].nil?
39
+ list = []
40
+ FILTER_OPTION.each do |k|
41
+ list << k if o[k].present?
42
+ end
43
+ list.count == 1
44
+ end
45
+
34
46
  # data convert
35
47
  #
36
48
  # @param data [Hash]
@@ -38,7 +50,6 @@ module Idcf
38
50
  # @param table_flag [Boolean]
39
51
  # @return Hash
40
52
  def filter(data, o, table_flag)
41
- return data unless [Hash, Array].include?(data.class)
42
53
  result = data.deep_dup
43
54
  FILTER_OPTION.each do |k|
44
55
  next if o[k].nil? || o[k].empty?
@@ -0,0 +1,45 @@
1
+ require 'idcf/cli/conf/const'
2
+
3
+ module Idcf
4
+ module Cli
5
+ module Lib
6
+ # document
7
+ class Document
8
+ class << self
9
+ attr_reader :region, :version
10
+
11
+ def init(region: '', version: '')
12
+ @region = region
13
+ @version = version
14
+ end
15
+
16
+ def make_document_desc(link)
17
+ "reference : #{make_document_url(link)}"
18
+ end
19
+
20
+ def make_document_url(link)
21
+ result = URI(Idcf::Cli::Conf::Const::DOCUMENT_URL)
22
+ add_params = {
23
+ 'id' => make_document_id(link)
24
+ }.to_param
25
+ result.query = result.query ? "#{result.query}&#{add_params}" : add_params
26
+ result.to_s
27
+ end
28
+
29
+ def make_document_id(link)
30
+ titles = link.parent_titles
31
+ service_str = titles.shift.downcase
32
+ version_str = "#{Idcf::Cli::Conf::Const::DOCUMENT_SPACE_CONVERSION}#{@version}"
33
+ version_str = (@region.present? && @region != 'default' ? '' : version_str)
34
+ id_format = Idcf::Cli::Conf::Const::DOCUMENT_ID_PREFIX_FORMAT
35
+ prefix = format(id_format, service: service_str, version: version_str)
36
+ results = [prefix]
37
+ results.concat(titles)
38
+ result = results.join(Idcf::Cli::Conf::Const::DOCUMENT_ID_SEP)
39
+ result.gsub(/ /, Idcf::Cli::Conf::Const::DOCUMENT_SPACE_CONVERSION)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -12,7 +12,7 @@ module Idcf
12
12
  def mkdir(path)
13
13
  target = file?(path) ? File.dirname(path) : path
14
14
  FileUtils.mkdir_p(target, mode: 0o755)
15
- rescue => e
15
+ rescue StandardError => e
16
16
  raise Idcf::Cli::Error::CliError, e.message
17
17
  end
18
18
 
@@ -12,7 +12,7 @@ module Idcf
12
12
  class CliLogger
13
13
  class << self
14
14
  attr_reader :logger, :current_path
15
- LOG_METHODS = %w(debug error fatal info unknown warn).freeze
15
+ LOG_METHODS = %w[debug error fatal info unknown warn].freeze
16
16
 
17
17
  def log_instance
18
18
  return nil unless output_log?
@@ -68,7 +68,7 @@ module Idcf
68
68
  return false unless conf.get_user_conf('output_log').casecmp('y').zero?
69
69
  path = conf.get_user_conf('log_path')
70
70
  path.present?
71
- rescue => _e
71
+ rescue StandardError => _e
72
72
  false
73
73
  end
74
74
 
@@ -77,7 +77,7 @@ module Idcf
77
77
 
78
78
  path = "#{base_path}/#{Idcf::Cli::Conf::Const::LOG_FILE_NAME}"
79
79
  File.expand_path(path)
80
- rescue => _e
80
+ rescue StandardError => _e
81
81
  nil
82
82
  end
83
83
 
@@ -40,10 +40,10 @@ module Idcf
40
40
  def find(name, profile)
41
41
  begin
42
42
  @load_data[profile].fetch(name)
43
- rescue
43
+ rescue StandardError => _e
44
44
  @load_data['default'].fetch(name)
45
45
  end
46
- rescue
46
+ rescue StandardError => _e
47
47
  msg = "Error: could not read #{profile}:#{name}"
48
48
  raise Idcf::Cli::Error::CliError, msg
49
49
  end
@@ -5,20 +5,29 @@ module Idcf
5
5
  # input
6
6
  class Input
7
7
  class << self
8
+ # qa
9
+ #
10
+ # @param title [String]
11
+ # @param setting [Hash]
12
+ # @param nd [String]
13
+ # @return [String]
8
14
  def qa(title, setting, nd = '')
9
15
  loop do
10
- v = setting.class == Hash ? setting[:list] : nil
11
- v = v.nil? ? [] : v
12
- set_s = v.empty? ? '' : "(#{v.join('/')})"
13
- puts "#{title}#{set_s}[#{nd.empty? ? 'NONE' : nd}]"
16
+ v = qa_setting_list(setting)
17
+ qa_puts_question(title, nd, v)
14
18
  result = qa_answer_input(v, nd)
15
19
  return result unless result.empty?
16
20
  end
17
21
  end
18
22
 
23
+ # qa_answer_input
24
+ #
25
+ # @param list [Array]
26
+ # @param nd [String]
27
+ # @return [String]
19
28
  def qa_answer_input(list, nd = '')
20
29
  loop do
21
- res = STDIN.gets.strip
30
+ res = STDIN.gets.strip
22
31
  result = res.empty? ? nd : res
23
32
  return result if qa_answer?(result, list)
24
33
  puts "from this [#{list.join('/')}]"
@@ -28,6 +37,32 @@ module Idcf
28
37
 
29
38
  protected
30
39
 
40
+ # qa_puts_question
41
+ #
42
+ # @param title [String]
43
+ # @param nd [String]
44
+ # @param set_list [Array]
45
+ # @return nil
46
+ def qa_puts_question(title, nd, set_list)
47
+ set_s = set_list.blank? ? '' : "(#{set_list.join('/')})"
48
+ puts "#{title}#{set_s}[#{nd.empty? ? 'NONE' : nd}]"
49
+ nil
50
+ end
51
+
52
+ # qa_setting_list
53
+ #
54
+ # @param setting [Hash]
55
+ # @return [Array]
56
+ def qa_setting_list(setting)
57
+ v = setting.class == Hash ? setting[:list] : nil
58
+ v.nil? ? [] : v
59
+ end
60
+
61
+ # qa_answer?
62
+ #
63
+ # @param val [String]
64
+ # @param list [Array]
65
+ # @return [Boolean]
31
66
  def qa_answer?(val, list)
32
67
  return true if list.nil? || list.empty?
33
68
  return true if Regexp.new("\\A(#{list.join('|')})\\Z") =~ val