idcfcloud 0.1.4 → 0.2.0
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.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a3321422f5844f5854dde7ff528e58f4ffda585
|
4
|
+
data.tar.gz: 7061912c1a39b1f141673fbc7b56b0e81f9b7d84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a14919f258cd60e092fc8c1ef466301b505032f41078e1ce76864a19f392c33d569f14297d860d5f5501fb8297d1d0b54190f33b9638ddcc656925e7846b1e38
|
7
|
+
data.tar.gz: 644f7237434d2a3e0ff7d3e89c70a30695c13e2480ee4624a1bd9cc6dd04987e299df7a0523edc168ced200e2e651a91b2b09a0a50bf631946663f82aa933e2c
|
data/.codeclimate.yml
CHANGED
data/.gitignore
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
/output/
|
13
13
|
/config/config.ini
|
14
14
|
/lib/idcf/cli/conf/service/*.yml
|
15
|
+
/lib/idcf/cli/conf/service/*.json
|
15
16
|
|
16
17
|
.idea/*
|
17
18
|
*.iml
|
@@ -38,7 +39,7 @@ build-iPhoneSimulator/
|
|
38
39
|
## Documentation cache and generated files:
|
39
40
|
/.yardoc/
|
40
41
|
/_yardoc/
|
41
|
-
/doc
|
42
|
+
/doc/*
|
42
43
|
/rdoc/
|
43
44
|
|
44
45
|
## Environment normalization:
|
@@ -48,9 +49,10 @@ build-iPhoneSimulator/
|
|
48
49
|
|
49
50
|
# for a library or gem, you might want to ignore these files since the code is
|
50
51
|
# intended to run in multiple environments; otherwise, check them in:
|
51
|
-
|
52
|
-
|
52
|
+
Gemfile.lock
|
53
|
+
.ruby-version
|
53
54
|
# .ruby-gemset
|
55
|
+
.DS_Store
|
54
56
|
|
55
57
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
56
58
|
.rvmrc
|
data/.rubocop.yml
CHANGED
@@ -8,6 +8,7 @@ Metrics/LineLength:
|
|
8
8
|
Exclude:
|
9
9
|
- 'test/**/*'
|
10
10
|
Metrics/MethodLength:
|
11
|
+
Max: 14
|
11
12
|
Exclude:
|
12
13
|
- 'test/**/*'
|
13
14
|
Metrics/ClassLength:
|
@@ -23,4 +24,18 @@ Metrics/AbcSize:
|
|
23
24
|
Exclude:
|
24
25
|
- 'test/**/*'
|
25
26
|
LineLength:
|
26
|
-
Max: 100
|
27
|
+
Max: 100
|
28
|
+
Exclude:
|
29
|
+
- 'test/**/*'
|
30
|
+
Style/ClassLength:
|
31
|
+
Max: 130
|
32
|
+
Exclude:
|
33
|
+
- 'test/**/*'
|
34
|
+
Style/ModuleLength:
|
35
|
+
Max: 150
|
36
|
+
Exclude:
|
37
|
+
- 'test/**/*'
|
38
|
+
ParameterLists:
|
39
|
+
Max: 6
|
40
|
+
Style/DoubleNegation:
|
41
|
+
Enabled: false
|
data/README.md
CHANGED
@@ -35,20 +35,56 @@ $ idcfcloud <serviceName> <command> [attributes] [option]
|
|
35
35
|
|
36
36
|
If you want to set more than one attribute, use the json form.
|
37
37
|
|
38
|
-
```ex)
|
38
|
+
``` ex)
|
39
39
|
'{"ipaddress": "0.0.0.0", "port": 80}'
|
40
40
|
```
|
41
41
|
|
42
|
+
Or you can also define the GET or POST parameter in the JSON file and hand it using xargs.
|
43
|
+
|
44
|
+
``` ex) xargs
|
45
|
+
cat [attributes file path] | echo -e "'"$(cat)"'" | xargs -L1 idcfcloud <serviceName> <command> [option]
|
46
|
+
```
|
47
|
+
|
48
|
+
### Service Options
|
49
|
+
|
50
|
+
| option | alias | default | note |
|
51
|
+
|:---|:---|:---|:---|
|
52
|
+
| output | o | json | Output formats (table/json/xml/csv) |
|
53
|
+
| profile | | default | Switching profiles |
|
54
|
+
| api-key | | [Configuration file description] | API Key |
|
55
|
+
| secret-key | | [Configuration file description] | Secret Key |
|
56
|
+
| no-ssl | | | Not using SSL |
|
57
|
+
| no-vssl | | | Not using Verify SSL |
|
58
|
+
| json-path | | | Narrowing the data part of a return value using json-path<br/>https://github.com/joshbuddy/jsonpath |
|
59
|
+
| fields | | | Limiting the return value to be displayed (applied only to the latest hash)<br/>Punctuation: comma (",") |
|
60
|
+
|
61
|
+
|
62
|
+
#### How to Narrow Down (Examples)
|
63
|
+
```
|
64
|
+
idcfcloud your list_billing_history --json-path '$.data[?(@.month=="2017-10")]' --fields month,billing_amount
|
65
|
+
```
|
66
|
+
|
42
67
|
## ServiceName
|
68
|
+
[Compute](#compute)
|
69
|
+
|
43
70
|
[ILB](#ilb)
|
44
71
|
|
72
|
+
[CDN](#cdn)
|
73
|
+
|
74
|
+
[DNS](#dns)
|
75
|
+
|
45
76
|
[Your](#your)
|
46
77
|
|
47
|
-
|
78
|
+
### Compute(Bata)<a name="compute"></a>
|
79
|
+
\* If you encounter any problem, please contact us or file a pull request.
|
80
|
+
|
81
|
+
http://docs.idcf.jp/cloud/api/
|
82
|
+
|
83
|
+
### ILB<a name="ilb"></a>
|
48
84
|
|
49
85
|
https://github.com/idcf/idcf-ilb-ruby
|
50
86
|
|
51
|
-
|
87
|
+
#### ILB Extend Commands
|
52
88
|
|
53
89
|
add server
|
54
90
|
|
@@ -67,17 +103,36 @@ delete server
|
|
67
103
|
$ idcfcloud ilb delete_server_for_protocol <lb_id> <protocol> <protocol_port> <data> [option]
|
68
104
|
```
|
69
105
|
|
70
|
-
|
106
|
+
check_job
|
71
107
|
|
72
|
-
|
108
|
+
``` code
|
109
|
+
$ idcfcloud ilb check_job <job_id>
|
110
|
+
```
|
111
|
+
|
112
|
+
sslalgorithms_ids
|
113
|
+
|
114
|
+
``` code
|
115
|
+
$ idcfcloud ilb sslalgorithms_ids
|
116
|
+
```
|
117
|
+
|
118
|
+
### CDN<a name="cdn"></a>
|
119
|
+
|
120
|
+
https://www.idcf.jp/help/cache/docs/pdf/cache_api.pdf?cl=rd_0046
|
121
|
+
|
122
|
+
### DNS<a name="dns"></a>
|
73
123
|
|
124
|
+
http://docs.idcf.jp/cloud/dns/#s_fid=4FEB16B56007BA5C-0BFB42ABA668ADA8
|
125
|
+
|
126
|
+
### Your<a name="your"></a>
|
127
|
+
|
128
|
+
http://docs.idcf.jp/cloud/billing/
|
74
129
|
|
75
130
|
## Development
|
76
131
|
|
77
132
|
Running the following test code is possible, but not recommended nor supported. Run only a code of a target.
|
78
133
|
|
79
134
|
```code
|
80
|
-
$ bundle exec ruby test/run_test.rb idcf/cli/controller/
|
135
|
+
$ bundle exec ruby test/run_test.rb idcf/cli/controller/test_your.rb
|
81
136
|
```
|
82
137
|
|
83
138
|
In order to avoid collapsed setting in ILB, make sure you understand how things work before running a code.
|
data/exe/idcfcloud
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
require 'idcf/cli/index'
|
2
2
|
|
3
|
-
|
3
|
+
if ARGV[0] && %w(morio).include?(ARGV[0].downcase)
|
4
|
+
cls = "idcf/cli/command/#{ARGV[0].downcase}"
|
5
|
+
require cls
|
6
|
+
cls.classify.constantize.new.exec
|
7
|
+
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
Idcf::Cli::Index.init(ARGV)
|
4
12
|
Idcf::Cli::Index.start(ARGV)
|
data/idcfcloud.gemspec
CHANGED
@@ -26,18 +26,20 @@ Gem::Specification.new do |spec|
|
|
26
26
|
|
27
27
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
28
28
|
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'test-unit', '~> 3.2', '>= 3.2.5'
|
30
|
+
spec.add_development_dependency 'test-unit-notify', '~> 1.0', '>= 1.0.4'
|
29
31
|
|
30
|
-
spec.add_dependency '
|
31
|
-
spec.add_dependency 'test-unit-notify', '~> 1.0', '>= 1.0.4'
|
32
|
-
|
33
|
-
spec.add_dependency 'activerecord', '~> 4.2', '>= 4.2.3'
|
32
|
+
spec.add_dependency 'activemodel', '~> 4.2', '>= 4.2.3'
|
34
33
|
spec.add_dependency 'activesupport', '~> 4.2', '>= 4.2.3'
|
35
34
|
spec.add_dependency 'inifile', '~> 3.0', '>= 3.0.0'
|
36
35
|
spec.add_dependency 'thor', '~> 0.19.4'
|
37
36
|
spec.add_dependency 'builder', '~> 3.1'
|
38
37
|
spec.add_dependency 'kosi', '~> 1.0', '>= 1.0.0'
|
39
38
|
|
40
|
-
spec.add_dependency '
|
41
|
-
spec.add_dependency 'idcf-
|
42
|
-
spec.add_dependency 'idcf-
|
39
|
+
spec.add_dependency 'open_uri_redirections', '~> 0.2.1'
|
40
|
+
spec.add_dependency 'idcf-json_hyper_schema', '~> 0.1.0'
|
41
|
+
spec.add_dependency 'idcf-faraday_middleware', '~> 0.0.2'
|
42
|
+
spec.add_dependency 'jsonpath', '~> 0.8.10'
|
43
|
+
spec.add_dependency 'facter', '~> 2.5.1'
|
44
|
+
spec.add_dependency 'CFPropertyList', '~> 2.3.5'
|
43
45
|
end
|
data/lib/idcf/cli/conf/conf.yml
CHANGED
@@ -1,10 +1,44 @@
|
|
1
1
|
output: json #json xml csv table
|
2
|
+
log_limit: 20
|
2
3
|
ilb:
|
3
4
|
v1:
|
4
|
-
|
5
|
-
jp-east:
|
6
|
-
|
7
|
-
|
5
|
+
region:
|
6
|
+
jp-east:
|
7
|
+
schema: https://ilb.jp-east.idcfcloud.com/api/v1/schema
|
8
|
+
host: ilb.jp-east.idcfcloud.com
|
9
|
+
jp-east-2:
|
10
|
+
schema: https://ilb.jp-east-2.idcfcloud.com/api/v1/schema
|
11
|
+
host: ilb.jp-east-2.idcfcloud.com
|
12
|
+
jp-west:
|
13
|
+
schema: https://ilb.jp-west.idcfcloud.com/api/v1/schema
|
14
|
+
host: ilb.jp-west.idcfcloud.com
|
8
15
|
your:
|
9
16
|
v1:
|
10
|
-
|
17
|
+
region:
|
18
|
+
default:
|
19
|
+
schema: https://your.idcfcloud.com/api/v1/schema
|
20
|
+
host: your.idcfcloud.com
|
21
|
+
cdn:
|
22
|
+
v0:
|
23
|
+
region:
|
24
|
+
default:
|
25
|
+
schema: https://cdn.idcfcloud.com/api/v1/schema
|
26
|
+
host: cdn.idcfcloud.com
|
27
|
+
dns:
|
28
|
+
v1:
|
29
|
+
region:
|
30
|
+
default:
|
31
|
+
schema: https://dns.idcfcloud.com/api/v1/schema
|
32
|
+
host: dns.idcfcloud.com
|
33
|
+
compute:
|
34
|
+
v1:
|
35
|
+
region:
|
36
|
+
jp-east:
|
37
|
+
schema: https://compute.jp-east.idcfcloud.com/api/v1/schema
|
38
|
+
host: compute.jp-east.idcfcloud.com
|
39
|
+
jp-east-2:
|
40
|
+
schema: https://compute.jp-east-2.idcfcloud.com/api/v1/schema
|
41
|
+
host: compute.jp-east-2.idcfcloud.com
|
42
|
+
jp-west:
|
43
|
+
schema: https://compute.jp-west.idcfcloud.com/api/v1/schema
|
44
|
+
host: compute.jp-west.idcfcloud.com
|
data/lib/idcf/cli/conf/const.rb
CHANGED
@@ -1,36 +1,61 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'logger'
|
3
|
+
require 'idcf/cli/version'
|
1
4
|
module Idcf
|
2
5
|
module Cli
|
3
6
|
module Conf
|
4
7
|
# const
|
5
8
|
class Const
|
9
|
+
VERSION_STR = "idcfcloud version #{Idcf::Cli::VERSION}".freeze
|
10
|
+
now = DateTime.now.strftime('%Y%m%d%H%M%S%6N')
|
6
11
|
dir_path = File.dirname(__FILE__)
|
7
12
|
BASE_PATH = File.expand_path("#{dir_path}/../../../")
|
8
13
|
LOCAL_ERROR_PREFIX = '[idcfcli]'.freeze
|
9
|
-
HEADERS =
|
10
|
-
|
11
|
-
|
14
|
+
HEADERS =
|
15
|
+
{
|
16
|
+
'User-Agent': "IDCF CLI v#{Idcf::Cli::VERSION}"
|
17
|
+
}.freeze
|
18
|
+
USER_DIR_PATH = '~/.idcfcloud'.freeze
|
12
19
|
VALIDATOR_DIR_PATH = 'idcf/cli/validate/define'.freeze
|
13
20
|
CODE_CONF_PATH = "#{BASE_PATH}/idcf/cli/conf/conf.yml".freeze
|
14
|
-
USER_CONF_PATH =
|
21
|
+
USER_CONF_PATH = "#{USER_DIR_PATH}/config.ini".freeze
|
15
22
|
USER_CONF_GLOBAL = "#{BASE_PATH}/../config/config.ini".freeze
|
16
23
|
REGIONS = %w(jp-east jp-east-2 jp-west).freeze
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
GLOBAL_CONF_ITEMS =
|
25
|
+
{
|
26
|
+
output_log: {
|
27
|
+
default: 'Y',
|
28
|
+
list: %w(Y n)
|
29
|
+
},
|
30
|
+
log_path: {
|
31
|
+
default: '~/.idcfcloud/log'
|
32
|
+
}
|
33
|
+
}.freeze
|
34
|
+
USER_CONF_ITEMS =
|
35
|
+
{
|
36
|
+
api_key: nil,
|
37
|
+
secret_key: nil,
|
38
|
+
region: {
|
39
|
+
list: REGIONS
|
40
|
+
}
|
41
|
+
}.freeze
|
42
|
+
FULL_HREF_REGEXP = Regexp.new('\A[a-zA-Z]*:?//').freeze
|
22
43
|
CMD_FILE_DIR = "#{BASE_PATH}/idcf/cli/conf/service".freeze
|
23
|
-
CMD_FILE_EXT = '
|
44
|
+
CMD_FILE_EXT = 'json'.freeze
|
24
45
|
SERVICE_PATH = 'idcf/cli/service'.freeze
|
25
46
|
TEMPLATE_DIR = "#{BASE_PATH}/idcf/cli/templates".freeze
|
26
47
|
OUT_DIR = "#{BASE_PATH}/../output".freeze
|
27
|
-
|
28
|
-
|
29
|
-
~/.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
48
|
+
COMP_PATHS = {
|
49
|
+
bash: '~/.bash_profile',
|
50
|
+
zsh: '~/.zprofile'
|
51
|
+
}.freeze
|
52
|
+
LOG_FILE_PREFIX = 'cli_log_'.freeze
|
53
|
+
LOG_FILE_NAME = "#{LOG_FILE_PREFIX}#{now}.log".freeze
|
54
|
+
LOG_LEVEL = Logger::INFO.freeze
|
55
|
+
CLASSIFY_RULE = [
|
56
|
+
%w(sslalgorithms_ids SslalgorithmsIds),
|
57
|
+
%w(dns Dns)
|
58
|
+
].freeze
|
34
59
|
end
|
35
60
|
end
|
36
61
|
end
|
@@ -3,12 +3,14 @@ require 'json'
|
|
3
3
|
require 'active_support'
|
4
4
|
require 'active_support/core_ext'
|
5
5
|
require 'idcf/cli/conf/const'
|
6
|
-
require 'idcf/cli/lib/util/ini_conf'
|
7
|
-
require 'idcf/cli/lib/util/yml_conf'
|
8
|
-
require 'active_record'
|
9
6
|
require 'idcf/cli/lib/convert/helper'
|
7
|
+
require 'idcf/json_hyper_schema'
|
8
|
+
require 'idcf/json_hyper_schema/expands/link_info_base'
|
9
|
+
require 'idcf/cli/gem_ext/idcf/json_hyper_schema/expands/link_info_base_extension'
|
10
10
|
require_relative './extend/init'
|
11
11
|
require_relative './include/init'
|
12
|
+
require 'jsonpath'
|
13
|
+
require 'idcf/cli/lib/include/recurring_calling'
|
12
14
|
|
13
15
|
module Idcf
|
14
16
|
module Cli
|
@@ -32,105 +34,173 @@ module Idcf
|
|
32
34
|
desc: 'not use ssl'
|
33
35
|
class_option :no_vssl,
|
34
36
|
desc: 'not use verify ssl'
|
37
|
+
class_option :json_path,
|
38
|
+
desc: 'data filter json_path'
|
39
|
+
class_option :fields,
|
40
|
+
desc: 'field filter'
|
35
41
|
|
36
42
|
attr_reader :config, :code_conf, :cmd, :m_classes
|
37
43
|
|
38
44
|
extend Idcf::Cli::Controller::Extend::Init
|
39
45
|
include Idcf::Cli::Controller::Include::Init
|
46
|
+
include Idcf::Cli::Lib::Include::RecurringCalling
|
40
47
|
|
41
48
|
class << self
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
register_sdk_method! cf.find('')
|
49
|
+
attr_accessor :links
|
50
|
+
|
51
|
+
def init(argv)
|
52
|
+
o = Thor::Options.new(class_options).parse(argv)
|
53
|
+
register_schema_method(o)
|
54
|
+
|
55
|
+
make_module_classes.each do |cn, c|
|
56
|
+
register_module_method!(cn, c)
|
51
57
|
end
|
58
|
+
end
|
52
59
|
|
53
|
-
|
60
|
+
def register_schema_method(o)
|
61
|
+
path = make_schema_path(o)
|
62
|
+
|
63
|
+
return nil unless File.exist?(path)
|
64
|
+
|
65
|
+
analyst = Idcf::JsonHyperSchema::Analyst.new
|
66
|
+
@links = analyst.load(path).links
|
67
|
+
@links.each do |link|
|
68
|
+
register_schema_method_by_link!(link)
|
69
|
+
end
|
54
70
|
end
|
55
71
|
|
56
|
-
#
|
72
|
+
# service name
|
57
73
|
#
|
58
|
-
# @
|
59
|
-
def
|
60
|
-
|
61
|
-
methods.each do |command, s|
|
62
|
-
register_method!(command, s[:params], s[:options])
|
63
|
-
end
|
74
|
+
# @return String
|
75
|
+
def service_name
|
76
|
+
name.underscore.split('/').last
|
64
77
|
end
|
65
78
|
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
79
|
+
# service version
|
80
|
+
#
|
81
|
+
# @param o [Hash]
|
82
|
+
# @return String
|
83
|
+
def service_version(o)
|
84
|
+
sn = service_name
|
85
|
+
list = Idcf::Cli::Lib::Configure.get_code_conf(sn, o)
|
86
|
+
result = o[:version].nil? ? list.keys.last : o[:version]
|
87
|
+
msg = "not found input version[#{o[:version]}]"
|
88
|
+
raise Idcf::Cli::Error::CliError, msg unless list.keys.include?(result)
|
89
|
+
result
|
71
90
|
end
|
72
91
|
end
|
73
92
|
|
74
93
|
protected
|
75
94
|
|
76
95
|
def execute(cmd, *args)
|
77
|
-
data = run(cmd, args)
|
96
|
+
data = run(cmd, args, options)
|
78
97
|
puts make_result_str(data, false, options)
|
98
|
+
Idcf::Cli::Lib::Util::CliLogger.delete
|
99
|
+
Idcf::Cli::Lib::Util::CliLogger.cleaning(options)
|
79
100
|
rescue => e
|
80
|
-
|
81
|
-
exit 1
|
101
|
+
self.class.error_exit(e)
|
82
102
|
end
|
83
103
|
|
84
|
-
def run(cmd, args)
|
104
|
+
def run(cmd, args, o)
|
85
105
|
@cmd = cmd
|
86
|
-
check_params(self.class.make_module_classes, cmd, *args)
|
87
|
-
o = options
|
88
106
|
data = do_validate(o)
|
89
|
-
if data
|
90
|
-
|
91
|
-
exit 1
|
92
|
-
end
|
107
|
+
raise Idcf::Cli::Error::CliError, data[:message].flatten if data
|
108
|
+
|
93
109
|
data = make_result_data(do_command(cmd, *args, o), o)
|
94
110
|
data
|
95
111
|
end
|
96
112
|
|
113
|
+
# do command
|
114
|
+
#
|
115
|
+
# @param cmd [String]
|
116
|
+
# @param *args [Array]
|
117
|
+
# @param o [Hash]
|
118
|
+
# @return Mixed
|
119
|
+
# @raise
|
97
120
|
def do_command(cmd, *args, o)
|
98
|
-
|
121
|
+
self_class = self.class
|
122
|
+
s_class = self_class.search_module_class(cmd)
|
99
123
|
|
100
124
|
arg = convert_arg_json(*args)
|
101
|
-
client = make_client(o)
|
102
|
-
|
103
|
-
|
125
|
+
client = make_client(o, self_class.get_region(o))
|
126
|
+
api = Idcf::Cli::Lib::Api.new(links: self_class.links, client: client)
|
127
|
+
return do_service(s_class, api, o, arg) unless s_class.nil?
|
128
|
+
do_api(cmd, api, o, arg)
|
104
129
|
end
|
105
130
|
|
106
|
-
#
|
131
|
+
# do service
|
107
132
|
#
|
108
|
-
# @
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
133
|
+
# @param service_class [Idcf::Cli::Service::Base]
|
134
|
+
# @param api [Idcf::Cli::Lib::Api]
|
135
|
+
# @param arg [Array]
|
136
|
+
# @param o [Hash]
|
137
|
+
# @return Mixed
|
138
|
+
# @raise
|
139
|
+
def do_service(service_class, api, o, arg)
|
140
|
+
obj = service_class.new
|
141
|
+
obj.between_param?(arg.size)
|
142
|
+
result = obj.do(api, o, *arg)
|
143
|
+
return result if obj.last_command.empty?
|
144
|
+
do_api(obj.last_command, api, o, obj.last_command_args)
|
115
145
|
end
|
116
146
|
|
117
|
-
#
|
147
|
+
# do api
|
118
148
|
#
|
119
|
-
# @param
|
120
|
-
# @
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
result
|
127
|
-
|
149
|
+
# @param cmd [String]
|
150
|
+
# @param api [Idcf::Cli::Lib::Api]
|
151
|
+
# @param arg [Array]
|
152
|
+
# @param o [Hash]
|
153
|
+
# @return Mixed
|
154
|
+
# @raise
|
155
|
+
def do_api(cmd, api, o, arg)
|
156
|
+
result = api_result(api.do(cmd, *arg))
|
157
|
+
link = api.find_link(cmd)
|
158
|
+
resource = link.async? ? do_async(api, result, o, link) : nil
|
159
|
+
sync_result = api.result_api(cmd, arg, result, async_id(resource))
|
160
|
+
return sync_result if sync_result
|
161
|
+
link.async? ? resource : result
|
162
|
+
rescue Idcf::Cli::Error::ApiError => e
|
163
|
+
raise e, raise_api_error_msg(e)
|
164
|
+
end
|
165
|
+
|
166
|
+
def api_result(val)
|
167
|
+
val
|
168
|
+
end
|
169
|
+
|
170
|
+
def async_id(resource)
|
171
|
+
return resource['resource_id'] if !resource.nil? && resource.class == Hash
|
172
|
+
nil
|
173
|
+
end
|
174
|
+
|
175
|
+
# do_async
|
176
|
+
#
|
177
|
+
# @param _api [Idcf::Cli::Lib::Api]
|
178
|
+
# @param _api_result [Mixed]
|
179
|
+
# @param _o [Hash]
|
180
|
+
# @param _executed_link [Idcf::JsonHyperSchema::Expands::LinkInfoBase]
|
181
|
+
# @result Mixed
|
182
|
+
def do_async(_api, _api_result, _o, _executed_link)
|
183
|
+
nil
|
184
|
+
end
|
185
|
+
|
186
|
+
# raise api error msg
|
187
|
+
#
|
188
|
+
# @param res [Faraday::Responce]
|
189
|
+
# @return [String]
|
190
|
+
def raise_api_error_msg(res)
|
191
|
+
"HTTP status code: #{res.status}, " \
|
192
|
+
"Error message: #{res.body['message']}, " \
|
193
|
+
"Reference: #{res.body['reference']}"
|
128
194
|
end
|
129
195
|
|
130
196
|
def make_result_data(data, o)
|
131
|
-
|
132
|
-
|
133
|
-
|
197
|
+
format = output_format(o, '')
|
198
|
+
table_flag = %w(csv table).include?(format)
|
199
|
+
helper = Idcf::Cli::Lib::Convert::Helper.new
|
200
|
+
|
201
|
+
if helper.filter_target?(o)
|
202
|
+
result = helper.filter(data, o, table_flag)
|
203
|
+
elsif table_flag
|
134
204
|
result = make_table_data(data)
|
135
205
|
else
|
136
206
|
result = make_base_response
|
@@ -1,38 +1,40 @@
|
|
1
1
|
require 'idcf/cli/conf/const'
|
2
|
+
require 'idcf/cli/lib/api'
|
2
3
|
module Idcf
|
3
4
|
module Cli
|
4
5
|
module Controller
|
5
6
|
module Extend
|
6
7
|
# command
|
7
8
|
module Command
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
# register schema method by link
|
10
|
+
#
|
11
|
+
# @param link [Idcf::JsonHyperSchema::Expands::LinkInfoBase]
|
12
|
+
def register_schema_method_by_link!(link)
|
13
|
+
param_str = Idcf::Cli::Lib::Api.command_param_str(link)
|
14
|
+
method_desc = "#{link.title} #{param_str}"
|
15
|
+
desc method_desc.strip, link.description
|
16
|
+
define_method link.title.to_sym do |*args|
|
13
17
|
execute(__method__, *args)
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
17
|
-
#
|
21
|
+
# register module mothod
|
18
22
|
#
|
19
|
-
# @param
|
20
|
-
# @
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
cp << format(f, param[:name])
|
23
|
+
# @param name [String] command_name
|
24
|
+
# @param cls [Idcf::Cli::Service::Base]
|
25
|
+
def register_module_method!(name, cls)
|
26
|
+
register_method_option! cls.options
|
27
|
+
desc "#{name} #{cls.make_param_s}", cls.description
|
28
|
+
define_method name.to_sym do |*args|
|
29
|
+
execute(__method__, *args)
|
27
30
|
end
|
28
|
-
cp.join(' ')
|
29
31
|
end
|
30
32
|
|
31
33
|
# regist method option
|
32
34
|
#
|
33
35
|
# @param values [Hash] name => desc
|
34
36
|
def register_method_option!(values)
|
35
|
-
return if values.nil?
|
37
|
+
return nil if values.nil?
|
36
38
|
values.each do |opn, op|
|
37
39
|
option = {}
|
38
40
|
op.each do |ok, ov|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative './override'
|
2
2
|
require_relative './search_module'
|
3
3
|
require_relative './command'
|
4
|
+
require_relative './util'
|
4
5
|
module Idcf
|
5
6
|
module Cli
|
6
7
|
module Controller
|
@@ -10,6 +11,7 @@ module Idcf
|
|
10
11
|
include Override
|
11
12
|
include SearchModule
|
12
13
|
include Command
|
14
|
+
include Util
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|