2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Bell Canada.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.onap.policy.models.simulators;
22 import java.nio.charset.StandardCharsets;
23 import java.util.Base64;
26 import lombok.ToString;
27 import org.onap.policy.common.parameters.ParameterGroupImpl;
28 import org.onap.policy.common.parameters.ParameterRuntimeException;
29 import org.onap.policy.common.parameters.annotations.Max;
30 import org.onap.policy.common.parameters.annotations.Min;
31 import org.onap.policy.common.parameters.annotations.NotNull;
36 public class CdsServerParameters extends ParameterGroupImpl {
38 // Port range constants
39 private static final int MIN_USER_PORT = 1024;
40 private static final int MAX_USER_PORT = 65535;
42 private static final String SERVER_PROPERTIES_TYPE = "CDS gRPC Server Properties";
44 // CDS carrier properties
46 // Request timeout in seconds
50 @Min(value = MIN_USER_PORT)
51 @Max(value = MAX_USER_PORT)
55 private int successRepeatCount;
57 private int requestedResponseDelayMs;
63 private String username;
66 private String password;
69 private String resourceLocation;
72 public String getName() {
73 return SERVER_PROPERTIES_TYPE;
77 public void setName(final String name) {
78 throw new ParameterRuntimeException("The name of this ParameterGroup implementation is always " + getName());
82 * Generate base64-encoded Authorization header from username and password.
84 * @return Base64 encoded string
86 public String getBasicAuth() {
87 String encodedAuth = Base64.getEncoder().encodeToString(
88 String.format("%s:%s", getUsername(), getPassword()).getBytes(StandardCharsets.UTF_8));
89 // Return encoded basic auth header
90 return "Basic " + encodedAuth;