blob: 16cc1f322f22eca1c13cca1fa6b6f5b754ac614d [file] [log] [blame]
sebdeteb8e3f12021-01-24 18:12:36 +01001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP POLICY-CLAMP
4 * ================================================================================
5 * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
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 */
22
23export default class PolicyService {
24 static getPoliciesList() {
sebdeta0a3a032021-02-16 14:53:43 +010025 return fetch(window.location.pathname + 'restservices/clds/v2/policies', {
sebdeteb8e3f12021-01-24 18:12:36 +010026 method: 'GET',
27 credentials: 'same-origin'
28 })
29 .then(function (response) {
30 console.debug("getPoliciesList response received: ", response.status);
31 if (response.ok) {
32 return response.json();
33 } else {
34 console.error("getPoliciesList query failed");
35 return {};
36 }
37 })
38 .catch(function (error) {
39 console.error("getPoliciesList error received", error);
40 return {};
41 });
42 }
sebdetc427e642021-02-17 17:53:17 +010043 static createNewPolicy(policyModelType, policyModelVersion, policyJson) {
44 return fetch(window.location.pathname + 'restservices/clds/v2/policies/' + policyModelType + '/' + policyModelVersion, {
45 method: 'POST',
46 credentials: 'same-origin',
47 headers: {
48 "Content-Type": "application/json"
49 },
50 body: JSON.stringify(policyJson)
51 })
52 .then(function (response) {
53 console.debug("createNewPolicy response received: ", response.status);
54 if (response.ok) {
55 return response.text;
56 } else {
57 console.error("createNewPolicy query failed");
58 return "";
59 }
60 })
61 .catch(function (error) {
62 console.error("createNewPolicy error received", error);
63 throw new Error(error)
64 });
65 }
sebdeteb8e3f12021-01-24 18:12:36 +010066}