Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Commit 7914fae

Browse files
authored
Updating GetAtt values. (#43)
* Updating GetAtt values. * Removing silly log statement. * We don't need duplicate attributes for ReadHandler and adding Arn to GetAtt.
1 parent 92392f1 commit 7914fae

File tree

15 files changed

+73
-56
lines changed

15 files changed

+73
-56
lines changed

aws-codeartifact-domain/aws-codeartifact-domain.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
"pattern": "[0-9]{12}",
1616
"type": "string"
1717
},
18+
"Name": {
19+
"description": "The name of the domain. This field is used for GetAtt",
20+
"type": "string",
21+
"pattern": "^([a-z][a-z0-9\\-]{0,48}[a-z0-9])$",
22+
"minLength": 2,
23+
"maxLength": 50
24+
},
25+
"Owner": {
26+
"description": "The 12-digit account ID of the AWS account that owns the domain. This field is used for GetAtt",
27+
"pattern": "[0-9]{12}",
28+
"type": "string"
29+
},
1830
"EncryptionKey": {
1931
"description": "The ARN of an AWS Key Management Service (AWS KMS) key associated with a domain.",
2032
"type": "string"
@@ -41,9 +53,10 @@
4153
"/properties/EncryptionKey"
4254
],
4355
"readOnlyProperties": [
44-
"/properties/DomainOwner",
45-
"/properties/DomainName",
46-
"/properties/EncryptionKey"
56+
"/properties/Owner",
57+
"/properties/Name",
58+
"/properties/EncryptionKey",
59+
"/properties/Arn"
4760
],
4861
"primaryIdentifier": [
4962
"/properties/Arn"

aws-codeartifact-domain/src/main/java/software/amazon/codeartifact/domain/BaseHandlerStd.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ boolean policyIsUnchanged(final ResourceModel desiredModel, final ResourceModel
8383

8484
protected boolean doesDomainExist(
8585
final ResourceModel model,
86-
final ProxyClient<CodeartifactClient> proxyClient,
87-
ResourceHandlerRequest<ResourceModel> request
86+
final ProxyClient<CodeartifactClient> proxyClient
8887
) {
8988
try {
9089
proxyClient.injectCredentialsAndInvokeV2(
91-
Translator.translateToReadRequest(model, request), proxyClient.client()::describeDomain);
90+
Translator.translateToReadRequest(model), proxyClient.client()::describeDomain);
9291
return true;
9392
} catch (ResourceNotFoundException e) {
9493
return false;

aws-codeartifact-domain/src/main/java/software/amazon/codeartifact/domain/CreateHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private ProgressEvent<ResourceModel, CallbackContext> createDomain(
4646
return proxy.initiate("AWS-CodeArtifact-Domain::Create", proxyClient,progress.getResourceModel(), progress.getCallbackContext())
4747
.translateToServiceRequest(Translator::translateToCreateRequest)
4848
.makeServiceCall((awsRequest, client) -> createDomainSdkCall(progress, client, awsRequest))
49-
.stabilize((awsRequest, awsResponse, client, model, context) -> isStabilized(model, client, request))
49+
.stabilize((awsRequest, awsResponse, client, model, context) -> isStabilized(model, client))
5050
.progress();
5151
}
5252

@@ -73,11 +73,10 @@ private boolean hasReadOnlyProperties(final ResourceModel model) {
7373

7474
private boolean isStabilized(
7575
final ResourceModel model,
76-
final ProxyClient<CodeartifactClient> proxyClient,
77-
ResourceHandlerRequest<ResourceModel> request
76+
final ProxyClient<CodeartifactClient> proxyClient
7877
) {
7978
DescribeDomainResponse describeDomainResponse = proxyClient.injectCredentialsAndInvokeV2(
80-
Translator.translateToReadRequest(model, request), proxyClient.client()::describeDomain);
79+
Translator.translateToReadRequest(model), proxyClient.client()::describeDomain);
8180

8281
String domainStatus = describeDomainResponse.domain()
8382
.status()

aws-codeartifact-domain/src/main/java/software/amazon/codeartifact/domain/DeleteHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
3434

3535
// if domain does not exist, deleteDomain does not throw an exception, so we must do this
3636
// to be under the ResourceHandler Contract
37-
if (!doesDomainExist(model, proxyClient, request)) {
37+
if (!doesDomainExist(model, proxyClient)) {
3838
throw new CfnNotFoundException(model.getDomainName(), ResourceModel.TYPE_NAME);
3939
}
4040

@@ -53,7 +53,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
5353
return awsResponse;
5454
})
5555
// STEP 2.3 [Stabilize to check if the resource got deleted]
56-
.stabilize((deleteDomainRequest, deleteDomainResponse, proxyInvocation, resourceModel, context) -> !doesDomainExist(model, proxyClient, request))
56+
.stabilize((deleteDomainRequest, deleteDomainResponse, proxyInvocation, resourceModel, context) -> !doesDomainExist(model, proxyClient))
5757
.success();
5858

5959

aws-codeartifact-domain/src/main/java/software/amazon/codeartifact/domain/ReadHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
2525
return proxy.initiate("AWS-CodeArtifact-Domain::Read", proxyClient, request.getDesiredResourceState(), callbackContext)
2626

2727
// STEP 2 [construct a body of a request]
28-
.translateToServiceRequest((model) -> Translator.translateToReadRequest(model, request))
28+
.translateToServiceRequest(Translator::translateToReadRequest)
2929
// STEP 3 [make an api call]
3030
.makeServiceCall((awsRequest, client) -> {
3131
logger.log(String.format("%s read handler is being invoked", ResourceModel.TYPE_NAME));

aws-codeartifact-domain/src/main/java/software/amazon/codeartifact/domain/Translator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ static CreateDomainRequest translateToCreateRequest(final ResourceModel model) {
5858
/**
5959
* Request to read a resource
6060
* @param model resource model
61-
* @param request resource handler request
6261
* @return awsRequest the aws service request to describe a resource
6362
*/
64-
static DescribeDomainRequest translateToReadRequest(
65-
final ResourceModel model, final ResourceHandlerRequest<ResourceModel> request
66-
) {
63+
static DescribeDomainRequest translateToReadRequest(final ResourceModel model) {
6764
String domainName = model.getDomainName();
6865
String domainOwner = model.getDomainOwner();
6966

@@ -88,9 +85,9 @@ static DescribeDomainRequest translateToReadRequest(
8885
static ResourceModel translateFromReadResponse(final DescribeDomainResponse awsResponse) {
8986
DomainDescription domain = awsResponse.domain();
9087
return ResourceModel.builder()
91-
.domainName(domain.name())
9288
.encryptionKey(domain.encryptionKey())
93-
.domainOwner(domain.owner())
89+
.name(domain.name())
90+
.owner(domain.owner())
9491
.arn(domain.arn())
9592
.build();
9693
}

aws-codeartifact-domain/src/main/java/software/amazon/codeartifact/domain/UpdateHandler.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package software.amazon.codeartifact.domain;
22

3+
import java.util.Objects;
34
import software.amazon.awssdk.awscore.exception.AwsServiceException;
45
import software.amazon.awssdk.services.codeartifact.CodeartifactClient;
5-
import software.amazon.awssdk.services.codeartifact.model.ResourceNotFoundException;
66
import software.amazon.cloudformation.exceptions.CfnNotUpdatableException;
77
import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy;
88
import software.amazon.cloudformation.proxy.Logger;
99
import software.amazon.cloudformation.proxy.ProgressEvent;
1010
import software.amazon.cloudformation.proxy.ProxyClient;
1111
import software.amazon.cloudformation.proxy.ResourceHandlerRequest;
12-
import java.util.Objects;
1312

1413
public class UpdateHandler extends BaseHandlerStd {
1514
private Logger logger;
@@ -24,11 +23,13 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
2423

2524
this.logger = logger;
2625

27-
String desiredDomainName = request.getDesiredResourceState().getDomainName();
28-
String previousDomainName = request.getPreviousResourceState().getDomainName();
29-
if (!Objects.equals(previousDomainName, desiredDomainName)) {
30-
// cannot update domainName because it's CreateOnly
31-
throw new CfnNotUpdatableException(ResourceModel.TYPE_NAME, desiredDomainName);
26+
ResourceModel desiredResourceState = request.getDesiredResourceState();
27+
ResourceModel previousResourceState = request.getPreviousResourceState();
28+
if (!Objects.equals(previousResourceState.getDomainName(), desiredResourceState.getDomainName()) ||
29+
!Objects.equals(previousResourceState.getEncryptionKey(), desiredResourceState.getEncryptionKey())
30+
) {
31+
// cannot update domainName/EncryptionKey because it's CreateOnly
32+
throw new CfnNotUpdatableException(ResourceModel.TYPE_NAME, desiredResourceState.getArn());
3233
}
3334

3435
return ProgressEvent.progress(request.getDesiredResourceState(), callbackContext)

aws-codeartifact-domain/src/test/java/software/amazon/codeartifact/domain/CreateHandlerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public class CreateHandlerTest extends AbstractTestBase {
7070
.build();
7171

7272
private final ResourceModel desiredOutputModel = ResourceModel.builder()
73-
.domainName(DOMAIN_NAME)
74-
.domainOwner(DOMAIN_OWNER)
73+
.name(DOMAIN_NAME)
74+
.owner(DOMAIN_OWNER)
7575
.arn(DOMAIN_ARN)
7676
.encryptionKey(ENCRYPTION_KEY_ARN)
7777
.build();

aws-codeartifact-domain/src/test/java/software/amazon/codeartifact/domain/ReadHandlerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public void handleRequest_simpleSuccess() {
9595
final ProgressEvent<ResourceModel, CallbackContext> response = handler.handleRequest(proxy, request, new CallbackContext(), proxyClient, logger);
9696

9797
final ResourceModel desiredOutputModel = ResourceModel.builder()
98-
.domainName(DOMAIN_NAME)
99-
.domainOwner(DOMAIN_OWNER)
98+
.name(DOMAIN_NAME)
99+
.owner(DOMAIN_OWNER)
100100
.arn(DOMAIN_ARN)
101101
.encryptionKey(ENCRYPTION_KEY_ARN)
102102
.build();
@@ -146,8 +146,8 @@ public void handleRequest_withOnlyArn() {
146146
final ProgressEvent<ResourceModel, CallbackContext> response = handler.handleRequest(proxy, request, new CallbackContext(), proxyClient, logger);
147147

148148
final ResourceModel desiredOutputModel = ResourceModel.builder()
149-
.domainName(DOMAIN_NAME)
150-
.domainOwner(DOMAIN_OWNER)
149+
.name(DOMAIN_NAME)
150+
.owner(DOMAIN_OWNER)
151151
.arn(DOMAIN_ARN)
152152
.encryptionKey(ENCRYPTION_KEY_ARN)
153153
.build();

aws-codeartifact-domain/src/test/java/software/amazon/codeartifact/domain/UpdateHandlerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public class UpdateHandlerTest extends AbstractTestBase {
5959
.build();
6060

6161
private final ResourceModel desiredOutputModel = ResourceModel.builder()
62-
.domainName(DOMAIN_NAME)
63-
.domainOwner(DOMAIN_OWNER)
62+
.owner(DOMAIN_OWNER)
63+
.name(DOMAIN_NAME)
6464
.arn(DOMAIN_ARN)
6565
.encryptionKey(ENCRYPTION_KEY_ARN)
6666
.build();

0 commit comments

Comments
 (0)