2021-05-08 19:25:00 +02:00
|
|
|
package bolt
|
|
|
|
|
2021-05-08 22:25:31 +02:00
|
|
|
import (
|
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
|
|
)
|
2021-05-08 19:25:00 +02:00
|
|
|
|
2021-09-10 00:41:36 +02:00
|
|
|
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-09 23:31:06 +02:00
|
|
|
|
2021-09-01 16:38:28 +02:00
|
|
|
return
|
2021-05-08 19:25:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) GetAccessKeys(projectID int, params db.RetrieveQueryParams) ([]db.AccessKey, error) {
|
|
|
|
var keys []db.AccessKey
|
2021-05-13 21:45:54 +02:00
|
|
|
err := d.getObjects(projectID, db.AccessKeyProps, params, nil, &keys)
|
2021-05-08 19:25:00 +02:00
|
|
|
return keys, err
|
|
|
|
}
|
|
|
|
|
2021-09-09 23:31:06 +02:00
|
|
|
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
|
2021-09-10 00:41:36 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-09-09 23:31:06 +02:00
|
|
|
return d.updateObject(*key.ProjectID, db.AccessKeyProps, key)
|
2021-05-08 19:25:00 +02:00
|
|
|
}
|
|
|
|
|
2021-05-08 22:25:31 +02:00
|
|
|
func (d *BoltDb) CreateAccessKey(key db.AccessKey) (db.AccessKey, error) {
|
2021-09-01 21:17:28 +02:00
|
|
|
err := key.SerializeSecret()
|
|
|
|
if err != nil {
|
|
|
|
return db.AccessKey{}, err
|
|
|
|
}
|
2021-05-14 13:47:32 +02:00
|
|
|
newKey, err := d.createObject(*key.ProjectID, db.AccessKeyProps, key)
|
2021-05-08 22:25:31 +02:00
|
|
|
return newKey.(db.AccessKey), err
|
2021-05-08 19:25:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteAccessKey(projectID int, accessKeyID int) error {
|
2021-05-13 21:45:54 +02:00
|
|
|
return d.deleteObject(projectID, db.AccessKeyProps, intObjectID(accessKeyID))
|
2021-05-08 19:25:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteAccessKeySoft(projectID int, accessKeyID int) error {
|
2021-05-13 21:45:54 +02:00
|
|
|
return d.deleteObjectSoft(projectID, db.AccessKeyProps, intObjectID(accessKeyID))
|
2021-09-09 23:31:06 +02:00
|
|
|
}
|