英文:
Github Oauth token for Golang
问题
我们使用AWS CodeDeploy将Github项目部署到Ec2实例中,每次部署时都会要求提供Github用户名和密码以下载存储库。找到以下解决方法:
- 提供用户名和密码(不推荐)
- 设置SSH密钥(由于实例的IP地址不断变化,不可行)
- 使用OAuth令牌
为PHP存储库设置OAuth是通过将其添加到composer auth.json文件中完成的。.composer/auth.json。
{
"http-basic": {},
"github-oauth": {"github.com": "xyzasasasauhu"}
}
但是找不到在Golang项目中执行此操作的方法。通常,我们希望能够在不显式提供凭据的情况下执行go get https://github.com/username/reponame命令。
英文:
We use AWS code deploy to deploy the Github projects to Ec2 instances every time it deploys it asks for Github username and password to download the repository. Found following ways to solve this
- Supply Uname & Pwd (not preferred)
- Setup SSH Key (not possible as the instance keeps changing ip)
- Oauth token
Setting up Oauth for PHP repository was done by adding it in composer auth.json .composer/auth.json.
{
"http-basic": {},
"github-oauth": {"github.com": "xyzasasasauhu"}
}
But couldn't find a way to do this for Golang project. Typically we want to achieve go get https://github.com/username/reponame without supplying the credentials explicitly.
答案1
得分: 2
这个问题有两个解决方案:
-
不部署代码。Go是一种静态编译的编程语言,你不需要在打算运行Go程序的服务器上放置Go源代码。
-
不使用
go get
来获取你的私有GitHub仓库的代码。只要代码最终放在正确的子目录($GOPATH/src/github.com/org/project
),Go就不关心它是如何到达那里的。只需在构建脚本中添加几个命令:DIR=$GOPATH/src/github.com/org/project TOKEN=yourtoken if [ -d $DIR ]; then cd $DIR git reset --hard git clean -dfx else mkdir -p $DIR cd $DIR git init fi git pull https://$TOKEN@github.com/org/project.git
英文:
There are two solutions to this problem:
-
Don't deploy code. Go is a statically compiled programming language. There's no need to have Go source code on the server you intend to run the Go program on.
-
Don't use
go get
to get the code for your private GitHub repo. As long as the code ends up in the correct subdirectory ($GOPATH/src/github.com/org/project
), Go doesn't care how it got there. Simply add to your build script a few commands:DIR=$GOPATH/src/github.com/org/project TOKEN=yourtoken if [ -d $DIR ]; then cd $DIR git reset --hard git clean -dfx else mkdir -p $DIR cd $DIR git init fi git pull https://$TOKEN@github.com/org/project.git
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论