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