New API for deploy key: add/enable a deploy key to a project
Closed
New API for deploy key: add/enable a deploy key to a project
Created by: drakeguan
Summary: A new API for deploy key to add or enable an existing deploy key to a project.
In Gitlab API, I spot a way to add a new deploy key to a project, but I can't add an existing one. I have tried to dig the code in lib/api/deploy_keys.rb but it's still hard for me to figure out the way to do that.
Created by: Razer6
Is the following sentence the solution?
Creates a new deploy key for a project. If deploy key already exists in another project - it will be joined to project but only if original one was is accessible by same user
It says If you do it same as for a new key, but the key already exists, the projects will be joined using the same key.
By Administrator on 2013-06-06T16:44:23 (imported from GitLab project)
Created by: drakeguan
I'm wondering if anyone has succesfully enabled an existing devploy key to a project throught this API? If it works for someone else and I can't provide any further information, I should close this thread.
By Administrator on 2013-06-24T03:19:41 (imported from GitLab project)
Created by: drakeguan
Here is what I tried to enable/add a deploy key to a project:
-
Making use of httpie to ease http protocol handling and json's formatting.
-
I picked a project and it's project id (let's assume it is 24) through
http http://SECRET.digimax.com.tw/api/v3/projects PRIVATE-TOKEN:SECRET
-
Then, I used
http http://SECRET.digimax.com.tw/api/v3/projects/24/keys PRIVATE-TOKEN:SECRET
to make sure there is no enabled deploy keys for this project. -
Finally, I tried to add an existing deploy key to this project by
http --form POST http://SECRET.digimax.com.tw/api/v3/projects/24/keys PRIVATE-TOKEN:SECRET title=dgtools key="ssh-rsa SECRET"
and I got the following response:HTTP/1.0 404 Not Found Cache-Control: no-cache Content-Length: 27 Content-Type: application/json Date: Thu, 27 Jun 2013 03:27:43 GMT Proxy-Connection: close Server: nginx/0.7.65 X-Rack-Cache: invalidate, pass X-Request-Id: 92cfcd1a0c46deed5a129d74c344ba3b X-Runtime: 0.052340 X-UA-Compatible: IE=Edge,chrome=1
{ "message": "404 Not Found" }
Any idea for this? Or did I misunderstand the API?
By Administrator on 2013-06-27T03:29:54 (imported from GitLab project)
-
Created by: Razer6
Can confirm. For some reason a
not_found
is triggered here: https://github.com/gitlabhq/gitlabhq/blob/master/lib/api/deploy_keys.rb#L70Unfortunately I don't have enough ruby skills to dig in further
By Administrator on 2013-06-29T18:36:04 (imported from GitLab project)
Created by: m4tthumphrey
I would assume that it's actually failing here: https://github.com/gitlabhq/gitlabhq/blob/master/lib/api/deploy_keys.rb#L58 as the reason you are getting the 404 is because it's getting to the stage where it would try and add a brand new key rather than assign an existing key to the project, which is obviously failing because it already exists. I'll have a proper look on Monday.
My first guess would be because the key is not identical to the existing one, possibly line breaks or missing/extra spaces, or possibly the comment is missing.
By Administrator on 2013-07-13T13:51:43 (imported from GitLab project)
Created by: Onkelborg
Hm, actually, I think it's a "sort of bug like bug thing", maybe not a bug?
I called the API with a dedicated "api user" and added my key to a specific project. All fine. Then tried to add the same key to a different project. Fail.. The problem: Even though my user is admin the list of accessible deploy keys only contains keys belonging to projects I'm directly involved in, our a group I'm directly involved in. For fun I made my "api user" a member of a test group with a test project, and added the key to that group first. Now the other projects are working as well..
By Administrator on 2013-09-04T19:51:13 (imported from GitLab project)
Created by: drakeguan
Really interesting but significant discovery. It seems to be a logical bug.
On Thu, Sep 5, 2013 at 3:51 AM, Oskar Johansson notifications@github.comwrote:
Hm, actually, I think it's a "sort of bug like bug thing", maybe not a bug?
I called the API with a dedicated "api user" and added my key to a specific project. All fine. Then tried to add the same key to a different project. Fail.. The problem: Even though my user is admin the list of accessible deploy keys only contains keys belonging to projects I'm directly involved in, our a group I'm directly involved in. For fun I made my "api user" a member of a test group with a test project, and added the key to that group first. Now the other projects are working as well..
— Reply to this email directly or view it on GitHubhttps://github.com/gitlabhq/gitlabhq/issues/4241#issuecomment-23818686 .
Drake S.-H. Guan R&D Manager, Digimax, Inc. / Sponsorship Lead, PyConAPAC/TW 2014 http://about.me/drakeguan
By Administrator on 2013-09-05T01:33:34 (imported from GitLab project)
Created by: devaroop
curl "http://YOUR_HOST.com/api/v3/projects/48/keys" -H "PRIVATE-TOKEN: api_key" -H "Accept: application/json" -H "Content-type: application/json" -X POST --data '{ "title": "apitest", "key": "correct sha key"}'
Make sure you mentioned the correct sha key(its validated in the api server) and given the headers "accept" and "content-type". It works all fine with the above curl call. Caution: without those headers, you get a 404. I broke my head before that.
By Administrator on 2013-09-27T17:54:52 (imported from GitLab project)
Created by: drakeguan
Continuing the previous test with different environment and method
- Getlab version: 6.0.0 b1bb3701.
- Use httpie to ease the testing still.
http -v POST http://OOXX/api/v3/projects/25/keys PRIVATE-TOKEN:OOXX title=OOXX key="OOXX"
- Get the following response.
{ "created_at": "2013-06-03T08:46:27Z", "id": 10, "key": "ssh-rsa ....", "title": "OOXX" }
It works right here now!
By Administrator on 2013-10-01T03:55:20 (imported from GitLab project)