Public keys belong to Users and are used for Git authentication and deployments.
id | integer | Unique ID of the PublicKey. |
---|---|---|
account_id | integer | ID of the associated Account. |
user_id | integer | ID of the User who owns the key. |
name | string | Human-readable name of the key. |
content | string | Public SSH key. |
updated_at | datetime | Time when the Invitation was last updated. |
created_at | datetime | Time when the Invitation was first added to the system. |
name | string | Optional, will be derived from the content if possible or filled with a date stamp. |
---|---|---|
content | string | Required. Should contain a single public SSH key. |
It’s important to note that admins can list, update, create and delete keys for all users under account while regular users can only work with their own keys. If you are logged in as an admin and you want to create/update/delete key that belongs to another user from your account, just add a user_id
parameter to the URL.
Admins can pass user_id
parameter to fetch keys for all account’s users. Otherwise only current user’s keys are returned.
GET /api/public_keys.json
GET /api/public_keys.json?user_id={USER_ID}
Click to expand…
json http-response[
{
"public_key": {
"name": "Mac Pro",
"created_at": "2011/07/29 22:56:13 +0800",
"updated_at": "2011/07/29 22:56:13 +0800",
"account_id": 2,
"id": 2,
"user_id": 2,
"content": "ssh-rsa AAAA...hfs1Q=="
}
},{
"public_key": {
"name": "IBM PC Compatible",
"created_at": "2011/07/29 22:56:13 +0800",
"updated_at": "2011/07/29 22:56:13 +0800",
"account_id": 2,
"id": 4,
"user_id": 2,
"content": "ssh-rsa AAAA...fe4gQ=="
}
}
]
GET /api/public_keys.xml
GET /api/public_keys.xml?user_id={USER_ID}
Click to expand…
xml http-response<?xml version="1.0" encoding="UTF-8"?>
<public-keys type="array">
<public-key>
<id type="integer">6</id>
<account-id type="integer">8</account-id>
<user-id type="integer">5638</user-id>
<name>ilya@MacBookPro.local</name>
<content>
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q==
</content>
<created-at type="datetime">2011-03-14T18:36:45+07:00</created-at>
<updated-at type="datetime">2011-03-14T18:51:28+07:00</updated-at>
</public-key>
</public-keys>
Admins can view other users’ keys. Regular users can view their own keys only.
GET /api/public_keys/{PUBLIC_KEY_ID}.json
Click to expand…
json http-response{
"public_key": {
"name": "Mac Pro",
"created_at": "2011/07/29 22:56:13 +0800",
"updated_at": "2011/07/29 22:56:13 +0800",
"account_id": 2,
"id": 2,
"user_id": 2,
"content": "ssh-rsa AAAA...hfs1Q=="
}
}
GET /api/public_keys/{PUBLIC_KEY_ID}.xml
Click to expand…
xml http-response<?xml version="1.0" encoding="UTF-8"?>
<public-key>
<id type="integer">6</id>
<account-id type="integer">8</account-id>
<user-id type="integer">5638</user-id>
<name>ilya@MacBookPro.local</name>
<content>
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q==
</content>
<created-at type="datetime">2011-03-14T18:36:45+07:00</created-at>
<updated-at type="datetime">2011-03-14T18:51:28+07:00</updated-at>
</public-key>
Admins can pass user_id
parameter to create a key for a specific user under that account, otherwise the key will be created for a currently logged in user.
Name is optional and will be derived from the key if possible. Otherwise it will be stubbed with a date stamp.
POST /api/public_keys.json
{
"public_key": {
"name": "Special Name",
"content": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q== ilya@MacBookPro.local"
}
}
Click to expand…
json http-response{
"public_key": {
"name": "Special Name",
"created_at": "2011/07/29 22:56:13 +0800",
"updated_at": "2011/07/29 22:56:13 +0800",
"account_id": 2,
"id": 2,
"user_id": 2,
"content": "ssh-rsa AAAA...fhfs1Q=="
}
}
POST /api/public_keys.xml
<?xml version="1.0" encoding="UTF-8"?>
<public_key>
<content>
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q== ilya@MacBookPro.local
</content>
</public_key>
Click to expand…
xml http-response<?xml version="1.0" encoding="UTF-8"?>
<public-key>
<id type="integer">7</id>
<account-id type="integer">8</account-id>
<user-id type="integer">5638</user-id>
<name>ilya@MacBookPro.local</name>
<content>
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q==
</content>
<created-at type="datetime">2011-03-14T18:36:45+07:00</created-at>
<updated-at type="datetime">2011-03-14T18:51:28+07:00</updated-at>
</public-key>
--OR IF INVALID--
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>Content is not a valid public SSH key</error>
</errors>
Admins can update other users’ keys. Regular users can update their own keys only.
PUT /api/public_keys/{PUBLIC_KEY_ID}.json
{
"public_key": {
"name": "Awesome Key"
}
}
Click to expand…
json http-response{
"public_key": {
"name": "Awesome Key",
"created_at": "2011/07/29 22:56:13 +0800",
"updated_at": "2011/07/29 22:56:13 +0800",
"account_id": 2,
"id": 2,
"user_id": 2,
"content": "ssh-rsa AAAA...hfs1Q=="
}
}
PUT /api/public_keys/{PUBLIC_KEY_ID}.xml
<?xml version="1.0" encoding="UTF-8"?>
<public_key>
<name>New Name</name>
</public_key>
Click to expand…
xml http-response<?xml version="1.0" encoding="UTF-8"?>
<public-key>
<id type="integer">7</id>
<account-id type="integer">8</account-id>
<user-id type="integer">5638</user-id>
<name>New Name</name>
<content>
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...fhfs1Q==
</content>
<created-at type="datetime">2011-03-14T18:36:45+07:00</created-at>
<updated-at type="datetime">2011-03-14T18:51:28+07:00</updated-at>
</public-key>
--OR IF INVALID--
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>
A public key can only be used once in each account.
Since this key already exists for John Doe,
please generate a new one.
</error>
</errors>
Admins can delete other users’ keys. Regular users can delete their own keys only.
DELETE /api/public_keys/{PUBLIC_KEY_ID}.json
Click to expand…
json http-responseHEAD 200 OK
--OR IF INVALID--
{
"errors": ["Name can't be blank"]
}
DELETE /api/public_keys/{PUBLIC_KEY_ID}.xml
Click to expand…
xml http-responseHEAD 200 OK
--OR IF INVALID--
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>Delete failed. Please try again later.</error>
</errors>