static isTagValid()

in source/services/tagHandler/lib/EC2Helper.ts [141:173]


  static isTagValid(tagSchema: string): boolean {
    logger.info({
      label: "PolicyManager/isTagValid",
      message: `checking if tag is valid`,
    });

    try {
      const t = JSON.parse(tagSchema);
      logger.debug({
        label: "EC2Helper/isTagValid",
        message: `tag: ${JSON.stringify(tagSchema)}`,
      });
      if (
        (Object.prototype.hasOwnProperty.call(t, "Key") ||
          Object.prototype.hasOwnProperty.call(t, "key")) &&
        (Object.prototype.hasOwnProperty.call(t, "Value") ||
          Object.prototype.hasOwnProperty.call(t, "value")) &&
        Object.keys(t).length === 2
      ) {
        logger.info({
          label: "EC2Helper/isTagValid",
          message: `tag is valid`,
        });
        return true;
      } else throw new Error("invalid tag");
    } catch (e) {
      logger.error({
        label: "EC2Helper/isTagValid",
        message: `${(e as Error).message}`,
      });
      return false;
    }
  }