Adding user access key to Stash via REST API

It appears that Stash supports 2 kinds of SSH keys:


1. Per-user keys, which are used to authenticate a user and repository/project
2. Access keys, which provide read or read-write access to a repository without being linked to a particular user.

To add a project access key, you send a POST HTTP request to http://your.stash.server/rest/keys/latest/projects/{projectKey}/sshwith the following contents:
{
"key": {
"text": "ssh-rsa AAAAB3... me@127.0.0.1"
},
"permission": "PROJECT_WRITE"
}

where key.text is the PUBLIC key of the SSH key pair that you want to add to the project. Permission at the project level is either PROJECT_READ or PROJECT_WRITE.

If you want to add an access key to a repository, you do something very similar. You send a POST to http://your.stash.server/rest/keys/latest/projects/{projectKey}/repos/{repoSlug}/sshwith the following contents:
{
"key": {
"text": "ssh-rsa AAAAB3... me@127.0.0.1"
},
"permission": "REPO_READ"
}

Again key.text is the public key, but the permission should now be a repository permission: REPO_READ or REPO_WRITE. Note that the WRITE permissions imply READ permission as well.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request
Powered by Zendesk