当前位置: 首页>>代码示例>>Scala>>正文


Scala ProfileCredentialsProvider类代码示例

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


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

示例1: AwsContextProvider

//设置package包名称以及导入依赖的类
package aws

import com.amazonaws.auth.{
  AWSCredentialsProviderChain,
  AWSStaticCredentialsProvider,
  BasicAWSCredentials,
  ContainerCredentialsProvider
}
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.regions.Regions
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient
import com.amazonaws.services.s3.AmazonS3Client
import play.api.Logger

object AwsContextProvider {

  def genContext(isRunningInCompose: Boolean, region: Regions): (AmazonDynamoDBClient, AmazonS3Client) = {
    if (isRunningInCompose) {
      Logger.info("Running in compose")
      System.setProperty("com.amazonaws.sdk.disableCertChecking", "true")
      val awsCreds                      = new AWSStaticCredentialsProvider(new BasicAWSCredentials("key", "secret"))
      val dClient: AmazonDynamoDBClient = new AmazonDynamoDBClient(awsCreds).withRegion(region)
      val s3Client: AmazonS3Client      = new AmazonS3Client(awsCreds).withRegion(region)
      dClient.setEndpoint(sys.env("LOCAL_DYNAMO"))
      (dClient, s3Client)
    } else {
      val awsCreds = new AWSCredentialsProviderChain(
        new ContainerCredentialsProvider(),
        new ProfileCredentialsProvider()
      )
      (new AmazonDynamoDBClient(awsCreds).withRegion(region), new AmazonS3Client(awsCreds).withRegion(region))
    }
  }
} 
开发者ID:ovotech,项目名称:comms-template-manager,代码行数:35,代码来源:AwsContextProvider.scala

示例2: client

//设置package包名称以及导入依赖的类
package sbtecr

import com.amazonaws.AmazonWebServiceClient
import com.amazonaws.auth._
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.regions.Region

private[sbtecr] trait Aws {

  def client[T <: AmazonWebServiceClient](clientClass: Class[T], region: Region): T = {
    region.createClient(clientClass, credentialsProvider(), null)
  }

  private def credentialsProvider(): AWSCredentialsProvider =
    new AWSCredentialsProviderChain(
      new EnvironmentVariableCredentialsProvider(),
      new SystemPropertiesCredentialsProvider(),
      new ProfileCredentialsProvider(sys.env.getOrElse("AWS_DEFAULT_PROFILE", "default")),
      new InstanceProfileCredentialsProvider()
    )
} 
开发者ID:sbilinski,项目名称:sbt-ecr,代码行数:22,代码来源:Aws.scala

示例3: DynamoClientProvider

//设置package包名称以及导入依赖的类
package aws

import com.amazonaws.ClientConfiguration
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.client.builder.AwsClientBuilder
import com.amazonaws.services.dynamodbv2.{AmazonDynamoDB, AmazonDynamoDBClientBuilder}
import com.google.inject.Singleton

@Singleton
class DynamoClientProvider {

  def apply(): AmazonDynamoDB = client

  val client: AmazonDynamoDB = AmazonDynamoDBClientBuilder.standard()
    .withCredentials(new ProfileCredentialsProvider())
    .withClientConfiguration(config())
    .withEndpointConfiguration(
      new AwsClientBuilder.EndpointConfiguration("https://dynamodb.eu-west-1.amazonaws.com", "eu-west-1"))
    .build();

  def config(): ClientConfiguration = {
    val clientConfig = new ClientConfiguration()
    clientConfig.setProxyHost("surf.proxy.agis.allianz")
    clientConfig.setProxyPort(8080)
    clientConfig
  }

} 
开发者ID:olo-b,项目名称:FoodService,代码行数:29,代码来源:DynamoClientProvider.scala

示例4: PanDomainAuthService

//设置package包名称以及导入依赖的类
package lib

import java.util.Date

import com.amazonaws.auth._
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.gu.pandomainauth.PanDomainAuth
import com.gu.pandomainauth.model.{AuthenticatedUser, User}
import com.gu.pandomainauth.service.LegacyCookie

object PanDomainAuthService extends PanDomainAuth {
  lazy val system    = Config.system
  lazy val domain    = Config.domain

  override lazy val awsCredentialsProvider: AWSCredentialsProvider =
    new AWSCredentialsProviderChain(
      new EnvironmentVariableCredentialsProvider(),
      new ProfileCredentialsProvider("workflow"))

  val oneDaysMillis: Long = 1000 * 60 * 60 * 24

  def generateCookie(email: String, firstName: String, lastName: String): String = {

    val authedUser = AuthenticatedUser(
      user = User(firstName, lastName, email, None),
      authenticatingSystem = system,
      authenticatedIn = Set(system),
      expires = new Date().getTime + oneDaysMillis,
      multiFactor = true
    )

    LegacyCookie.generateCookieData(authedUser, settings.secret)
  }
}

case class PandaCookie(key: String, value: String)
object PandaCookie {
  def apply(
             firstName:String = Config.userFirstName,
             lastName:String  = Config.userSecondName,
             email:String     = Config.userEmail
             ): PandaCookie  = {
    val cookieValue = PanDomainAuthService.generateCookie(email, firstName, lastName)

    PandaCookie("gutoolsAuth", cookieValue)
  }
} 
开发者ID:carriercomm,项目名称:editorial-tools-production-monitoring,代码行数:48,代码来源:PanDomainAuthService.scala

示例5: AwsProvider

//设置package包名称以及导入依赖的类
package com.ovoenergy.orchestration.aws

import com.amazonaws.auth._
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.regions.Regions
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient
import com.ovoenergy.comms.templates.TemplatesContext
import org.slf4j.LoggerFactory

object AwsProvider {

  private val log = LoggerFactory.getLogger("AwsClientProvider")

  def dynamoClient(isRunningInLocalDocker: Boolean, region: Regions): AmazonDynamoDBClient = {
    if (isRunningInLocalDocker) {
      log.warn("Running in local docker")
      System.setProperty("com.amazonaws.sdk.disableCertChecking", "true")
      val awsCreds                           = getCreds(isRunningInLocalDocker, region)
      val dynamoClient: AmazonDynamoDBClient = new AmazonDynamoDBClient(awsCreds).withRegion(region)
      dynamoClient.setEndpoint(sys.env("LOCAL_DYNAMO"))
      dynamoClient
    } else {
      val awsCreds = getCreds(isRunningInLocalDocker, region)
      new AmazonDynamoDBClient(awsCreds).withRegion(region)
    }
  }

  def templatesContext(isRunningInLocalDocker: Boolean, region: Regions) = {
    val awsCreds = getCreds(isRunningInLocalDocker, region)
    TemplatesContext.cachingContext(awsCreds)
  }

  private def getCreds(isRunningInLocalDocker: Boolean, region: Regions): AWSCredentialsProvider = {
    if (isRunningInLocalDocker)
      new AWSStaticCredentialsProvider(new BasicAWSCredentials("key", "secret"))
    else
      new AWSCredentialsProviderChain(
        new ContainerCredentialsProvider(),
        new ProfileCredentialsProvider()
      )
  }
} 
开发者ID:ovotech,项目名称:comms-orchestration,代码行数:43,代码来源:AwsProvider.scala

示例6: AuthTokenProvider

//设置package包名称以及导入依赖的类
package uk.co.telegraph.cloud.aws

import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.auth.{AWSCredentialsProvider, AWSStaticCredentialsProvider, BasicAWSCredentials, EnvironmentVariableCredentialsProvider}
import uk.co.telegraph.cloud.{AuthCredentials, AuthEnvVars, AuthProfile, AuthToken}

package object auth {

  implicit object AuthTokenProvider extends AuthProvider[AuthToken]{
    override def authenticate(authToken: AuthToken): AWSCredentialsProvider = {
      val basicAuth = new BasicAWSCredentials(authToken.accessToken, authToken.secretToken)
      new AWSStaticCredentialsProvider(basicAuth)
    }
  }

  implicit object AuthProfileProvider extends AuthProvider[AuthProfile]{
    override def authenticate(authProfile: AuthProfile): AWSCredentialsProvider = {
      new ProfileCredentialsProvider(authProfile.profileName.orNull)
    }
  }

  implicit object AuthEnvVarsProvider extends AuthProvider[AuthEnvVars]{
    override def authenticate(x: AuthEnvVars): AWSCredentialsProvider = {
      new EnvironmentVariableCredentialsProvider()
    }
  }

  private def doAuthenticate[A <: AuthCredentials:AuthProvider](thing:A) = AuthProvider[A].authenticate(thing)

  implicit class AuthenticationOper[A <: AuthCredentials]( authentication: A){
    def toProvider: AWSCredentialsProvider = {
      //TODO: There must be a way to remove this thing!
      authentication match {
        case auth:AuthProfile => doAuthenticate( auth )
        case auth:AuthToken   => doAuthenticate( auth )
        case auth:AuthEnvVars => doAuthenticate( auth )
      }
    }
  }
} 
开发者ID:telegraph,项目名称:sbt-pipeline-plugin,代码行数:41,代码来源:package.scala

