2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.config;
23 import org.openecomp.sdc.ci.tests.datatypes.UserCredentials;
24 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
25 import org.yaml.snakeyaml.Yaml;
30 public class UserCredentialsFromFile {
32 private static final String CREDENTIALS_FILE = "credentials.yaml";
33 private static Map<String, UserCredentials> credentials;
34 private static Yaml yaml = new Yaml();
36 private static final UserCredentialsFromFile instance = new UserCredentialsFromFile();
38 public static UserCredentialsFromFile getInstance(){
42 private UserCredentialsFromFile() {
46 File credentialsFileRemote = new File(FileHandling.getBasePath() + File.separator + "conf" + File.separator + CREDENTIALS_FILE);
47 // File credentialsFileLocal = new File(FileHandling.getConfFilesPath() + CREDENTIALS_FILE);
48 File credentialsFileLocal = new File(FileHandling.getSdcVnfsPath() + File.separator + "conf"
49 + File.separator + CREDENTIALS_FILE);
50 File[] credentialFiles = {credentialsFileRemote, credentialsFileLocal};
51 for (File credentialsFile : credentialFiles){
52 if (credentialsFile.exists()){
54 credentials = (Map<String, UserCredentials>) FileHandling.parseYamlFile(credentialsFile.getAbsolutePath());
55 } catch (Exception e) {
65 public UserCredentials getUserCredentialsByRole(String userRole) {
66 Map<String, String> credentialsMap = (Map<String, String>) credentials.get(userRole);
67 UserCredentials userCredentials = new UserCredentials();
68 userCredentials.setUserId(credentialsMap.get("username"));
69 userCredentials.setFirstName(credentialsMap.get("firstname"));
70 userCredentials.setLastName(credentialsMap.get("lastname"));
71 userCredentials.setPassword(credentialsMap.get("password"));
72 return userCredentials;