• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala RegionUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中com.amazonaws.regions.RegionUtils的典型用法代码示例。如果您正苦于以下问题:Scala RegionUtils类的具体用法?Scala RegionUtils怎么用?Scala RegionUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了RegionUtils类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: DynamoDbConfigurationSource

//设置package包名称以及导入依赖的类
package com.gu.cm

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.regions.RegionUtils
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient
import com.amazonaws.services.dynamodbv2.document.{PrimaryKey, DynamoDB}
import com.typesafe.config.{ConfigFactory, Config}
import scala.util.{Failure, Success, Try}

class DynamoDbConfigurationSource(dynamoDb: DynamoDB, identity: Identity, prefix: String) extends ConfigurationSource {

  val tableName = s"$prefix${identity.stack}"

  override def load: Config = {
    val config = for {
      table <- Try(dynamoDb.getTable(tableName))
      item <- Try(table.getItem(new PrimaryKey("App", identity.app, "Stage", identity.stage)))
    } yield {
      ConfigFactory.parseMap(item.getMap("Config"), s"Dynamo DB table $tableName [App=${identity.app}, Stage=${identity.stage}]")
    }

    config match {
      case Success(theConfig) => theConfig
      case Failure(theFailure) => ConfigFactory.empty(s"no DynamoDB config (or failed to load) for $tableName [App=${identity.app}, Stage=${identity.stage}], exception=[$theFailure]")
    }
  }
}

object DynamoDbConfigurationSource {
  def apply(identity: Identity, prefix: String = "config-"): DynamoDbConfigurationSource = {
    val dynamoDb = {
      val client = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain())
      client.setRegion(RegionUtils.getRegion(identity.region))
      new DynamoDB(client)
    }
    new DynamoDbConfigurationSource(dynamoDb, identity, prefix)
  }
} 
开发者ID:guardian,项目名称:configuration-magic,代码行数:39,代码来源:DynamoDbConfigurationSource.scala


示例2: S3ConfigurationSource

//设置package包名称以及导入依赖的类
package com.gu.cm

import com.amazonaws.auth.{AWSCredentialsProvider, DefaultAWSCredentialsProviderChain}
import com.amazonaws.regions.RegionUtils
import com.amazonaws.regions.ServiceAbbreviations.S3
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.model.GetObjectRequest
import com.typesafe.config.{Config, ConfigFactory}

import scala.util.{Failure, Success, Try}

class S3ConfigurationSource(s3: AmazonS3Client, identity: Identity, bucket: String, version: Option[Int]) extends ConfigurationSource {

  override def load: Config = {
    val configPath = versionedFilePath(identity, version)
    val request = new GetObjectRequest(bucket, configPath)
    val config = for {
      result <- Try(s3.getObject(request))
      item <- Try(scala.io.Source.fromInputStream(result.getObjectContent, "UTF-8").mkString)
    } yield {
      ConfigFactory.parseString(item)
    }

    config match {
      case Success(theConfig) => theConfig
      case Failure(theFailure) => ConfigFactory.empty(s"no s3 config (or failed to load) for bucket=$bucket path=$configPath, exception=[$theFailure]")
    }
  }

  def versionedFilePath(identity: Identity, version:Option[Int]): String = {
    val fileVersion = version.map(".v" + _).getOrElse("")
    s"config/${identity.region}-${identity.stack}$fileVersion.conf"
  }
}

object S3ConfigurationSource {
  def apply(identity: Identity, bucket: String, credentials: AWSCredentialsProvider = new DefaultAWSCredentialsProviderChain(), version: Option[Int] = None): S3ConfigurationSource = {
    val s3 = {
      val client = new AmazonS3Client(credentials)
      client.setRegion(RegionUtils.getRegion(identity.region))
      client.setEndpoint(RegionUtils.getRegion(identity.region).getServiceEndpoint(S3))
      client
    }
    new S3ConfigurationSource(s3, identity, bucket, version)
  }
} 
开发者ID:guardian,项目名称:configuration-magic,代码行数:47,代码来源:S3ConfigurationSource.scala


