-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fixing some of the contract tests for Domain. #22
Merged
jonjara
merged 2 commits into
aws-cloudformation:main
from
jonjara:domain-contract-tests
Aug 24, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"CREATE": { | ||
"/PermissionsPolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": "*", | ||
"Action": "codeartifact:*", | ||
"Resource": "*" | ||
} | ||
] | ||
}, | ||
"/EncryptionKey": null, | ||
"/DomainOwner": null | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
package software.amazon.codeartifact.domain; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import software.amazon.awssdk.awscore.exception.AwsServiceException; | ||
import software.amazon.awssdk.services.codeartifact.CodeartifactClient; | ||
import software.amazon.awssdk.services.codeartifact.model.DescribeDomainResponse; | ||
import software.amazon.awssdk.services.codeartifact.model.GetDomainPermissionsPolicyRequest; | ||
import software.amazon.awssdk.services.codeartifact.model.PutDomainPermissionsPolicyResponse; | ||
import software.amazon.awssdk.services.codeartifact.model.ResourceNotFoundException; | ||
import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy; | ||
import software.amazon.cloudformation.proxy.Logger; | ||
import software.amazon.cloudformation.proxy.ProgressEvent; | ||
import software.amazon.cloudformation.proxy.ProxyClient; | ||
import software.amazon.cloudformation.proxy.ResourceHandlerRequest; | ||
import software.amazon.cloudformation.proxy.delay.Constant; | ||
import org.apache.http.HttpStatus; | ||
import java.time.Duration; | ||
|
||
public abstract class BaseHandlerStd extends BaseHandler<CallbackContext> { | ||
|
||
private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
@Override | ||
public final ProgressEvent<ResourceModel, CallbackContext> handleRequest( | ||
final AmazonWebServicesClientProxy proxy, | ||
|
@@ -47,40 +45,54 @@ protected ProgressEvent<ResourceModel, CallbackContext> putDomainPermissionsPoli | |
final ProxyClient<CodeartifactClient> proxyClient, | ||
final Logger logger | ||
) { | ||
final ResourceModel desiredModel = progress.getResourceModel(); | ||
if (desiredModel.getPolicyDocument() == null) { | ||
return ProgressEvent.progress(desiredModel, callbackContext); | ||
} | ||
return proxy.initiate("AWS-CodeArtifact-Domain::Update::PutDomainPermissionsPolicy", proxyClient, | ||
progress.getResourceModel(), progress.getCallbackContext()) | ||
.translateToServiceRequest(Translator::translatePutDomainPolicyRequest) | ||
.makeServiceCall((awsRequest, client) -> { | ||
PutDomainPermissionsPolicyResponse awsResponse = null; | ||
try { | ||
awsResponse = client.injectCredentialsAndInvokeV2(awsRequest, client.client()::putDomainPermissionsPolicy); | ||
logger.log("Domain permission policy successfully added."); | ||
} catch (final AwsServiceException e) { | ||
String domainName = desiredModel.getDomainName(); | ||
Translator.throwCfnException(e, Constants.PUT_DOMAIN_POLICY, domainName); | ||
} | ||
return awsResponse; | ||
}) | ||
.stabilize((awsRequest, awsResponse, client, model, context) -> domainPolicyIsStabilized(model, client, request)) | ||
.progress(); | ||
|
||
final ResourceModel desiredModel = progress.getResourceModel(); | ||
final ResourceModel previousModel = request.getPreviousResourceState(); | ||
|
||
if (desiredModel.getPermissionsPolicyDocument() == null || policyIsUnchanged(desiredModel, previousModel)) { | ||
return ProgressEvent.progress(desiredModel, callbackContext); | ||
} | ||
return proxy.initiate("AWS-CodeArtifact-Domain::Update::PutDomainPermissionsPolicy", proxyClient, progress.getResourceModel(), progress.getCallbackContext()) | ||
.translateToServiceRequest(Translator::translatePutDomainPolicyRequest) | ||
.makeServiceCall((awsRequest, client) -> { | ||
PutDomainPermissionsPolicyResponse awsResponse = null; | ||
try { | ||
awsResponse = client.injectCredentialsAndInvokeV2(awsRequest, client.client()::putDomainPermissionsPolicy); | ||
logger.log("Domain permission policy successfully added."); | ||
} catch (final AwsServiceException e) { | ||
String domainName = desiredModel.getDomainName(); | ||
Translator.throwCfnException(e, Constants.PUT_DOMAIN_POLICY, domainName); | ||
} | ||
return awsResponse; | ||
}) | ||
.progress(); | ||
} | ||
|
||
private boolean domainPolicyIsStabilized( | ||
boolean policyIsUnchanged(final ResourceModel desiredModel, final ResourceModel previousModel) { | ||
if (previousModel == null) { | ||
return false; | ||
} | ||
|
||
if (desiredModel.getPermissionsPolicyDocument() == null || previousModel.getPermissionsPolicyDocument() == null) { | ||
return false; | ||
} | ||
JsonNode desiredPolicy = MAPPER.valueToTree(desiredModel.getPermissionsPolicyDocument()); | ||
JsonNode currentPolicy = MAPPER.valueToTree(previousModel.getPermissionsPolicyDocument()); | ||
return desiredPolicy.equals(currentPolicy); | ||
} | ||
|
||
protected boolean doesDomainExist( | ||
final ResourceModel model, | ||
final ProxyClient<CodeartifactClient> proxyClient, | ||
ResourceHandlerRequest<ResourceModel> request | ||
) { | ||
try { | ||
proxyClient.injectCredentialsAndInvokeV2( | ||
Translator.translateToGetDomainPermissionPolicy(model, request), proxyClient.client()::getDomainPermissionsPolicy); | ||
return true; | ||
} catch (ResourceNotFoundException e) { | ||
return false; | ||
} | ||
try { | ||
proxyClient.injectCredentialsAndInvokeV2( | ||
Translator.translateToReadRequest(model, request), proxyClient.client()::describeDomain); | ||
return true; | ||
} catch (ResourceNotFoundException e) { | ||
return false; | ||
} | ||
} | ||
Comment on lines
+89
to
96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if this little green squares mean you have weird whitespace or something. Maybe accidentally had a couple of tabs instead of spaces? |
||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#60
minLength
/maxLength
is specifically forstring
typesissue to catch these automatically