2012-04-23 103 views
2

保持数据库安全的API密钥和访问细节的最佳实践是什么?保持数据库安全的API密钥和访问细节

我们将用Nodejitsus jitsu deploy进行部署,所以我的想法是有一个配置文件,不会是git的一部分。我将有.gitignore'd

module.exports = (app) -> 

    app.configure 'development', -> 

     global.config = 
      dbUrl: 'mongodb://username:[email protected]:port/closet' 
      foursquare: 
       client_id: 'xxx' 
       client_secret: 'xxx' 
       redirect_uri: 'http://127.0.0.1:3000/account/auth/foursquare/done' 

     return 

    app.configure 'production', -> 

     global.config = 
      dbUrl: 'mongodb://username:[email protected]:port/closet' 
      foursquare: 
       client_id: 'yyy' 
       client_secret: 'yyy' 
       redirect_uri: 'http://example.com/account/auth/foursquare/done' 

     return 


    return 

回答

2

通常我做的是保存我的配置在config.json,将其添加到我的.gitignore,然后包括.npmignore使NPM不使用.gitignore决定捆绑什么。这样,git不会添加config.json,但jitsu会在部署时捆绑它。

env变量,如booyaa建议的那样,也可以工作。

1

你可以使用jitsu env命令存储API密钥(和其他机密)作为环境变量

我们目前的配置文件。然后使用process.env在node.js应用程序中获取这些变量。