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