mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-04 13:50:39 +00:00
1. A key can either be an ssh user key or a deploy key. It cannot be both. 2. If a key is a user key - it can only be associated with one user. 3. If a key is a deploy key - it can be used in multiple repositories and the permissions it has on those repositories can be different. 4. If a repository is deleted, its deploy keys must be deleted too. We currently don't enforce any of this and multiple repositories access with different permissions doesn't work at all. This PR enforces the following constraints: - [x] You should not be able to add the same user key as another user - [x] You should not be able to add a ssh user key which is being used as a deploy key - [x] You should not be able to add a ssh deploy key which is being used as a user key - [x] If you add an ssh deploy key to another repository you should be able to use it in different modes without losing the ability to use it in the other mode. - [x] If you delete a repository you must delete all its deploy keys. Fix #1357
This commit is contained in:
parent
634cbaad2b
commit
01c10a951b
14 changed files with 697 additions and 345 deletions
|
@ -32,6 +32,31 @@ func UpdateDeployKeyUpdated(keyID int64, repoID int64) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetDeployKey check if repo has deploy key
|
||||
func GetDeployKey(keyID, repoID int64) (*models.DeployKey, error) {
|
||||
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/repositories/%d/keys/%d", repoID, keyID)
|
||||
log.GitLogger.Trace("GetDeployKey: %s", reqURL)
|
||||
|
||||
resp, err := newInternalRequest(reqURL, "GET").Response()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
switch resp.StatusCode {
|
||||
case 404:
|
||||
return nil, nil
|
||||
case 200:
|
||||
var dKey models.DeployKey
|
||||
if err := json.NewDecoder(resp.Body).Decode(&dKey); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &dKey, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("Failed to get deploy key: %s", decodeJSONError(resp).Err)
|
||||
}
|
||||
}
|
||||
|
||||
// HasDeployKey check if repo has deploy key
|
||||
func HasDeployKey(keyID, repoID int64) (bool, error) {
|
||||
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/repositories/%d/has-keys/%d", repoID, keyID)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue