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

GitHub workflow #9

Merged
merged 4 commits into from
Sep 14, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.aseemsavio.dynamokt.extensions.crud.sync.client

import software.amazon.awssdk.services.dynamodb.DynamoDbClient
import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder

/**
* DSL for building a synchronous DynamoDb Client.
*
* @since 0.0.1
*/
fun dynamoDbClient(block: DynamoDbClientBuilder.() -> Unit): DynamoDbClient = DynamoDbClient.builder().apply(block).build()
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.aseemsavio.dynamokt.extensions.crud.sync.client

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder

/**
* DSL for applying a [StaticCredentialsProvider] to [DynamoDbClientBuilder].
*/
fun DynamoDbClientBuilder.credentials(block: StaticCredentialsBuilder.() -> Unit): DynamoDbClientBuilder = apply {
credentialsProvider(StaticCredentialsBuilder().apply(block).build())
}

class StaticCredentialsBuilder {

var accessKey: String? = null
var secretKey: String? = null

fun build(): StaticCredentialsProvider {
checkNotNull(accessKey) { "accessKey should not be null" }
checkNotNull(secretKey) { "secretKey should not be null" }
return StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.aseemsavio.dynamokt.extensions.crud.sync.client

import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder

/**
* DSL for applying a [Region] to [DynamoDbClientBuilder].
*/
fun DynamoDbClientBuilder.region(block: () -> String): DynamoDbClientBuilder = apply { region(Region.of(block())) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.aseemsavio.dynamokt.extensions.crud.sync.tables

import software.amazon.awssdk.core.waiters.WaiterResponse
import software.amazon.awssdk.services.dynamodb.DynamoDbClient
import software.amazon.awssdk.services.dynamodb.model.*


// https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/examples-dynamodb.html

/**
* DSL for creating a new Dynamo DB table.
*/
fun DynamoDbClient.newTable(block: CreateTableRequest.Builder.() -> Unit): TableName {
val waiter = waiter()
val createTableRequest = CreateTableRequest.builder().apply(block).build()
val tableName = createTableRequest.tableName()
val createTableResponse = createTable(createTableRequest)
val describeTableRequest = DescribeTableRequest.builder()
.tableName(tableName)
.build()
val waiterResponse: WaiterResponse<DescribeTableResponse> = waiter.waitUntilTableExists(describeTableRequest)
waiterResponse.matched().response().ifPresent { println(it) }
return TableName(createTableResponse.tableDescription().tableName())
}

/**
* DSL for creating an [AttributeDefinition].
*/
fun attributeDefinition(block: AttributeDefinition.Builder.() -> Unit): AttributeDefinition =
AttributeDefinition.builder().apply(block).build()

/**
* DSL for creating a [KeySchemaElement].
*/
fun keySchemaElement(block: KeySchemaElement.Builder.() -> Unit): KeySchemaElement =
KeySchemaElement.builder().apply(block).build()

/**
* DSL for creating a [GlobalSecondaryIndex].
*/
fun globalSecondaryIndex(block: GlobalSecondaryIndex.Builder.() -> Unit): GlobalSecondaryIndex =
GlobalSecondaryIndex.builder().apply(block).build()

/**
* DSL for creating a [LocalSecondaryIndex].
*/
fun localSecondaryIndex(block: LocalSecondaryIndex.Builder.() -> Unit): LocalSecondaryIndex =
LocalSecondaryIndex.builder().apply(block).build()

/**
* DSL for creating a [Tag].
*/
fun tag(block: Tag.Builder.() -> Unit): Tag = Tag.builder().apply(block).build()

/**
* DSL for creating [SSESpecification].
*/
fun CreateTableRequest.Builder.sseSpecificationDynamoKt(block: SSESpecification.Builder.() -> Unit) = apply {
sseSpecification(SSESpecification.builder().apply(block).build())
}

/**
* DSL for creating [ProvisionedThroughput].
*/
fun CreateTableRequest.Builder.provisionedThroughputDynamoKt(block: ProvisionedThroughput.Builder.() -> Unit) = apply {
provisionedThroughput(ProvisionedThroughput.builder().apply(block).build())
}

/**
* DSL for creating [StreamSpecification].
*/
fun CreateTableRequest.Builder.streamSpecificationDynamoKt(block: StreamSpecification.Builder.() -> Unit) = apply {
streamSpecification(StreamSpecification.builder().apply(block).build())
}

/**
* [TableName] is a [String].
*/
@JvmInline
value class TableName(val value: String)
Loading