trek10inc / serverless-secrets

An opinionated tool for safely managing and deploying Serverless projects and their secrets.
Other
165 stars 27 forks source link

bug: environment messed up #31

Open franciscocpg opened 6 years ago

franciscocpg commented 6 years ago

Giving the following serverless configuration

function1:
  handler: file1.handler
  environmentSecrets:
      ENV1: '/my-project/${opt:stage}/ENV1'

function2:
  handler: file2.handler
  environmentSecrets:
      ENV2: '/my-project/${opt:stage}/ENV2'

When invoking function1 the environment is injected with ENV2 variable instead of ENV1. And that's because of the the code below: https://github.com/trek10inc/serverless-secrets/blob/948e5db949dc63cc0b2cac6486c1a5c9c41e9589/plugin/index.js#L240-L247

I've done a fix for me (https://github.com/franciscocpg/serverless-secrets/commit/19140522150c3e9aeac16c879e586d6ceb607964) and it worked the way I've expected but before proposing a PR I'd like to know the rationale behind this split.

Maybe there is something I'm not seeing.

sneha-nagole commented 6 years ago

Thank you for the plugin.

When all functions have same handler is another case where environment is messed up. Below is the sample config.

function1: handler: file.handler environment: ENV1: 'fn1 env1 value' environmentSecrets: ENVSECRET1: '/my-project/${opt:stage}/ENVSECRET1'

function2: handler: file.handler environment: ENV1: 'fn2 env1 value' environmentSecrets: ENVSECRET1: '/my-project/${opt:stage}/ENVSECRET2'

If we can generate environments object by function name instead, it would be a more generic fix.

sneha-nagole commented 6 years ago

Prepared PR to fix this issue - https://github.com/trek10inc/serverless-secrets/pull/38.