Semaphore/db/bolt/access_key.go

61 lines
1.5 KiB
Go
Raw Normal View History

package bolt
import (
"github.com/ansible-semaphore/semaphore/db"
)
func (d *BoltDb) GetAccessKey(projectID int, accessKeyID int) (key db.AccessKey, err error) {
2021-09-01 16:38:28 +02:00
err = d.getObject(projectID, db.AccessKeyProps, intObjectID(accessKeyID), &key)
if err != nil {
return
}
2021-09-01 16:38:28 +02:00
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 {
2021-09-04 08:39:16 +02:00
err := key.Validate(key.OverrideSecret)
2021-09-01 16:38:28 +02:00
if err != nil {
return err
}
2021-09-04 08:39:16 +02:00
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)
2021-09-04 08:39:16 +02:00
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))
}