117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/morpheus/cli/commands/library_option_lists_command.rb', line 117
def _get(id, options)
params = {}
params.merge!(parse_query_options(options))
begin
@option_type_lists_interface.setopts(options)
if options[:dry_run]
if id.to_s =~ /\A\d{1,}\Z/
print_dry_run @option_type_lists_interface.dry.get(id.to_i, params)
else
print_dry_run @option_type_lists_interface.dry.list(params.merge({name: id}))
end
return
end
option_type_list = find_option_type_list_by_name_or_id(id)
return 1 if option_type_list.nil?
list_items = nil
if options[:list_items]
list_items = option_type_list['listItems']
if list_items.nil?
begin
list_items = @option_type_lists_interface.list_items(option_type_list['id'])['listItems']
rescue => e
puts_error "Failed to load option list items: #{e.message}"
end
end
end
json_response = {'optionTypeList' => option_type_list}
render_result = render_with_format(json_response, options, 'optionTypeList')
return 0 if render_result
print_h1 "Option List Details", options
print cyan
if option_type_list['type'] == 'manual'
print_description_list({
"ID" => 'id',
"Name" => 'name',
"Description" => 'description',
"Labels" => lambda {|it| format_list(it['labels']) },
"Type" => lambda {|it| it['type'].to_s.capitalize },
}, option_type_list)
else
option_list_columns = {
"ID" => 'id',
"Name" => 'name',
"Description" => 'description',
"Labels" => lambda {|it| format_list(it['labels']) },
"Type" => lambda {|it| it['type'] },
"API Type" => lambda {|it| it['apiType'] },
"Source URL" => 'sourceUrl',
"Real Time" => lambda {|it| format_boolean it['realTime'] },
"Ignore SSL Errors" => lambda {|it| format_boolean it['ignoreSSLErrors'] },
"Source Method" => lambda {|it| it['sourceMethod'].to_s.upcase },
"Credentials" => lambda {|it| it['credential'] ? (it['credential']['type'] == 'local' ? '(Local)' : it['credential']['name']) : nil },
"Username" => 'serviceUsername',
"Password" => 'servicePassword',
}
option_list_columns.delete("API Type") if option_type_list['type'] != 'api'
option_list_columns.delete("Credentials") if !['rest','ldap'].include?(option_type_list['type'])
option_list_columns.delete("Username") if !['rest','ldap'].include?(option_type_list['type']) || !(option_type_list['serviceUsername'])
option_list_columns.delete("Password") if !['rest','ldap'].include?(option_type_list['type']) || !(option_type_list['servicePassword'])
= []
if option_type_list['config'] && option_type_list['config']['sourceHeaders']
= option_type_list['config']['sourceHeaders'].collect do ||
{name: ['name'], value: ['value'], masked: format_boolean(['masked'])}
end
end
print_description_list(option_list_columns, option_type_list)
if && !.empty?
print cyan
print_h2 "Source Headers"
print as_pretty_table(, [:name, :value, :masked], options)
end
if !option_type_list['initialDataset'].empty?
print_h2 "Initial Dataset"
print reset,"#{option_type_list['initialDataset']}","\n",reset
end
if !option_type_list['translationScript'].empty?
print_h2 "Translation Script"
print reset,"#{option_type_list['translationScript']}","\n",reset
end
if !option_type_list['requestScript'].empty?
print_h2 "Request Script"
print reset,"#{option_type_list['requestScript']}","\n",reset
end
end
if options[:list_items]
print_h2 "List Items"
if list_items && list_items.size > 0
print as_pretty_table(list_items, [:name, :value], options)
({size: list_items.size, total: list_items.size})
else
print cyan,"No list items found.",reset,"\n"
end
end
print reset,"\n"
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|