示例7: S3Service

//设置package包名称以及导入依赖的类
package services

import java.io.InputStream
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.services.s3.{AmazonS3, AmazonS3Client}
import com.amazonaws.services.s3.model._
import play.api.Logger
import scala.util.{Try, Failure, Success}




object S3Service {

  val logger: Logger = Logger("S3ServiceLogger")
  lazy val s3Client: AmazonS3 = initialize()

  def initialize(): AmazonS3Client = {

    try {
      val s3Client: AmazonS3Client = new AmazonS3Client(new ProfileCredentialsProvider())
      logger.info("The process of getting credentials and creating s3Client object completed successfully")
      s3Client
    } catch {
      case e: Exception => {
        logger.error("An error occurred while getting credentials and creating s3Client object")
        throw e
      }
    }
  }


  def storeDataToAmazonS3(key: String, inputStream: InputStream): Try[Unit] = {

    try {
      val lenght: Int = inputStream.available()
      val objectMetadata: ObjectMetadata = new ObjectMetadata()
      objectMetadata.setContentLength(lenght)
      val request: PutObjectRequest = new PutObjectRequest(ConfigurationService.bucketName, key, inputStream, objectMetadata)
      s3Client.putObject(request)
      logger.info("Request was transmitted to Amazon S3 successfully")
      Success(Unit)

    } catch {
      case e: Exception =>{
        Failure(e)
      }
    }
  }
} 
开发者ID:emrekarakis,项目名称:AmazonProject,代码行数:51,代码来源:S3Service.scala

示例8: AwsClientProvider

//设置package包名称以及导入依赖的类
package aws

import com.amazonaws.auth.{
  AWSCredentialsProviderChain,
  AWSStaticCredentialsProvider,
  BasicAWSCredentials,
  ContainerCredentialsProvider
}
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.regions.Regions
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient
import com.amazonaws.services.s3.AmazonS3Client
import play.api.Logger

object AwsClientProvider {

  def genClients(runningInDockerOnDevMachine: Boolean, region: Regions): (AmazonDynamoDBClient, AmazonS3Client) = {
    if (runningInDockerOnDevMachine) {
      Logger.info("Running in compose")
      System.setProperty("com.amazonaws.sdk.disableCertChecking", "true")
      val awsCreds = new AWSStaticCredentialsProvider(new BasicAWSCredentials("key", "secret"))
      val dClient: AmazonDynamoDBClient = new AmazonDynamoDBClient(awsCreds).withRegion(region)
      val s3Client: AmazonS3Client = new AmazonS3Client(awsCreds).withRegion(region)
      dClient.setEndpoint(sys.env("LOCAL_DYNAMO"))
      (dClient, s3Client)
    } else {
      val awsCreds = new AWSCredentialsProviderChain(
        new ContainerCredentialsProvider(),
        new ProfileCredentialsProvider("default")
      )
      (new AmazonDynamoDBClient(awsCreds).withRegion(region), new AmazonS3Client(awsCreds).withRegion(region))
    }
  }
} 
开发者ID:ovotech,项目名称:comms-audit-log,代码行数:35,代码来源:AwsClientProvider.scala

示例9: TemplateContextFactory

//设置package包名称以及导入依赖的类
package com.ovoenergy.comms.composer.aws

import com.amazonaws.auth._
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.ovoenergy.comms.templates.TemplatesContext

object TemplateContextFactory {

  def apply(runningInDockerCompose: Boolean, region: String) = {
    val awsCredentials: AWSCredentialsProvider = {
      if (runningInDockerCompose)
        new AWSStaticCredentialsProvider(new BasicAWSCredentials("service-test", "dummy"))
      else
        new AWSCredentialsProviderChain(
          new ContainerCredentialsProvider(),
          new ProfileCredentialsProvider()
        )
    }
    TemplatesContext.cachingContext(awsCredentials)
  }
} 
开发者ID:ovotech,项目名称:comms-composer,代码行数:22,代码来源:TemplateContextFactory.scala

示例10: Client

//设置package包名称以及导入依赖的类
package com.ovoenergy.event.gateway.manager.sqs

import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.auth.{
  AWSCredentialsProviderChain,
  AWSStaticCredentialsProvider,
  BasicAWSCredentials,
  ContainerCredentialsProvider
}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.regions.Regions
import com.amazonaws.services.sqs.{AmazonSQS, AmazonSQSClientBuilder}
import com.ovoenergy.event.gateway.manager.logging.LoggingWithMDC

