MuranoCLI 2.2.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.agignore +3 -0
- data/.gitignore +18 -1
- data/.rubocop.yml +222 -0
- data/.trustme.sh +185 -0
- data/.trustme.vim +24 -0
- data/Gemfile +23 -4
- data/LICENSE.txt +1 -1
- data/MuranoCLI.gemspec +43 -8
- data/README.markdown +9 -11
- data/Rakefile +187 -143
- data/TODO.taskpaper +2 -2
- data/bin/murano +51 -52
- data/docs/basic_example.rst +436 -0
- data/docs/completions/murano_completion-bash +3484 -0
- data/docs/demo.md +32 -32
- data/docs/develop.rst +391 -0
- data/lib/MrMurano.rb +21 -7
- data/lib/MrMurano/Account.rb +159 -174
- data/lib/MrMurano/Business.rb +381 -0
- data/lib/MrMurano/Config-Migrate.rb +32 -26
- data/lib/MrMurano/Config.rb +407 -128
- data/lib/MrMurano/Content.rb +191 -0
- data/lib/MrMurano/Gateway.rb +489 -0
- data/lib/MrMurano/Keystore.rb +48 -0
- data/lib/MrMurano/Passwords.rb +103 -0
- data/lib/MrMurano/ProjectFile.rb +121 -79
- data/lib/MrMurano/ReCommander.rb +114 -10
- data/lib/MrMurano/Setting.rb +90 -0
- data/lib/MrMurano/Solution-ServiceConfig.rb +89 -45
- data/lib/MrMurano/Solution-Services.rb +461 -166
- data/lib/MrMurano/Solution-Users.rb +70 -31
- data/lib/MrMurano/Solution.rb +372 -13
- data/lib/MrMurano/SolutionId.rb +73 -0
- data/lib/MrMurano/SyncRoot.rb +137 -0
- data/lib/MrMurano/SyncUpDown.rb +594 -284
- data/lib/MrMurano/Webservice-Cors.rb +71 -0
- data/lib/MrMurano/Webservice-Endpoint.rb +234 -0
- data/lib/MrMurano/Webservice-File.rb +193 -0
- data/lib/MrMurano/Webservice.rb +51 -0
- data/lib/MrMurano/commands.rb +18 -15
- data/lib/MrMurano/commands/business.rb +300 -6
- data/lib/MrMurano/commands/completion-bash.erb +166 -0
- data/lib/MrMurano/commands/{zshcomplete.erb → completion-zsh.erb} +0 -0
- data/lib/MrMurano/commands/completion.rb +76 -39
- data/lib/MrMurano/commands/config.rb +108 -44
- data/lib/MrMurano/commands/content.rb +115 -72
- data/lib/MrMurano/commands/cors.rb +29 -14
- data/lib/MrMurano/commands/devices.rb +286 -0
- data/lib/MrMurano/commands/domain.rb +52 -12
- data/lib/MrMurano/commands/gb.rb +24 -9
- data/lib/MrMurano/commands/globals.rb +64 -0
- data/lib/MrMurano/commands/init.rb +377 -155
- data/lib/MrMurano/commands/keystore.rb +92 -82
- data/lib/MrMurano/commands/link.rb +300 -0
- data/lib/MrMurano/commands/login.rb +74 -11
- data/lib/MrMurano/commands/logs.rb +63 -32
- data/lib/MrMurano/commands/mock.rb +57 -29
- data/lib/MrMurano/commands/password.rb +57 -39
- data/lib/MrMurano/commands/postgresql.rb +127 -94
- data/lib/MrMurano/commands/settings.rb +203 -0
- data/lib/MrMurano/commands/show.rb +79 -38
- data/lib/MrMurano/commands/solution.rb +423 -5
- data/lib/MrMurano/commands/solution_picker.rb +547 -0
- data/lib/MrMurano/commands/status.rb +195 -61
- data/lib/MrMurano/commands/sync.rb +78 -39
- data/lib/MrMurano/commands/timeseries.rb +71 -55
- data/lib/MrMurano/commands/tsdb.rb +113 -87
- data/lib/MrMurano/commands/usage.rb +57 -15
- data/lib/MrMurano/hash.rb +100 -10
- data/lib/MrMurano/http.rb +187 -43
- data/lib/MrMurano/makePretty.rb +16 -14
- data/lib/MrMurano/optparse.rb +2178 -0
- data/lib/MrMurano/progress.rb +138 -0
- data/lib/MrMurano/schema/resource-v1.0.0.yaml +32 -0
- data/lib/MrMurano/template/projectFile.murano.erb +16 -13
- data/lib/MrMurano/verbosing.rb +166 -29
- data/lib/MrMurano/version.rb +30 -1
- data/spec/Account-Passwords_spec.rb +21 -4
- data/spec/Account_spec.rb +69 -146
- data/spec/Business_spec.rb +290 -0
- data/spec/ConfigFile_spec.rb +1 -0
- data/spec/ConfigMigrate_spec.rb +12 -8
- data/spec/Config_spec.rb +40 -34
- data/spec/Content_spec.rb +363 -0
- data/spec/GatewayBase_spec.rb +54 -0
- data/spec/GatewayDevice_spec.rb +321 -0
- data/spec/GatewayResource_spec.rb +266 -0
- data/spec/GatewaySettings_spec.rb +120 -0
- data/spec/Http_spec.rb +18 -8
- data/spec/Mock_spec.rb +2 -2
- data/spec/ProjectFile_spec.rb +25 -14
- data/spec/Setting_spec.rb +110 -0
- data/spec/Solution-ServiceConfig_spec.rb +44 -5
- data/spec/Solution-ServiceEventHandler_spec.rb +23 -14
- data/spec/Solution-ServiceModules_spec.rb +47 -37
- data/spec/Solution-UsersRoles_spec.rb +10 -8
- data/spec/Solution_spec.rb +17 -8
- data/spec/SyncRoot_spec.rb +46 -20
- data/spec/SyncUpDown_spec.rb +437 -201
- data/spec/Verbosing_spec.rb +12 -4
- data/spec/{Solution-Cors_spec.rb → Webservice-Cors_spec.rb} +23 -20
- data/spec/{Solution-Endpoint_spec.rb → Webservice-Endpoint_spec.rb} +43 -41
- data/spec/{Solution-File_spec.rb → Webservice-File_spec.rb} +44 -33
- data/spec/Webservice-Setting_spec.rb +89 -0
- data/spec/_workspace.rb +4 -4
- data/spec/cmd_business_spec.rb +9 -4
- data/spec/cmd_common.rb +44 -1
- data/spec/cmd_content_spec.rb +43 -17
- data/spec/cmd_cors_spec.rb +4 -4
- data/spec/cmd_device_spec.rb +61 -16
- data/spec/cmd_domain_spec.rb +29 -6
- data/spec/cmd_init_spec.rb +281 -126
- data/spec/cmd_keystore_spec.rb +3 -3
- data/spec/cmd_link_spec.rb +98 -0
- data/spec/cmd_password_spec.rb +1 -1
- data/spec/cmd_setting_application_spec.rb +260 -0
- data/spec/cmd_setting_product_spec.rb +220 -0
- data/spec/cmd_status_spec.rb +223 -114
- data/spec/cmd_syncdown_spec.rb +115 -35
- data/spec/cmd_syncup_spec.rb +68 -15
- data/spec/cmd_usage_spec.rb +35 -8
- data/spec/fixtures/dumped_config +6 -4
- data/spec/fixtures/gateway_resource_files/resources.notyaml +12 -0
- data/spec/fixtures/gateway_resource_files/resources.yaml +13 -0
- data/spec/fixtures/gateway_resource_files/resources_invalid.yaml +13 -0
- data/spec/fixtures/mrmuranorc_deleted_bob +0 -2
- data/spec/fixtures/product_spec_files/lightbulb.yaml +20 -13
- data/spec/fixtures/{syncable_content → syncable_conflict}/services/devdata.lua +1 -1
- data/spec/fixtures/{syncable_content → syncable_conflict}/services/timers.lua +0 -0
- data/spec/spec_helper.rb +5 -0
- metadata +262 -171
- data/bin/mr +0 -8
- data/lib/MrMurano/Product-1P-Device.rb +0 -145
- data/lib/MrMurano/Product-Resources.rb +0 -205
- data/lib/MrMurano/Product.rb +0 -358
- data/lib/MrMurano/Solution-Cors.rb +0 -47
- data/lib/MrMurano/Solution-Endpoint.rb +0 -191
- data/lib/MrMurano/Solution-File.rb +0 -166
- data/lib/MrMurano/commands/assign.rb +0 -57
- data/lib/MrMurano/commands/businessList.rb +0 -45
- data/lib/MrMurano/commands/product.rb +0 -14
- data/lib/MrMurano/commands/productCreate.rb +0 -39
- data/lib/MrMurano/commands/productDelete.rb +0 -33
- data/lib/MrMurano/commands/productDevice.rb +0 -87
- data/lib/MrMurano/commands/productDeviceIdCmds.rb +0 -89
- data/lib/MrMurano/commands/productList.rb +0 -45
- data/lib/MrMurano/commands/productWrite.rb +0 -27
- data/lib/MrMurano/commands/solutionCreate.rb +0 -41
- data/lib/MrMurano/commands/solutionDelete.rb +0 -34
- data/lib/MrMurano/commands/solutionList.rb +0 -45
- data/spec/ProductBase_spec.rb +0 -113
- data/spec/ProductContent_spec.rb +0 -162
- data/spec/ProductResources_spec.rb +0 -329
- data/spec/Product_1P_Device_spec.rb +0 -202
- data/spec/Product_1P_RPC_spec.rb +0 -175
- data/spec/Product_spec.rb +0 -153
- data/spec/Solution-ServiceDevice_spec.rb +0 -176
- data/spec/cmd_assign_spec.rb +0 -51
data/lib/MrMurano/ReCommander.rb
CHANGED
@@ -1,13 +1,25 @@
|
|
1
|
+
# Last Modified: 2017.08.16 /coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright © 2016-2017 Exosite LLC.
|
5
|
+
# License: MIT. See LICENSE.txt.
|
6
|
+
# vim:tw=0:ts=2:sw=2:et:ai
|
7
|
+
|
8
|
+
require 'optparse'
|
9
|
+
require 'MrMurano/optparse'
|
10
|
+
|
11
|
+
require 'MrMurano/verbosing'
|
1
12
|
|
2
13
|
module MrMurano
|
3
14
|
class Hooked
|
4
15
|
include Verbose
|
5
|
-
attr :section
|
6
16
|
|
7
17
|
def initialize(section)
|
8
18
|
@section = section
|
9
19
|
end
|
10
20
|
|
21
|
+
attr_reader :section
|
22
|
+
|
11
23
|
def check_run_pre_hook
|
12
24
|
prehook = $cfg["#{section}.pre-hook"]
|
13
25
|
return if prehook.nil?
|
@@ -23,37 +35,129 @@ module MrMurano
|
|
23
35
|
verbose "calling post-hook: #{posthook}"
|
24
36
|
system(posthook)
|
25
37
|
end
|
26
|
-
|
27
38
|
end
|
28
39
|
end
|
29
40
|
|
30
41
|
module Commander
|
42
|
+
class Command
|
43
|
+
# A command sets project_not_required if it
|
44
|
+
# can run from without a project directory.
|
45
|
+
attr_accessor :project_not_required
|
46
|
+
# A command sets restrict_to_cur_dir if it
|
47
|
+
# should not climb the directory hierarchy
|
48
|
+
# in search of a .murano/config file.
|
49
|
+
attr_accessor :restrict_to_cur_dir
|
50
|
+
# A command sets prompt_if_logged_off if it
|
51
|
+
# is okay to ask the user for their password.
|
52
|
+
attr_accessor :prompt_if_logged_off
|
53
|
+
|
54
|
+
def verify_arg_count!(args, max_args=0, mandatory=[])
|
55
|
+
if !max_args.nil? && max_args.zero?
|
56
|
+
if args.count > 0
|
57
|
+
MrMurano::Verbose.error('Not expecting any arguments')
|
58
|
+
exit 2
|
59
|
+
end
|
60
|
+
elsif !max_args.nil? && args.count > max_args
|
61
|
+
MrMurano::Verbose.error("Not expecting more than #{max_args} arguments")
|
62
|
+
exit 2
|
63
|
+
elsif args.count < mandatory.length
|
64
|
+
(args.count..(mandatory.length - 1)).to_a.each do |ix|
|
65
|
+
MrMurano::Verbose.error(mandatory[ix])
|
66
|
+
end
|
67
|
+
exit 2
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
31
72
|
class Runner
|
32
|
-
|
73
|
+
attr_accessor :command_exit
|
74
|
+
|
75
|
+
# run_active_command is called by commander-rb's at_exit hook.
|
76
|
+
# We override -- monkey patch -- it to do other stuff.
|
77
|
+
alias old_run_active_command run_active_command
|
33
78
|
def run_active_command
|
79
|
+
exit @command_exit if @command_exit
|
34
80
|
section = active_command.name
|
35
81
|
hooked = MrMurano::Hooked.new(section)
|
36
82
|
hooked.check_run_pre_hook
|
37
83
|
|
38
84
|
begin
|
39
85
|
old_run_active_command
|
86
|
+
rescue LocalJumpError => _err
|
87
|
+
# This happens when you `return` from a command, since
|
88
|
+
# commands are blocks, and returning from a block would
|
89
|
+
# really mean returning from the thing running the block,
|
90
|
+
# which would be bad. So Ruby barfs instead.
|
91
|
+
return
|
92
|
+
rescue OptionParser::InvalidArgument => err
|
93
|
+
MrMurano::Verbose.whirly_stop
|
94
|
+
MrMurano::Verbose.error err.message
|
95
|
+
exit 1
|
96
|
+
rescue OptionParser::InvalidOption => err
|
97
|
+
MrMurano::Verbose.whirly_stop
|
98
|
+
MrMurano::Verbose.error err.message
|
99
|
+
MrMurano::Verbose.error 'invalid command' if section == 'help'
|
100
|
+
exit 1
|
101
|
+
rescue OptionParser::MissingArgument => err
|
102
|
+
MrMurano::Verbose.whirly_stop
|
103
|
+
MrMurano::Verbose.error err.message
|
104
|
+
exit 1
|
105
|
+
rescue OptionParser::NeedlessArgument => err
|
106
|
+
MrMurano::Verbose.whirly_stop
|
107
|
+
MrMurano::Verbose.error err.message
|
108
|
+
pattern = /^needless argument: --(?<arg>[_a-zA-Z0-9]+)=(?<val>.*)/
|
109
|
+
md = pattern.match(err.message)
|
110
|
+
unless md.nil?
|
111
|
+
puts %(Try the option without the equals sign, e.g.,)
|
112
|
+
puts %( --#{md[:arg]} "#{md[:val]}")
|
113
|
+
end
|
114
|
+
exit 1
|
40
115
|
rescue MrMurano::ConfigError => err
|
41
|
-
|
116
|
+
# Clear whirly if it was running.
|
117
|
+
MrMurano::Verbose.whirly_stop
|
118
|
+
MrMurano::Verbose.error err.message
|
42
119
|
exit 1
|
43
|
-
rescue StandardError =>
|
120
|
+
rescue StandardError => _err
|
44
121
|
raise
|
45
122
|
end
|
46
123
|
|
47
124
|
hooked.check_run_post_hook
|
48
125
|
end
|
49
126
|
|
50
|
-
alias
|
127
|
+
alias old_parse_global_options parse_global_options
|
51
128
|
def parse_global_options
|
52
|
-
defopts = ($cfg["#{active_command.name}.options"]
|
53
|
-
@args.push(
|
54
|
-
|
129
|
+
defopts = ($cfg["#{active_command.name}.options"] || '').split
|
130
|
+
@args.push(*defopts)
|
131
|
+
begin
|
132
|
+
old_parse_global_options
|
133
|
+
rescue OptionParser::MissingArgument => err
|
134
|
+
if err.message.start_with?('missing argument:')
|
135
|
+
puts err.message
|
136
|
+
else
|
137
|
+
MrMurano::Verbose.error(
|
138
|
+
"There was a problem interpreting the options: ‘#{err.message}’"
|
139
|
+
)
|
140
|
+
end
|
141
|
+
exit 2
|
142
|
+
end
|
55
143
|
end
|
144
|
+
|
145
|
+
# Weird. --help doesn't work if other flags also specified.
|
146
|
+
# E.g., this shows the help for usage:
|
147
|
+
# $ murano --help usage
|
148
|
+
# but if a flag is added, the command gets run, e.g.,
|
149
|
+
# $ murano usage --id 1234 --help
|
150
|
+
# ignores the --help and runs the usage command.
|
151
|
+
# ([lb] walked the code and it looks like when Commander tries to
|
152
|
+
# validate the args, it doesn't like the --id flag (maybe because
|
153
|
+
# the "help" command is being used to validate?). Then it removes
|
154
|
+
# the --id flags (after --help was previously removed) and tries
|
155
|
+
# the command *again* (in gems/commander-4.4.3/lib/commander/runner.rb,
|
156
|
+
# look for the comment, "Remove the offending args and retry").
|
157
|
+
#
|
158
|
+
# 2017-06-14: [lb] tried to override run! here to show help correctly
|
159
|
+
# in this use case, but I could not get it to work. Oh, well... a
|
160
|
+
# minor annoyance; just live with it, I guess.
|
56
161
|
end
|
57
162
|
end
|
58
163
|
|
59
|
-
# vim: set ai et sw=2 ts=2 :
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'MrMurano/verbosing'
|
2
|
+
|
3
|
+
module MrMurano
|
4
|
+
class Setting
|
5
|
+
include Verbose
|
6
|
+
|
7
|
+
SERVICE_MAP = {
|
8
|
+
'Device2' => 'Gateway',
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
## Map service names into actual class names.
|
12
|
+
#
|
13
|
+
# Some of the service names have changed over time and no longer match the class
|
14
|
+
# names that implement them. This maps them back, as well as correcting casing.
|
15
|
+
#
|
16
|
+
# @param service [String] User facing service name
|
17
|
+
# @return [String] Internal class name for service
|
18
|
+
def mapservice(service)
|
19
|
+
service = service.to_s.downcase
|
20
|
+
SERVICE_MAP.each_pair do |k, v|
|
21
|
+
if service == k.downcase || service == v.downcase
|
22
|
+
return v
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return service.sub(/(.)(.*)/){"#{$1.upcase}#{$2.downcase}"}
|
26
|
+
end
|
27
|
+
|
28
|
+
def read(service, setting)
|
29
|
+
begin
|
30
|
+
debug %{Looking up class "MrMurano::#{mapservice(service)}::Settings"}
|
31
|
+
gb = Object::const_get("MrMurano::#{mapservice(service)}::Settings").new
|
32
|
+
meth = setting.to_sym
|
33
|
+
debug %{Looking up method "#{meth}"}
|
34
|
+
if gb.respond_to?(meth)
|
35
|
+
return gb.__send__(meth)
|
36
|
+
else
|
37
|
+
error "Unknown setting '#{setting}' on '#{service}'"
|
38
|
+
end
|
39
|
+
rescue NameError => e
|
40
|
+
error "No Settings on \"#{service}\""
|
41
|
+
if $cfg['tool.debug'] then
|
42
|
+
error e.message
|
43
|
+
error e.to_s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def write(service, setting, value)
|
49
|
+
begin
|
50
|
+
debug %(Looking up class "MrMurano::#{mapservice(service)}::Settings")
|
51
|
+
gb = Object::const_get("MrMurano::#{mapservice(service)}::Settings").new
|
52
|
+
meth = "#{setting}=".to_sym
|
53
|
+
debug %(Looking up method "#{meth}")
|
54
|
+
if gb.respond_to? meth then
|
55
|
+
return gb.__send__(meth, value)
|
56
|
+
else
|
57
|
+
error "Unknown setting '#{setting}' on '#{service}'"
|
58
|
+
end
|
59
|
+
rescue NameError => e
|
60
|
+
error %(No Settings on "#{service}")
|
61
|
+
if $cfg['tool.debug'] then
|
62
|
+
error e.message
|
63
|
+
error e.to_s
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# List all Settings classes and the accessors on them.
|
70
|
+
#
|
71
|
+
# This is for letting users know which things can be read and written in the
|
72
|
+
# settings command.
|
73
|
+
def list
|
74
|
+
result = {}
|
75
|
+
::MrMurano.constants.each do |maybe|
|
76
|
+
begin
|
77
|
+
gb = Object::const_get("MrMurano::#{maybe}::Settings")
|
78
|
+
result[maybe] = gb.instance_methods(false).select{|i| i.to_s[-1] != '='}
|
79
|
+
rescue
|
80
|
+
end
|
81
|
+
end
|
82
|
+
result
|
83
|
+
# MAYBE/2017-08-17:
|
84
|
+
# sort_by_name(result)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# vim: set ai et sw=2 ts=2 :
|
90
|
+
|
@@ -1,33 +1,76 @@
|
|
1
|
+
# Last Modified: 2017.08.17 /coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright © 2016-2017 Exosite LLC.
|
5
|
+
# License: MIT. See LICENSE.txt.
|
6
|
+
# vim:tw=0:ts=2:sw=2:et:ai
|
7
|
+
|
1
8
|
require 'MrMurano/Solution'
|
2
9
|
|
3
10
|
module MrMurano
|
4
11
|
# …/serviceconfig
|
5
12
|
class ServiceConfig < SolutionBase
|
6
|
-
def initialize
|
13
|
+
def initialize(sid=nil)
|
7
14
|
super
|
8
|
-
@uriparts <<
|
15
|
+
@uriparts << :serviceconfig
|
9
16
|
@scid = nil
|
10
17
|
end
|
11
18
|
|
12
|
-
def list
|
13
|
-
ret = get()
|
14
|
-
return []
|
19
|
+
def list(call=nil, data=nil, &block)
|
20
|
+
ret = get(call, data, &block)
|
21
|
+
return [] unless ret.is_a?(Hash) && !ret.key?(:error)
|
22
|
+
return [] unless ret.key?(:items)
|
15
23
|
ret[:items]
|
24
|
+
# MAYBE/2017-08-17:
|
25
|
+
# sort_by_name(ret[:items])
|
16
26
|
end
|
27
|
+
|
28
|
+
def search(svc_name)
|
29
|
+
#path = nil
|
30
|
+
path = '?select=id,service,script_key'
|
31
|
+
# 2017-07-02: This is what yeti-ui queries on:
|
32
|
+
#path = '?select=service,id,solution_id,script_key,alias'
|
33
|
+
super(svc_name, path)
|
34
|
+
end
|
35
|
+
|
17
36
|
def fetch(id)
|
18
37
|
get('/' + id.to_s)
|
19
38
|
end
|
20
39
|
|
21
40
|
def scid_for_name(name)
|
22
|
-
name = name.to_s unless name.
|
23
|
-
scr = list
|
41
|
+
name = name.to_s unless name.is_a? String
|
42
|
+
scr = list.select { |i| i[:service] == name }.first
|
24
43
|
return nil if scr.nil?
|
25
44
|
scr[:id]
|
26
45
|
end
|
27
46
|
|
28
47
|
def scid
|
29
48
|
return @scid unless @scid.nil?
|
30
|
-
@scid = scid_for_name(@
|
49
|
+
@scid = scid_for_name(@service_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
def create(pid, name=nil, &block) #? script_key?
|
53
|
+
name = pid if name.to_s.empty?
|
54
|
+
raise 'Missing name/script_key?' if name.to_s.empty?
|
55
|
+
# See pegasus_registry PostServiceConfig for the POST properties.
|
56
|
+
# pegasus_registry/api/swagger/paths/serviceconfig.yaml
|
57
|
+
# pegasus_registry/api/swagger/definitions/serviceconfig.yaml
|
58
|
+
post(
|
59
|
+
'/',
|
60
|
+
{
|
61
|
+
solution_id: @sid,
|
62
|
+
service: pid,
|
63
|
+
# 2017-06-26: "name" seems to work, but "script_key" is what web UI uses.
|
64
|
+
# See yeti-ui/bridge/src/js/api/services.js::linkApplicationService
|
65
|
+
#name: name,
|
66
|
+
script_key: name,
|
67
|
+
},
|
68
|
+
&block
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def remove(id)
|
73
|
+
delete("/#{id}")
|
31
74
|
end
|
32
75
|
|
33
76
|
def info(id=scid)
|
@@ -39,8 +82,8 @@ module MrMurano
|
|
39
82
|
end
|
40
83
|
|
41
84
|
def call(opid, meth=:get, data=nil, id=scid, &block)
|
42
|
-
raise "Service '#{@
|
43
|
-
call = "/#{id
|
85
|
+
raise "Service '#{@service_name}' not enabled for this Solution" if id.nil?
|
86
|
+
call = "/#{id}/call/#{opid}"
|
44
87
|
debug "Will call: #{call}"
|
45
88
|
case meth
|
46
89
|
when :get
|
@@ -57,7 +100,6 @@ module MrMurano
|
|
57
100
|
raise "Unknown method: #{meth}"
|
58
101
|
end
|
59
102
|
end
|
60
|
-
|
61
103
|
end
|
62
104
|
|
63
105
|
## This is only used for debugging and deciphering APIs.
|
@@ -69,26 +111,29 @@ module MrMurano
|
|
69
111
|
# A much better UI/UX happens with human intervention.
|
70
112
|
# :nocov:
|
71
113
|
class Services < SolutionBase
|
72
|
-
def initialize
|
114
|
+
def initialize(sid=nil)
|
73
115
|
super
|
74
|
-
@uriparts <<
|
116
|
+
@uriparts << :service
|
75
117
|
end
|
76
118
|
|
77
119
|
def sid_for_name(name)
|
78
|
-
name = name.to_s unless name.
|
79
|
-
scr = list
|
120
|
+
name = name.to_s unless name.is_a? String
|
121
|
+
scr = list.select { |i| i[:alias] == name }.first
|
80
122
|
scr[:id]
|
81
123
|
end
|
82
124
|
|
83
125
|
def sid
|
84
126
|
return @sid unless @sid.nil?
|
85
|
-
@sid = sid_for_name(@
|
127
|
+
@sid = sid_for_name(@service_name)
|
86
128
|
end
|
87
129
|
|
88
130
|
def list
|
89
|
-
ret = get
|
90
|
-
return []
|
131
|
+
ret = get
|
132
|
+
return [] unless ret.is_a?(Hash) && !ret.key?(:error)
|
133
|
+
return [] unless ret.key?(:items)
|
91
134
|
ret[:items]
|
135
|
+
# MAYBE/2017-08-17:
|
136
|
+
# sort_by_name(ret[:items])
|
92
137
|
end
|
93
138
|
|
94
139
|
def schema(id=sid)
|
@@ -102,44 +147,43 @@ module MrMurano
|
|
102
147
|
calls = []
|
103
148
|
scm[:paths].each do |path, methods|
|
104
149
|
methods.each do |method, params|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
150
|
+
next unless params.is_a?(Hash)
|
151
|
+
call = [method]
|
152
|
+
call << path.to_s if all
|
153
|
+
call << params[:operationId]
|
154
|
+
call << (params['x-internal-use'.to_sym] || false) if all
|
155
|
+
calls << call
|
112
156
|
end
|
113
157
|
end
|
114
158
|
calls
|
115
159
|
end
|
160
|
+
|
161
|
+
def all_events
|
162
|
+
sevs = list
|
163
|
+
ret = []
|
164
|
+
sevs.each do |srv|
|
165
|
+
scm = schema(srv[:id]) || {}
|
166
|
+
(scm['x-events'.to_sym] || {}).each_pair do |event, _info|
|
167
|
+
ret << [srv[:alias], event]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
ret
|
171
|
+
end
|
116
172
|
end
|
117
173
|
# :nocov:
|
118
174
|
|
119
|
-
|
120
|
-
|
121
|
-
|
175
|
+
class ServiceConfigApplication < ServiceConfig
|
176
|
+
def initialize(sid=nil)
|
177
|
+
@solntype = 'application.id'
|
122
178
|
super
|
123
|
-
@serviceName = 'device'
|
124
179
|
end
|
180
|
+
end
|
125
181
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
details[:parameters] = {:pid=>products}
|
131
|
-
|
132
|
-
put('/'+scid, details)
|
133
|
-
end
|
134
|
-
|
135
|
-
def showTriggers
|
136
|
-
details = fetch(scid)
|
137
|
-
|
138
|
-
return [] if details[:triggers].nil?
|
139
|
-
details[:triggers][:pid]
|
182
|
+
class ServiceConfigProduct < ServiceConfig
|
183
|
+
def initialize(sid=nil)
|
184
|
+
@solntype = 'product.id'
|
185
|
+
super
|
140
186
|
end
|
141
|
-
|
142
187
|
end
|
143
188
|
end
|
144
189
|
|
145
|
-
# vim: set ai et sw=2 ts=2 :
|