270e79dee91ae2a455a6424612e090b0c4dfe330
[portal/ric-dashboard.git] / webapp-frontend / src / app / services / caas-ingress / caas-ingress.service.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20
21 import { Injectable } from '@angular/core';
22 import { HttpClient } from '@angular/common/http';
23 import { V1PodList } from '@kubernetes/client-node';
24 import { Observable } from 'rxjs';
25
26 /**
27 * Services for calling the Dashboard's caas-ingress endpoints to get Kubernetes details.
28 */
29 @Injectable({
30   providedIn: 'root'
31 })
32 export class CaasIngressService {
33
34   private basePath = 'api/caas-ingress';
35   private podsPath = 'pods';
36
37   private buildPath(...args: any[]) {
38     let result = this.basePath;
39     args.forEach(part => {
40       result = result + '/' + part;
41     });
42     return result;
43   }
44
45   constructor(private httpClient: HttpClient) {
46     // injects to variable httpClient
47   }
48
49   /**
50    * Gets list of pods
51    * @returns Observable that should yield a V1PodList
52    */
53   getPodList(cluster: string, namespace: string): Observable<V1PodList> {
54     const url = this.buildPath('pods', 'cluster', cluster, 'namespace', namespace);
55     return this.httpClient.get<V1PodList>(url);
56   }
57
58 }