kubernetix / k8x

Deploy and manage reusable k8s apps with ts/js
0 stars 0 forks source link

Allow .env parsing as lists or objects #14

Open nhh opened 1 month ago

nhh commented 1 month ago

When you want to parse annotations or labels or simple lists like [1,2,3,4]

nhh commented 1 month ago
 declare const $env: {
  /** Parses `K8X_MY_TEST=abc` into abc */
  get<T>(name: string): T;

  /** Parses some env variables with the same prefix into a object
   * @example
   * 
   * $env.get("INGRESS_CLASS_ANNOTATIONS")
   * -----------
   * K8X_INGRESS_CLASS_ANNOTATIONS_KEY_1=nginx.ingress.kubernetes.io/app-root
   * K8X_INGRESS_CLASS_ANNOTATIONS_VALUE_1='/var/www/html'
   * -----------
   * K8X_INGRESS_CLASS_ANNOTATIONS_KEY_2=nginx.ingress.kubernetes.io/enable-cors
   * K8X_INGRESS_CLASS_ANNOTATIONS_VALUE_2=true
   * -----------
   * {
   *   "nginx.ingress.kubernetes.io/app-root": '/var/www/html',
   *   "nginx.ingress.kubernetes.io/enable-cors": true
   * }
   */
  getAsObject(prefix: string): k8x.Tuple;

  /** Parses a env variables as list
   * Consider these Variables:
   * K8X_MY_TEST_1=a
   * K8X_MY_TEST_2=b
   * K8X_MY_TEST_3=c
   * K8X_MY_TEST_4=d
   * K8X_MY_TEST_5=e
   * Will be parsed into
   * ["a", "b", "c", "d", "e"]
   */
  getAsList<T>(prefix: string): T[];
};