-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from ohnosequences/pr/53
Refactor AMIs
- Loading branch information
Showing
4 changed files
with
170 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
src/main/scala/ohnosequences/awstools/regions/aliases.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ohnosequences.awstools.regions | ||
|
||
import com.amazonaws.regions._ | ||
|
||
/* ## Geographical aliales | ||
This sealed class reflects the `Regions` from the SDK, but allows us to have | ||
- convenient aliases based on the geographical locations | ||
- precise type for each region and dispatch on it in implicit resolution (see AMIs code) | ||
This type is also implicitly converted to `Region`, `Regions` and `AwsRegionProvider` types, so you can use it anywhere those types are expected (once you've imported `ohnosequences.awstools.regions._`) | ||
*/ | ||
sealed abstract class RegionAlias(val region: Regions) | ||
|
||
/* - Asia Pacific */ | ||
case object Tokyo extends RegionAlias(Regions.AP_NORTHEAST_1) | ||
case object Seoul extends RegionAlias(Regions.AP_NORTHEAST_2) | ||
case object Mumbai extends RegionAlias(Regions.AP_SOUTH_1) | ||
case object Singapore extends RegionAlias(Regions.AP_SOUTHEAST_1) | ||
case object Sydney extends RegionAlias(Regions.AP_SOUTHEAST_2) | ||
/* - China */ | ||
case object Beijing extends RegionAlias(Regions.CN_NORTH_1) | ||
/* - Europe */ | ||
case object Frankfurt extends RegionAlias(Regions.EU_CENTRAL_1) | ||
case object Ireland extends RegionAlias(Regions.EU_WEST_1) | ||
/* - Somewhere in CIA */ | ||
case object GovCloud extends RegionAlias(Regions.GovCloud) | ||
/* - South America */ | ||
case object SaoPaulo extends RegionAlias(Regions.SA_EAST_1) | ||
/* - US East */ | ||
case object NorthernVirginia extends RegionAlias(Regions.US_EAST_1) | ||
// TODO: update sdk version: | ||
case object Ohio extends RegionAlias(Regions.US_EAST_2) | ||
/* - US West */ | ||
case object NorthernCalifornia extends RegionAlias(Regions.US_WEST_1) | ||
case object Oregon extends RegionAlias(Regions.US_WEST_2) |
30 changes: 30 additions & 0 deletions
30
src/main/scala/ohnosequences/awstools/regions/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ohnosequences.awstools | ||
|
||
import com.amazonaws.regions._ | ||
|
||
package object regions { | ||
|
||
/* Adding SDK types to the scope without SDK imports: */ | ||
type Regions = com.amazonaws.regions.Regions | ||
type Region = com.amazonaws.regions.Region | ||
type AwsRegionProvider = com.amazonaws.regions.AwsRegionProvider | ||
type DefaultAwsRegionProviderChain = com.amazonaws.regions.DefaultAwsRegionProviderChain | ||
|
||
/* ### Implicits */ | ||
|
||
/* - `Regions` enum → `Region` and `AwsRegionProvider` */ | ||
implicit def RegionsToRegion(regions: Regions): Region = Region.getRegion(regions) | ||
implicit def RegionsToProvider(region: Regions): AwsRegionProvider = RegionToProvider(region) | ||
|
||
/* - `Region` type ⇄ `AwsRegionProvider` */ | ||
implicit def RegionToProvider(region: Region): AwsRegionProvider = new AwsRegionProvider { | ||
override def getRegion(): String = region.getName | ||
} | ||
implicit def ProviderToRegion(provider: AwsRegionProvider): Region = Regions.fromName(provider.getRegion) | ||
|
||
/* - `RegionAlias` → each of the other three */ | ||
implicit def RegionAliasToRegions (alias: RegionAlias): Regions = alias.region | ||
implicit def RegionAliasToRegion (alias: RegionAlias): Region = alias.region | ||
implicit def RegionAliasToProvider(alias: RegionAlias): AwsRegionProvider = alias.region | ||
|
||
} |