<commit_before>import { IPromise } from 'angular';
import { AccountService } from 'core/account/AccountService';

export interface IApplicationNameValidationMessage {
  cloudProvider?: string;
  message: string;
}

export interface IValidationResult {
  warnings: string[];
  errors: string[];
}

export interface IApplicationNameValidationResult {
  warnings: IApplicationNameValidationMessage[];
  errors: IApplicationNameValidationMessage[];
}

export interface IApplicationNameValidator {
  validate: (applicationName: string) => IValidationResult;
}

/**
 * Responsible for registering validators around the application name, then running them
 * when creating a new application.
 */
export class ApplicationNameValidator {
  private static providerMap: Map<string, IApplicationNameValidator[]> = new Map<string, IApplicationNameValidator[]>();

  /**
   * Registers a validator for a cloud provider.
   * @param cloudProvider the key of the cloud provider, e.g. "aws", "gce"
   * @param validator the actual validator
   */
  public static registerValidator(cloudProvider: string, validator: IApplicationNameValidator) {
    if (!this.providerMap.has(cloudProvider)) {
      this.providerMap.set(cloudProvider, []);
    }
    this.providerMap.get(cloudProvider).push(validator);
  }

  /**
   * Performs the actual validation. If there are no providers supplied, all configured validators will fire
   * and add their messages to the result.
   * @param applicationName the name of the application
   * @param providersToTest the configured cloud providers; if empty, validators for all providers will fire
   * @returns {{errors: Array, warnings: Array}}
   */
  public static validate(
    applicationName: string,
    providersToTest: string[],
  ): IPromise<IApplicationNameValidationResult> {
    return AccountService.listProviders().then((availableProviders: string[]) => {
      const toCheck = providersToTest && providersToTest.length ? providersToTest : availableProviders;

      const errors: IApplicationNameValidationMessage[] = [];
      const warnings: IApplicationNameValidationMessage[] = [];
      toCheck.forEach((provider: string) => {<commit_msg>feat(validation): Allow app name validators to be overridden (#8584)<commit_after>import { IPromise } from 'angular';
import { AccountService } from 'core/account/AccountService';

export interface IApplicationNameValidationMessage {
  cloudProvider?: string;
  message: string;
}

export interface IValidationResult {
  warnings: string[];
  errors: string[];
}

export interface IApplicationNameValidationResult {
  warnings: IApplicationNameValidationMessage[];
  errors: IApplicationNameValidationMessage[];
}

export interface IApplicationNameValidator {
  validate: (applicationName: string) => IValidationResult;
}

/**
 * Responsible for registering validators around the application name, then running them
 * when creating a new application.
 */
export class ApplicationNameValidator {
  private static providerMap: Map<string, IApplicationNameValidator[]> = new Map<string, IApplicationNameValidator[]>();

  /**
   * Registers a validator for a cloud provider.
   * @param cloudProvider the key of the cloud provider, e.g. "aws", "gce"
   * @param validator the actual validator
   */
  public static registerValidator(cloudProvider: string, validator: IApplicationNameValidator) {
    if (!this.providerMap.has(cloudProvider)) {
      this.providerMap.set(cloudProvider, []);
    }
    this.providerMap.get(cloudProvider).push(validator);
  }

  /**
   * Overwrites the validators of a cloud provider with the given array.
   * @param cloudProvider the key of the cloud provider, e.g. "aws", "gce"
   * @param validators the validators to use for the provider
   */
  public static setValidators(cloudProvider: string, validators: IApplicationNameValidator[]) {
    this.providerMap.set(cloudProvider, validators);
  }

  /**
   * Performs the actual validation. If there are no providers supplied, all configured validators will fire
   * and add their messages to the result.
   * @param applicationName the name of the application
   * @param providersToTest the configured cloud providers; if empty, validators for all providers will fire
   * @returns {{errors: Array, warnings: Array}}
   */
  public static validate(
    applicationName: string,
    providersToTest: string[],
  ): IPromise<IApplicationNameValidationResult> {
    return AccountService.listProviders().then((availableProviders: string[]) => {
      const toCheck = providersToTest && providersToTest.length ? providersToTest : availableProviders;

      const errors: IApplicationNameValidationMessage[] = [];
      const warnings: IApplicationNameValidationMessage[] = [];
      toCheck.forEach((provider: string) => {
{'fraction_non_alphanumeric': 0.09454089102698181, 'fraction_numerical': 0.0008366450533361222, 'mean_word_length': 4.8531211750306, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2897018', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1209, 'n_words': 385}