且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用访问令牌下载bitBucket私有存储库的powershell脚本

更新时间:2023-11-16 23:01:16

我在Powershell方面的经验绝对为零,但是我尝试在node中执行类似的任务,这是我的发现.

I have absolutely zero experience in powershell, but I tried to do the similar task in node and here are my findings.

  1. 首先,您在bitbucket帐户设置的访问管理部分中创建"Oauth".这为您提供了一个密钥"和一个秘密".

  1. First you create an "Oauth" in access management section of your bitbucket account setting. This gives you a "Key" and a "Secret".

现在,使用这些密钥和秘密",您要求Bitbucket提供令牌.就我而言,我向 https://bitbucket.org/site/oauth2/access_token 发出了http请求.在您的情况下,您应该使用等效的CURL(也许是Invoke-RestMethod?).CURL命令是这样的:

Now using these Key and Secret you ask Bitbucket for a token. In my case I made a http request to https://bitbucket.org/site/oauth2/access_token. In your case you should use an equivalent of CURL (Invoke-RestMethod maybe?). the CURL command is like this:

$ curl -X POST -u "yourKeyHere:yourSecretHere" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials

我的http请求是这样的(在节点中使用超级代理),我的 Content-Type 设置为 application/x-www-form-urlencoded :

my http request was like this (using superagent in node) with my Content-Type set to application/x-www-form-urlencoded:

request.post("https://yourKeyHere:yourSecretHere@bitbucket.org/site/oauth2/access_token").send('grant_type=client_credentials');

  • 现在您有了令牌,您的程序或命令就可以使用它克隆一个私有仓库.但是,您的仓库的网址应该是这样的(将令牌括在括号中):

  • Now that you have the token, your program or your command can clone a private repo with it. But the url to your repo should be like this (keep the bracket around token):

    https://x-token-auth:{tokenHere}@bitbucket.org/youRepoOwnerHere/RepoNameHere.git
    

  • 现在,您已经在计算机上拥有了完整的代码库.但是您只需要一个文件,而不是整个仓库,我将您引荐给这个从存储库中检索单个文件,但请记住,将上面的repo url与令牌一起使用,而不是常规的repo url.

  • Now you have the whole codebase on your machine. But you want a single file rather than the whole repo which I refer you to this Retrieve a single file from a repository but remember to use above repo url with the token instead of a normal repo url.