Created
January 6, 2017 05:04
-
-
Save TJC/654e5b2c2e7b27a81929c762addb535e to your computer and use it in GitHub Desktop.
Test jets3t library again Minio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Download the files below into some directory. | |
| Edit setup_env.sh to point to a Minio server. | |
| source ./setup_env.sh | |
| sbt run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lazy val root = (project in file(".")). | |
| settings( | |
| name := "testS3", | |
| version := "0.1", | |
| scalaVersion := "2.11.8" | |
| ) | |
| libraryDependencies ++= Seq( | |
| "net.java.dev.jets3t" % "jets3t" % "0.9.4" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export S3_BUCKET=test | |
| export S3_ACCESS_KEY=guest | |
| export S3_SECRET_KEY=password | |
| export S3_ENDPOINT=localhost | |
| export S3_PORT=9000 | |
| export S3_ENDPOINT_URL=http://$S3_ENDPOINT:$S3_PORT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package tjc.testS3 | |
| // JetS3t stuff: | |
| import org.jets3t.service.impl.rest.httpclient.RestS3Service | |
| import org.jets3t.service.security.AWSCredentials | |
| import org.jets3t.service.model.S3Object | |
| import org.jets3t.service.{Jets3tProperties,Constants} | |
| object main extends App { | |
| get("test.txt") | |
| def get(key: String): String = { | |
| val s3Service = s3_connect | |
| val bucketName = sys.env("S3_BUCKET") | |
| val bucket = s3Service.getOrCreateBucket(bucketName) | |
| val result = s3Service.getObject(bucket, key) | |
| result.toString | |
| } | |
| def s3_connect: RestS3Service = { | |
| val awsAccessKey = sys.env("S3_ACCESS_KEY") | |
| val awsSecretKey = sys.env("S3_SECRET_KEY") | |
| // A hack to fix the S3 endpoint: | |
| val s3props = Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME) | |
| s3props.setProperty("s3service.s3-endpoint", sys.env("S3_ENDPOINT")) | |
| s3props.setProperty("s3service.s3-endpoint-http-port", sys.env("S3_PORT")) | |
| s3props.setProperty("s3service.disable-dns-buckets", "true") | |
| s3props.setProperty("s3service.https-only", "false") | |
| val awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey) | |
| val s3Service = new RestS3Service(awsCredentials) | |
| s3Service | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment