idcfcloud 0.2.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,5 +1,4 @@
1
1
  require_relative './base'
2
- require 'idcf/faraday_middleware/cdn_signature'
3
2
 
4
3
  module Idcf
5
4
  module Cli
@@ -16,7 +15,7 @@ module Idcf
16
15
 
17
16
  class << self
18
17
  def description
19
- 'Computeing Service(beta)'
18
+ 'Computeing Service'
20
19
  end
21
20
  end
22
21
 
@@ -38,6 +37,20 @@ module Idcf
38
37
  faraday
39
38
  end
40
39
 
40
+ def make_table_data(data)
41
+ return data unless data.class == Hash
42
+ keys = data.keys
43
+ return data unless keys.count == 2 && keys.include?('count')
44
+ data.each do |k, v|
45
+ return v unless k == 'count'
46
+ end
47
+ data
48
+ end
49
+
50
+ def make_field_data(data)
51
+ make_table_data(data)
52
+ end
53
+
41
54
  # raise api error msg
42
55
  #
43
56
  # @param res [Faraday::Responce]
@@ -1,18 +1,24 @@
1
1
  require 'idcf/cli/conf/const'
2
2
  require 'idcf/cli/lib/api'
3
+ require 'idcf/cli/lib/document'
3
4
  module Idcf
4
5
  module Cli
5
6
  module Controller
6
7
  module Extend
7
8
  # command
8
9
  module Command
10
+ attr_reader :public_commands
11
+
9
12
  # register schema method by link
10
13
  #
11
14
  # @param link [Idcf::JsonHyperSchema::Expands::LinkInfoBase]
12
15
  def register_schema_method_by_link!(link)
13
- param_str = Idcf::Cli::Lib::Api.command_param_str(link)
16
+ param_str = Idcf::Cli::Lib::Api.command_param_str(link)
14
17
  method_desc = "#{link.title} #{param_str}"
15
- desc method_desc.strip, link.description
18
+ description = link.description
19
+ desc method_desc.strip, description
20
+ description = "#{description}\n\n#{Idcf::Cli::Lib::Document.make_document_desc(link)}"
21
+ long_desc description
16
22
  define_method link.title.to_sym do |*args|
17
23
  execute(__method__, *args)
18
24
  end
@@ -43,6 +49,23 @@ module Idcf
43
49
  method_option opn, option
44
50
  end
45
51
  end
52
+
53
+ def desc(usage, description, options = {})
54
+ super(usage, description, options)
55
+ @public_commands ||= []
56
+ cmd = usage.split(' ').shift
57
+ @public_commands << cmd unless @public_commands.include?(cmd)
58
+ end
59
+
60
+ def subcommand_structure
61
+ result = super
62
+ list = @public_commands
63
+ list.concat(superclass.public_commands) if superclass.respond_to?(:public_commands)
64
+ list.each do |cmd|
65
+ result[cmd] = nil unless result.key?(cmd)
66
+ end
67
+ result
68
+ end
46
69
  end
47
70
  end
48
71
  end
@@ -22,7 +22,6 @@ module Idcf
22
22
  def make_module_classes
23
23
  return @m_classes if @m_classes
24
24
  result = {}
25
- add_classify_rule
26
25
 
27
26
  make_service_paths.each do |fn, path|
28
27
  require path
@@ -32,15 +31,6 @@ module Idcf
32
31
  @m_classes = result
33
32
  end
34
33
 
35
- # add classify rule
36
- def add_classify_rule
37
- Idcf::Cli::Conf::Const::CLASSIFY_RULE.each do |rule|
38
- ActiveSupport::Inflector.inflections do |inflect|
39
- inflect.irregular(*rule)
40
- end
41
- end
42
- end
43
-
44
34
  # make service paths
45
35
  #
46
36
  # @return Hash
@@ -27,6 +27,18 @@ module Idcf
27
27
  v = service_version(o)
28
28
  "#{dir}/#{fn}_#{v}_#{region}.#{ext}"
29
29
  end
30
+
31
+ # service version
32
+ #
33
+ # @param o [Hash]
34
+ # @return String
35
+ def service_version(o)
36
+ versions = service_versions(get_region(o))
37
+ result = o[:version].nil? ? versions.last : o[:version]
38
+ msg = "not found input version[#{o[:version]}]"
39
+ raise Idcf::Cli::Error::CliError, msg unless versions.include?(result)
40
+ result
41
+ end
30
42
  end
31
43
  end
32
44
  end
@@ -54,7 +54,7 @@ module Idcf
54
54
  def faraday_setting(faraday, o)
55
55
  prof = Idcf::Cli::Lib::Configure.get_profile(o)