示例3: IdentitySpec

//设置package包名称以及导入依赖的类
package com.gu.cm

import com.amazonaws.regions.{RegionUtils, Region}
import org.specs2.mutable.Specification
import org.specs2.specification.Scope

class IdentitySpec extends Specification {
  "InstanceDescriber" should {
    "describe a test instance" in new InstanceDescriberScope {
      override val mode = Mode.Test
      instanceDescriber.whoAmI shouldEqual LocalApplication("Test App")
    }
    "describe a dev instance" in new InstanceDescriberScope {
      override val mode = Mode.Dev
      instanceDescriber.whoAmI shouldEqual LocalApplication("Test App")
    }
    "fail to describe a prod instance without tags" in new InstanceDescriberScope {
      instanceDescriber.whoAmI should throwA[RuntimeException]
    }
    "fail to describe a prod instance without the right tags" in new InstanceDescriberScope {
      override val instanceTags = Map("bleurg" -> "ouch")
      instanceDescriber.whoAmI should throwA[RuntimeException]
    }
    "describe a prod instance with the right tags" in new InstanceDescriberScope {
      override val instanceTags = Map("App" -> "myApp", "Stage" -> "TEST", "Stack" -> "myStack")
      instanceDescriber.whoAmI shouldEqual AwsApplication("myStack", "myApp", "TEST", "eu-west-1")
    }
  }

  trait InstanceDescriberScope extends Scope {
    def mode: Mode = Mode.Prod

    def instanceTags = Map.empty[String, String]

    def awsInstance = new AwsInstance {
      override def region: Option[Region] = Some(RegionUtils.getRegion("eu-west-1"))
      override def tags: Map[String, String] = instanceTags
    }

    def instanceDescriber = new InstanceDescriber(
      defaultAppName = "Test App",
      mode = mode,
      awsInstance = awsInstance
    )
  }
} 
开发者ID:guardian,项目名称:configuration-magic,代码行数:47,代码来源:IdentitySpec.scala


示例4: s3ConfigurationSourceSpec

//设置package包名称以及导入依赖的类
package com.gu.cm

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.regions.RegionUtils
import com.amazonaws.regions.ServiceAbbreviations._
import com.amazonaws.services.s3.AmazonS3Client
import org.specs2.mutable.Specification
import org.specs2.specification.Scope

class s3ConfigurationSourceSpec extends Specification {
  "a s3 configuration Source" should {
    "look for a versioned file if a version is present" in new s3Scope {
      val version = 2
      val filePath = s3ConfigurationSource.versionedFilePath(identity, Some(version))
      filePath shouldEqual "config/eu-west-1-test-stack.v2.conf"
    }

    "look for a non versioned file if a version is not present" in new s3Scope {
      val filePath = s3ConfigurationSource.versionedFilePath(identity, None)
      filePath shouldEqual "config/eu-west-1-test-stack.conf"
    }
  }

  trait s3Scope extends Scope {

    val identity = AwsApplication(
      stack = "test-stack",
      app = "configuration-magic",
      stage = "test",
      region = "eu-west-1"
    )

    val s3 = {
      val client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain())
      client.setRegion(RegionUtils.getRegion(identity.region))
      client.setEndpoint(RegionUtils.getRegion(identity.region).getServiceEndpoint(S3))
      client
    }

    val s3ConfigurationSource = new S3ConfigurationSource(s3, identity, "frontend", Some(1))

  }
} 
开发者ID:guardian,项目名称:configuration-magic,代码行数:44,代码来源:s3ConfigurationSourceSpec.scala



注:本文中的com.amazonaws.regions.RegionUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Protos类代码示例发布时间:2022-05-23
下一篇:
Scala ExpressionEncoder类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap