Skip to content

Commit

Permalink
[PLAT-14534]Add regex match for GCP Instance template
Browse files Browse the repository at this point in the history
Summary:
Added regex match for gcp instance template.
Regex taken from gcp documentation [[https://cloud.google.com/compute/docs/reference/rest/v1/instanceTemplates | here]].

Test Plan: Tested manually that validation fails with invalid characters.

Reviewers: #yba-api-review!, svarshney

Reviewed By: svarshney

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D36543
  • Loading branch information
asharma-yb authored and vaibhav-yb committed Jul 23, 2024
1 parent 334358b commit 6ac1ba9
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.yugabyte.yw.models.configs.validators;

import static play.mvc.Http.Status.BAD_REQUEST;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.api.services.compute.model.Firewall;
Expand Down Expand Up @@ -39,6 +41,7 @@ public class GCPProviderValidator extends ProviderFieldsValidator {

private final GCPCloudImpl gcpCloudImpl;
private final RuntimeConfGetter runtimeConfGetter;
private final String INSTANCE_TEMPLATE_REGEX = "[a-z]([-a-z0-9]*[a-z0-9])?";

@Inject
public GCPProviderValidator(
Expand Down Expand Up @@ -229,6 +232,12 @@ private void validateInstanceTempl(
.get("jsonPath")
.asText();
try {
if (!instanceTemplate.matches(INSTANCE_TEMPLATE_REGEX)) {
throw new PlatformServiceException(
BAD_REQUEST,
"Instance template must start with a lowercase character and can only contain"
+ " alphanumeric characters and '-'");
}
if (!apiClient.checkInstanceTempelate(instanceTemplate)) {
String errorMsg =
String.format(
Expand Down

0 comments on commit 6ac1ba9

Please sign in to comment.