56
56
  op = {}
57
- [:api_key, :secret_key].each do |v|
57
+ %i[api_key secret_key].each do |v|
58
58
  op[v] = o.key?(v) ? o[v] : Idcf::Cli::Lib::Configure.get_user_conf(v.to_s, prof)
59
59
  end
60
60
  faraday.request(faraday_request)
@@ -20,7 +20,7 @@ module Idcf
20
20
  args.each do |v|
21
21
  begin
22
22
  result << JSON.parse(v, symbolize_names: false)
23
- rescue
23
+ rescue StandardError => _e
24
24
  result << v
25
25
  end
26
26
  end
@@ -12,10 +12,10 @@ module Idcf
12
12
  # @param err_f [Boolean]
13
13
  # @param o [Hash]
14
14
  # @return Stirng
15
- def make_result_str(data, err_f, o)
15
+ def make_result_str(data, o)
16
16
  message = data.class == Hash ? data[:message] : {}
17
17
  f = output_format(o, message)
18
- Idcf::Cli::Lib::Convert::Helper.new.format(data, err_f, f)
18
+ Idcf::Cli::Lib::Convert::Helper.new.format(data, f)
19
19
  end
20
20
 
21
21
  # output format
@@ -25,9 +25,7 @@ module Idcf
25
25
  # @return String
26
26
  def output_format(o, message)
27
27
  default_output = Idcf::Cli::Lib::Configure.get_code_conf('output', o)
28
- if message.class == Hash && !message[:output].nil?
29
- return default_output
30
- end
28
+ return default_output if message.class == Hash && !message[:output].nil?
31
29
 
32
30
  f = o[:output]
33
31
  f.nil? ? default_output : f
@@ -60,7 +60,7 @@ module Idcf
60
60
  next
61
61
  end
62
62
  end
63
- cli_error 'Validate load error'
63
+ cli_error('Validate load error')
64
64
  end
65
65
 
66
66
  # make validation error
@@ -25,9 +25,7 @@ module Idcf
25
25
 
26
26
  def make_profiles(config, o)
27
27
  [].tap do |result|
28
- if o[:profile] != 'default' && !check_profile?(config, 'default')
29
- result << 'default'
30
- end
28
+ result << 'default' if o[:profile] != 'default' && !check_profile?(config, 'default')
31
29
  result << o[:profile]
32
30
  end
33
31
  end
@@ -35,7 +33,7 @@ module Idcf
35
33
  def check_profile?(config, name)
36
34
  conf = config[name]
37
35
  return false if conf.nil?
38
- Idcf::Cli::Conf::Const::USER_CONF_ITEMS.each do |k, _v|
36
+ Idcf::Cli::Conf::Const::USER_CONF_ITEMS.each_key do |k|
39
37
  return false if conf[k.to_s].strip.empty?
40
38
  end
41
39
  true
@@ -37,7 +37,7 @@ module Idcf
37
37
  def output_default_schema(service, version, regions)
38
38
  return nil if regions.keys.include?('default')
39
39
  latist = latest_schema(regions.values)
40
- path = make_schema_file_path(service, version, 'default')
40
+ path = make_schema_file_path(service, version, 'default')
41
41
  output_complement_file(JSON.pretty_generate(latist), path)
42
42
  end
43
43
 
@@ -47,11 +47,11 @@ module Idcf
47
47
  # @return Hash or nil
48
48
  def latest_schema(schemas)
49
49
  result = nil
50
- v_str = '$version'
50
+ v_str = '$version'
51
51
  schemas.each do |data|
52
52
  result ||= data
53
- v1 = Gem::Version.create(data[v_str])
54
- v2 = Gem::Version.create(result[v_str])
53
+ v1 = Gem::Version.create(data[v_str])
54
+ v2 = Gem::Version.create(result[v_str])
55
55
  next unless v1 > v2
56
56
  result = data
57
57
  end
@@ -62,9 +62,9 @@ module Idcf
62
62
  view = Idcf::Cli::Lib::Util::Template.new
63
63
  view.set('variables', make_script_variables)
64
64
  paths = {}
65
- Idcf::Cli::Conf::Const::COMP_PATHS.each do |k, _v|
66
- str = view.fetch("#{k}/#{COMP_N}.erb")
67
- path = "#{Idcf::Cli::Conf::Const::OUT_DIR}/#{COMP_N}.#{k}"
65
+ Idcf::Cli::Conf::Const::COMP_PATHS.each_key do |k|
66
+ str = view.fetch("#{k}/#{COMP_N}.erb")
67
+ path = "#{Idcf::Cli::Conf::Const::OUT_DIR}/#{COMP_N}.#{k}"
68
68
  paths[k] = File.expand_path(path)
