dtk-client 0.7.4.1 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dtk +10 -3
- data/bin/dtk-shell +1 -1
- data/lib/command_helpers/git_repo.rb +26 -20
- data/lib/command_helpers/jenkins_client.rb +4 -3
- data/lib/command_helpers/service_importer.rb +37 -25
- data/lib/commands.rb +2 -2
- data/lib/commands/common/thor/assembly_workspace.rb +185 -173
- data/lib/commands/common/thor/base_command_helper.rb +42 -0
- data/lib/commands/common/thor/clone.rb +1 -1
- data/lib/commands/common/thor/module.rb +37 -58
- data/lib/commands/common/thor/module/import.rb +1 -1
- data/lib/commands/common/thor/pull_from_remote.rb +7 -12
- data/lib/commands/common/thor/purge_clone.rb +1 -1
- data/lib/commands/common/thor/push_clone_changes.rb +3 -1
- data/lib/commands/common/thor/task_status.rb +52 -75
- data/lib/commands/common/thor/task_status/refresh_mode.rb +56 -0
- data/lib/commands/common/thor/task_status/snapshot_mode.rb +11 -0
- data/lib/commands/common/thor/task_status/stream_mode.rb +31 -0
- data/lib/commands/common/thor/task_status/stream_mode/element.rb +90 -0
- data/lib/commands/common/thor/task_status/stream_mode/element/no_results.rb +10 -0
- data/lib/commands/common/thor/task_status/stream_mode/element/render.rb +88 -0
- data/lib/commands/common/thor/task_status/stream_mode/element/stage.rb +13 -0
- data/lib/commands/common/thor/task_status/stream_mode/element/task_end.rb +10 -0
- data/lib/commands/common/thor/task_status/stream_mode/element/task_start.rb +10 -0
- data/lib/commands/thor/account.rb +10 -8
- data/lib/commands/thor/assembly.rb +9 -2
- data/lib/commands/thor/component_module.rb +0 -52
- data/lib/commands/thor/library.rb +1 -0
- data/lib/commands/thor/node.rb +1 -36
- data/lib/commands/thor/node_template.rb +4 -47
- data/lib/commands/thor/service.rb +57 -46
- data/lib/commands/thor/service_module.rb +2 -49
- data/lib/commands/thor/target.rb +7 -7
- data/lib/commands/thor/workspace.rb +44 -27
- data/lib/context_router.rb +4 -0
- data/lib/core.rb +71 -99
- data/lib/domain/response.rb +9 -0
- data/lib/domain/response/error_handler.rb +61 -0
- data/lib/dtk-client/version.rb +1 -1
- data/lib/dtk_client.rb +14 -0
- data/lib/dtk_error.rb +91 -0
- data/lib/error.rb +3 -9
- data/lib/execute/cli_pure/cli_rerouter.rb +82 -0
- data/lib/parser/adapters/thor.rb +3 -0
- data/lib/shell.rb +2 -1
- data/lib/shell/domain/context_params.rb +2 -0
- data/lib/util/console.rb +1 -1
- data/lib/util/os_util.rb +1 -0
- data/lib/util/remote_dependency_util.rb +20 -3
- data/lib/view_processor/table_print.rb +7 -25
- metadata +17 -5
- data/lib/commands/common/thor/test_action_agent.rb +0 -39
- data/lib/commands/thor/repo.rb +0 -35
@@ -20,7 +20,7 @@ module DTK::Client
|
|
20
20
|
include PurgeCloneMixin
|
21
21
|
include AssemblyWorkspaceMixin
|
22
22
|
include ActionResultHandler
|
23
|
-
|
23
|
+
|
24
24
|
def get_workspace_name(workspace_id)
|
25
25
|
get_name_from_id_helper(workspace_id)
|
26
26
|
end
|
@@ -43,7 +43,7 @@ module DTK::Client
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# using extended_context when we want to use autocomplete from other context
|
46
|
-
# e.g. we are in assembly/apache context and want to create-component we will use extended context to add
|
46
|
+
# e.g. we are in assembly/apache context and want to create-component we will use extended context to add
|
47
47
|
# component-templates to autocomplete
|
48
48
|
def self.extended_context()
|
49
49
|
{
|
@@ -56,13 +56,13 @@ module DTK::Client
|
|
56
56
|
},
|
57
57
|
:command => {
|
58
58
|
:edit_component_module => {
|
59
|
-
:endpoint => "assembly",
|
60
|
-
:url => "assembly/info_about",
|
59
|
+
:endpoint => "assembly",
|
60
|
+
:url => "assembly/info_about",
|
61
61
|
:opts => {:subtype=>"instance", :about=>"modules"}
|
62
62
|
},
|
63
63
|
:push_component_module_updates => {
|
64
|
-
:endpoint => "assembly",
|
65
|
-
:url => "assembly/info_about",
|
64
|
+
:endpoint => "assembly",
|
65
|
+
:url => "assembly/info_about",
|
66
66
|
:opts => {:subtype=>"instance", :about=>"modules"}
|
67
67
|
},
|
68
68
|
:delete_node => {
|
@@ -142,7 +142,7 @@ module DTK::Client
|
|
142
142
|
]
|
143
143
|
},
|
144
144
|
:identifier_only => {
|
145
|
-
:node
|
145
|
+
:node => [
|
146
146
|
['add-component',"add-component COMPONENT","# Add a component to the node."],
|
147
147
|
['delete-component',"delete-component COMPONENT-NAME [-y]","# Delete component from workspace's node"],
|
148
148
|
['info',"info","# Return info about node instance belonging to given workspace."],
|
@@ -154,7 +154,7 @@ module DTK::Client
|
|
154
154
|
['stop', "stop", "# Stop node instance."],
|
155
155
|
['ssh', "ssh REMOTE-USER [-i PATH-TO-PEM]","# SSH into node, optional parameters are path to identity file."]
|
156
156
|
],
|
157
|
-
|
157
|
+
|
158
158
|
:component => [
|
159
159
|
['info',"info","# Return info about component instance belonging to given node."],
|
160
160
|
['edit',"edit","# Edit component module related to given component."],
|
@@ -181,11 +181,20 @@ module DTK::Client
|
|
181
181
|
# clear_tasks_aux(context_params)
|
182
182
|
#end
|
183
183
|
|
184
|
+
desc "WORKSPACE-NAME/ID execute-workflow WORKFLOW-ACTION [WORKFLOW-PARAMS] [-m COMMIT-MSG]", "Execute workflow."
|
185
|
+
method_option "commit_msg",:aliases => "-m",
|
186
|
+
:type => :string,
|
187
|
+
:banner => "COMMIT-MSG",
|
188
|
+
:desc => "Commit message"
|
189
|
+
def execute_workflow(context_params)
|
190
|
+
converge_aux(context_params)
|
191
|
+
end
|
192
|
+
|
184
193
|
desc "WORKSPACE-NAME/ID converge [-m COMMIT-MSG]", "Converge workspace instance."
|
185
194
|
method_option "commit_msg",:aliases => "-m" ,
|
186
195
|
:type => :string,
|
187
196
|
:banner => "COMMIT-MSG",
|
188
|
-
:desc => "Commit message"
|
197
|
+
:desc => "Commit message"
|
189
198
|
def converge(context_params)
|
190
199
|
converge_aux(context_params)
|
191
200
|
end
|
@@ -205,7 +214,7 @@ module DTK::Client
|
|
205
214
|
|
206
215
|
desc "WORKSPACE-NAME/ID push-assembly-updates [NAMESPACE:]SERVICE-MODULE-NAME/ASSEMBLY-NAME", "Push changes made to this workspace to the designated assembly."
|
207
216
|
def push_assembly_updates(context_params)
|
208
|
-
workspace_id, qualified_assembly_name = context_params.retrieve_arguments([:workspace_id!,:option_1!],method_argument_names)
|
217
|
+
workspace_id, qualified_assembly_name = context_params.retrieve_arguments([:workspace_id!,:option_1!],method_argument_names)
|
209
218
|
if qualified_assembly_name =~ /(^[^\/]*)\/([^\/]*$)/
|
210
219
|
service_module_name, assembly_template_name = [$1,$2]
|
211
220
|
else
|
@@ -218,7 +227,7 @@ module DTK::Client
|
|
218
227
|
end
|
219
228
|
|
220
229
|
desc "WORKSPACE-NAME/ID create-assembly [NAMESPACE:]SERVICE-MODULE-NAME ASSEMBLY-NAME [-p] [-m DESCRIPTION]", "Create a new assembly from the workspace instance in the designated service module."
|
221
|
-
# The option -p will purge the workspace after assembly creation."
|
230
|
+
# The option -p will purge the workspace after assembly creation."
|
222
231
|
method_option :purge, :aliases => '-p', :type => :boolean, :default => false
|
223
232
|
method_option "description",:aliases => "-m" ,
|
224
233
|
:type => :string,
|
@@ -257,7 +266,7 @@ module DTK::Client
|
|
257
266
|
|
258
267
|
#only supported at node-level
|
259
268
|
# using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
|
260
|
-
desc "
|
269
|
+
desc "WORKSPACE-NAME/ID add-component COMPONENT", "Add a component to a workspace."
|
261
270
|
def add_component(context_params)
|
262
271
|
response = create_component_aux(context_params)
|
263
272
|
return response unless response.ok?
|
@@ -319,18 +328,18 @@ module DTK::Client
|
|
319
328
|
response = delete_component_aux(context_params)
|
320
329
|
return response unless response.ok?
|
321
330
|
@@invalidate_map << :service_node_component
|
322
|
-
|
331
|
+
|
323
332
|
response
|
324
333
|
end
|
325
334
|
# delete_aux(context_params)
|
326
335
|
end
|
327
336
|
|
328
337
|
# using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
|
329
|
-
desc "
|
338
|
+
desc "WORKSPACE-NAME/ID delete-component COMPONENT-NAME [-y]","Delete component from the workspace."
|
330
339
|
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
331
340
|
def delete_component(context_params)
|
332
341
|
response = delete_component_aux(context_params)
|
333
|
-
|
342
|
+
|
334
343
|
@@invalidate_map << :service
|
335
344
|
@@invalidate_map << :service_node
|
336
345
|
@@invalidate_map << :service_node_component
|
@@ -379,9 +388,15 @@ module DTK::Client
|
|
379
388
|
edit_module_aux(context_params)
|
380
389
|
end
|
381
390
|
|
382
|
-
desc "WORKSPACE-NAME/ID
|
391
|
+
desc "WORKSPACE-NAME/ID create-workflow WORKFLOW-NAME [--from BASE-WORKFLOW-NAME]", "Create a new workflow in the workspace."
|
392
|
+
method_option :from, :type => :string
|
393
|
+
def create_workflow(context_params)
|
394
|
+
edit_or_create_workflow_aux(context_params,:create => true,:create_from => options.from)
|
395
|
+
end
|
396
|
+
|
397
|
+
desc "WORKSPACE-NAME/ID edit-workflow [WORKFLOW-NAME]", "Edit a workflow in the workspace."
|
383
398
|
def edit_workflow(context_params)
|
384
|
-
|
399
|
+
edit_or_create_workflow_aux(context_params)
|
385
400
|
end
|
386
401
|
|
387
402
|
desc "WORKSPACE-NAME/ID edit-attributes", "Edit workspace's attributes."
|
@@ -399,7 +414,7 @@ module DTK::Client
|
|
399
414
|
# TODO: DTK-2027 might subsume by the dtk actions; currently server changes does not support this command
|
400
415
|
# using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
|
401
416
|
desc "HIDE_FROM_BASE execute-tests [--component COMPONENT-NAME] [--timeout TIMEOUT]", "Execute tests. --component filters execution per component, --timeout changes default execution timeout"
|
402
|
-
method_option :component, :type => :string, :desc => "Component name"
|
417
|
+
method_option :component, :type => :string, :desc => "Component name"
|
403
418
|
method_option :timeout, :type => :string, :desc => "Timeout"
|
404
419
|
def execute_tests(context_params)
|
405
420
|
execute_tests_aux(context_params)
|
@@ -436,7 +451,7 @@ module DTK::Client
|
|
436
451
|
def list_ssh_access(context_params)
|
437
452
|
list_ssh_access_aux(context_params)
|
438
453
|
end
|
439
|
-
|
454
|
+
|
440
455
|
desc "WORKSPACE-NAME/ID info", "Get info about content of the workspace."
|
441
456
|
def info(context_params)
|
442
457
|
info_aux(context_params)
|
@@ -447,11 +462,6 @@ module DTK::Client
|
|
447
462
|
link_attributes_aux(context_params)
|
448
463
|
end
|
449
464
|
|
450
|
-
#desc "WORKSPACE-NAME/ID list-attribute-mappings SERVICE-LINK-NAME/ID", "List attribute mappings associated with service link"
|
451
|
-
#def list_attribute_mappings(context_params)
|
452
|
-
# list_attribute_mappings_aux(context_params)
|
453
|
-
#end
|
454
|
-
|
455
465
|
desc "list", ""
|
456
466
|
def list(context_params)
|
457
467
|
if context_params.is_last_command_eql_to?(:node)
|
@@ -460,7 +470,7 @@ module DTK::Client
|
|
460
470
|
end
|
461
471
|
|
462
472
|
desc "WORKSPACE-NAME/ID list-attributes [-f FORMAT] [-t TAG,..] [--links]","List attributes associated with workspace."
|
463
|
-
method_option :format, :aliases => '-f'
|
473
|
+
method_option :format, :aliases => '-f'
|
464
474
|
method_option :tags, :aliases => '-t'
|
465
475
|
method_option :links, :type => :boolean, :default => false, :aliases => '-l'
|
466
476
|
def list_attributes(context_params)
|
@@ -493,11 +503,16 @@ module DTK::Client
|
|
493
503
|
list_tasks_aux(context_params)
|
494
504
|
end
|
495
505
|
|
496
|
-
desc "WORKSPACE-NAME/ID workflow-info", "Get the
|
506
|
+
desc "WORKSPACE-NAME/ID workflow-info [WORKFLOW-NAME]", "Get the contents of a workflow associated with the workspace."
|
497
507
|
def workflow_info(context_params)
|
498
508
|
workflow_info_aux(context_params)
|
499
509
|
end
|
500
510
|
|
511
|
+
desc "WORKSPACE-NAME/ID workflow-list", "List the workflows associated with the workspace."
|
512
|
+
def workflow_list(context_params)
|
513
|
+
workflow_list_aux(context_params)
|
514
|
+
end
|
515
|
+
|
501
516
|
desc "WORKSPACE-NAME/ID list-violations", "Finds violations in the workspace that will prevent a converge operation."
|
502
517
|
def list_violations(context_params)
|
503
518
|
list_violations_aux(context_params)
|
@@ -525,8 +540,10 @@ module DTK::Client
|
|
525
540
|
set_target_aux(context_params)
|
526
541
|
end
|
527
542
|
|
528
|
-
desc "WORKSPACE-NAME/ID set-attribute ATTRIBUTE-NAME [VALUE] [-u]", "(Un)Set attribute value. The option -u will unset the attribute's value."
|
543
|
+
desc "WORKSPACE-NAME/ID set-attribute ATTRIBUTE-NAME [VALUE] [-u] [-c] [-n]", "(Un)Set attribute value. The option -u will unset the attribute's value, -c to set component-attribute, -n to set node-attribute."
|
529
544
|
method_option :unset, :aliases => '-u', :type => :boolean, :default => false
|
545
|
+
method_option :component_attribute, :aliases => '-c', :type => :boolean, :default => false
|
546
|
+
method_option :node_attribute, :aliases => '-n', :type => :boolean, :default => false
|
530
547
|
def set_attribute(context_params)
|
531
548
|
set_attribute_aux(context_params)
|
532
549
|
end
|
data/lib/context_router.rb
CHANGED
@@ -6,8 +6,12 @@ module DTK
|
|
6
6
|
#
|
7
7
|
class ContextRouter
|
8
8
|
|
9
|
+
extend DTK::Client::Auxiliary
|
10
|
+
|
9
11
|
# This method invokes target context task
|
10
12
|
def self.routeTask(target_context, target_method, target_context_params, conn)
|
13
|
+
target_context = target_context.to_s
|
14
|
+
target_method = target_method.to_s
|
11
15
|
|
12
16
|
# Initing required params and invoking target_context.target_method
|
13
17
|
load_command(target_context)
|
data/lib/core.rb
CHANGED
@@ -33,7 +33,7 @@ def top_level_execute(entity_name, method_name, context_params=nil, options_args
|
|
33
33
|
rescue DTK::Client::DtkLoginRequiredError
|
34
34
|
# re-logging user and repeating request
|
35
35
|
DTK::Client::OsUtil.print("Session expired: re-establishing session & repeating given task", :yellow)
|
36
|
-
DTK::Client::Session.re_initialize
|
36
|
+
DTK::Client::Session.re_initialize
|
37
37
|
top_level_execute_core(entity_name, method_name, context_params, options_args, shell_execute)
|
38
38
|
end
|
39
39
|
end
|
@@ -48,7 +48,7 @@ def top_level_execute_core(entity_name, method_name, context_params=nil, options
|
|
48
48
|
|
49
49
|
entity_name = entity_name.gsub("-","_")
|
50
50
|
load_command(entity_name)
|
51
|
-
conn = DTK::Client::Session.get_connection
|
51
|
+
conn = DTK::Client::Session.get_connection
|
52
52
|
|
53
53
|
# if connection parameters are not set up properly then don't execute any command
|
54
54
|
return if validate_connection(conn)
|
@@ -63,23 +63,11 @@ def top_level_execute_core(entity_name, method_name, context_params=nil, options
|
|
63
63
|
|
64
64
|
response_ruby_obj = entity_class.execute_from_cli(conn,method_name,context_params,options_args,shell_execute)
|
65
65
|
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
# this will find appropriate render adapter and give output, returns boolean
|
70
|
-
if print = response_ruby_obj.render_data()
|
71
|
-
print = [print] unless print.kind_of?(Array)
|
72
|
-
print.each do |el|
|
73
|
-
if el.kind_of?(String)
|
74
|
-
el.each_line{|l| STDOUT << l}
|
75
|
-
else
|
76
|
-
PP.pp(el,STDOUT)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
66
|
+
# it will raise DTK::Client::Error in case of error response
|
67
|
+
print_method_response!(response_ruby_obj)
|
80
68
|
|
81
69
|
# process/print queued message from server
|
82
|
-
DTK::Shell::MessageQueue.print_messages
|
70
|
+
DTK::Shell::MessageQueue.print_messages
|
83
71
|
|
84
72
|
rescue DTK::Client::DtkLoginRequiredError => e
|
85
73
|
# this error is handled in method above
|
@@ -107,7 +95,25 @@ def top_level_execute_core(entity_name, method_name, context_params=nil, options
|
|
107
95
|
# this are expected application errors
|
108
96
|
DtkLogger.instance.error_pp(e.message, e.backtrace)
|
109
97
|
rescue Exception => e
|
110
|
-
|
98
|
+
client_internal_error = DTK::Client::DtkError::Client.label()
|
99
|
+
DtkLogger.instance.fatal_pp("[#{client_internal_error}] DTK has encountered an error #{e.class}: #{e.message}", e.backtrace)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def print_method_response!(response_ruby_obj)
|
104
|
+
# this will raise error if found
|
105
|
+
DTK::Client::ResponseErrorHandler.check(response_ruby_obj)
|
106
|
+
|
107
|
+
# this will find appropriate render adapter and give output, returns boolean
|
108
|
+
if print = response_ruby_obj.render_data
|
109
|
+
print = [print] unless print.kind_of?(Array)
|
110
|
+
print.each do |el|
|
111
|
+
if el.kind_of?(String)
|
112
|
+
el.each_line{|l| STDOUT << l}
|
113
|
+
else
|
114
|
+
PP.pp(el,STDOUT)
|
115
|
+
end
|
116
|
+
end
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
@@ -125,6 +131,8 @@ def validate_connection(connection)
|
|
125
131
|
puts "\nDTK will now exit. Please set up your connection properly and try again."
|
126
132
|
return true
|
127
133
|
end
|
134
|
+
|
135
|
+
false
|
128
136
|
end
|
129
137
|
|
130
138
|
# check if .add_direct_access file exists, if not then add direct access and create .add_direct_access file
|
@@ -133,13 +141,13 @@ def resolve_direct_access(params, config_exists=nil)
|
|
133
141
|
|
134
142
|
puts "Processing ..." if config_exists
|
135
143
|
# check to see if catalog credentials are set
|
136
|
-
conn = DTK::Client::Session.get_connection
|
144
|
+
conn = DTK::Client::Session.get_connection
|
137
145
|
response = conn.post DTK::Client::CommandBase.class, conn.rest_url("account/check_catalog_credentials"), {}
|
138
146
|
|
139
147
|
# set catalog credentails
|
140
148
|
if response.ok? && !response.data['catalog_credentials_set']
|
141
149
|
# setting up catalog credentials
|
142
|
-
catalog_creds = DTK::Client::Configurator.ask_catalog_credentials
|
150
|
+
catalog_creds = DTK::Client::Configurator.ask_catalog_credentials
|
143
151
|
unless catalog_creds.empty?
|
144
152
|
response = conn.post DTK::Client::CommandBase.class, conn.rest_url("account/set_catalog_credentials"), { :username => catalog_creds[:username], :password => catalog_creds[:password], :validate => true}
|
145
153
|
if errors = response['errors']
|
@@ -149,20 +157,20 @@ def resolve_direct_access(params, config_exists=nil)
|
|
149
157
|
end
|
150
158
|
|
151
159
|
# response = DTK::Client::Account.add_access(params[:ssh_key_path])
|
152
|
-
response, matched_pub_key, matched_username = DTK::Client::Account.add_key(params[:ssh_key_path])
|
160
|
+
response, matched_pub_key, matched_username = DTK::Client::Account.add_key(params[:ssh_key_path], true, "#{DTK::Client::Session.connection_username}-client")
|
153
161
|
|
154
162
|
if !response.ok?
|
155
163
|
DTK::Client::OsUtil.print("We were not able to add access for current user. #{response.error_message}. In order to properly use dtk-shell you will have to add access manually ('dtk account add-ssh-key').\n", :yellow)
|
156
164
|
elsif matched_pub_key
|
157
165
|
# message will be displayed by add key # TODO: Refactor this flow
|
158
166
|
DTK::Client::OsUtil.print("Provided SSH PUB key has already been added.", :yellow)
|
159
|
-
DTK::Client::Configurator.add_current_user_to_direct_access
|
167
|
+
DTK::Client::Configurator.add_current_user_to_direct_access
|
160
168
|
elsif matched_username
|
161
169
|
DTK::Client::OsUtil.print("User with provided name already exists.", :yellow)
|
162
170
|
else
|
163
171
|
# commented out because 'add_key' method called above will also print the same message
|
164
172
|
# DTK::Client::OsUtil.print("Your SSH PUB key has been successfully added.", :yellow)
|
165
|
-
DTK::Client::Configurator.add_current_user_to_direct_access
|
173
|
+
DTK::Client::Configurator.add_current_user_to_direct_access
|
166
174
|
end
|
167
175
|
|
168
176
|
response
|
@@ -173,10 +181,10 @@ module DTK
|
|
173
181
|
class ResponseErrorHandler
|
174
182
|
class << self
|
175
183
|
|
176
|
-
def check_for_session_expiried(
|
184
|
+
def check_for_session_expiried(response)
|
177
185
|
error_code = nil
|
178
|
-
if
|
179
|
-
|
186
|
+
if response && response['errors']
|
187
|
+
response['errors'].each do |err|
|
180
188
|
error_code = err["code"]||(err["errors"] && err["errors"].first["code"])
|
181
189
|
end
|
182
190
|
end
|
@@ -184,60 +192,12 @@ module DTK
|
|
184
192
|
return (error_code == "forbidden")
|
185
193
|
end
|
186
194
|
|
187
|
-
def check(
|
188
|
-
|
189
|
-
|
190
|
-
unless response_ruby_obj["errors"].nil?
|
191
|
-
error_msg = ""
|
192
|
-
error_internal = nil
|
193
|
-
error_backtrace = nil
|
194
|
-
error_code = nil
|
195
|
-
error_on_server = nil
|
196
|
-
|
197
|
-
#TODO: below just 'captures' first error
|
198
|
-
response_ruby_obj['errors'].each do |err|
|
199
|
-
error_msg += err["message"] unless err["message"].nil?
|
200
|
-
error_msg += err["error"] unless err["error"].nil?
|
201
|
-
error_on_server = true unless err["on_client"]
|
202
|
-
error_code = err["code"]||(err["errors"] && err["errors"].first["code"])
|
203
|
-
error_internal ||= (err["internal"] or error_code == "not_found") #"not_found" code is at Ramaze level; so error_internal not set
|
204
|
-
error_backtrace ||= err["backtrace"]
|
205
|
-
end
|
206
|
-
|
207
|
-
# normalize it for display
|
208
|
-
error_msg = error_msg.empty? ? 'Internal DTK Client error, please try again' : "#{error_msg}"
|
209
|
-
|
210
|
-
# if error_internal.first == true
|
211
|
-
if error_code == "unauthorized"
|
212
|
-
raise DTK::Client::DtkError, "[UNAUTHORIZED] Your session has been suspended, please log in again."
|
213
|
-
elsif error_code == "session_timeout"
|
214
|
-
raise DTK::Client::DtkError, "[SESSION TIMEOUT] Your session has been suspended, please log in again."
|
215
|
-
elsif error_code == "broken"
|
216
|
-
raise DTK::Client::DtkError, "[BROKEN] Unable to connect to the DTK server at host: #{Config[:server_host]}"
|
217
|
-
elsif error_code == "forbidden"
|
218
|
-
raise DTK::Client::DtkLoginRequiredError, "[FORBIDDEN] Access not granted, please log in again."
|
219
|
-
elsif error_code == "timeout"
|
220
|
-
raise DTK::Client::DtkError, "[TIMEOUT ERROR] Server is taking too long to respond."
|
221
|
-
elsif error_code == "connection_refused"
|
222
|
-
raise DTK::Client::DtkError, "[CONNECTION REFUSED] Connection refused by server."
|
223
|
-
elsif error_code == "resource_not_found"
|
224
|
-
raise DTK::Client::DtkError, "[RESOURCE NOT FOUND] #{error_msg}"
|
225
|
-
elsif error_code == "pg_error"
|
226
|
-
raise DTK::Client::DtkError, "[PG_ERROR] #{error_msg}"
|
227
|
-
elsif error_internal
|
228
|
-
where = (error_on_server ? "SERVER" : "CLIENT")
|
229
|
-
#opts = (error_backtrace ? {:backtrace => error_backtrace} : {})
|
230
|
-
raise DTK::Client::DtkError.new("[#{where} INTERNAL ERROR] #{error_msg}", :backtrace => error_backtrace)
|
231
|
-
else
|
232
|
-
# if usage error occurred, display message to console and display that same message to log
|
233
|
-
raise DTK::Client::DtkError, "[ERROR] #{error_msg}"
|
234
|
-
end
|
235
|
-
end
|
195
|
+
def check(response)
|
196
|
+
DtkError.raise_if_error?(response)
|
236
197
|
end
|
237
198
|
end
|
238
199
|
end
|
239
200
|
|
240
|
-
|
241
201
|
class Log
|
242
202
|
#TODO Stubs
|
243
203
|
def self.info(msg)
|
@@ -269,26 +229,26 @@ module DTK
|
|
269
229
|
Config.instance[k]
|
270
230
|
end
|
271
231
|
private
|
272
|
-
def initialize
|
273
|
-
set_defaults
|
274
|
-
load_config_file
|
275
|
-
validate
|
232
|
+
def initialize
|
233
|
+
set_defaults
|
234
|
+
load_config_file
|
235
|
+
validate
|
276
236
|
end
|
277
|
-
def set_defaults
|
237
|
+
def set_defaults
|
278
238
|
self[:server_port] = 80
|
279
239
|
self[:assembly_module_base_location] = 'assemblies'
|
280
240
|
self[:secure_connection] = true
|
281
241
|
self[:secure_connection_server_port] = 443
|
282
242
|
end
|
283
243
|
|
284
|
-
def load_config_file
|
244
|
+
def load_config_file
|
285
245
|
parse_key_value_file(CONFIG_FILE).each{|k,v|self[k]=v}
|
286
246
|
end
|
287
247
|
|
288
248
|
def validate
|
289
249
|
#TODO: need to check for legal values
|
290
250
|
missing_keys = REQUIRED_KEYS - keys
|
291
|
-
raise DTK::Client::DtkError,"Missing config keys (#{missing_keys.join(",")}). Please check your configuration file #{CONFIG_FILE} for required keys!" unless missing_keys.empty?
|
251
|
+
raise DTK::Client::DtkError, "Missing config keys (#{missing_keys.join(",")}). Please check your configuration file #{CONFIG_FILE} for required keys!" unless missing_keys.empty?
|
292
252
|
end
|
293
253
|
|
294
254
|
end
|
@@ -303,31 +263,35 @@ module DTK
|
|
303
263
|
|
304
264
|
attr_accessor :conn
|
305
265
|
|
306
|
-
def initialize
|
307
|
-
@conn = DTK::Client::Conn.new
|
266
|
+
def initialize
|
267
|
+
@conn = DTK::Client::Conn.new
|
308
268
|
end
|
309
269
|
|
310
|
-
def self.get_connection
|
270
|
+
def self.get_connection
|
311
271
|
Session.instance.conn
|
312
272
|
end
|
313
273
|
|
314
|
-
def self.
|
274
|
+
def self.connection_username
|
275
|
+
Session.instance.conn.get_username
|
276
|
+
end
|
277
|
+
|
278
|
+
def self.re_initialize
|
315
279
|
Session.instance.conn = nil
|
316
|
-
Session.instance.conn = DTK::Client::Conn.new
|
280
|
+
Session.instance.conn = DTK::Client::Conn.new
|
317
281
|
Session.instance.conn.cookies
|
318
282
|
end
|
319
283
|
|
320
|
-
def self.logout
|
284
|
+
def self.logout
|
321
285
|
# from this point @conn is not valid, since there are no cookies set
|
322
|
-
Session.instance.conn.logout
|
286
|
+
Session.instance.conn.logout
|
323
287
|
end
|
324
288
|
end
|
325
289
|
|
326
290
|
class Conn
|
327
|
-
def initialize
|
291
|
+
def initialize
|
328
292
|
@cookies = Hash.new
|
329
293
|
@connection_error = nil
|
330
|
-
login
|
294
|
+
login
|
331
295
|
end
|
332
296
|
|
333
297
|
VERBOSE_MODE_ON = ::DTK::Configuration.get(:verbose_rest_calls)
|
@@ -338,7 +302,7 @@ module DTK
|
|
338
302
|
require 'ap'
|
339
303
|
end
|
340
304
|
|
341
|
-
def self.get_timeout
|
305
|
+
def self.get_timeout
|
342
306
|
DefaultRestOpts[:timeout]
|
343
307
|
end
|
344
308
|
|
@@ -346,6 +310,9 @@ module DTK
|
|
346
310
|
DefaultRestOpts[:timeout] = timeout_sec
|
347
311
|
end
|
348
312
|
|
313
|
+
def get_username
|
314
|
+
get_credentials[:username]
|
315
|
+
end
|
349
316
|
|
350
317
|
def rest_url(route=nil)
|
351
318
|
protocol, port = "http", Config[:server_port].to_s
|
@@ -387,7 +354,7 @@ module DTK
|
|
387
354
|
if ResponseErrorHandler.check_for_session_expiried(response)
|
388
355
|
# re-logging user and repeating request
|
389
356
|
DTK::Client::OsUtil.print("Session expired: re-establishing session & re-trying request ...", :yellow)
|
390
|
-
@cookies = DTK::Client::Session.re_initialize
|
357
|
+
@cookies = DTK::Client::Session.re_initialize
|
391
358
|
response = rest_method_func.call
|
392
359
|
end
|
393
360
|
|
@@ -405,7 +372,7 @@ module DTK
|
|
405
372
|
return !@connection_error.nil?
|
406
373
|
end
|
407
374
|
|
408
|
-
def logout
|
375
|
+
def logout
|
409
376
|
response = get_raw rest_url("user/process_logout")
|
410
377
|
|
411
378
|
# save cookies - no need to persist them
|
@@ -439,8 +406,8 @@ module DTK
|
|
439
406
|
|
440
407
|
include ParseFile
|
441
408
|
|
442
|
-
def login
|
443
|
-
creds = get_credentials
|
409
|
+
def login
|
410
|
+
creds = get_credentials
|
444
411
|
response = post_raw rest_url("user/process_login"),creds
|
445
412
|
errors = response['errors']
|
446
413
|
|
@@ -455,14 +422,19 @@ module DTK
|
|
455
422
|
end
|
456
423
|
end
|
457
424
|
|
458
|
-
def
|
425
|
+
def set_credentials(username, password)
|
426
|
+
@parsed_credentials = { :username => username, :password => password}
|
427
|
+
end
|
428
|
+
|
429
|
+
def get_credentials
|
459
430
|
unless @parsed_credentials
|
460
431
|
cred_file = Config::CRED_FILE
|
461
432
|
raise DTK::Client::DtkError,"Authorization configuration file (#{cred_file}) does not exist" unless File.exists?(cred_file)
|
462
433
|
ret = parse_key_value_file(cred_file)
|
463
|
-
[:username,:password].each{ |k| raise DTK::Client::DtkError,"cannot find #{k}" unless ret[k] }
|
434
|
+
[:username,:password].each{ |k| raise DTK::Client::DtkError, "cannot find #{k}" unless ret[k] }
|
464
435
|
@parsed_credentials = ret
|
465
436
|
end
|
437
|
+
|
466
438
|
@parsed_credentials
|
467
439
|
end
|
468
440
|
|