8f35ea5e7e8b706d767b9ae4e715e4d3ec833ca3
[dcaegen2/services/sdk.git] /
1 /*
2  * ============LICENSE_START====================================
3  * DCAEGEN2-SERVICES-SDK
4  * =========================================================
5  * Copyright (C) 2019 Nokia. 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.dcaegen2.services.sdk.rest.services.cbs.client.api;
22
23 import org.immutables.value.Value;
24
25 /**
26  * Immutable object which helps with construction of cloudRequestObject for specified Client. For usage take a look in
27  * CloudConfigurationClient.class
28  *
29  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 11/16/18
30  * @version 1.0.0 can be passed to ReactiveCloudConfigurationProvider, can be constructed out of
31  * org.onap.dcaegen2.services.sdk library.
32  * @since 1.0.0
33  */
34 @Value.Immutable(prehash = true)
35 public interface EnvProperties {
36
37     /**
38      * Name of environment variable containing Consul host name.
39      */
40     String ENV_CONSUL_HOST = "CONSUL_HOST";
41
42     /**
43      * Name of environment variable containing Config Binding Service <em>service name</em> as registered in Consul
44      * services API.
45      */
46     String ENV_CBS_NAME = "CONFIG_BINDING_SERVICE";
47
48     /**
49      * Name of environment variable containing current application name.
50      */
51     String ENV_APP_NAME = "HOSTNAME";
52
53     @Value.Parameter
54     String consulHost();
55
56     @Value.Parameter
57     Integer consulPort();
58
59     @Value.Parameter
60     String cbsName();
61
62     @Value.Parameter
63     String appName();
64
65     /**
66      * Creates EnvProperties from system environment variables.
67      *
68      * @return an instance of EnvProperties
69      * @throws NullPointerException when at least one of required parameters is missing
70      */
71     static EnvProperties fromEnvironment() {
72         return ImmutableEnvProperties.builder()
73                 .consulHost(System.getenv(ENV_CONSUL_HOST))
74                 .consulPort(8500)
75                 .cbsName(System.getenv(ENV_CBS_NAME))
76                 .appName(System.getenv(ENV_APP_NAME))
77                 .build();
78     }
79 }