7a84524603a7f64ee13400e5ed85616d2eae0080
[dcaegen2/collectors/datafile.git] /
1 /*-
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2018,2019 Nordix Foundation. All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6  * in compliance with the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License
11  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12  * or implied. See the License for the specific language governing permissions and limitations under
13  * the License.
14  * ============LICENSE_END========================================================================
15  */
16
17 package org.onap.dcaegen2.collectors.datafile.configuration;
18
19 import java.net.MalformedURLException;
20 import java.net.URL;
21 import org.immutables.gson.Gson;
22 import org.immutables.value.Value;
23 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
24 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration;
25
26 @Value.Immutable
27 @Value.Style(redactedMask = "####")
28 @Gson.TypeAdapters
29 public interface PublisherConfiguration {
30
31     String publishUrl();
32
33     String logUrl();
34
35     String userName();
36
37     @Value.Redacted
38     String passWord();
39
40     String trustStorePath();
41
42     String trustStorePasswordPath();
43
44     String keyStorePath();
45
46     String keyStorePasswordPath();
47
48     Boolean enableDmaapCertAuth();
49
50     String changeIdentifier();
51
52     /**
53      * Get the publisher configuration in SDK format.
54      *
55      * @return a <code>DmaapPublisherConfiguration</code> contining the publisher configuration.
56      * @throws MalformedURLException if the publish URL is malformed.
57      */
58     default DmaapPublisherConfiguration toDmaap() throws MalformedURLException {
59         URL url = new URL(publishUrl());
60         String urlPath = url.getPath();
61
62         return new ImmutableDmaapPublisherConfiguration.Builder() //
63             .dmaapContentType("application/octet-stream") //
64             .dmaapPortNumber(url.getPort()) //
65             .dmaapHostName(url.getHost()) //
66             .dmaapTopicName(urlPath) //
67             .dmaapProtocol(url.getProtocol()) //
68             .dmaapUserName(this.userName()) //
69             .dmaapUserPassword(this.passWord()) //
70             .trustStorePath(this.trustStorePath()) //
71             .trustStorePasswordPath(this.trustStorePasswordPath()) //
72             .keyStorePath(this.keyStorePath()) //
73             .keyStorePasswordPath(this.keyStorePasswordPath()) //
74             .enableDmaapCertAuth(this.enableDmaapCertAuth()) //
75             .build();
76     }
77 }