Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/main/scala/io/findify/s3mock/Main.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
package io.findify.s3mock

import better.files.File
import com.amazonaws.auth.{AWSStaticCredentialsProvider, AnonymousAWSCredentials}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.s3.{AmazonS3, AmazonS3ClientBuilder}
import io.findify.s3mock.provider.FileProvider

/**
* Created by shutty on 8/9/16.
*/
object Main {
val port = sys.env.get("S3MOCK_PORT").map(Integer.parseInt).getOrElse(8001)

def main(args: Array[String]): Unit = {
val server = new S3Mock(8001, new FileProvider(File.newTemporaryDirectory(prefix = "s3mock").pathAsString))
val server = new S3Mock(port, new FileProvider(
sys.env.get("REPOSITORY_PATH") match {
case Some(path) => File(path).pathAsString
case None => File.newTemporaryDirectory(prefix = "s3mock").pathAsString
}))
server.start

sys.env.get("BUCKET_NAME").foreach(name => createBucket(name))
}

def createBucket(bucketName: String): Unit = {
val client = clientFor("localhost", port)
client.createBucket(bucketName)
println("Created bucket: " + bucketName)
client.shutdown()
}

def clientFor(host: String, port: Int): AmazonS3 = {
val endpoint = new EndpointConfiguration(s"http://$host:$port", "eu-west-1")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the region parameterised, too?

AmazonS3ClientBuilder.standard()
.withPathStyleAccessEnabled(true)
.withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()))
.withEndpointConfiguration(endpoint)
.build()
}
}