-
Notifications
You must be signed in to change notification settings - Fork 6
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
don't raise error in get if certificate is empty #84
don't raise error in get if certificate is empty #84
Conversation
ed5ec4b
to
6a721c9
Compare
0008172
to
80cbd7b
Compare
Signed-off-by: rishichawda <[email protected]>
Signed-off-by: rishichawda <[email protected]>
80cbd7b
to
d94d5b6
Compare
Signed-off-by: rishichawda <[email protected]>
d94d5b6
to
c52c0fd
Compare
f5cb4e1
to
48363eb
Compare
Signed-off-by: rishichawda <[email protected]>
48363eb
to
0049fca
Compare
Rishi, I think I found a couple of the problems. I am also working out some issues with the unit tests failing. |
@johnmccrae Please let me know if there's something I can help with. |
def valid?(certificate_thumbprint, store_location: "", store_name: "") | ||
cert_validate(certificate_thumbprint, store_location: store_location, store_name: store_name) | ||
cert_validate(certificate_thumbprint, store_location: store_location, store_name: store_name).yield_self do |x| | ||
if x.is_a?(TrueClass) || x.is_a?(FalseClass) | ||
x | ||
else | ||
false | ||
end | ||
end | ||
end |
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 think the implementations of valid?
and cert_validate
should have been other way round or somewhat swapped, i.e. valid?
should contain the validation logic that cert_validate
has, returning a bool, while cert_validate
should use valid?
to check and raise error or formatted error string. Something like below -
def valid?
# validation logic
# return boolean
end
def cert_validate
# use valid? to check
# raise error or return formatted error string (based on use case)
end
def get!(certificate_thumbprint, store_name: @store_name, store_location: @store_location) | ||
cert_pem = cert_get(certificate_thumbprint, store_name: store_name, store_location: store_location) | ||
|
||
raise ArgumentError, "Unable to retrieve the certificate" if cert_pem.empty? |
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.
ArgumentError
would be fitting if we were validating arguments here but since we are calling an external entity/store, we should either relay/wrap that entity's error or define a custom exception.
unless cert_pem.empty? | ||
build_openssl_obj(cert_pem) | ||
end | ||
cert_pem.empty? ? cert_pem : build_openssl_obj(cert_pem) |
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 think this should return nil or cert_pem/object. This would also clean .empty?
checks at other places.
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.
Can we get on Teams and talk about this? I feel like we have competing agendas and I want to make sure I am doing this correctly.
Signed-off-by: rishichawda [email protected]
Description
Currently
cert_get
call is checking if the value returned byget_cert_pem
forpowershell_exec!
output is empty, and raises an error. However, we do have acert_validate
that achieves the same thing by callingverify_certificate
which will return "Certificate not found" as string. It doesn't throw any errors, and only returns the string with the error message. This should also be eliminated since thevalid?
call is expected to return eithertrue
orfalse
.Complete details on the idea behind these changes are in #83
Issues Resolved
#83
chef/chef#11994
[List any existing issues this PR resolves, or any Discourse or
StackOverflow discussions that are relevant]
Check List