Migrate sdc-sdc-workflow-designer docs
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / config / Configuration.js
1 /*
2  * Copyright © 2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 import configData from './config.json';
17
18 class Configuration {
19     get(key) {
20         return configData[key];
21     }
22
23     set(key, value) {
24         var prev = configData[key];
25         configData[key] = value;
26         return prev;
27     }
28
29     setCatalogApiRoot(CatalogApiRoot) {
30         let restCatalogPrefix = CatalogApiRoot,
31             restPrefix = CatalogApiRoot.replace(
32                 /\/feProxy\b[^:]*$/,
33                 '/feProxy/onboarding-api'
34             );
35
36         this.set('restPrefix', restPrefix);
37         this.set('restCatalogPrefix', restCatalogPrefix);
38     }
39
40     setCatalogApiHeaders(CatalogApiHeaders) {
41         this.set('CatalogApiHeaders', CatalogApiHeaders);
42
43         let { userId: { value: UserID } = {} } = CatalogApiHeaders;
44         this.set('UserID', UserID);
45     }
46 }
47
48 const configuration = new Configuration();
49
50 (function setDefaultRestPrefixes(configuration) {
51     configuration.set('restPrefix', configuration.get('defaultRestPrefix'));
52     configuration.set(
53         'restCatalogPrefix',
54         configuration.get('defaultRestCatalogPrefix')
55     );
56     configuration.set(
57         'activitiesRestPrefix',
58         configuration.get('activitiesRestPrefix')
59     );
60     configuration.set('appContextPath', configuration.get('appContextPath'));
61 })(configuration);
62
63 export default configuration;