1+ /*******************************************************************************
2+ * Copyright © 2021-2022 VMware, Inc. All Rights Reserved.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+ * in compliance with the License. You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+ * or implied. See the License for the specific language governing permissions and limitations under
12+ * the License.
13+ *
14+ * @author : Huaqiao Zhang, <huaqiaoz@vmware.com>
15+ *******************************************************************************/
16+
117import { HttpClient , HttpHeaders } from '@angular/common/http' ;
218import { Injectable } from '@angular/core' ;
319import { Observable } from 'rxjs' ;
420import { catchError } from 'rxjs/operators' ;
521import { ErrorService } from './error.service' ;
6- import { AppService } from '../contracts/v2/app-service/app-service' ;
22+
723
824@Injectable ( {
925 providedIn : 'root'
1026} )
1127export class AppServiceService {
1228
13- endpoint : string = "/app-service" ;
29+
1430 version : string = "/api/v2" ;
1531
16- appServiceUrl : string = `${ this . endpoint } ${ this . version } ` ;
32+ appSvcDeployConfigUrl : string = `${ this . version } /appsvc/deploy/servicekey` ;
33+ appSvcGetConfigUrl : string = `${ this . version } /appsvc/config/servicekey` ;
1734
1835 httpPostOrPutJSONOptions = {
1936 headers : new HttpHeaders ( {
@@ -24,27 +41,16 @@ export class AppServiceService {
2441
2542 constructor ( private http : HttpClient , private errorSvc : ErrorService ) { }
2643
27- getAppServiceConfig ( ) : Observable < AppService > {
28- let url = `${ this . appServiceUrl } /config` ;
29- return this . http . get < AppService > ( url ) . pipe (
30- catchError ( error => this . errorSvc . handleError ( error ) )
31- )
32- }
33-
34- downloadAppServiceConfig ( serviceKey : string ) : Observable < any > {
35- let url = `${ this . version } /appservice/download/servicekey/` + serviceKey ;
36- return this . http . get ( url , {
37- responseType : "blob" ,
38- observe : 'response' ,
39- headers : new HttpHeaders ( ) . append ( "Content-Type" , "application/json" )
40- } ) . pipe (
44+ getAppSvcConfigBySvcKey ( svcKey : string ) : Observable < any > {
45+ let url = `${ this . appSvcGetConfigUrl } /${ svcKey } ` ;
46+ return this . http . get ( url ) . pipe (
4147 catchError ( error => this . errorSvc . handleError ( error ) )
4248 )
4349 }
4450
45- deployToConsul ( appServiceWritable : any , serviceKey : string ) : Observable < string > {
46- let url = `${ this . version } /appservice/deploy/servicekey/` + serviceKey ;
47- return this . http . post < string > ( url , JSON . stringify ( appServiceWritable ) , this . httpPostOrPutJSONOptions )
51+ deployToConsul ( appServiceWritable : any , svcKey : string ) : Observable < any > {
52+ let url = `${ this . appSvcDeployConfigUrl } / ${ svcKey } ` ;
53+ return this . http . post ( url , JSON . stringify ( appServiceWritable ) , this . httpPostOrPutJSONOptions )
4854 . pipe (
4955 catchError ( error => this . errorSvc . handleError ( error ) )
5056 )
0 commit comments