@@ -103,6 +103,7 @@ type APIClient struct {
103
103
ua string
104
104
logger LG.ILogger
105
105
subUser string
106
+ roleSeparator string
106
107
}
107
108
108
109
// RequestOptions represents the options for an API request.
@@ -127,6 +128,7 @@ func NewAPIClient() *APIClient {
127
128
curlopts : map [string ]string {},
128
129
ua : "" ,
129
130
logger : nil ,
131
+ roleSeparator : ":" ,
130
132
}
131
133
cl .UseLIVESystem ()
132
134
cl .SetDefaultLogger ()
@@ -297,7 +299,7 @@ func (cl *APIClient) GetVersion() string {
297
299
func (cl * APIClient ) SaveSession (sessionobj map [string ]interface {}) * APIClient {
298
300
sessionobj ["socketcfg" ] = map [string ]string {
299
301
"session" : cl .socketConfig .GetSession (),
300
- "login" : cl .socketConfig .GetLogin (),
302
+ "login" : cl .socketConfig .GetLogin (),
301
303
}
302
304
return cl
303
305
}
@@ -306,7 +308,7 @@ func (cl *APIClient) SaveSession(sessionobj map[string]interface{}) *APIClient {
306
308
// to rebuild and reuse connection settings
307
309
func (cl * APIClient ) ReuseSession (sessionobj map [string ]interface {}) * APIClient {
308
310
cfg := sessionobj ["socketcfg" ].(map [string ]string )
309
- cl .SetLogin (cfg ["login" ])
311
+ cl .SetCredentials (cfg ["login" ])
310
312
cl .SetSession (cfg ["session" ])
311
313
return cl
312
314
}
@@ -323,31 +325,39 @@ func (cl *APIClient) SetSession(value string) *APIClient {
323
325
return cl
324
326
}
325
327
326
- // Set Login method to set an API user id to be used for API communication
327
- func (cl * APIClient ) SetLogin (value string ) * APIClient {
328
- cl .socketConfig .SetLogin (value )
329
- return cl
330
- }
331
-
332
328
// SetPersistent method sets the API connection to use a persistent session
333
329
func (cl * APIClient ) SetPersistent () * APIClient {
334
330
cl .socketConfig .SetPersistent ()
335
331
return cl
336
332
}
337
333
338
334
// SetCredentials method to set Credentials to be used for API communication
339
- func (cl * APIClient ) SetCredentials (uid string , pw string ) * APIClient {
340
- cl .socketConfig .SetLogin (uid )
341
- cl .socketConfig .SetPassword (pw )
335
+ func (cl * APIClient ) SetCredentials (params ... string ) * APIClient {
336
+ fmt .Printf ("params: %v\n " , params )
337
+ if len (params ) > 0 {
338
+ cl .socketConfig .SetLogin (params [0 ])
339
+ }
340
+ if len (params ) > 1 {
341
+ cl .socketConfig .SetPassword (params [1 ])
342
+ }
342
343
return cl
343
344
}
344
345
345
346
// SetRoleCredentials method to set Role User Credentials to be used for API communication
346
- func (cl * APIClient ) SetRoleCredentials (uid string , role string , pw string ) * APIClient {
347
- if len (role ) > 0 {
348
- return cl .SetCredentials (uid + ":" + role , pw )
347
+ func (cl * APIClient ) SetRoleCredentials (params ... string ) * APIClient {
348
+ if len (params ) > 0 {
349
+ uid := params [0 ]
350
+ if len (params ) > 1 && len (params [1 ]) > 0 {
351
+ role := params [1 ]
352
+ uid = uid + cl .roleSeparator + role
353
+ }
354
+ if len (params ) > 2 {
355
+ pw := params [2 ]
356
+ return cl .SetCredentials (uid , pw )
357
+ }
358
+ return cl .SetCredentials (uid )
349
359
}
350
- return cl . SetCredentials ( uid , pw )
360
+ return cl
351
361
}
352
362
353
363
// Login method to perform API login to start session-based communication
0 commit comments