9c301871aaca2953a150514a1720d5a03db21cc6
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / util / AAIConfigCommandLinePropGetter.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.util;
23
24 import org.onap.aai.exceptions.AAIException;
25
26 /*
27  * The script deobfuscatePW.sh needs to retrieve pws from the AAIConfig file.
28  * As AAIConfig has no main to be callable on the command line, this class helps
29  * by providing one for accessing AAIConfig that way.
30  * (AAIConfig deobfuscates pws itself, so we just need to call its .get() on the desired pw.)
31  * 
32  * This could be used to get any property from AAIConfig via the command line,
33  * not just the pws, even though it was made for pw-related needs.
34  */
35 public class AAIConfigCommandLinePropGetter {
36
37         /**
38          * The main method.
39          *
40          * @param args the arguments
41          */
42         /*
43          * usage:
44          * AAIConfigCommandLinePropGetter propertyname
45          */
46         public static void main(String[] args) {
47                 if (args.length != 1) {
48                         System.out.println("only one property may be requested at a time");
49                         System.out.println("usage: AAIConfigCommandLinePropGetter propertyname");
50                 }
51                 try {
52                         AAIConfig.init();
53                         String value = AAIConfig.get(args[0]);
54                         if (value != null) {
55                                 System.out.println(value); //bc this utility used by a shell script so it needs the result sent to stdout
56                         } else {
57                                 System.out.println("requested property could not be found");
58                         }
59                 } catch(AAIException e) {
60                         System.out.println("exception:" + e.toString()); //TODO is this reasonable?
61                 } finally {
62                         System.exit(0);
63                 }
64
65         }
66
67 }