69
69
  output_complement_file(str, paths[k])
70
70
  end
@@ -82,7 +82,7 @@ module Idcf
82
82
  end
83
83
 
84
84
  def startup_script_qa(paths, script)
85
- list = %w(y N)
85
+ list = %w[y N]
86
86
  puts "Do you want to edit the startup script?(#{list.join('/')})"
87
87
  puts "[#{startup_script_path(script)}]"
88
88
  ans = Idcf::Cli::Lib::Util::Input.qa_answer_input(list)
@@ -106,7 +106,7 @@ module Idcf
106
106
  # @param paths [Hash]
107
107
  def output_startup_script(script, paths)
108
108
  s_script_path = startup_script_path(script)
109
- write_str = "source #{paths[script]}"
109
+ write_str = "source #{paths[script]}"
110
110
 
111
111
  if write_path?(s_script_path, write_str)
112
112
  File.open(s_script_path, 'a') do |f|
@@ -154,7 +154,7 @@ module Idcf
154
154
  def output_manual_writing(paths)
155
155
  puts 'please write in'
156
156
  Idcf::Cli::Conf::Const::COMP_PATHS.each do |k, v|
157
- puts v, paths[k]
157
+ puts v, "source #{paths[k]}"
158
158
  end
159
159
  end
160
160
 
@@ -169,20 +169,20 @@ module Idcf
169
169
  # @param names [Array]
170
170
  # @return Hash
171
171
  def make_flat_variables(list, names = [])
172
- {}.tap do |result|
173
- name = names.empty? ? 'top' : names.join('_')
174
- result[name] = list.keys
175
- list.each do |k, v|
176
- next unless v.class == Hash
177
- names << k
178
- result.merge!(make_flat_variables(v, names))
179
- names.pop
180
- end
172
+ result = {}
173
+ name = names.empty? ? 'top' : names.join('_')
174
+ result[name] = list.keys
175
+ list.each do |k, v|
176
+ next unless v.class == Hash
177
+ names << k
178
+ result.merge!(make_flat_variables(v, names))
179
+ names.pop
181
180
  end
181
+ result
182
182
  end
183
183
 
184
184
  def extract_commands(thor_class, commands)
185
- thor_class.commands.keys.each do |k_c|
185
+ thor_class.commands.each_key do |k_c|
186
186
  commands << k_c if commands.index(k_c).nil?
187
187
  end
188
188
 
@@ -192,7 +192,7 @@ module Idcf
192
192
  def extract_command_infos(t_class, s_name, infos)
193
193
  commands = []
194
194
  return extract_commands(t_class, commands) if infos[s_name].nil?
195
- infos[s_name].keys.each do |name|
195
+ infos[s_name].each_key do |name|
196
196
  commands << name.to_s
197
197
  end
198
198
  extract_commands(t_class, commands)
@@ -7,8 +7,17 @@ module Idcf
7
7
  module Extend
8
8
  # update file
9
9
  module UpdateFile
10
- BROKEN_UPDATE_FILE = 'The update file is damaged. '\
11
- 'Please consult with the administrator.'.freeze
10
+ BROKEN_UPDATE_FILE = <<-TEXT.strip_heredoc.freeze
11
+ The update file is damaged.
12
+ Please consult with the administrator.
13
+ TEXT
14
+ BROKEN_JSON_SCHEMA = <<-TEXT.strip_heredoc.freeze
15
+ Failed to verify the update file.
16
+ Use the following commands to try updating the gem.
17
+
18
+ # gem update idcfcloud
19
+ # idcfcloud init
20
+ TEXT
12
21
 
13
22
  protected
14
23
 
@@ -36,7 +45,7 @@ module Idcf
36
45
  def download_schema_file(path)
37
46
  d = file_load(path)
38
47
  JSON.parse(d)
39
- rescue
48
+ rescue StandardError => _e
40
49
  Idcf::Cli::Lib::Util::CliLogger.info("json format error:#{path}")
41
50
  raise Idcf::Cli::Error::CliError, BROKEN_UPDATE_FILE
42
51
  end
@@ -49,16 +58,16 @@ module Idcf
49
58
  def check_json_schema(j)
50
59
  analyst = Idcf::JsonHyperSchema::Analyst.new
51
60
  analyst.schema_links(j)
52
- rescue => e
61
+ rescue StandardError => e
53
62
  Idcf::Cli::Lib::Util::CliLogger.info('json-schema format error')
54
- log_msg = "#{BROKEN_UPDATE_FILE}:#{e.message}"
63
+ log_msg = "#{BROKEN_JSON_SCHEMA}:#{e.message}"
55
64
  Idcf::Cli::Lib::Util::CliLogger.error(log_msg)