object Client extends LoggingWithMDC {

  def build(isRunningInCompose: Boolean, region: Regions): AmazonSQS = {
    val clientBuilder = AmazonSQSClientBuilder.standard()
    if (isRunningInCompose) {
      logInfo(Map(), "Building SQS Client for docker-compose")
      clientBuilder.setEndpointConfiguration(new EndpointConfiguration("http://sqs:4100", "eu-west-1"))
      clientBuilder.setCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("key", "secret")))
    } else {
      clientBuilder.setCredentials(
        new AWSCredentialsProviderChain(
          new ContainerCredentialsProvider(),
          new ProfileCredentialsProvider("default")
        ))
      clientBuilder.setRegion(region.getName)
    }
    clientBuilder.build()
  }

  override def loggerName: String = "SQSClientBuilder"
} 
开发者ID:ovotech,项目名称:comms-gateway-event-manager,代码行数:36,代码来源:Client.scala

示例11: Client

//设置package包名称以及导入依赖的类
package com.ovoenergy.event.gateway.manager.dynamo

import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.auth.{
  AWSCredentialsProviderChain,
  AWSStaticCredentialsProvider,
  BasicAWSCredentials,
  ContainerCredentialsProvider
}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.regions.Regions
import com.amazonaws.services.dynamodbv2.{AmazonDynamoDB, AmazonDynamoDBClientBuilder}
import com.ovoenergy.event.gateway.manager.logging.LoggingWithMDC

object Client extends LoggingWithMDC {

  def build(isRunningInCompose: Boolean, region: Regions): AmazonDynamoDB = {
    if (isRunningInCompose) {
      logInfo(Map(), "Running in compose")
      val awsCreds = new AWSStaticCredentialsProvider(new BasicAWSCredentials("key", "secret"))

      AmazonDynamoDBClientBuilder
        .standard()
        .withCredentials(awsCreds)
        .withEndpointConfiguration(new EndpointConfiguration(sys.env("LOCAL_DYNAMO"), "eu-west-1"))
        .build()
    } else {
      val awsCreds = new AWSCredentialsProviderChain(
        new ContainerCredentialsProvider(),
        new ProfileCredentialsProvider("default")
      )

      AmazonDynamoDBClientBuilder
        .standard()
        .withCredentials(awsCreds)
        .withRegion(region)
        .build()
    }
  }

  override def loggerName: String = "DynamoDbClientBuilder"
} 
开发者ID:ovotech,项目名称:comms-gateway-event-manager,代码行数:43,代码来源:Client.scala

示例12: CapiFirehoseService

//设置package包名称以及导入依赖的类
package services

import javax.inject._

import com.amazonaws.auth.{AWSCredentialsProviderChain, InstanceProfileCredentialsProvider, STSAssumeRoleSessionCredentialsProvider}
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.regions.{Region, Regions}
import com.gu.contentapi.firehose.ContentApiFirehoseConsumer
import com.gu.contentapi.firehose.kinesis.KinesisStreamReaderConfig

trait FirehoseService { }

@Singleton
class CapiFirehoseService @Inject()(playconfig: play.Configuration, consumerLogic: ConsumerLogicService) extends FirehoseService {

  val appName = playconfig.getString("appName")
  val roleArn = playconfig.getString("roleArn")
  val streamName = playconfig.getString("streamName")
  val regionName = playconfig.getString("regionName")
  val profileName = playconfig.getString("profileName")

  val dynamoChain = new AWSCredentialsProviderChain(
    new ProfileCredentialsProvider(profileName),
    new InstanceProfileCredentialsProvider()
  )

  val kinesisChain = new AWSCredentialsProviderChain(
    new ProfileCredentialsProvider(profileName),
    new STSAssumeRoleSessionCredentialsProvider.Builder(
      roleArn,
      profileName
    ).build()
  )

  val region = Region.getRegion(
    Regions.fromName(regionName)
  )

  val kinesisStreamReaderConfig = KinesisStreamReaderConfig(
    streamName = streamName,
    app = appName,
    stage = "PROD",
    mode = "live",
    suffix = None,
    kinesisCredentialsProvider = kinesisChain,
    dynamoCredentialsProvider = dynamoChain,
    awsRegion = regionName
  )

  val client: ContentApiFirehoseConsumer = new ContentApiFirehoseConsumer(
    kinesisStreamReaderConfig,
    consumerLogic
  )

  client.start()

} 
开发者ID:guardian,项目名称:indexapi-integration,代码行数:58,代码来源:CapiFirehoseService.scala


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