-
Notifications
You must be signed in to change notification settings - Fork 55
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
base: main
Are you sure you want to change the base?
feature:add validate #114
Conversation
@@ -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."); |
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.
Is it possible to let caller know which part is invalid and why?
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.
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) |
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.
If new fields are added to this class, is it still OK to return here?
And shall we check certificateId if user enables HTTPS?
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 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.");
}
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.
- You can have a try with the
enableHttps
change. - Maybe performing validation in the service is a better idea.
backend/src/main/java/com/alibaba/higress/console/controller/dto/Route.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/alibaba/higress/console/controller/util/ValidateUtil.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/alibaba/higress/console/util/TypeUtil.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/alibaba/higress/console/util/TypeUtil.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/alibaba/higress/console/util/TypeUtil.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/alibaba/higress/console/util/TypeUtil.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/alibaba/higress/console/controller/util/ValidateUtil.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/alibaba/higress/console/controller/dto/TlsCertificate.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/alibaba/higress/console/controller/dto/Route.java
Outdated
Show resolved
Hide resolved
return false; | ||
} | ||
if (StringUtils.isNotEmpty(enableHttps)) { | ||
return EnableHttps.OFF.equals(enableHttps) || EnableHttps.ON.equals(enableHttps) |
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.
- You can have a try with the
enableHttps
change. - Maybe performing validation in the service is a better idea.
3aa2f26
to
7d7666c
Compare
sorry, I fix in my side. but i do not push it to origin. |
7d7666c
to
f653bf7
Compare
if (Objects.isNull(validityStart) || Objects.isNull(validityEnd)) { | ||
return false; | ||
} | ||
return validityEnd.isAfter(validityStart); |
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.
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."); |
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.
Is it possible to let user know why it is invalid?
f653bf7
to
9d7d46d
Compare
backend/src/main/java/com/alibaba/higress/console/controller/DomainsController.java
Show resolved
Hide resolved
if (StringUtils.isNotEmpty(message)) { | ||
throw new ValidationException("Domain is invalid. Because " + message); | ||
} | ||
if (domain.getEnableHttps().equals(Domain.EnableHttps.ON.getValue())) { |
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.
FORCE 也是开 HTTPS 的意思
backend/src/main/java/com/alibaba/higress/console/controller/RoutesController.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/alibaba/higress/console/controller/dto/TlsCertificate.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/com/alibaba/higress/console/controller/dto/TlsCertificate.java
Outdated
Show resolved
Hide resolved
9d7d46d
to
a077add
Compare
@jameszhangyukun Hello, Is there any progress on this work? Could you resolve the conflicts first? |
Ⅰ. 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