Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitEnv 2.0 #4

Closed
rechenberger opened this issue Jul 28, 2022 · 2 comments
Closed

GitEnv 2.0 #4

rechenberger opened this issue Jul 28, 2022 · 2 comments

Comments

@rechenberger
Copy link
Contributor

rechenberger commented Jul 28, 2022

GitEnv 2.0

UI

JS

  • make it still hackable via gitenv.config.js ?
  • Libary stacking vs Libary scope explosion

Tech Stack

https://github.com/t3-oss/create-t3-app

@sean-nicholas
Copy link
Contributor

Here is a revised idea for the config and extension files:

// --- EnvConfig: gitenvs.config.json --- //

export type PointerOrValue =
  | {
      type: 'pointer'
      fileId: string
      stage: string
      key: string
    }
  | {
      type: 'value'
      value: string
      encrypted: boolean
    }

export type EnvVar = {
  // BASICS:
  fileId: string
  stage: string
  key: string

  // Just for DTO. All pointers resolved, funcs have been run & values are decrypted
  _value?: string
} & (
  | {
      type: 'func'
      func: {
        name: string
        params?: Record<string, PointerOrValue | PointerOrValue[]>
      }
    }
  | {
      type: 'content'
      content: PointerOrValue
    }
)

export type EnvFile = {
  fileId: string
  name: string
  path: string
  type:
    | 'dotenv'
    | 'typescript'
    // Can be used as a collection of variables. These variables can be reused in real files
    // `path` will be ignored.` TODO: Maybe we need better naming
    | 'variables'
    // Can be extended by extension file -> fileWriters
    | string
}

export type EnvStage = {
  name: string
  publicKey: string
  encryptedPrivateKey: string
}

export type EnvConfig = {
  version: 1
  envVars: EnvVar[]
  files: EnvFile[]
  stages: EnvStage[]
  // extensionsPath: string
}
// --- Extension File: gitenvs.extensions.js --- //

export type FuncContext<Params = Record<string, string | string[]>> = {
  params: Params
  currentEnvVar: EnvVar
}

export type Func<Input> = (options: {
  input: Input
  context: FuncContext
}) => Promise<string>

export type EnvFileWriter = (options: { TODO: any }) => Promise<string>

export type ExtensionFile = {
  funcs: {
    [funcName: string]: Func<any>
  }
  writers: {
    [writerName: string]: EnvFileWriter
  }
}

Some infos why the functions are designed how they are:

  • If you have a func you can't have a pointer or a value. But you get params that can contain multiple pointer or a value
  • With this configuration the following examples are possible
    • getIPAddr: Return the current IP address. Does not depend on params
    • getJWTSecretForHasura: Hasura needs the secret in a JSON with additional info. params would be:
      {
        "jwtSecret": [{"type": "pointer", "fileId"...}],
      }
    • joinEnvVars: Gets a list of env files and joins them with a user defined symbol. Useful for something like: API_KEYS=[multiple_api_keys_comma_separated_that_are_used_in_other_env_vars_too]. params would be:
      {
        "envVarsToJoin": [{"type": "pointer", "fileId"...}],
        "separator": { "type": "value", "value": ",", "encrypted": false }
      }

@sean-nicholas
Copy link
Contributor

sean-nicholas commented Oct 10, 2022

Nice thing about params for functions is that

  • it enables functions to access multiple EnvVars
  • we can keep track which EnvVars are used and display that in the UI. (For example: Show an error if you want to delete an EnvVar that is being used to somewhere else)
  • functions can have plain text or encrypted arguments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants