Unit test cases for iaas impl package
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / main / java / org / onap / appc / adapter / iaas / impl / ServiceCatalogFactory.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP : APPC\r
4  * ================================================================================\r
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Copyright (C) 2017 Amdocs\r
8  * =============================================================================\r
9  * Licensed under the Apache License, Version 2.0 (the "License");\r
10  * you may not use this file except in compliance with the License.\r
11  * You may obtain a copy of the License at\r
12  * \r
13  *      http://www.apache.org/licenses/LICENSE-2.0\r
14  * \r
15  * Unless required by applicable law or agreed to in writing, software\r
16  * distributed under the License is distributed on an "AS IS" BASIS,\r
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
18  * See the License for the specific language governing permissions and\r
19  * limitations under the License.\r
20  * \r
21  * ============LICENSE_END=========================================================\r
22  */\r
23 \r
24 package org.onap.appc.adapter.iaas.impl;\r
25 \r
26 import java.util.Properties;\r
27 \r
28 import com.att.eelf.configuration.EELFLogger;\r
29 import com.att.eelf.configuration.EELFManager;\r
30 \r
31 public class ServiceCatalogFactory {\r
32         \r
33         private static EELFLogger logger= EELFManager.getInstance().getLogger(org.onap.appc.adapter.iaas.impl.ServiceCatalogFactory.class);\r
34 \r
35     /**\r
36      * This method accepts a fully qualified identity service URL and uses that to determine which version of the\r
37      * serviceCatalog to load.\r
38      *\r
39      * @param url The parsed URL of the identity service\r
40      * @param projectIdentifier The project or tenant to be used to connect to the service\r
41      * @param principal The principal or user to be used to connect to the service\r
42      * @param ceredential The credential or password to be used to connect to the service\r
43      * @param properties Properties object for proxy information\r
44      * @return The serviceCatalog for identity service version specified in the url, null if not supported.\r
45      */\r
46     public static ServiceCatalog getServiceCatalog(String url, String projectIdentifier, String principal,\r
47             String credential, String domain, Properties properties) {\r
48         IdentityURL idUrl = IdentityURL.parseURL(url);\r
49         if(idUrl == null){\r
50                 logger.error("Url " + url + " could not be parsed.");\r
51                 return null;\r
52         }\r
53         String version = idUrl.getVersion();\r
54         String prefix = version.split("\\.")[0];\r
55         if("v2".equals(prefix)){\r
56                 return new ServiceCatalogV2(url, projectIdentifier, principal, credential, properties);\r
57         }\r
58         else if("v3".equals(prefix)){\r
59                 return new ServiceCatalogV3(url, projectIdentifier, principal, credential, domain, properties);\r
60         }\r
61         return null;\r
62     }\r
63 }\r