简体   繁体   English

通过赛普拉斯在命令行中传递自定义API密钥

[英]Pass custom API key in command line with Cypress

I am testing with Cypress, connecting to an external API that requires a key, however I am conscious about not pushing a private key publicly on GitHub. 我正在使用Cypress进行测试,并连接到需要密钥的外部API,但是我意识到不要在GitHub上公开推送私钥。

Is there a way in which I can pass my API key through the command line or in another safe way at the time of running the Cypress app? 在运行赛普拉斯应用程序时,是否可以通过命令行或其他安全方式传递API密钥?

"run-cypress": "cypress run --browser chrome --reporter-options configFile=cypress.json"

Could I append something such as 我可以附加一些诸如

apiKey=abcdefg...

after configFile... ? configFile...之后 And how would I access this in the code? 我将如何在代码中访问它?

If you're using it alongside some CI tool (eg TravisCI or CircleCI), you can save your API key as the environment variable in your CI dashboard. 如果将它与某些CI工具(例如TravisCI或CircleCI)一起使用,则可以将API密钥另存为CI仪表板中的环境变量。 Then during the CI build, key is read from your settings and therefore never needs to be pushed to source control. 然后,在CI生成期间,将从您的设置中读取密钥,因此永远不需要将其推送到源代码管理。

I was in the very same situation as you couple of weeks ago. 几个星期前,我的处境与您一样。 Here's my Pull Request where I've removed the key (and then manually put it to our CI settings instead) 这是我的“ 拉取请求”中删除了密钥的位置(然后将其手动设置为CI设置)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM