blob: 7e6cc1e502040c7d44df94859120121931655a5e [file] [log] [blame]
Daniel Parkdeefa702018-07-17 17:55:51 +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 */
Jian Li2a2d26c2018-10-08 11:29:31 +090016package org.onosproject.openstacknode.api;
Daniel Parkdeefa702018-07-17 17:55:51 +090017
18import com.google.common.base.MoreObjects;
Daniel Parkdeefa702018-07-17 17:55:51 +090019
20import java.util.Objects;
21
22import static com.google.common.base.Preconditions.checkArgument;
23/**
24 * Implementation class of ssh authentication.
25 */
26public final class DefaultOpenstackSshAuth implements OpenstackSshAuth {
27 private final String id;
28 private final String password;
29
30 private static final String NOT_NULL_MSG = "% cannot be null";
31
32 /**
33 * A default constructor of ssh authentication instance.
34 *
35 * @param id ssh auth ID
36 * @param password ssh auth password
37 */
38 private DefaultOpenstackSshAuth(String id, String password) {
39 this.id = id;
40 this.password = password;
41 }
42
43 @Override
44 public String id() {
45 return id;
46 }
47
48 @Override
49 public String password() {
50 return password;
51 }
52
53 @Override
54 public boolean equals(Object obj) {
55 if (this == obj) {
56 return true;
57 }
58
59 if (obj instanceof DefaultOpenstackSshAuth) {
60 DefaultOpenstackSshAuth that = (DefaultOpenstackSshAuth) obj;
61 return Objects.equals(id, that.id) &&
62 Objects.equals(password, that.password);
63 }
64
65 return false;
66 }
67
68 @Override
69 public int hashCode() {
70 return Objects.hash(id, password);
71 }
72
73 @Override
74 public String toString() {
75 return MoreObjects.toStringHelper(getClass())
76 .add("id", id)
77 .add("password", password)
78 .toString();
79 }
80
81 /**
82 * Returns new builder instance.
83 *
84 * @return ssh authentication instance builder
85 */
86 public static Builder builder() {
87 return new Builder();
88 }
89
90 /**
91 * Builder of OpenstackSshAuth instance.
92 */
93 public static final class Builder implements OpenstackSshAuth.Builder {
94 private String id;
95 private String password;
96
97 private Builder() {
98
99 }
100
101 @Override
102 public OpenstackSshAuth build() {
103 checkArgument(id != null, NOT_NULL_MSG, "id");
104 checkArgument(password != null, NOT_NULL_MSG, "password");
105
106 return new DefaultOpenstackSshAuth(id, password);
107 }
108
109 @Override
110 public Builder id(String id) {
111 this.id = id;
112 return this;
113 }
114
115 @Override
116 public Builder password(String password) {
117 this.password = password;
118 return this;
119 }
120 }
121}