public static List getRegexes()

in metadata/src/main/java/com/google/cloud/teleport/metadata/util/MetadataUtils.java [128:249]


  public static List<String> getRegexes(Annotation parameterAnnotation) {
    switch (parameterAnnotation.annotationType().getSimpleName()) {
      case "Text":
        TemplateParameter.Text simpleTextParam = (TemplateParameter.Text) parameterAnnotation;
        if (simpleTextParam.regexes() != null
            && simpleTextParam.regexes().length > 0
            && !(simpleTextParam.regexes().length == 1
                && simpleTextParam.regexes()[0].equals(""))) {
          return Arrays.asList(simpleTextParam.regexes());
        }
        return null;
      case "JavascriptUdfFile":
        TemplateParameter.JavascriptUdfFile javascriptUdfFileParam =
            (TemplateParameter.JavascriptUdfFile) parameterAnnotation;
        return List.of("^gs:\\/\\/[^\\n\\r]+$");
      case "GcsReadFile":
        TemplateParameter.GcsReadFile gcsReadFileParam =
            (TemplateParameter.GcsReadFile) parameterAnnotation;
        return List.of("^gs:\\/\\/[^\\n\\r]+$");
      case "GcsReadBucket":
        TemplateParameter.GcsReadBucket gcsReadBucketParam =
            (TemplateParameter.GcsReadBucket) parameterAnnotation;
        return List.of("^gs:\\/\\/[^\\n\\r]+$");
      case "GcsReadFolder":
        TemplateParameter.GcsReadFolder gcsReadFolderParam =
            (TemplateParameter.GcsReadFolder) parameterAnnotation;
        return List.of("^gs:\\/\\/[^\\n\\r]+$");
      case "GcsWriteFile":
        TemplateParameter.GcsWriteFile gcsWriteFileParam =
            (TemplateParameter.GcsWriteFile) parameterAnnotation;
        return List.of("^gs:\\/\\/[^\\n\\r]+$");
      case "GcsWriteFolder":
        TemplateParameter.GcsWriteFolder gcsWriteFolderParam =
            (TemplateParameter.GcsWriteFolder) parameterAnnotation;
        return List.of("^gs:\\/\\/[^\\n\\r]+$");
      case "GcsWriteBucket":
        TemplateParameter.GcsWriteBucket gcsWriteBucketParam =
            (TemplateParameter.GcsWriteBucket) parameterAnnotation;
        return List.of("^gs:\\/\\/[^\\n\\r]+$");
      case "PubsubSubscription":
        TemplateParameter.PubsubSubscription pubsubSubscriptionParam =
            (TemplateParameter.PubsubSubscription) parameterAnnotation;
        return List.of("^projects\\/[^\\n\\r\\/]+\\/subscriptions\\/[^\\n\\r\\/]+$|^$");
      case "PubsubTopic":
        TemplateParameter.PubsubTopic pubsubTopicParam =
            (TemplateParameter.PubsubTopic) parameterAnnotation;
        return List.of("^projects\\/[^\\n\\r\\/]+\\/topics\\/[^\\n\\r\\/]+$|^$");
      case "Password":
        TemplateParameter.Password passwordParam = (TemplateParameter.Password) parameterAnnotation;
        return null;
      case "ProjectId":
        TemplateParameter.ProjectId projectIdParam =
            (TemplateParameter.ProjectId) parameterAnnotation;
        return List.of("[a-z0-9\\-\\.\\:]+");
      case "Boolean":
        TemplateParameter.Boolean booleanParam = (TemplateParameter.Boolean) parameterAnnotation;
        return List.of("^(true|false)$");
      case "Integer":
        TemplateParameter.Integer integerParam = (TemplateParameter.Integer) parameterAnnotation;
        return List.of("^[0-9]+$");
      case "Long":
        TemplateParameter.Long longParam = (TemplateParameter.Long) parameterAnnotation;
        return List.of("^[0-9]+$");
      case "Float":
        TemplateParameter.Float floatParam = (TemplateParameter.Float) parameterAnnotation;
        return List.of("^-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][-+]?[0-9]+)?$");
      case "Double":
        TemplateParameter.Double doubleParam = (TemplateParameter.Double) parameterAnnotation;
        return List.of("^-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][-+]?[0-9]+)?$");
      case "Enum":
        TemplateParameter.Enum enumParam = (TemplateParameter.Enum) parameterAnnotation;

        String optionsRegex =
            Arrays.stream(enumParam.enumOptions())
                .map(TemplateEnumOption::value)
                .collect(Collectors.joining("|"));

        return List.of("^(" + optionsRegex + ")$");
      case "DateTime":
        TemplateParameter.DateTime dateTimeParam = (TemplateParameter.DateTime) parameterAnnotation;
        return List.of(
            "^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):(([0-9]{2})(\\.[0-9]+)?)Z$");
      case "BigQueryTable":
        TemplateParameter.BigQueryTable bigQueryTableParam =
            (TemplateParameter.BigQueryTable) parameterAnnotation;
        return List.of(BIGQUERY_TABLE_PATTERN);
      case "KmsEncryptionKey":
        TemplateParameter.KmsEncryptionKey kmsEncryptionKeyParam =
            (TemplateParameter.KmsEncryptionKey) parameterAnnotation;
        return List.of(
            "^projects\\/[^\\n"
                + "\\r"
                + "\\/]+\\/locations\\/[^\\n"
                + "\\r"
                + "\\/]+\\/keyRings\\/[^\\n"
                + "\\r"
                + "\\/]+\\/cryptoKeys\\/[^\\n"
                + "\\r"
                + "\\/]+$");
      case "Duration":
        TemplateParameter.Duration durationParam = (TemplateParameter.Duration) parameterAnnotation;
        return List.of("^[1-9][0-9]*[s|m|h]$");
      case "MachineType":
        TemplateParameter.MachineType machineTypeParam =
            (TemplateParameter.MachineType) parameterAnnotation;
        return List.of("^[a-z0-9]+(-[a-z0-9]+)+$");
      case "ServiceAccount":
        TemplateParameter.ServiceAccount serviceAccountParam =
            (TemplateParameter.ServiceAccount) parameterAnnotation;
        return List.of("^[-a-z0-9]{6,30}@[-a-z0-9]{6,30}.iam.gserviceaccount.com$");
      case "WorkerRegion":
        TemplateParameter.WorkerRegion workerRegionParam =
            (TemplateParameter.WorkerRegion) parameterAnnotation;
        return List.of("[a-z]+-[a-z]+[0-9]+");
      case "WorkerZone":
        TemplateParameter.WorkerZone workerZoneParam =
            (TemplateParameter.WorkerZone) parameterAnnotation;
        return List.of("[a-z]+-[a-z]+[0-9]+-[a-z]");
      default:
        return null;
    }
  }