mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 20:35:24 +01:00
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package bolt
|
|
|
|
import (
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
)
|
|
|
|
func (d *BoltDb) GetAccessKey(projectID int, accessKeyID int) (key db.AccessKey, err error) {
|
|
err = d.getObject(projectID, db.AccessKeyProps, intObjectID(accessKeyID), &key)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (d *BoltDb) GetAccessKeys(projectID int, params db.RetrieveQueryParams) ([]db.AccessKey, error) {
|
|
var keys []db.AccessKey
|
|
err := d.getObjects(projectID, db.AccessKeyProps, params, nil, &keys)
|
|
return keys, err
|
|
}
|
|
|
|
func (d *BoltDb) UpdateAccessKey(key db.AccessKey) error {
|
|
err := key.Validate(key.OverrideSecret)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if key.OverrideSecret {
|
|
err = key.SerializeSecret()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
} else { // accept only new name, ignore other changes
|
|
oldKey, err2 := d.GetAccessKey(*key.ProjectID, key.ID)
|
|
if err2 != nil {
|
|
return err2
|
|
}
|
|
oldKey.Name = key.Name
|
|
key = oldKey
|
|
}
|
|
|
|
return d.updateObject(*key.ProjectID, db.AccessKeyProps, key)
|
|
}
|
|
|
|
func (d *BoltDb) CreateAccessKey(key db.AccessKey) (db.AccessKey, error) {
|
|
err := key.SerializeSecret()
|
|
if err != nil {
|
|
return db.AccessKey{}, err
|
|
}
|
|
newKey, err := d.createObject(*key.ProjectID, db.AccessKeyProps, key)
|
|
return newKey.(db.AccessKey), err
|
|
}
|
|
|
|
func (d *BoltDb) DeleteAccessKey(projectID int, accessKeyID int) error {
|
|
return d.deleteObject(projectID, db.AccessKeyProps, intObjectID(accessKeyID))
|
|
}
|
|
|
|
func (d *BoltDb) DeleteAccessKeySoft(projectID int, accessKeyID int) error {
|
|
return d.deleteObjectSoft(projectID, db.AccessKeyProps, intObjectID(accessKeyID))
|
|
} |