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
 
   9  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  17  * SPDX-License-Identifier: Apache-2.0
 
  18  * ============LICENSE_END=========================================================
 
  20 package org.onap.so.adapters.vnfmadapter;
 
  22 import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL;
 
  23 import static org.onap.so.adapters.vnfmadapter.Constants.ETSI_SUBSCRIPTION_NOTIFICATION_BASE_URL;
 
  24 import static org.onap.so.adapters.vnfmadapter.Constants.OPERATION_NOTIFICATION_ENDPOINT;
 
  25 import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL;
 
  26 import static org.slf4j.LoggerFactory.getLogger;
 
  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;
 
  38  * Provides VNFM Adapter endpoint URLs
 
  40  * @author Waqas Ikram (waqas.ikram@est.tech)
 
  44 public class VnfmAdapterUrlProvider {
 
  46     private static final Logger logger = getLogger(VnfmAdapterUrlProvider.class);
 
  47     private static final String COLON = ":";
 
  48     private static final int LIMIT = 2;
 
  50     private final String vnfmAdapterEndpoint;
 
  51     private final String msoKeyString;
 
  52     private final String vnfmAdapterAuth;
 
  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;
 
  63     public String getEtsiSubscriptionNotificationBaseUrl() {
 
  64         return vnfmAdapterEndpoint + ETSI_SUBSCRIPTION_NOTIFICATION_BASE_URL;
 
  67     public URI getSubscriptionUri(final String subscriptionId) {
 
  68         return URI.create(getSubscriptionUriString(subscriptionId));
 
  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]);
 
  77         logger.error("Unexpected auth value: {}", vnfmAdapterAuth);
 
  78         return ImmutablePair.nullPair();
 
  81     public String getSubscriptionUriString(final String subscriptionId) {
 
  82         return vnfmAdapterEndpoint + PACKAGE_MANAGEMENT_BASE_URL + "/subscriptions/" + subscriptionId;
 
  85     public String getVnfLcmOperationOccurrenceNotificationUrl() {
 
  86         return vnfmAdapterEndpoint + BASE_URL + OPERATION_NOTIFICATION_ENDPOINT;
 
  89     public String getVnfPackageUrl(final String vnfPkgId) {
 
  90         return vnfmAdapterEndpoint + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/" + vnfPkgId;
 
  93     public String getVnfPackageVnfdUrl(final String vnfPkgId) {
 
  94         return getVnfPackageUrl(vnfPkgId) + "/vnfd";
 
  97     public String getVnfPackageContentUrl(final String vnfPkgId) {
 
  98         return getVnfPackageUrl(vnfPkgId) + "/package_content";
 
 101     public String getOauthTokenUrl() {
 
 102         return vnfmAdapterEndpoint + "/oauth/token";