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

Allow to get the ACCESS_TOKEN from an environment variable #50

Merged
merged 3 commits into from
Apr 3, 2017

Conversation

aboglioli
Copy link
Contributor

From #40

It allows to use environment variables to replace variables from .stdlib.
It's possible to set the ACCESS_TOKEN directly in an environment variable called ACCESS_TOKEN.

Copy link

@wKovacs64 wKovacs64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts on this:

  1. Should the environment variable be called something more specific to avoid potential collisions? Perhaps STDLIB_ACCESS_TOKEN?
  2. As it stands, this change will still require the .stdlib file to exist (it'll throw otherwise). Should the majority of the readCredentials function be wrapped in an if to skip reading the file if the environment variable is present?
  3. Do we need another env variable correlating to the CREATED_AT key from .stdlib? Probably not, as it doesn't appear to be used anywhere other than when writing the file. Just curious.

@aboglioli
Copy link
Contributor Author

That's correct! I thought in a .stdlib file without ACCESS_TOKEN, or with any random string but this solution could bring problems as you said.

I'm going to fix this. This was thought as a fast solution to deploy with any CI system.

Thanks for your review!

@aboglioli
Copy link
Contributor Author

The only problem is: if in the future stdlib needs new data from new variables, they have to be added to the object returned inside the if (process.env.STDLIB_ACCESS_TOKEN) and check if they are present.

@keithwhor
Copy link
Contributor

keithwhor commented Feb 21, 2017

What I would do instead is something like this;

if (process.env.hasOwnProperty('STDLIB_ACCESS_TOKEN')) {
  let prefix = 'STDLIB_';
  return Object.keys(process.env)
    .filter(key => key.indexOf(prefix) === 0)
    .map(key => key.substr(prefix.length))
    .reduce((obj, key) => {
      obj[key] = process.env[prefix + key];
      return obj;
    }, {});
}

That way you can add more variables in the future if necessary. If you make this change I can merge it. :)

@aboglioli
Copy link
Contributor Author

👍

@keithwhor keithwhor merged commit 4b68e8e into acode:master Apr 3, 2017
@keithwhor
Copy link
Contributor

I merged this, but we'll be updating the .stdlib usage soon. :)

@aboglioli
Copy link
Contributor Author

Great! I think .stdlib file could be in user configuration (for example, /home/user/.config/stdlib/config_filein Linux). You don't have to care about this file in a public repository.

And overwriting the same configuration with environment variables.

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

Successfully merging this pull request may close these issues.

3 participants