2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
20 import { HttpClient } from '@angular/common/http';
21 import { Injectable } from '@angular/core';
22 import { Observable } from 'rxjs';
23 import { DashboardSuccessTransport, EcompUser } from '../../interfaces/dashboard.types';
30 * Services to query the dashboard's admin endpoints.
32 export class DashboardService {
34 private adminPath = 'admin';
36 constructor(private httpClient: HttpClient) {
37 // injects to variable httpClient
41 * Builds the path for a controller method (including arguments) to use as the
42 * first argument to a HTTP client method.
43 * This function encapsulates the API prefix and RIC instance constants.
44 * @param component Controller method prefix; e.g., "admin"
45 * @param instanceKey RIC instance key; e.g., "i1" (optional).
46 * If null or empty, adds no RIC instance path components.
47 * @param args List of method path components, argument keys and values
48 * @returns Path string; e.g., "api/admin/method2/arg1/foo"
50 buildPath(component: string, instanceKey: string, ...args: any[]) {
51 let result = 'api/' + component;
53 result = result + '/ric/' + instanceKey;
55 args.forEach(part => {
56 result = result + '/' + part;
63 * @returns Observable that yields a DashboardSuccessTransport
65 getHealth(): Observable<DashboardSuccessTransport> {
66 const path = this.buildPath(this.adminPath, null, 'health');
67 return this.httpClient.get<DashboardSuccessTransport>(path);
71 * Gets Dashboard version details
72 * @returns Observable that yields a DashboardSuccessTransport object
74 getVersion(): Observable<DashboardSuccessTransport> {
75 const path = this.buildPath(this.adminPath, null, 'version');
76 return this.httpClient.get<DashboardSuccessTransport>(path);
80 * Gets Dashboard users
81 * @returns Observable that yields an EcompUser array
83 getUsers(): Observable<EcompUser[]> {
84 const path = this.buildPath(this.adminPath, null, 'user');
85 return this.httpClient.get<EcompUser[]>(path);