Skip to content

Commit

Permalink
Merge pull request awsdocs#3206 from scmacdon/main
Browse files Browse the repository at this point in the history
S3 Kotlin Style Change (No code changes)
  • Loading branch information
beqqrry-aws authored Jun 1, 2022
2 parents e573738 + 7fef32c commit f1c4bad
Show file tree
Hide file tree
Showing 14 changed files with 532 additions and 532 deletions.
2 changes: 1 addition & 1 deletion kotlin/services/s3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {
}

dependencies {
implementation("aws.sdk.kotlin:s3:0.14.3-beta")
implementation("aws.sdk.kotlin:s3:0.15.2-beta")
testImplementation("org.junit.jupiter:junit-jupiter:5.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")
implementation("com.fasterxml.jackson.core:jackson-databind:2.11.4")
Expand Down
65 changes: 32 additions & 33 deletions kotlin/services/s3/src/main/kotlin/com/kotlin/s3/CopyObject.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//snippet-sourcedescription:[CopyObject.kt demonstrates how to copy an object from one Amazon Simple Storage Service (Amazon S3) bucket to another.]
//snippet-keyword:[AWS SDK for Kotlin]
//snippet-keyword:[Code Sample]
//snippet-service:[Amazon S3]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[11/05/2021]
//snippet-sourceauthor:[scmacdon-aws]
// snippet-sourcedescription:[CopyObject.kt demonstrates how to copy an object from one Amazon Simple Storage Service (Amazon S3) bucket to another.]
// snippet-keyword:[AWS SDK for Kotlin]
// snippet-keyword:[Code Sample]
// snippet-service:[Amazon S3]
// snippet-sourcetype:[full-example]
// snippet-sourcedate:[05/30/2021]

/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand All @@ -23,10 +22,10 @@ import kotlin.system.exitProcess
// snippet-end:[s3.kotlin.copy_object.import]

/**
To run this Kotlin code example, ensure that you have setup your development environment,
Before running this Kotlin code example, set up your development environment,
including your credentials.
For information, see this documentation topic:
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/

Expand All @@ -37,9 +36,9 @@ suspend fun main(args: Array<String>) {
<objectKey> <fromBucket> <toBucket>
Where:
objectKey - the name of the object (for example, book.pdf).
fromBucket - the Amazon S3 bucket name that contains the object (for example, bucket1).
toBucket - the Amazon S3 bucket to copy the object to (for example, bucket2).
objectKey - The name of the object (for example, book.pdf).
fromBucket - The Amazon S3 bucket name that contains the object (for example, bucket1).
toBucket - The Amazon S3 bucket to copy the object to (for example, bucket2).
"""

if (args.size != 3) {
Expand All @@ -54,26 +53,26 @@ suspend fun main(args: Array<String>) {
}

// snippet-start:[s3.kotlin.copy_object.main]
suspend fun copyBucketObject(
fromBucket: String,
objectKey: String,
toBucket: String) {
suspend fun copyBucketObject(
fromBucket: String,
objectKey: String,
toBucket: String
) {

var encodedUrl=""
try {
encodedUrl = URLEncoder.encode("$fromBucket/$objectKey", StandardCharsets.UTF_8.toString())

} catch (e: UnsupportedEncodingException) {
println("URL could not be encoded: " + e.message)
}
var encodedUrl = ""
try {
encodedUrl = URLEncoder.encode("$fromBucket/$objectKey", StandardCharsets.UTF_8.toString())
} catch (e: UnsupportedEncodingException) {
println("URL could not be encoded: " + e.message)
}

val request = CopyObjectRequest {
copySource = encodedUrl
bucket = toBucket
key= objectKey
}
S3Client { region = "us-east-1" }.use { s3 ->
s3.copyObject(request)
}
}
// snippet-end:[s3.kotlin.copy_object.main]
val request = CopyObjectRequest {
copySource = encodedUrl
bucket = toBucket
key = objectKey
}
S3Client { region = "us-east-1" }.use { s3 ->
s3.copyObject(request)
}
}
// snippet-end:[s3.kotlin.copy_object.main]
47 changes: 23 additions & 24 deletions kotlin/services/s3/src/main/kotlin/com/kotlin/s3/CreateBucket.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//snippet-sourcedescription:[CreateBucket.kt demonstrates how to create an Amazon Simple Storage Service (Amazon S3) bucket.]
//snippet-keyword:[AWS SDK for Kotlin]
//snippet-keyword:[Code Sample]
//snippet-service:[Amazon S3]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[11/05/2021]
//snippet-sourceauthor:[scmacdon-aws]
// snippet-sourcedescription:[CreateBucket.kt demonstrates how to create an Amazon Simple Storage Service (Amazon S3) bucket.]
// snippet-keyword:[AWS SDK for Kotlin]
// snippet-keyword:[Code Sample]
// snippet-service:[Amazon S3]
// snippet-sourcetype:[full-example]
// snippet-sourcedate:[05/30/2021]

/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand All @@ -20,10 +19,10 @@ import kotlin.system.exitProcess
// snippet-end:[s3.kotlin.create_bucket.import]

/**
To run this Kotlin code example, ensure that you have setup your development environment,
Before running this Kotlin code example, set up your development environment,
including your credentials.
For information, see this documentation topic:
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main(args: Array<String>) {
Expand All @@ -33,27 +32,27 @@ suspend fun main(args: Array<String>) {
<bucketName>
Where:
bucketName - the name of the Amazon S3 bucket to create. The Amazon S3 bucket name must be unique, or an error occurs.
bucketName - The name of the Amazon S3 bucket to create. The Amazon S3 bucket name must be unique, or an error occurs.
"""

if (args.size != 1) {
if (args.size != 1) {
println(usage)
exitProcess(0)
}
}
val bucketName = args[0]
createNewBucket(bucketName)
}

// snippet-start:[s3.kotlin.create_bucket.main]
suspend fun createNewBucket(bucketName: String) {

val request = CreateBucketRequest {
bucket = bucketName
}

S3Client { region = "us-east-1" }.use { s3 ->
s3.createBucket(request)
println("$bucketName is ready")
}
}
// snippet-end:[s3.kotlin.create_bucket.main]
suspend fun createNewBucket(bucketName: String) {

val request = CreateBucketRequest {
bucket = bucketName
}

S3Client { region = "us-east-1" }.use { s3 ->
s3.createBucket(request)
println("$bucketName is ready")
}
}
// snippet-end:[s3.kotlin.create_bucket.main]
41 changes: 20 additions & 21 deletions kotlin/services/s3/src/main/kotlin/com/kotlin/s3/DeleteBucket.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//snippet-sourcedescription:[DeleteBucket.kt demonstrates how to delete an Amazon Simple Storage Service (Amazon S3) bucket.]
//snippet-keyword:[AWS SDK for Kotlin]
//snippet-keyword:[Code Sample]
//snippet-service:[Amazon S3]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[11/05/2021]
//snippet-sourceauthor:[scmacdon-aws]
// snippet-sourcedescription:[DeleteBucket.kt demonstrates how to delete an Amazon Simple Storage Service (Amazon S3) bucket.]
// snippet-keyword:[AWS SDK for Kotlin]
// snippet-keyword:[Code Sample]
// snippet-service:[Amazon S3]
// snippet-sourcetype:[full-example]
// snippet-sourcedate:[05/30/2021]

/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand All @@ -20,10 +19,10 @@ import kotlin.system.exitProcess
// snippet-end:[s3.kotlin.del_bucket.import]

/**
To run this Kotlin code example, ensure that you have setup your development environment,
Before running this Kotlin code example, set up your development environment,
including your credentials.
For information, see this documentation topic:
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main(args: Array<String>) {
Expand All @@ -33,27 +32,27 @@ suspend fun main(args: Array<String>) {
<bucketName>
Where:
bucketName - the name of the Amazon S3 bucket to delete.
bucketName - The name of the Amazon S3 bucket to delete.
"""

if (args.size != 1) {
println(usage)
exitProcess(0)
}
}

val bucketName = args[0]
deleteExistingBucket(bucketName)
}

// snippet-start:[s3.kotlin.del_bucket.main]
suspend fun deleteExistingBucket(bucketName: String?) {

val request = DeleteBucketRequest {
bucket = bucketName
}
S3Client { region = "us-east-1" }.use { s3 ->
s3.deleteBucket(request)
println("The $bucketName was successfully deleted!")
}
suspend fun deleteExistingBucket(bucketName: String?) {

val request = DeleteBucketRequest {
bucket = bucketName
}
// snippet-end:[s3.kotlin.del_bucket.main]
S3Client { region = "us-east-1" }.use { s3 ->
s3.deleteBucket(request)
println("The $bucketName was successfully deleted!")
}
}
// snippet-end:[s3.kotlin.del_bucket.main]
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//snippet-sourcedescription:[DeleteBucketPolicy.kt demonstrates how to delete a policy from an Amazon Simple Storage Service (Amazon S3) bucket.]
//snippet-keyword:[AWS SDK for Kotlin]
//snippet-keyword:[Code Sample]
//snippet-service:[Amazon S3]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[11/05/2021]
//snippet-sourceauthor:[scmacdon-aws]
// snippet-sourcedescription:[DeleteBucketPolicy.kt demonstrates how to delete a policy from an Amazon Simple Storage Service (Amazon S3) bucket.]
// snippet-keyword:[AWS SDK for Kotlin]
// snippet-keyword:[Code Sample]
// snippet-service:[Amazon S3]
// snippet-sourcetype:[full-example]
// snippet-sourcedate:[05/30/2021]

/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand All @@ -20,10 +19,10 @@ import kotlin.system.exitProcess
// snippet-end:[s3.kotlin.delete_bucket_policy.import]

/**
To run this Kotlin code example, ensure that you have setup your development environment,
Before running this Kotlin code example, set up your development environment,
including your credentials.
For information, see this documentation topic:
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/

Expand All @@ -34,28 +33,28 @@ suspend fun main(args: Array<String>) {
<bucketName>
Where:
bucketName - the Amazon S3 bucket from which to delete the policy.
bucketName - The Amazon S3 bucket from which to delete the policy.
"""

if (args.size != 1) {
println(usage)
exitProcess(0)
}
if (args.size != 1) {
println(usage)
exitProcess(0)
}

val bucketName = args[0]
deleteS3BucketPolicy(bucketName)
}

// snippet-start:[s3.kotlin.delete_bucket_policy.main]
suspend fun deleteS3BucketPolicy( bucketName: String?) {

val request = DeleteBucketPolicyRequest {
bucket = bucketName
}

S3Client { region = "us-east-1" }.use { s3 ->
s3.deleteBucketPolicy(request)
println("Done!")
}
}
// snippet-end:[s3.kotlin.delete_bucket_policy.main]
suspend fun deleteS3BucketPolicy(bucketName: String?) {

val request = DeleteBucketPolicyRequest {
bucket = bucketName
}

S3Client { region = "us-east-1" }.use { s3 ->
s3.deleteBucketPolicy(request)
println("Done!")
}
}
// snippet-end:[s3.kotlin.delete_bucket_policy.main]
Loading

0 comments on commit f1c4bad

Please sign in to comment.