在 travis

编程入门 行业动态 更新时间:2024-10-09 03:28:14
本文介绍了在 travis-ci 上使用秘密 api 密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想将 travis-ci 用于我的一个 项目.

I'd like to use travis-ci for one of my projects.

该项目是一个 API 包装器,因此许多测试依赖于秘密 API 密钥的使用.为了在本地进行测试,我只是将它们存储为环境变量.在 Travis 上使用这些密钥的安全方法是什么?

The project is an API wrapper, so many of the tests rely on the use of secret API keys. To test locally, I just store them as environment variables. What's a safe way to use those keys on Travis?

推荐答案

Travis 具有加密环境变量的功能 ("加密环境变量").这可用于保护您的秘密 API 密钥.我已成功将其用于 Heroku API 密钥.

Travis has a feature to encrypt environment variables ("Encrypting environment variables"). This can be used to protect your secret API keys. I've successfully used this for my Heroku API key.

您所要做的就是安装 travis gem,加密您想要的字符串并将加密的字符串添加到您的 .travis.yml 中.加密仅对一个存储库有效.travis 命令获取您的存储库的公钥,然后可以在构建期间解密字符串.

All you have to do is install the travis gem, encrypt the string you want and add the encrypted string in your .travis.yml. The encryption is only valid for one repository. The travis command gets your public key for your repo and can then decrypt the string during the build.

gem install --user travis
travis encrypt MY_SECRET_ENV=super_secret -r my_username/my_repo

这会为您提供以下输出:

This gives you the following output:

Please add the following to your .travis.yml file:

  secure: "OrEeqU0z6GJdC6Sx/XI7AMiQ8NM9GwPpZkVDq6cBHcD6OlSppkSwm6JvopTR\newLDTdtbk/dxKurUzwTeRbplIEe9DiyVDCzEiJGfgfq7woh+GRo+q6+UIWLE\n3nowpI9AzXt7iBhoKhV9lJ1MROrnn4DnlKxAEUlHTDi4Wk8Ei/g="

这篇关于在 travis-ci 上使用秘密 api 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 03:10:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/928291.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:travis

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!