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.fasterxml.jackson.annotation.JsonProperty;
18
19 import java.util.Collections;
20 import java.util.Map;
21
22 /**
23  * Endpoint configuration for a service in a partition.
24  */

25 public class Service {
26
27     /**
28      * endpoint configuration for every region in a partition.
29      */

30     private final Map<String, Endpoint> endpoints;
31
32     /**
33      * default endpoint configuration for a service across all regions in the
34      * partition
35      */

36     private Endpoint defaults;
37
38     /**
39      * the region name if the service is enabled partition wide.
40      */

41     private String partitionEndpoint;
42
43     /**
44      * Returns true if the service is regionalized.
45      */

46     private boolean isRegionalized;
47
48     public Service(@JsonProperty(value = "endpoints") Map<String,
49             Endpoint> endpoints) {
50         // Technically the endpoints member should never be null if the
51         // endpoints file is properly formed, but this is currently not always
52         // true. See TRE-739 for details
53         this.endpoints = endpoints == null ? Collections.<String, Endpoint>emptyMap() : endpoints;
54     }
55
56     /**
57      * Returns the endpoints configuration for all regions in a partition
58      * that service supports.
59      */

60     public Map<String, Endpoint> getEndpoints() {
61         return endpoints;
62     }
63
64     /**
65      * returns the default endpoints configuration for all regions in a
66      * partition.
67      */

68     public Endpoint getDefaults() {
69         return defaults;
70     }
71
72     /**
73      * Sets the default endpoints configuration for all regions in a
74      * partition.
75      */

76     public void setDefaults(Endpoint defaults) {
77         this.defaults = defaults;
78     }
79
80     /**
81      * returns the region name if the service is enabled partition wide.
82      */

83     public String getPartitionEndpoint() {
84         return partitionEndpoint;
85     }
86
87     /**
88      * sets the region name if the service is enabled partition wide.
89      */

90     @JsonProperty(value = "partitionEndpoint")
91     public void setPartitionEndpoint(String partitionEndpoint) {
92         this.partitionEndpoint = partitionEndpoint;
93     }
94
95     /**
96      * returns true if the service is regionalized.
97      */

98     public boolean isRegionalized() {
99         return isRegionalized;
100     }
101
102     /**
103      * sets the regionalized property for a service..
104      */

105     @JsonProperty(value = "isRegionalized")
106     public void setRegionalized(boolean regionalized) {
107         isRegionalized = regionalized;
108     }
109
110     /**
111      * A convienient method that returns true if a service has a partition
112      * wide endpoint available.
113      */

114     public boolean isPartitionWideEndpointAvailable() {
115         return this.partitionEndpoint != null;
116     }
117 }
118