Skip to content

Commit

Permalink
updated B2Bi resources for outbound EDI feature release (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewchiu authored Oct 3, 2024
1 parent 050caaf commit a1f3a79
Show file tree
Hide file tree
Showing 47 changed files with 1,998 additions and 213 deletions.
4 changes: 3 additions & 1 deletion aws-b2bi-capability/.rpdk-config
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
"protocolVersion": "2.0.0"
},
"logProcessorEnabled": "true",
"executableEntrypoint": "software.amazon.b2bi.capability.HandlerWrapperExecutable"
"executableEntrypoint": "software.amazon.b2bi.capability.HandlerWrapperExecutable",
"contractSettings": {},
"canarySettings": {}
}
17 changes: 16 additions & 1 deletion aws-b2bi-capability/aws-b2bi-capability.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
}
]
},
"CapabilityDirection": {
"type": "string",
"enum": [
"INBOUND",
"OUTBOUND"
]
},
"CapabilityType": {
"type": "string",
"enum": [
Expand All @@ -28,6 +35,9 @@
"EdiConfiguration": {
"type": "object",
"properties": {
"CapabilityDirection": {
"$ref": "#/definitions/CapabilityDirection"
},
"Type": {
"$ref": "#/definitions/EdiType"
},
Expand Down Expand Up @@ -322,7 +332,12 @@
"tagOnCreate": true,
"tagProperty": "/properties/Tags",
"tagUpdatable": true,
"taggable": true
"taggable": true,
"permissions": [
"b2bi:ListTagsForResource",
"b2bi:TagResource",
"b2bi:UntagResource"
]
},
"additionalProperties": false
}
12 changes: 12 additions & 0 deletions aws-b2bi-capability/docs/ediconfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ To declare this entity in your AWS CloudFormation template, use the following sy

<pre>
{
"<a href="#capabilitydirection" title="CapabilityDirection">CapabilityDirection</a>" : <i>String</i>,
"<a href="#type" title="Type">Type</a>" : <i><a href="editype.md">EdiType</a></i>,
"<a href="#inputlocation" title="InputLocation">InputLocation</a>" : <i><a href="s3location.md">S3Location</a></i>,
"<a href="#outputlocation" title="OutputLocation">OutputLocation</a>" : <i><a href="s3location.md">S3Location</a></i>,
Expand All @@ -18,6 +19,7 @@ To declare this entity in your AWS CloudFormation template, use the following sy
### YAML

<pre>
<a href="#capabilitydirection" title="CapabilityDirection">CapabilityDirection</a>: <i>String</i>
<a href="#type" title="Type">Type</a>: <i><a href="editype.md">EdiType</a></i>
<a href="#inputlocation" title="InputLocation">InputLocation</a>: <i><a href="s3location.md">S3Location</a></i>
<a href="#outputlocation" title="OutputLocation">OutputLocation</a>: <i><a href="s3location.md">S3Location</a></i>
Expand All @@ -26,6 +28,16 @@ To declare this entity in your AWS CloudFormation template, use the following sy

## Properties

#### CapabilityDirection

_Required_: No

_Type_: String

_Allowed Values_: <code>INBOUND</code> | <code>OUTBOUND</code>

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### Type

_Required_: Yes
Expand Down
8 changes: 4 additions & 4 deletions aws-b2bi-capability/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>b2bi</artifactId>
<version>2.24.5</version>
<version>2.28.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/sdk-core -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sdk-core</artifactId>
<version>2.24.5</version>
<version>2.28.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/aws-core -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-core</artifactId>
<version>2.24.5</version>
<version>2.28.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/utils -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>utils</artifactId>
<version>2.24.5</version>
<version>2.28.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ object ClientBuilder {
fun getClient(): B2BiClient = B2BiClient.builder()
.httpClient(LambdaWrapper.HTTP_CLIENT)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ class CreateHandler : BaseHandlerStd() {
companion object {
private const val OPERATION = "AWS-B2BI-Capability::Create"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ object TagHelper {
fun getPreviouslyAttachedTags(handlerRequest: ResourceHandlerRequest<ResourceModel>): Map<String, String> {
return getTags(
handlerRequest.previousResourceTags,
handlerRequest.systemTags,
convertToMap(handlerRequest.previousResourceState.tags)
)
}
Expand All @@ -59,6 +60,7 @@ object TagHelper {
fun getNewDesiredTags(handlerRequest: ResourceHandlerRequest<ResourceModel>): Map<String, String> {
return getTags(
handlerRequest.desiredResourceTags,
handlerRequest.systemTags,
convertToMap(handlerRequest.desiredResourceState.tags)
)
}
Expand Down Expand Up @@ -106,14 +108,19 @@ object TagHelper {
addedTags: Map<String, String>,
logger: Logger
): ProgressEvent<ResourceModel, CallbackContext?> {
return proxy.initiate(TAG_OPERATION, proxyClient, resourceModel, callbackContext)
.translateToServiceRequest { model -> Translator.translateToTagResourceRequest(model, addedTags) }
.makeServiceCall { request, client ->
val response = proxy.injectCredentialsAndInvokeV2(request, client.client()::tagResource)
logger.log("Successfully tagged ${ResourceModel.TYPE_NAME} ${resourceModel.capabilityId}")
response
}
.progress()
return if (addedTags.isNotEmpty()) {
proxy.initiate(TAG_OPERATION, proxyClient, resourceModel, callbackContext)
.translateToServiceRequest { model -> Translator.translateToTagResourceRequest(model, addedTags) }
.makeServiceCall { request, client ->
val response = proxy.injectCredentialsAndInvokeV2(request, client.client()::tagResource)
logger.log("Successfully tagged ${ResourceModel.TYPE_NAME} ${resourceModel.capabilityId}")
response
}
.progress()
} else {

ProgressEvent.progress(resourceModel, callbackContext)
}
}

/**
Expand All @@ -129,14 +136,18 @@ object TagHelper {
removedTags: Set<String>,
logger: Logger
): ProgressEvent<ResourceModel, CallbackContext?> {
return proxy.initiate(UNTAG_OPERATION, proxyClient, resourceModel, callbackContext)
.translateToServiceRequest { model -> Translator.translateToUntagResourceRequest(model, removedTags) }
.makeServiceCall { request, client ->
val response = proxy.injectCredentialsAndInvokeV2(request, client.client()::untagResource)
logger.log("Successfully untagged ${ResourceModel.TYPE_NAME} ${resourceModel.capabilityId}")
response
}
.progress()
return if (removedTags.isNotEmpty()) {
proxy.initiate(UNTAG_OPERATION, proxyClient, resourceModel, callbackContext)
.translateToServiceRequest { model -> Translator.translateToUntagResourceRequest(model, removedTags) }
.makeServiceCall { request, client ->
val response = proxy.injectCredentialsAndInvokeV2(request, client.client()::untagResource)
logger.log("Successfully untagged ${ResourceModel.TYPE_NAME} ${resourceModel.capabilityId}")
response
}
.progress()
} else {
ProgressEvent.progress(resourceModel, callbackContext)
}
}

/**
Expand Down Expand Up @@ -217,4 +228,4 @@ object TagHelper {
fun SdkTag.toResourceTag(): ResourceTag {
return ResourceTag.builder().key(this.key()).value(this.value()).build()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package software.amazon.b2bi.capability

import com.google.common.collect.Lists
import software.amazon.awssdk.awscore.AwsRequest
import software.amazon.awssdk.awscore.AwsResponse
import software.amazon.awssdk.awscore.exception.AwsServiceException
import software.amazon.awssdk.services.b2bi.model.AccessDeniedException
import software.amazon.awssdk.services.b2bi.model.ConflictException
Expand Down Expand Up @@ -31,9 +28,6 @@ import software.amazon.cloudformation.exceptions.CfnServiceInternalErrorExceptio
import software.amazon.cloudformation.exceptions.CfnServiceLimitExceededException
import software.amazon.cloudformation.exceptions.CfnThrottlingException
import java.time.Instant
import java.util.*
import java.util.stream.Collectors
import java.util.stream.Stream
import software.amazon.awssdk.services.b2bi.model.S3Location as SdkS3Location
import software.amazon.b2bi.capability.S3Location as ResourceS3Location
import software.amazon.awssdk.services.b2bi.model.CapabilityConfiguration as SdkCapabilityConfiguration
Expand Down Expand Up @@ -132,9 +126,7 @@ object Translator {
*/
fun translateToListRequest(nextToken: String?): ListCapabilitiesRequest {
return ListCapabilitiesRequest.builder()
.apply {
nextToken?.let { nextToken(it) }
}
.apply { nextToken?.let { nextToken(it) } }
.build()
}

Expand Down Expand Up @@ -200,53 +192,47 @@ object Translator {
else -> CfnGeneralServiceException(this)
}

fun ResourceS3Location.toSdkS3Location(): SdkS3Location {
return SdkS3Location.builder().bucketName(this.bucketName).key(this.key).build()
}

fun SdkS3Location.toResourceS3Location(): ResourceS3Location {
return ResourceS3Location.builder().bucketName(this.bucketName()).key(this.key()).build()
}

fun ResourceCapabilityConfiguration.toSdkCapabilityConfiguration(): SdkCapabilityConfiguration {
return SdkCapabilityConfiguration.builder().edi(this.edi.toSdkEdiConfiguration()).build()
}
fun ResourceCapabilityConfiguration.toSdkCapabilityConfiguration(): SdkCapabilityConfiguration =
SdkCapabilityConfiguration.builder().edi(this.edi.toSdkEdiConfiguration()).build()

fun ResourceEdiConfiguration.toSdkEdiConfiguration(): SdkEdiConfiguration {
return SdkEdiConfiguration.builder()
.type(this.type.toSdkEdiType())
.capabilityDirection(this.capabilityDirection)
.inputLocation(this.inputLocation.toSdkS3Location())
.outputLocation(this.outputLocation.toSdkS3Location())
.transformerId(this.transformerId)
.build()
}

fun ResourceEdiType.toSdkEdiType(): SdkEdiType {
return SdkEdiType.builder().x12Details(this.x12Details.toSdkX12Details()).build()
}
fun ResourceEdiType.toSdkEdiType(): SdkEdiType =
SdkEdiType.builder().x12Details(this.x12Details.toSdkX12Details()).build()

fun ResourceX12Details.toSdkX12Details(): SdkX12Details {
return SdkX12Details.builder().transactionSet(this.transactionSet).version(this.version).build()
}
fun ResourceX12Details.toSdkX12Details(): SdkX12Details =
SdkX12Details.builder().transactionSet(this.transactionSet).version(this.version).build()

fun SdkCapabilityConfiguration.toResourceCapabilityConfiguration(): ResourceCapabilityConfiguration {
return ResourceCapabilityConfiguration.builder().edi(this.edi().toResourceEdiConfiguration()).build()
}
fun ResourceS3Location.toSdkS3Location(): SdkS3Location =
SdkS3Location.builder().bucketName(this.bucketName).key(this.key).build()

fun SdkCapabilityConfiguration.toResourceCapabilityConfiguration(): ResourceCapabilityConfiguration =
ResourceCapabilityConfiguration.builder().edi(this.edi().toResourceEdiConfiguration()).build()

fun SdkEdiConfiguration.toResourceEdiConfiguration(): ResourceEdiConfiguration {
return ResourceEdiConfiguration.builder()
.type(this.type().toResourceEdiType())
.capabilityDirection(this.capabilityDirectionAsString())
.inputLocation(this.inputLocation().toResourceS3Location())
.outputLocation(this.outputLocation().toResourceS3Location())
.transformerId(this.transformerId())
.build()
}

fun SdkEdiType.toResourceEdiType(): ResourceEdiType {
return ResourceEdiType.builder().x12Details(this.x12Details().toResourceX12Details()).build()
}
fun SdkEdiType.toResourceEdiType(): ResourceEdiType =
ResourceEdiType.builder().x12Details(this.x12Details().toResourceX12Details()).build()

fun SdkX12Details.toResourceX12Details(): ResourceX12Details {
return ResourceX12Details.builder().transactionSet(this.transactionSetAsString()).version(this.versionAsString()).build()
}
fun SdkX12Details.toResourceX12Details(): ResourceX12Details =
ResourceX12Details.builder().transactionSet(this.transactionSetAsString()).version(this.versionAsString()).build()

fun SdkS3Location.toResourceS3Location(): ResourceS3Location =
ResourceS3Location.builder().bucketName(this.bucketName()).key(this.key()).build()
}
4 changes: 3 additions & 1 deletion aws-b2bi-partnership/.rpdk-config
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
"protocolVersion": "2.0.0"
},
"logProcessorEnabled": "true",
"executableEntrypoint": "software.amazon.b2bi.partnership.HandlerWrapperExecutable"
"executableEntrypoint": "software.amazon.b2bi.partnership.HandlerWrapperExecutable",
"contractSettings": {},
"canarySettings": {}
}
Loading

0 comments on commit a1f3a79

Please sign in to comment.