github.com/argoproj/argo-cd@v1.8.7/ui/src/app/applications/components/application-parameters/kustomize-image.ts (about)

     1  const pattern = /^(.*):([a-zA-Z0-9._-]*)$/;
     2  
     3  export interface Image {
     4      name: string;
     5      newName?: string;
     6      newTag?: string;
     7      digest?: string;
     8  }
     9  
    10  function parseOverwrite(arg: string, overwriteImage: boolean): {name: string; digest?: string; tag?: string} {
    11      // match <image>@<digest>
    12      const parts = arg.split('@');
    13      if (parts.length > 1) {
    14          return {name: parts[0], digest: parts[1]};
    15      }
    16  
    17      // match <image>:<tag>
    18      const groups = pattern.exec(arg);
    19      if (groups && groups.length === 3) {
    20          return {name: groups[1], tag: groups[2]};
    21      }
    22  
    23      // match <image>
    24      if (arg.length > 0 && overwriteImage) {
    25          return {name: arg};
    26      }
    27      return {name: arg};
    28  }
    29  
    30  export function parse(arg: string): Image {
    31      // matches if there is an image name to overwrite
    32      // <image>=<new-image><:|@><new-tag>
    33      const parts = arg.split('=');
    34      if (parts.length === 2) {
    35          const overwrite = parseOverwrite(parts[1], true);
    36          return {
    37              name: parts[0],
    38              newName: overwrite.name,
    39              newTag: overwrite.tag,
    40              digest: overwrite.digest
    41          };
    42      }
    43  
    44      // matches only for <tag|digest> overwrites
    45      // <image><:|@><new-tag>
    46      const p = parseOverwrite(arg, false);
    47      return {name: p.name, newTag: p.tag, digest: p.digest};
    48  }
    49  
    50  export function format(image: Image) {
    51      const imageName = image.newName ? `${image.name}=${image.newName}` : image.name;
    52      if (image.newTag) {
    53          return `${imageName}:${image.newTag}`;
    54      } else if (image.digest) {
    55          return `${imageName}@${image.digest}`;
    56      }
    57      return imageName;
    58  }