From b89b073da99eea4360ec1a26fe381c1c7e196e9b Mon Sep 17 00:00:00 2001 From: Arunav Sanyal Date: Tue, 25 Oct 2016 18:55:05 -0700 Subject: [PATCH] : First commit for AWS Cognito - Anonymous Identity Client. : feature. --- build.sbt | 2 ++ .../scala/awscala/cognito/CognitoClient.scala | 30 +++++++++++++++++++ src/test/scala/awscala/CognitoSpec.scala | 10 +++++++ 3 files changed, 42 insertions(+) create mode 100644 src/main/scala/awscala/cognito/CognitoClient.scala create mode 100644 src/test/scala/awscala/CognitoSpec.scala diff --git a/build.sbt b/build.sbt index 88402c8d..3091f448 100644 --- a/build.sbt +++ b/build.sbt @@ -20,6 +20,8 @@ lazy val root = (project in file(".")).settings( "com.amazonaws" % "aws-java-sdk-redshift" % awsJavaSdkVersion, "com.amazonaws" % "aws-java-sdk-dynamodb" % awsJavaSdkVersion, "com.amazonaws" % "aws-java-sdk-simpledb" % awsJavaSdkVersion, + "com.amazonaws" % "aws-java-sdk-cognitosync" % awsJavaSdkVersion, + "com.amazonaws" % "aws-java-sdk-cognitoidentity" % awsJavaSdkVersion, "joda-time" % "joda-time" % "2.9.4", "org.joda" % "joda-convert" % "1.8.1", "com.decodified" %% "scala-ssh" % "0.7.0" % "provided", diff --git a/src/main/scala/awscala/cognito/CognitoClient.scala b/src/main/scala/awscala/cognito/CognitoClient.scala new file mode 100644 index 00000000..65e3c422 --- /dev/null +++ b/src/main/scala/awscala/cognito/CognitoClient.scala @@ -0,0 +1,30 @@ +package awscala.cognito + +import awscala.Credentials +import com.amazonaws.auth.{AnonymousAWSCredentials, BasicAWSCredentials} +import com.amazonaws.services.cognitoidentity.model.GetIdRequest +import com.amazonaws.services.{cognitoidentity => cognito} + +/** + * Basic clent + */ +object CognitoClient { + + def apply(credentials: Credentials) = + new cognito.AmazonCognitoIdentityClient(new BasicAWSCredentials(credentials.getAWSSecretKey, + credentials.getAWSAccessKeyId)) + + def apply() = new cognito.AmazonCognitoIdentityClient(new AnonymousAWSCredentials()) +} + +case class CognitoIdentityParams(identityPoolId: String, accountId:String) + +trait CognitoClient extends cognito.AmazonCognitoIdentityClient { + + def getIdentityId(params: CognitoIdentityParams): String = { + val idRequest = new GetIdRequest() + idRequest.setAccountId(params.accountId) + idRequest.setIdentityPoolId(params.identityPoolId) + this.getId(idRequest).getIdentityId + } +} \ No newline at end of file diff --git a/src/test/scala/awscala/CognitoSpec.scala b/src/test/scala/awscala/CognitoSpec.scala new file mode 100644 index 00000000..b0593b2f --- /dev/null +++ b/src/test/scala/awscala/CognitoSpec.scala @@ -0,0 +1,10 @@ +package awscala + +import org.scalatest.{FlatSpec, Matchers} + +/** + * Created by arunavs on 10/25/16. + */ +class CognitoSpec extends FlatSpec with Matchers { + // TODO : Write tests here. +}