@@ -202,7 +202,7 @@ def creds_add(*args)
202
202
end
203
203
204
204
begin
205
- params . assert_valid_keys ( 'user' , 'password' , 'realm' , 'realm-type' , 'ntlm' , 'ssh-key' , 'hash' , 'host ' , 'port' )
205
+ params . assert_valid_keys ( 'user' , 'password' , 'realm' , 'realm-type' , 'ntlm' , 'ssh-key' , 'hash' , 'address ' , 'port' , 'protocol' , 'service-name ')
206
206
rescue ArgumentError => e
207
207
print_error ( e . message )
208
208
end
@@ -213,6 +213,13 @@ def creds_add(*args)
213
213
print_error ( "You can only specify a single Private type. Private types given: #{ private_keys . join ( ', ' ) } " )
214
214
return
215
215
end
216
+
217
+ login_keys = params . slice ( 'address' , 'port' , 'protocol' , 'service-name' )
218
+ if login_keys . any? and login_keys . length < 3
219
+ missing_login_keys = [ 'host' , 'port' , 'proto' , 'service-name' ] - login_keys . keys
220
+ print_error ( "Creating a login requires a address, a port, and a protocol. Missing params: #{ missing_login_keys } " )
221
+ return
222
+ end
216
223
217
224
data = {
218
225
workspace_id : framework . db . workspace ,
@@ -260,9 +267,17 @@ def creds_add(*args)
260
267
data [ :private_type ] = :nonreplayable_hash
261
268
data [ :private_data ] = params [ 'hash' ]
262
269
end
263
-
270
+
264
271
begin
265
- create_credential ( data )
272
+ if login_keys . any?
273
+ data [ :address ] = params [ 'address' ]
274
+ data [ :port ] = params [ 'port' ]
275
+ data [ :protocol ] = params [ 'protocol' ]
276
+ data [ :service_name ] = params [ 'service-name' ]
277
+ create_credential_and_login ( data )
278
+ else
279
+ create_credential ( data )
280
+ end
266
281
rescue ActiveRecord ::RecordInvalid => e
267
282
print_error ( "Failed to add #{ data [ 'private_type' ] } : #{ e } " )
268
283
end
0 commit comments