Skip to content

GitLab

  • Menu
    • Projects Groups Snippets
      Help
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Issues
  • #4241

Closed
Open
Created 12 years ago by Administrator@rootOwner
  • New issue

  • Report abuse

  • New issue

  • Report abuse

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.

Linked issues
0


  • Administrator
    Administrator @root · 12 years ago
    Owner

    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)

  • Administrator
    Administrator @root · 12 years ago
    Owner

    Created by: drakeguan

    I don't know if that applies. I got not valid while adding a deploy key to a project. I will check that again.

    By Administrator on 2013-06-09T16:57:22 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    Created by: Razer6

    Is it still an issue?

    By Administrator on 2013-06-22T18:03:40 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    Created by: drakeguan

    Still can't make it work here. But I can't provide any further information :(

    By Administrator on 2013-06-23T14:49:14 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    Created by: Razer6

    What's exact call? How can others try to reproduce?

    By Administrator on 2013-06-23T14:52:18 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    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)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    Created by: Razer6

    @drakeguan How to you try? Can you provide your API call that someone else can verify it's not working?

    By Administrator on 2013-06-24T04:42:27 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    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)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    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#L70

    Unfortunately I don't have enough ruby skills to dig in further

    By Administrator on 2013-06-29T18:36:04 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    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)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    Created by: m4tthumphrey

    Update: It appears I can't even add a brand new key to a project via the API...

    By Administrator on 2013-07-15T08:21:13 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    Created by: Razer6

    @m4tthumphrey I also experienced this with the steps provided by @drakeguan

    By Administrator on 2013-07-15T10:25:20 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    Created by: m4tthumphrey

    Am sorting out my VM and will take a proper look.

    By Administrator on 2013-07-15T10:53:55 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    Created by: sosedoff

    Same here. Cant create a new key via API.

    By Administrator on 2013-08-30T15:42:13 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    Created by: Onkelborg

    I can create a key via API as long as it's a brand new key, but can't add an existing key, then it's 404

    By Administrator on 2013-09-04T18:03:20 (imported from GitLab project)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    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)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    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)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    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)

  • Administrator
    Administrator @root · 11 years ago
    Owner

    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)

  • You're only seeing other activity in the feed. To add a comment, switch to one of the following options.
Please register or sign in to reply
0 Assignees
Assign to
Milestone
No milestone
None
None
Time tracking
Due date
None
None
2
Labels
API Awaiting developer action/feedback
Assign labels
  • No matching results
  • Manage project labels
Confidentiality
Not confidential

You are going to turn on confidentiality. Only team members with at least Reporter access will be able to see and leave comments on the issue.

Lock issue
Unlocked
participants
Reference:

Menu

Projects Groups Snippets
Help