4c759b2c668dbdc93664d7a2e3bc2ad60f0ef059
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / main / java / org / openecomp / appc / adapter / iaas / impl / ServiceCatalogFactory.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP : APPC\r
4  * ================================================================================\r
5  * Copyright (C) 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * ============LICENSE_END=========================================================\r
23  */\r
24 \r
25 package org.onap.appc.adapter.iaas.impl;\r
26 \r
27 import java.util.Properties;\r
28 \r
29 import com.att.eelf.configuration.EELFLogger;\r
30 import com.att.eelf.configuration.EELFManager;\r
31 \r
32 public class ServiceCatalogFactory {\r
33         \r
34         private static EELFLogger logger= EELFManager.getInstance().getLogger(org.onap.appc.adapter.iaas.impl.ServiceCatalogFactory.class);\r
35 \r
36     /**\r
37      * This method accepts a fully qualified identity service URL and uses that to determine which version of the\r
38      * serviceCatalog to load.\r
39      *\r
40      * @param url The parsed URL of the identity service\r
41      * @param projectIdentifier The project or tenant to be used to connect to the service\r
42      * @param principal The principal or user to be used to connect to the service\r
43      * @param ceredential The credential or password to be used to connect to the service\r
44      * @param properties Properties object for proxy information\r
45      * @return The serviceCatalog for identity service version specified in the url, null if not supported.\r
46      */\r
47     public static ServiceCatalog getServiceCatalog(String url, String projectIdentifier, String principal,\r
48             String credential, String domain, Properties properties) {\r
49         IdentityURL idUrl = IdentityURL.parseURL(url);\r
50         if(idUrl == null){\r
51                 logger.error("Url " + url + " could not be parsed.");\r
52                 return null;\r
53         }\r
54         String version = idUrl.getVersion();\r
55         if(version == null){\r
56                 logger.error("Invalid Identity URL check configuration");\r
57                 return null;\r
58         }\r
59         String prefix = version.split("\\.")[0];\r
60         if (prefix != null) {\r
61             switch (prefix) {\r
62                 case "v2":\r
63                     return new ServiceCatalogV2(url, projectIdentifier, principal, credential, properties);\r
64                 case "v3":\r
65                     return new ServiceCatalogV3(url, projectIdentifier, principal, credential, domain, properties);\r
66             }\r
67         }\r
68         return null;\r
69     }\r
70 }\r