blob: b324759a67aa2a1d187d183f93f25d1c00f8efa0 [file] [log] [blame]
Jian Lic704b672018-09-04 18:52:53 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * 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
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.openstacknode.api;
18
19import com.google.common.base.MoreObjects;
20
21import java.util.Objects;
22
23import static com.google.common.base.Preconditions.checkArgument;
24
25/**
26 * Implementation class of keystone config.
27 */
28public final class DefaultKeystoneConfig implements KeystoneConfig {
29
30 private final String endpoint;
31 private final OpenstackAuth auth;
32
33 private static final String NOT_NULL_MSG = "% cannot be null";
34
35 private DefaultKeystoneConfig(String endpoint, OpenstackAuth auth) {
36 this.endpoint = endpoint;
37 this.auth = auth;
38 }
39
40 @Override
41 public String endpoint() {
42 return endpoint;
43 }
44
45 @Override
46 public OpenstackAuth authentication() {
47 return auth;
48 }
49
50 @Override
51 public boolean equals(Object o) {
52 if (this == o) {
53 return true;
54 }
55
56 if (o instanceof DefaultKeystoneConfig) {
57 DefaultKeystoneConfig that = (DefaultKeystoneConfig) o;
58 return Objects.equals(endpoint, that.endpoint) &&
59 Objects.equals(auth, that.auth);
60 }
61 return false;
62 }
63
64 @Override
65 public int hashCode() {
66
67 return Objects.hash(endpoint, auth);
68 }
69
70 @Override
71 public String toString() {
72 return MoreObjects.toStringHelper(this)
73 .add("endpoint", endpoint)
74 .add("auth", auth)
75 .toString();
76 }
77
78 /**
79 * Returns new builder instance.
80 *
81 * @return keystone config instance builder
82 */
83 public static Builder builder() {
84 return new Builder();
85 }
86
87 /**
88 * A builder class for keystone config.
89 */
90 public static final class Builder implements KeystoneConfig.Builder {
91
92 private String endpoint;
93 private OpenstackAuth auth;
94
95 // private constructor not intended to use from external
96 private Builder() {
97 }
98
99 @Override
100 public KeystoneConfig build() {
101 checkArgument(endpoint != null, NOT_NULL_MSG, "endpoint");
102 checkArgument(auth != null, NOT_NULL_MSG, "auth");
103
104 return new DefaultKeystoneConfig(endpoint, auth);
105 }
106
107 @Override
108 public Builder endpoint(String endpoint) {
109 this.endpoint = endpoint;
110 return this;
111 }
112
113 @Override
114 public Builder authentication(OpenstackAuth auth) {
115 this.auth = auth;
116 return this;
117 }
118 }
119}