-
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
Fixing some of the contract tests for Domain. #22
Conversation
if (!doesDomainExist(request.getDesiredResourceState(), proxyClient, request)) { | ||
throw new CfnNotFoundException(request.getDesiredResourceState().getDomainName(), ResourceModel.TYPE_NAME); | ||
} |
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.
This is interesting to me as I know that a bunch of other CFN resources will not throw an exception if we are trying to delete something that is already deleted.... Do you know if this would show up in the console? Or if this is magically handled by CFN to be OK
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.
Just ran a test, internally the exception gets thrown. From the logs:
Resource of type 'domain-name' with identifier 'AWS::CodeArtifact::Domain' was not found. in a DELETE action on a AWS::CodeArtifact::Domain: software.amazon.cloudformation.exceptions.CfnNotFoundException: Resource of type 'poc-domain' with identifier 'AWS::CodeArtifact::Domain' was not found.
In the console, the stack ends up in DELETE_COMPLETE
, so it seems to be handled
return streamOfOrEmpty(awsResponse.domains()) | ||
.map(domain -> ResourceModel.builder() | ||
.arn(buildArn("us-west-2", domain.owner(), domain.name())) |
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.
why are we hardcoding us-west-2?
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.
cfn test
does not override regions and defaults to us-west-2, I hardcoded this and forgot to remove it :(
final String partition = "aws"; | ||
if (region.contains("us-gov-")) { | ||
partition.concat("-us-gov"); | ||
} | ||
|
||
if (region.contains("cn-")) { | ||
partition.concat("-cn"); | ||
} |
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.
I get that this is temporary until we can get the ListDomains to return the Arns, but i am surprised at the very least that there isnt some magic "give me my partition" in the CFN toolkit here. I know if you create a Region object (from sddv2) you can get the partition.
String accountId = request.getAwsAccountId(); | ||
return GetDomainPermissionsPolicyRequest.builder() | ||
.domain(model.getDomainName()) | ||
.domainOwner(accountId) | ||
.build(); |
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.
kinda odd that we were first using the caller's accountId instead of just grabbing it from the model itself
and now we are just omitting it. I get that the caller should be the domain owner in this case. But if we decide that anyone can create an independent resource for a DomainPolicy, we might pass in the domain Owner to that method and that would then need to be translated accordingly
82e2fcb
to
f20a56b
Compare
f20a56b
to
54f130c
Compare
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.
My comments are just nits. If you want to include them in another PR thats fine. If you ignore them, ill probably forget and tell you to do them in another PR haha, so up to you how you want to handle them
|
||
public abstract class BaseHandlerStd extends BaseHandler<CallbackContext> { | ||
|
||
public static final ObjectMapper MAPPER = new ObjectMapper(); |
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.
nit, this should be private, or if you're using this in subclasses, then protected
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.
updating
try { | ||
proxyClient.injectCredentialsAndInvokeV2( | ||
Translator.translateToReadRequest(model, request), proxyClient.client()::describeDomain); | ||
return true; | ||
} catch (ResourceNotFoundException e) { | ||
return false; | ||
} | ||
} |
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.
not sure if this little green squares mean you have weird whitespace or something. Maybe accidentally had a couple of tabs instead of spaces?
@@ -24,44 +23,43 @@ | |||
final Logger logger) { | |||
|
|||
this.logger = logger; | |||
ResourceModel model = request.getDesiredResourceState(); | |||
// STEP 1.0 [initialize a proxy context] | |||
ProgressEvent<ResourceModel, CallbackContext> test = proxy |
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.
nit, i'd call this something other than test.
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.
oops, I was supposed to change this to something meaningful..
4dc59b0
to
53ba117
Compare
"type": "object", | ||
"minLength": 2, | ||
"maxLength": 5120 |
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 for string
types
issue to catch these automatically
"type": "object", | |
"minLength": 2, | |
"maxLength": 5120 | |
"type": "object", |
Issue #, if available:
Description of changes:
Adding in some fixes that make the handlers to adhere to https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html.
contract_invalid_create
still doesn't pass and I am going to reach out to CloudFormation to get guidance on this testNOTES:
ListDomains
populates the arn in it's sdk response. The reason it's needed is because the primary identifier needs to be populated after alist
operationdomainOwner
from some of the operations because I am assuming that for for update/read permissions policies and describe domain, we are always doing so in the account the CFN stack is in.Testing
When I run the tests that
ERROR
by themselves they passBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.