darkmsph1t / _spartan

npm project to package & configure common security middleware && add security.js file to code repo
5 stars 0 forks source link

Allow use of/configuration of separate `.env` files #95

Open darkmsph1t opened 5 years ago

darkmsph1t commented 5 years ago

Is your feature request related to a problem? Please describe. Today _spartan only allows you to directly access environment variables if NODE_ENV !== 'production'. The application should accommodate scenarios in which different environment variable files can be accessed depending on the named environment

Describe the solution you'd like On calling fetchSecret(variable):

  1. _spartan checks process.env.NODE_ENV
  2. run this case:
    
    if (process.env.NODE_ENV === 'production'){
    require('dotenv').config({ path: '/full/custom/path/to/your/env/prod_vars' })
    return process.env[variable]
    } else if (process.env.NODE_ENV === 'development'){
    require('dotenv').config({ path: '/full/custom/path/to/your/env/dev_vars' })
    return process.env[variable]
    } else if (process.env.NODE_ENV === 'stage'){
    require('dotenv').config({ path: '/full/custom/path/to/your/env/stage_vars' })
    return process.env[variable]
    } 
    ... // have a case for each of the environments

else { let error = new Error ('secrets/no-matching-env') return error }


**Why does this feature belong in \_spartan?**
Ensures that _all_ secrets stored as environment variables can be loaded safely regardless of environment type and encourages developers to _not_ keep these in source code

**Describe alternatives you've considered**
N/A

**Additional context**
Add any other context or screenshots about the feature request here.