Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making the CredentialsProperties file optional #313

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -36,12 +36,12 @@ import com.amazonaws.auth.AWSCredentials
* @param location The location of the file which will be read _if it exists and is readable_,
* otherwise the parameters will be read from the System environment.
*/
class CredentialsProperties(location: File) extends Serializable with Logging {
class CredentialsProperties(location: Option[File]) extends Serializable with Logging {

val defaultAccessKey = System.getenv("AWS_ACCESS_KEY_ID")
val defaultSecretKey = System.getenv("AWS_SECRET_KEY")
private val defaultMap = Map("accessKey" -> defaultAccessKey, "secretKey" -> defaultSecretKey)
val configuration = new ConfigurationFile(location, Some(defaultMap))
val configuration = location.map(new ConfigurationFile(_, Some(defaultMap))).map(_.properties).getOrElse(defaultMap)

/**
* Retrieves the value associated with a given key from the configuration file.
Expand All @@ -62,15 +62,14 @@ class CredentialsProperties(location: File) extends Serializable with Logging {
*/
def configuredValue(keyName: String, suffix: Option[String] = None): String = {
suffix match {
case None => configuration.properties(keyName)
case Some(suffixString) => {
case None => configuration(keyName)
case Some(suffixString) =>
val combinedKey = "%s_%s".format(keyName, suffixString)
if (configuration.properties.contains(combinedKey)) {
configuration.properties(combinedKey)
if (configuration.contains(combinedKey)) {
configuration(combinedKey)
} else {
configuration.properties(keyName)
configuration(keyName)
}
}
}
}

Expand Down
Expand Up @@ -26,7 +26,7 @@ import org.scalatest.FunSuite

class ByteAccessSuite extends FunSuite {

lazy val credentials = new CredentialsProperties(new File(System.getProperty("user.home") + "/spark.conf"))
lazy val credentials = new CredentialsProperties(Some(new File(System.getProperty("user.home") + "/spark.conf")))
.awsCredentials(Some("s3"))

lazy val bucketName = System.getenv("BUCKET_NAME")
Expand Down
Expand Up @@ -187,7 +187,7 @@ object RDDFunSuite {

class AvroParquetRDDSuite extends SparkFunSuite {

lazy val credentials = new CredentialsProperties(new File(System.getProperty("user.home") + "/spark.conf"))
lazy val credentials = new CredentialsProperties(Some(new File(System.getProperty("user.home") + "/spark.conf")))
.awsCredentials(Some("s3"))

lazy val bucketName = System.getenv("BUCKET_NAME")
Expand Down
Expand Up @@ -27,7 +27,7 @@ import org.bdgenomics.adam.util.{ S3Test, NetworkConnected, CredentialsPropertie
import org.scalatest.FunSuite

class ParquetCommonSuite extends FunSuite {
lazy val credentials = new CredentialsProperties(new File(System.getProperty("user.home") + "/spark.conf"))
lazy val credentials = new CredentialsProperties(Some(new File(System.getProperty("user.home") + "/spark.conf")))
.awsCredentials(Some("s3"))

lazy val bucketName = System.getenv("bucket-name")
Expand Down
Expand Up @@ -25,7 +25,7 @@ class CredentialsPropertiesTestSuite extends FunSuite {
test("Can parse a simple configuration file with CredentialsProperties") {
val path = Thread.currentThread().getContextClassLoader.getResource("test.conf").getFile
val file = new File(path)
val cp = new CredentialsProperties(file)
val cp = new CredentialsProperties(Some(file))

val aws = cp.awsCredentials()
assert(aws.getAWSAccessKeyId === "accessKey")
Expand Down