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