56
- raise Idcf::Cli::Error::CliError, BROKEN_UPDATE_FILE
65
+ raise Idcf::Cli::Error::CliError, BROKEN_JSON_SCHEMA
57
66
  end
58
67
 
59
68
  def file_load(path)
60
- open(path).read
61
- rescue
69
+ URI.open(path).read
70
+ rescue StandardError => _e
62
71
  nil
63
72
  end
64
73
 
@@ -66,8 +75,10 @@ module Idcf
66
75
  {}.tap do |result|
67
76
  Idcf::Cli::Lib::Configure.get_code_conf(cls.service_name).each do |k, v|
68
77
  regions = {}
69
- v['region'].each do |region, info|
70
- regions[region] = create_schema_url(info['schema'])
78
+ v['region'].each_key do |region|
79
+ target = "#{cls.service_name}.#{k}.region.#{region}.schema"
80
+ url = Idcf::Cli::Lib::Configure.get_code_conf(target)
81
+ regions[region] = create_schema_url(url)
71
82
  end
72
83
 
73
84
  result[k] = regions
@@ -45,6 +45,22 @@ module Idcf
45
45
  make_params(args[url_param_names.size])
46
46
  end
47
47
 
48
+ def parent_titles(schema = nil)
49
+ result = []
50
+ if schema.present?
51
+ parent_schema = schema.parent
52
+ if parent_schema.present?
53
+ result << parent_schema.title if parent_schema.title.present?
54
+ result.concat(parent_titles(parent_schema))
55
+ end
56
+ else
57
+ result << title
58
+ result.concat(parent_titles(@data))
59
+ result.reverse!
60
+ end
61
+ result
62
+ end
63
+
48
64
  protected
49
65
 
50
66
  def make_result_api_params(target, args, api_result, resource_id)
@@ -79,7 +95,7 @@ module Idcf
79
95
  def result_api_str(target, args, api_result, resource_id)
80
96
  return resource_id if target == '#{resource_id}'
81
97
  result_api_str_regexp(target, args, api_result)
82
- rescue => e
98
+ rescue Standarderror => e
83
99
  raise Idcf::Cli::Error::CliError, e.message
84
100
  end
85
101
 
@@ -109,16 +125,16 @@ module Idcf
109
125
  end
110
126
 
111
127
  def make_query_params(param)
112
- {}.tap do |result|
113
- next unless param.class == Hash
114
- query_param_names.each do |k|
115
- result[k] = param[k] if param.key?(k)
116
- reg = Regexp.new("#{k}[\\.\\[].+")
117
- param.keys.each do |pk|
118
- result[pk] = param[pk] if (reg =~ pk).present?
119
- end
128
+ result = {}
129
+ return result unless param.class == Hash
130
+ query_param_names.each do |k|
131
+ result[k] = param[k] if param.key?(k)
132
+ reg = Regexp.new("#{k}[\\.\\[].+")
133
+ param.each_key do |pk|
134
+ result[pk] = param[pk] if (reg =~ pk).present?
120
135
  end
121
136
  end
137
+ result
122
138
  end
123
139
  end
124
140
  end
@@ -33,7 +33,8 @@ class Thor
33
33
  file_name = File.basename(f, '.*')
34
34
  next if file_name == 'base'
35
35
 
36
- command_regist file_name, "#{b_path}/#{under_path}/#{file_name}", arg
36
+ require_path = "#{b_path}/#{under_path}/#{file_name}"
37
+ command_regist(file_name, require_path, arg)
37
38
  end
38
39
  end
39
40
 
@@ -46,7 +47,8 @@ class Thor
46
47
  require require_path
47
48
 
48
49
  class_const = require_path.classify.constantize
49
- class_const.init(arg)
50
+ class_const.init(arg) if arg.include?(command) || map.values.include?(command.to_sym)
51
+
50
52
  register class_const,
51
53
  command,
52
54
  "#{command_help_string(command)} [OPTION]",
@@ -72,7 +74,7 @@ class Thor
72
74
 
73
75
  def subcommand_structure
74
76
  {}.tap do |result|
75
- commands.each do |k, _v|
77
+ commands.each_key do |k|
76
78
  result[k.to_s] = nil
77
79
  end
78
80
  result = subcommand_class_structure(result)
@@ -95,6 +97,7 @@ class Thor
95
97
 
96
98
  def subcommand_class_structure(result)
97
99
  subcommand_classes.each do |k, v|
100
+ v.init({})
98
101
  commands = v.subcommand_structure
99
102
  result[k.to_s] = nil
100
103
  result[k.to_s] = commands unless commands.empty?