Skip to content
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

feature:add validate #114

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jameszhangyukun
Copy link
Contributor

Ⅰ. Describe what this PR did

add validate for backend interface

Ⅱ. Does this pull request fix one issue?

#95

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@@ -56,6 +56,9 @@ public ResponseEntity<PaginatedResponse<Domain>> list(CommonPageQuery query) {

@PostMapping
public ResponseEntity<Response<Domain>> add(@RequestBody Domain domain) {
if (!domain.valid()) {
throw new ValidationException("Domain is invalid.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to let caller know which part is invalid and why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to know the reason. we need the valid() method return with some message

return false;
}
if (StringUtils.isNotEmpty(enableHttps)) {
return EnableHttps.OFF.equals(enableHttps) || EnableHttps.ON.equals(enableHttps)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If new fields are added to this class, is it still OK to return here?
And shall we check certificateId if user enables HTTPS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we add field in EnableHttps this may be not work. So we use eunum to replace EnableHttps

@Getter
    @AllArgsConstructor
    public enum EnableHttps {
        OFF("off"), ON("on"), FORCE("force");
        private final String value;

        public static EnableHttps getEnum(String value) {
            for (EnableHttps enableHttps : values()) {
                if (Objects.equals(enableHttps.value, value)) {
                    return enableHttps;
                }
            }
            return null;
        }
    }

then use getEnum to check enableHttps ?
if we neet to check certificateId if enableHttps. we can use TlsCertificateService in DomainsController then use this to check?

 TlsCertificate certificate = tlsCertificateService.query(domain.getCertIdentifier());
        if (Objects.isNull(certificate)) {
            throw new ValidationException("domain certificate is not exits.");
        }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You can have a try with the enableHttps change.
  2. Maybe performing validation in the service is a better idea.

return false;
}
if (StringUtils.isNotEmpty(enableHttps)) {
return EnableHttps.OFF.equals(enableHttps) || EnableHttps.ON.equals(enableHttps)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You can have a try with the enableHttps change.
  2. Maybe performing validation in the service is a better idea.

@jameszhangyukun
Copy link
Contributor Author

sorry, I fix in my side. but i do not push it to origin.

if (Objects.isNull(validityStart) || Objects.isNull(validityEnd)) {
return false;
}
return validityEnd.isAfter(validityStart);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domains, validityStart and validityEnd are extracted from cert data. Client doesn't submit them.

if (StringUtils.isNotEmpty(certificate.getName())) {
certificate.setName(certificateName);
} else if (!StringUtils.equals(certificateName, certificate.getName())) {
throw new ValidationException("TlsCertificate name in the URL doesn't match the one in the body.");
}
if (!certificate.valid()) {
throw new ValidationException("certificate is not valid.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to let user know why it is invalid?

if (StringUtils.isNotEmpty(message)) {
throw new ValidationException("Domain is invalid. Because " + message);
}
if (domain.getEnableHttps().equals(Domain.EnableHttps.ON.getValue())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FORCE 也是开 HTTPS 的意思

@CH3CHO
Copy link
Collaborator

CH3CHO commented May 9, 2023

@jameszhangyukun Hello, Is there any progress on this work? Could you resolve the conflicts first?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants