Fixing SO build
[so.git] / adapters / etsi-sol003-adapter / etsi-sol003-adapter-common / src / main / java / org / onap / so / adapters / etsi / sol003 / adapter / common / VnfmAdapterUrlProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.adapters.etsi.sol003.adapter.common;
21
22 import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.BASE_URL;
23 import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.ETSI_SUBSCRIPTION_NOTIFICATION_BASE_URL;
24 import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.OPERATION_NOTIFICATION_ENDPOINT;
25 import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.PACKAGE_MANAGEMENT_BASE_URL;
26 import static org.slf4j.LoggerFactory.getLogger;
27 import java.net.URI;
28 import java.security.GeneralSecurityException;
29 import org.apache.commons.lang3.tuple.ImmutablePair;
30 import org.onap.so.utils.CryptoUtils;
31 import org.slf4j.Logger;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.beans.factory.annotation.Value;
34 import org.springframework.context.annotation.Configuration;
35
36
37 /**
38  * Provides VNFM Adapter endpoint URLs
39  * 
40  * @author Waqas Ikram (waqas.ikram@est.tech)
41  *
42  */
43 @Configuration
44 public class VnfmAdapterUrlProvider {
45
46     private static final Logger logger = getLogger(VnfmAdapterUrlProvider.class);
47     private static final String COLON = ":";
48     private static final int LIMIT = 2;
49
50     private final String vnfmAdapterEndpoint;
51     private final String msoKeyString;
52     private final String vnfmAdapterAuth;
53
54     @Autowired
55     public VnfmAdapterUrlProvider(@Value("${vnfmadapter.endpoint}") final String vnfmAdapterEndpoint,
56             @Value("${mso.key}") final String msoKeyString,
57             @Value("${vnfmadapter.auth:BF29BA36F0CFE1C05507781F6B97EFBCA7EFAC9F595954D465FC43F646883EF585C20A58CBB02528A6FAAC}") final String vnfmAdapterAuth) {
58         this.vnfmAdapterEndpoint = vnfmAdapterEndpoint;
59         this.msoKeyString = msoKeyString;
60         this.vnfmAdapterAuth = vnfmAdapterAuth;
61     }
62
63     public String getEtsiSubscriptionNotificationBaseUrl() {
64         return vnfmAdapterEndpoint + ETSI_SUBSCRIPTION_NOTIFICATION_BASE_URL;
65     }
66
67     public URI getSubscriptionUri(final String subscriptionId) {
68         return URI.create(getSubscriptionUriString(subscriptionId));
69     }
70
71     public ImmutablePair<String, String> getDecryptAuth() throws GeneralSecurityException {
72         final String decryptedAuth = CryptoUtils.decrypt(vnfmAdapterAuth, msoKeyString);
73         final String[] auth = decryptedAuth.split(COLON, LIMIT);
74         if (auth.length > 1) {
75             return ImmutablePair.of(auth[0], auth[1]);
76         }
77         logger.error("Unexpected auth value: {}", vnfmAdapterAuth);
78         return ImmutablePair.nullPair();
79     }
80
81     public String getSubscriptionUriString(final String subscriptionId) {
82         return vnfmAdapterEndpoint + PACKAGE_MANAGEMENT_BASE_URL + "/subscriptions/" + subscriptionId;
83     }
84
85     public String getVnfLcmOperationOccurrenceNotificationUrl() {
86         return vnfmAdapterEndpoint + BASE_URL + OPERATION_NOTIFICATION_ENDPOINT;
87     }
88
89     public String getVnfPackageUrl(final String vnfPkgId) {
90         return vnfmAdapterEndpoint + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/" + vnfPkgId;
91     }
92
93     public String getVnfPackageVnfdUrl(final String vnfPkgId) {
94         return getVnfPackageUrl(vnfPkgId) + "/vnfd";
95     }
96
97     public String getVnfPackageContentUrl(final String vnfPkgId) {
98         return getVnfPackageUrl(vnfPkgId) + "/package_content";
99     }
100
101     public String getOauthTokenUrl() {
102         return vnfmAdapterEndpoint + "/oauth/token";
103     }
104
105 }