idcfcloud 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.gitignore +5 -3
- data/.rubocop.yml +16 -1
- data/README.md +61 -6
- data/exe/idcfcloud +9 -1
- data/idcfcloud.gemspec +9 -7
- data/lib/idcf/cli/conf/conf.yml +39 -5
- data/lib/idcf/cli/conf/const.rb +42 -17
- data/lib/idcf/cli/controller/base.rb +130 -60
- data/lib/idcf/cli/controller/extend/command.rb +18 -16
- data/lib/idcf/cli/controller/extend/init.rb +2 -0
- data/lib/idcf/cli/controller/extend/override.rb +1 -8
- data/lib/idcf/cli/controller/extend/search_module.rb +14 -0
- data/lib/idcf/cli/controller/ilb.rb +5 -34
- data/lib/idcf/cli/controller/include/command.rb +7 -80
- data/lib/idcf/cli/controller/include/init.rb +2 -4
- data/lib/idcf/cli/controller/include/util.rb +20 -63
- data/lib/idcf/cli/controller/include/validate.rb +7 -1
- data/lib/idcf/cli/controller/your.rb +0 -33
- data/lib/idcf/cli/error/cli_error.rb +7 -5
- data/lib/idcf/cli/extend/configure.rb +38 -33
- data/lib/idcf/cli/extend/update.rb +139 -54
- data/lib/idcf/cli/extend/update_file.rb +113 -18
- data/lib/idcf/cli/gem_ext/thor/init_util.rb +20 -7
- data/lib/idcf/cli/index.rb +21 -11
- data/lib/idcf/cli/lib/convert/formatter/base.rb +1 -1
- data/lib/idcf/cli/lib/convert/formatter/xml_format.rb +1 -1
- data/lib/idcf/cli/lib/convert/helper.rb +43 -7
- data/lib/idcf/cli/lib/util/ini_conf.rb +30 -8
- data/lib/idcf/cli/lib/util/yml_conf.rb +13 -2
- data/lib/idcf/cli/service/base.rb +121 -21
- data/lib/idcf/cli/service/ilb/add_server_for_protocol.rb +8 -3
- data/lib/idcf/cli/service/ilb/base_server_for_protocol.rb +21 -35
- data/lib/idcf/cli/service/ilb/delete_server_for_protocol.rb +9 -4
- data/lib/idcf/cli/validate/define/base.rb +3 -1
- data/lib/idcf/cli/validate/define/ilb/base.rb +0 -5
- data/lib/idcf/cli/version.rb +1 -1
- metadata +62 -23
- data/lib/idcf/cli/conf/service/.gitkeep +0 -0
- data/lib/idcf/cli/controller/include/override.rb +0 -30
- data/lib/idcf/cli/controller/include/sdk.rb +0 -94
@@ -5,14 +5,7 @@ module Idcf
|
|
5
5
|
# override methods
|
6
6
|
module Override
|
7
7
|
def description
|
8
|
-
raise Idcf::Cli::CliError, 'Require override'
|
9
|
-
end
|
10
|
-
|
11
|
-
# blank client
|
12
|
-
#
|
13
|
-
# @return Mixed
|
14
|
-
def make_blank_client
|
15
|
-
# blank client
|
8
|
+
raise Idcf::Cli::Error::CliError, 'Require override'
|
16
9
|
end
|
17
10
|
end
|
18
11
|
end
|
@@ -22,6 +22,8 @@ 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
|
make_service_paths.each do |fn, path|
|
26
28
|
require path
|
27
29
|
result[fn] = path.classify.constantize
|
@@ -30,6 +32,18 @@ module Idcf
|
|
30
32
|
@m_classes = result
|
31
33
|
end
|
32
34
|
|
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
|
+
# make service paths
|
45
|
+
#
|
46
|
+
# @return Hash
|
33
47
|
def make_service_paths
|
34
48
|
s_name = make_model_name
|
35
49
|
base_path = Idcf::Cli::Conf::Const::BASE_PATH
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative './base'
|
2
|
-
require 'idcf/ilb'
|
3
2
|
|
4
3
|
module Idcf
|
5
4
|
module Cli
|
@@ -12,49 +11,21 @@ module Idcf
|
|
12
11
|
type: :string,
|
13
12
|
aliases: '-r',
|
14
13
|
require: true,
|
15
|
-
desc:
|
14
|
+
desc: 'region: jp-east/jp-east-2/jp-west'
|
16
15
|
|
17
16
|
class << self
|
18
17
|
def description
|
19
18
|
'ILB Service'
|
20
19
|
end
|
21
|
-
|
22
|
-
def make_blank_client
|
23
|
-
Idcf::Ilb::Client.new(
|
24
|
-
api_key: '',
|
25
|
-
secret_key: ''
|
26
|
-
)
|
27
|
-
end
|
28
20
|
end
|
29
21
|
|
30
22
|
protected
|
31
23
|
|
32
|
-
def
|
33
|
-
[
|
34
|
-
|
35
|
-
Idcf::Ilb::Resources::Base
|
36
|
-
]
|
37
|
-
end
|
38
|
-
|
39
|
-
def responce_classes
|
40
|
-
[
|
41
|
-
Idcf::Ilb::Response
|
42
|
-
]
|
43
|
-
end
|
44
|
-
|
45
|
-
# Create a new client
|
46
|
-
# @param o [Hash] other options
|
47
|
-
# @return [Response] Idcf::Ilb::Client
|
48
|
-
def make_client(o)
|
49
|
-
region = get_region(o)
|
50
|
-
option = {
|
51
|
-
host: get_code_conf("ilb.v1.host.#{region}", o),
|
52
|
-
ssl: o.key?(:no_ssl) ? false : true,
|
53
|
-
verify_ssl: o.key?(:no_vssl) ? false : true
|
54
|
-
}
|
55
|
-
option.merge!(base_options(o))
|
24
|
+
def do_async(_api, api_result, o, _executed_link)
|
25
|
+
job_id = api_result['job_id']
|
26
|
+
return nil unless do_command('check_job', job_id, o)
|
56
27
|
|
57
|
-
|
28
|
+
do_command('get_job', job_id, o)
|
58
29
|
end
|
59
30
|
end
|
60
31
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'idcf/cli/conf/const'
|
2
|
+
require 'uri'
|
2
3
|
module Idcf
|
3
4
|
module Cli
|
4
5
|
module Controller
|
@@ -9,96 +10,22 @@ module Idcf
|
|
9
10
|
|
10
11
|
protected
|
11
12
|
|
13
|
+
# convert arg json
|
14
|
+
# json string to Hash
|
15
|
+
#
|
16
|
+
# @param args [Array]
|
17
|
+
# @return Array
|
12
18
|
def convert_arg_json(*args)
|
13
19
|
result = []
|
14
20
|
args.each do |v|
|
15
21
|
begin
|
16
|
-
result << JSON.parse(v, symbolize_names:
|
22
|
+
result << JSON.parse(v, symbolize_names: false)
|
17
23
|
rescue
|
18
24
|
result << v
|
19
25
|
end
|
20
26
|
end
|
21
27
|
result
|
22
28
|
end
|
23
|
-
|
24
|
-
# check params
|
25
|
-
#
|
26
|
-
# @param mcs [Array] module classes
|
27
|
-
# @option mcs [Object] not namespace class name => model class object
|
28
|
-
# @param command [String]
|
29
|
-
# @param *args [Array]
|
30
|
-
# @raise
|
31
|
-
def check_params(mcs, command, *args)
|
32
|
-
m_class = nil
|
33
|
-
mcs.each do |k, v|
|
34
|
-
m_class = v if k == command.to_s
|
35
|
-
end
|
36
|
-
if m_class.nil?
|
37
|
-
settings = load_command_setting(command)
|
38
|
-
between_param?(settings[:params], args.size)
|
39
|
-
else
|
40
|
-
between_param?(m_class.params, args.size)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def load_command_setting(command)
|
45
|
-
fn = self.class.to_s.underscore.split('/').pop
|
46
|
-
cm = command.to_sym
|
47
|
-
dir = Idcf::Cli::Conf::Const::CMD_FILE_DIR
|
48
|
-
ext = Idcf::Cli::Conf::Const::CMD_FILE_EXT
|
49
|
-
path = "#{dir}/#{fn}.#{ext}"
|
50
|
-
Idcf::Cli::Lib::Util::YmlConf.new(path).find(cm)
|
51
|
-
end
|
52
|
-
|
53
|
-
# between params
|
54
|
-
#
|
55
|
-
# @param params [Array]
|
56
|
-
# @param arg_size [int]
|
57
|
-
# @raise
|
58
|
-
def between_param?(params, arg_size)
|
59
|
-
p_cnt = params.nil? ? 0 : params.size
|
60
|
-
return true if method_rest?(params)
|
61
|
-
opt_cnt = method_option_cnt(params)
|
62
|
-
|
63
|
-
min = p_cnt - opt_cnt
|
64
|
-
msg = format('Argument: %s', self.class.make_param_s(params))
|
65
|
-
|
66
|
-
return if arg_size.between?(min, p_cnt)
|
67
|
-
raise Idcf::Cli::CliError, msg
|
68
|
-
end
|
69
|
-
|
70
|
-
# is rest
|
71
|
-
#
|
72
|
-
# @param params [Array]
|
73
|
-
# @return Boolean
|
74
|
-
def method_rest?(params)
|
75
|
-
unless params.nil?
|
76
|
-
params.each do |param|
|
77
|
-
case param[:arg_type]
|
78
|
-
when 'rest'
|
79
|
-
return true
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
false
|
84
|
-
end
|
85
|
-
|
86
|
-
# option count
|
87
|
-
#
|
88
|
-
# @param params [Array]
|
89
|
-
# @return int
|
90
|
-
def method_option_cnt(params)
|
91
|
-
result = 0
|
92
|
-
unless params.nil?
|
93
|
-
params.each do |param|
|
94
|
-
case param[:arg_type]
|
95
|
-
when 'opt'
|
96
|
-
result += 1
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
result
|
101
|
-
end
|
102
29
|
end
|
103
30
|
end
|
104
31
|
end
|
@@ -1,19 +1,17 @@
|
|
1
|
-
require_relative './override'
|
2
1
|
require_relative './validate'
|
3
2
|
require_relative './command'
|
4
3
|
require_relative './util'
|
5
|
-
require_relative './
|
4
|
+
require_relative './client'
|
6
5
|
module Idcf
|
7
6
|
module Cli
|
8
7
|
module Controller
|
9
8
|
module Include
|
10
9
|
# init load
|
11
10
|
module Init
|
12
|
-
include Override
|
13
11
|
include Validate
|
14
12
|
include Command
|
15
13
|
include Util
|
16
|
-
include
|
14
|
+
include Client
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
@@ -6,68 +6,6 @@ module Idcf
|
|
6
6
|
module Util
|
7
7
|
protected
|
8
8
|
|
9
|
-
# get user config value
|
10
|
-
#
|
11
|
-
# @param name [String]
|
12
|
-
# @param profile [String]
|
13
|
-
# @return String or Hash
|
14
|
-
# @raise
|
15
|
-
def get_user_conf(name, profile = 'default')
|
16
|
-
return @config.find(name, profile) if @config
|
17
|
-
@config = make_user_conf
|
18
|
-
msg = 'Run the command `configure`'
|
19
|
-
raise Idcf::Cli::CliError, msg unless @config
|
20
|
-
|
21
|
-
@config.find(name, profile)
|
22
|
-
end
|
23
|
-
|
24
|
-
def make_user_conf
|
25
|
-
[
|
26
|
-
Idcf::Cli::Conf::Const::USER_CONF_PATH,
|
27
|
-
Idcf::Cli::Conf::Const::USER_CONF_GLOBAL
|
28
|
-
].each do |v|
|
29
|
-
result = Idcf::Cli::Lib::Util::IniConf.new(v)
|
30
|
-
return result unless result.load_error?
|
31
|
-
end
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
|
35
|
-
# get code setting value
|
36
|
-
#
|
37
|
-
# @param path [String]
|
38
|
-
# @return String or Hash
|
39
|
-
# @raise
|
40
|
-
def get_code_conf(path, o)
|
41
|
-
profile = get_profile(o)
|
42
|
-
|
43
|
-
return get_user_conf(path, profile)
|
44
|
-
rescue
|
45
|
-
return @code_conf.find(path) if @code_conf
|
46
|
-
f_path = Idcf::Cli::Conf::Const::CODE_CONF_PATH
|
47
|
-
@code_conf = Idcf::Cli::Lib::Util::YmlConf.new(f_path)
|
48
|
-
@code_conf.find(path)
|
49
|
-
end
|
50
|
-
|
51
|
-
# get profile
|
52
|
-
#
|
53
|
-
# @param o [Hash] options
|
54
|
-
# @return String
|
55
|
-
def get_profile(o)
|
56
|
-
o[:profile] || 'default'
|
57
|
-
end
|
58
|
-
|
59
|
-
# get region
|
60
|
-
#
|
61
|
-
# @param o [Hash] options
|
62
|
-
# @return String
|
63
|
-
def get_region(o)
|
64
|
-
return o[:region] if o[:region]
|
65
|
-
region = get_user_conf('region')
|
66
|
-
region.empty? ? 'default' : region
|
67
|
-
rescue
|
68
|
-
'default'
|
69
|
-
end
|
70
|
-
|
71
9
|
# make result string
|
72
10
|
#
|
73
11
|
# @param data [Hash]
|
@@ -86,7 +24,7 @@ module Idcf
|
|
86
24
|
# @param message [Hash] Validate Hash
|
87
25
|
# @return String
|
88
26
|
def output_format(o, message)
|
89
|
-
default_output = get_code_conf('output', o)
|
27
|
+
default_output = Idcf::Cli::Lib::Configure.get_code_conf('output', o)
|
90
28
|
if message.class == Hash && !message[:output].nil?
|
91
29
|
return default_output
|
92
30
|
end
|
@@ -94,6 +32,25 @@ module Idcf
|
|
94
32
|
f = o[:output]
|
95
33
|
f.nil? ? default_output : f
|
96
34
|
end
|
35
|
+
|
36
|
+
# cli error
|
37
|
+
#
|
38
|
+
# @param msg [Strring]
|
39
|
+
# @raise
|
40
|
+
def cli_error(msg)
|
41
|
+
raise Idcf::Cli::Error::CliError, msg
|
42
|
+
end
|
43
|
+
|
44
|
+
# make response base data
|
45
|
+
#
|
46
|
+
# @return Hash
|
47
|
+
def make_base_response
|
48
|
+
{
|
49
|
+
status: 200,
|
50
|
+
message: '',
|
51
|
+
data: []
|
52
|
+
}
|
53
|
+
end
|
97
54
|
end
|
98
55
|
end
|
99
56
|
end
|
@@ -45,6 +45,12 @@ module Idcf
|
|
45
45
|
load_validate(paths, o)
|
46
46
|
end
|
47
47
|
|
48
|
+
# load validate
|
49
|
+
#
|
50
|
+
# @param paths [Array]
|
51
|
+
# @param o [Hash] Validator
|
52
|
+
# @return class
|
53
|
+
# @raise
|
48
54
|
def load_validate(paths, o)
|
49
55
|
paths.each do |path|
|
50
56
|
begin
|
@@ -54,7 +60,7 @@ module Idcf
|
|
54
60
|
next
|
55
61
|
end
|
56
62
|
end
|
57
|
-
|
63
|
+
cli_error 'Validate load error'
|
58
64
|
end
|
59
65
|
|
60
66
|
# make validation error
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative './base'
|
2
|
-
require 'idcf/your'
|
3
2
|
|
4
3
|
module Idcf
|
5
4
|
module Cli
|
@@ -12,13 +11,6 @@ module Idcf
|
|
12
11
|
def description
|
13
12
|
'Your Service'
|
14
13
|
end
|
15
|
-
|
16
|
-
def make_blank_client
|
17
|
-
Idcf::Your::Client.new(
|
18
|
-
api_key: '',
|
19
|
-
secret_key: ''
|
20
|
-
)
|
21
|
-
end
|
22
14
|
end
|
23
15
|
|
24
16
|
protected
|
@@ -26,31 +18,6 @@ module Idcf
|
|
26
18
|
def make_table_data(data)
|
27
19
|
data['data']
|
28
20
|
end
|
29
|
-
|
30
|
-
def resource_classes
|
31
|
-
[
|
32
|
-
Idcf::Your::Response
|
33
|
-
]
|
34
|
-
end
|
35
|
-
|
36
|
-
def responce_classes
|
37
|
-
[
|
38
|
-
Idcf::Your::Response
|
39
|
-
]
|
40
|
-
end
|
41
|
-
|
42
|
-
# Create a new client
|
43
|
-
# @param o [Hash] other options
|
44
|
-
# @return [Response] Idcf::Ilb::Client
|
45
|
-
def make_client(o)
|
46
|
-
option = {
|
47
|
-
host: get_code_conf('your.v1.host', o),
|
48
|
-
verify_ssl: o.key?(:no_vssl) ? false : true
|
49
|
-
}
|
50
|
-
option.merge!(base_options(o))
|
51
|
-
|
52
|
-
Idcf::Your::Client.new(option)
|
53
|
-
end
|
54
21
|
end
|
55
22
|
end
|
56
23
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module Idcf
|
2
2
|
module Cli
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Error
|
4
|
+
# cli custom error
|
5
|
+
class CliError < StandardError
|
6
|
+
def message
|
7
|
+
msg = super
|
8
|
+
"#{Idcf::Cli::Conf::Const::LOCAL_ERROR_PREFIX}#{msg}"
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -8,22 +8,28 @@ module Idcf
|
|
8
8
|
module Configure
|
9
9
|
protected
|
10
10
|
|
11
|
-
|
11
|
+
# configure settings
|
12
|
+
#
|
13
|
+
# @param o [Hash]
|
14
|
+
# @param init_f [Boolean]
|
15
|
+
def do_configure(o, init_f = false)
|
12
16
|
path = configure_path(o)
|
13
17
|
config = Idcf::Cli::Lib::Util::IniConf.new(path)
|
14
|
-
profiles =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
config.write(path)
|
18
|
+
profiles = make_profiles(config, o)
|
19
|
+
cls = Idcf::Cli::Conf::Const
|
20
|
+
prefix = o[:global] ? 'global' : 'local'
|
21
|
+
configure_input(config, profiles, cls::USER_CONF_ITEMS, prefix).write(path)
|
22
|
+
|
23
|
+
global_setting if init_f
|
21
24
|
end
|
22
25
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
def make_profiles(config, o)
|
27
|
+
[].tap do |result|
|
28
|
+
if o[:profile] != 'default' && !check_profile?(config, 'default')
|
29
|
+
result << 'default'
|
30
|
+
end
|
31
|
+
result << o[:profile]
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
35
|
def check_profile?(config, name)
|
@@ -32,38 +38,37 @@ module Idcf
|
|
32
38
|
Idcf::Cli::Conf::Const::USER_CONF_ITEMS.each do |k, _v|
|
33
39
|
return false if conf[k.to_s].strip.empty?
|
34
40
|
end
|
35
|
-
|
36
41
|
true
|
37
42
|
end
|
38
43
|
|
39
|
-
def
|
44
|
+
def global_setting
|
45
|
+
cls = Idcf::Cli::Conf::Const
|
46
|
+
path = cls::USER_CONF_GLOBAL
|
47
|
+
config = Idcf::Cli::Lib::Util::IniConf.new(File.expand_path(path))
|
48
|
+
configure_input(config, ['default'], cls::GLOBAL_CONF_ITEMS).write(path)
|
49
|
+
end
|
50
|
+
|
51
|
+
def configure_path(o)
|
52
|
+
cls = Idcf::Cli::Conf::Const
|
53
|
+
result = o[:global] ? cls::USER_CONF_GLOBAL : cls::USER_CONF_PATH
|
54
|
+
File.expand_path(result)
|
55
|
+
end
|
56
|
+
|
57
|
+
def configure_input(config, profiles, items, prefix = 'global')
|
40
58
|
profiles.each do |profile|
|
41
59
|
dt = config[profile] || {}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
dt[
|
60
|
+
items.each do |k, v|
|
61
|
+
key_s = k.to_s
|
62
|
+
nd = dt[key_s].nil? ? setting_extraction(v, :default).to_s : dt[key_s]
|
63
|
+
dt[key_s] = Idcf::Cli::Lib::Util::Input.qa("#{prefix}[#{profile}]:#{k}", v, nd)
|
46
64
|
end
|
47
65
|
config[profile] = dt
|
48
66
|
end
|
49
67
|
config
|
50
68
|
end
|
51
69
|
|
52
|
-
def
|
53
|
-
|
54
|
-
puts msg
|
55
|
-
res = STDIN.gets.strip
|
56
|
-
next unless !res.empty? || !nd.empty?
|
57
|
-
result = res.empty? ? nd : res
|
58
|
-
return result if confirmation_at_qa_preference?(result, setting)
|
59
|
-
puts "from this [#{setting.join('/')}]"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def confirmation_at_qa_preference?(val, setting)
|
64
|
-
return true if setting.nil?
|
65
|
-
return true if Regexp.new("\\A(#{setting.join('|')})\\Z") =~ val
|
66
|
-
false
|
70
|
+
def setting_extraction(setting, key)
|
71
|
+
setting.class == Hash ? setting[key] : nil
|
67
72
|
end
|
68
73
|
end
|
69
74
|
end
|