1 /*
2 * Copyright 2013-2019 the original author or authors.
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 * https://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
17 package org.springframework.cloud.aws.core.region;
18
19 import com.amazonaws.regions.Region;
20 import com.amazonaws.regions.Regions;
21
22 import org.springframework.cloud.aws.core.support.documentation.RuntimeUse;
23
24 /**
25 * Static {@link RegionProvider} implementation that can used to statically configure a
26 * region. The region could be provided through a configuration file at configuration
27 * time.
28 *
29 * @author Agim Emruli
30 * @since 1.0
31 */
32 public class StaticRegionProvider implements RegionProvider {
33
34 private final Region configuredRegion;
35
36 /**
37 * Constructs and configures the static region for this RegionProvider implementation.
38 * @param configuredRegion - the region that will be statically returned in
39 * {@link #getRegion()}
40 */
41 @RuntimeUse
42 public StaticRegionProvider(String configuredRegion) {
43 try {
44 this.configuredRegion = Region.getRegion(Regions.fromName(configuredRegion));
45 }
46 catch (IllegalArgumentException e) {
47 throw new IllegalArgumentException(
48 "The region '" + configuredRegion + "' is not a valid region!", e);
49 }
50 }
51
52 /**
53 * Return the configured Region configured at construction time.
54 * @return the configured region, for every call the same
55 */
56 @Override
57 public Region getRegion() {
58 return this.configuredRegion;
59 }
60
61 }
62