1717 */
1818
1919
20- import { CustomHttpUrlEncodingCodec } from '../encoder' ;
21- import { Instance } from '../../model/models/instance' ;
22- import { SysInfo } from '../../model/models/sysInfo' ;
20+ import { CustomHttpUrlEncodingCodec } from '../encoder' ;
21+ import { Instance } from '../../model/models/instance' ;
22+ import { SysInfo } from '../../model/models/sysInfo' ;
23+ import { User } from '../../model/models/user' ;
2324import { Inject , Injectable , Optional } from '@angular/core' ;
2425import { HttpClient , HttpHeaders , HttpParams } from '@angular/common/http' ;
2526import { Observable } from 'rxjs' ;
@@ -28,6 +29,8 @@ import {
2829 BASE_PATH ,
2930 INSTANCES ,
3031 NUMBER_OF_INSTANCES ,
32+ USERS ,
33+ NEW_USER ,
3134 SYS_INFO ,
3235 NEW_INSTANCE ,
3336 START_INSTANCE ,
@@ -37,6 +40,7 @@ import {
3740 DELETE_INSTANCE ,
3841 NEW_LABEL_INSTANCE ,
3942 INSTANCE_NETWORK ,
43+ DELETE_USER ,
4044 RECONNECT ,
4145 AUTH
4246} from '../variables' ;
@@ -92,7 +96,7 @@ export class ApiService {
9296 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
9397 * @param reportProgress flag to report request and response progress.
9498 */
95- public getNumberOfInstances ( componentType : string , observe : any = 'body' , reportProgress : boolean = false ) : Observable < number > {
99+ public getNumberOfInstances ( componentType : string , observe : any = 'body' , reportProgress : boolean = false ) : Observable < number > {
96100 return this . get ( NUMBER_OF_INSTANCES , componentType ) ;
97101 }
98102
@@ -169,7 +173,7 @@ export class ApiService {
169173 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
170174 * @param reportProgress flag to report request and response progress.
171175 */
172- public pauseInstance ( instanceId : string , observe : any = 'body' , reportProgress : boolean = false ) {
176+ public pauseInstance ( instanceId : string , observe : any = 'body' , reportProgress : boolean = false ) {
173177 return this . postAction ( PAUSE_INSTANCE , instanceId ) ;
174178 }
175179
@@ -200,10 +204,71 @@ export class ApiService {
200204 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
201205 * @param reportProgress flag to report request and response progress.
202206 */
203- public labelInstance ( instanceId : string , labelName : string , observe : any = 'body' , reportProgress : boolean = false ) {
207+ public labelInstance ( instanceId : string , labelName : string , observe : any = 'body' , reportProgress : boolean = false ) {
204208 return this . postLabel ( NEW_LABEL_INSTANCE , instanceId , labelName ) ;
205209 }
206210
211+ /**
212+ * Create a User
213+ * @param userName
214+ * @param secret
215+ * @param userType
216+ * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
217+ * @param reportProgress flag to report request and response progress.
218+ */
219+
220+ public postUser ( userName : string , secret : string , userType : string , observe : any = 'body' , reportProgress : boolean = false )
221+ : Observable < User > {
222+ return this . userAdd ( userName , secret , userType ) ;
223+ }
224+
225+ private userAdd ( username : string , secret : string , userType : string ) : Observable < User > {
226+ let headers = this . defaultHeaders ;
227+ // to determine the Accept header
228+ const httpHeaderAccepts : string [ ] = [
229+ 'application/json'
230+ ] ;
231+ const httpHeaderAcceptSelected : string | undefined = this . configuration . selectHeaderAccept ( httpHeaderAccepts ) ;
232+ if ( httpHeaderAcceptSelected !== undefined ) {
233+ headers = headers . set ( 'Accept' , httpHeaderAcceptSelected ) ;
234+ }
235+
236+ return this . httpClient . post < User > ( `${ this . basePath } ${ NEW_USER } ` , {
237+ userName : username ,
238+ secret : secret ,
239+ userType : userType
240+ } ,
241+ {
242+ withCredentials : this . configuration . withCredentials ,
243+ headers : headers
244+ }
245+ ) ;
246+ }
247+
248+ public deleteUser ( userId : string ) {
249+ return this . deleteAction ( DELETE_USER , userId ) ;
250+ }
251+
252+ /**
253+ * Delete a User
254+ * @param idUser
255+ * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
256+ * @param reportProgress flag to report request and response progress.
257+ */
258+
259+ private deleteAction ( endpoint : string , idUser : string , observe : any = 'body' , reportProgress : boolean = false ) {
260+ let queryParam = new HttpParams ( { encoder : new CustomHttpUrlEncodingCodec ( ) } ) ;
261+
262+ if ( idUser === null || idUser === undefined ) {
263+ throw new Error ( 'Required ID User parameter' ) ;
264+ } else {
265+ queryParam = queryParam . set ( 'userID' , < any > idUser ) ;
266+ }
267+
268+ return this . commonConf ( endpoint , queryParam , observe , reportProgress ) ;
269+ }
270+
271+
207272 private get < T > ( endpoint : string , componentType ?: string ) {
208273
209274 let queryParameters = new HttpParams ( { encoder : new CustomHttpUrlEncodingCodec ( ) } ) ;
@@ -301,6 +366,31 @@ export class ApiService {
301366 return this . commonConf ( endpoint , queryParam , observe , reportProgress ) ;
302367 }
303368
369+ public getUsers ( observe : any = 'body' , reportProgress : boolean = false ) : Observable < Array < User > > {
370+ return this . getList ( USERS ) ;
371+ }
372+
373+ private getList < T > ( endpoint : string ) {
374+
375+ let headers = this . defaultHeaders ;
376+
377+ // to determine the Accept header
378+ const httpHeaderAccepts : string [ ] = [
379+ 'application/json'
380+ ] ;
381+ const httpHeaderAcceptSelected : string | undefined = this . configuration . selectHeaderAccept ( httpHeaderAccepts ) ;
382+ if ( httpHeaderAcceptSelected !== undefined ) {
383+ headers = headers . set ( 'Accept' , httpHeaderAcceptSelected ) ;
384+ }
385+
386+ return this . httpClient . get < T > ( `${ this . basePath } ${ endpoint } ` ,
387+ {
388+ withCredentials : this . configuration . withCredentials ,
389+ headers : headers
390+ }
391+ ) ;
392+ }
393+
304394
305395 private commonConf ( endpoint : string , queryParameters : HttpParams , observe : any = 'body' , reportProgress : boolean = false ) {
306396 let headers = this . defaultHeaders ;
0 commit comments