1 /*
2  * Copyright 2016-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */

15 package com.amazonaws.partitions.model;
16
17 import com.amazonaws.Protocol;
18 import com.fasterxml.jackson.annotation.JsonProperty;
19
20 import java.util.Set;
21
22 /**
23  * Endpoint configuration.
24  */

25 public class Endpoint {
26
27     /**
28      * endpoint string.
29      */

30     private String hostName;
31
32     /**
33      * credential scope for the endpoint.
34      */

35     private CredentialScope credentialScope;
36
37     /**
38      * supported schemes for the endpoint.
39      */

40     private Set<String> protocols;
41
42     /**
43      * supported signature versions of the endpoint.
44      */

45     private Set<String> signatureVersions;
46
47     /**
48      * ssl common name for the endpoint.
49      */

50     private String sslCommonName;
51
52     /**
53      * Merges the given endpoints and returns the merged one.
54      */

55     public static Endpoint merge(Endpoint defaults, Endpoint override) {
56
57         if (defaults == null) {
58             defaults = new Endpoint();
59         }
60
61         if (override == null) {
62             override = new Endpoint();
63         }
64
65         final Endpoint merged = new Endpoint();
66
67         merged.setCredentialScope(override.getCredentialScope() != null
68                 ? override.getCredentialScope()
69                 : defaults.getCredentialScope());
70
71         merged.setHostName(override.getHostName() != null
72                 ? override.getHostName()
73                 : defaults.getHostName());
74
75         merged.setSslCommonName(override.getSslCommonName() != null
76                 ? override.getSslCommonName()
77                 : defaults.getSslCommonName());
78
79         merged.setProtocols(override.getProtocols() != null
80                 ? override.getProtocols()
81                 : defaults.getProtocols());
82
83         merged.setSignatureVersions(override.getSignatureVersions() != null
84                 ? override.getSignatureVersions()
85                 : defaults.getSignatureVersions()
86         );
87
88         return merged;
89
90     }
91
92     /**
93      * returns the endpoint string.
94      */

95     public String getHostName() {
96         return hostName;
97     }
98
99     /**
100      * sets the endpoint string.
101      */

102     @JsonProperty(value = "hostname")
103     public void setHostName(String hostName) {
104         this.hostName = hostName;
105     }
106
107     /**
108      * returns credential scope for the endpoint.
109      */

110     public CredentialScope getCredentialScope() {
111         return credentialScope;
112     }
113
114     /**
115      * sets the credential scope for the endpoint.
116      */

117     @JsonProperty(value = "credentialScope")
118     public void setCredentialScope(CredentialScope credentialScope) {
119         this.credentialScope = credentialScope;
120     }
121
122     /**
123      * returns the supported schemes for the endpoint.
124      */

125     public Set<String> getProtocols() {
126         return protocols;
127     }
128
129     /**
130      * sets the supported schemes for the endpoint.
131      */

132     @JsonProperty(value = "protocols")
133     public void setProtocols(Set<String> protocols) {
134         this.protocols = protocols;
135     }
136
137     /**
138      * returns the supported signature versions of the endpoint.
139      */

140     public Set<String> getSignatureVersions() {
141         return signatureVersions;
142     }
143
144     /**
145      * returns the supported signature versions of the endpoint.
146      */

147     @JsonProperty(value = "signatureVersions")
148     public void setSignatureVersions(Set<String> signatureVersions) {
149         this.signatureVersions = signatureVersions;
150     }
151
152     /**
153      * returns the ssl common name for the endpoint.
154      */

155     public String getSslCommonName() {
156         return sslCommonName;
157     }
158
159     /**
160      * sets the ssl common name for the endpoint.
161      */

162     @JsonProperty(value = "sslCommonName")
163     public void setSslCommonName(String sslCommonName) {
164         this.sslCommonName = sslCommonName;
165     }
166
167     /**
168      * A convienient methods that returns true if the endpoint support HTTPS
169      * scheme. Returns false otherwise.
170      */

171     public boolean hasHttpsSupport() {
172         return isProtocolSupported(Protocol.HTTPS);
173     }
174
175     /**
176      * A convienient methods that returns true if the endpoint support HTTP
177      * scheme. Returns false otherwise.
178      */

179     public boolean hasHttpSupport() {
180         return isProtocolSupported(Protocol.HTTP);
181     }
182
183     private boolean isProtocolSupported(Protocol protocol) {
184         return protocols != null && protocols.contains(protocol.toString());
185     }
186
187 }
188