Semaphore/db/bolt/webhook.go

198 lines
5.9 KiB
Go
Raw Normal View History

2023-07-03 01:41:13 +02:00
package bolt
import (
"github.com/ansible-semaphore/semaphore/db"
)
/*
2024-02-11 20:52:14 +01:00
Integrations
2023-07-03 01:41:13 +02:00
*/
2024-02-11 20:52:14 +01:00
func (d *BoltDb) CreateIntegration(integration db.Integration) (db.Integration, error) {
err := integration.Validate()
2023-07-03 01:41:13 +02:00
if err != nil {
2024-02-11 20:52:14 +01:00
return db.Integration{}, err
2023-07-03 01:41:13 +02:00
}
2024-02-11 20:52:14 +01:00
newIntegration, err := d.createObject(integration.ProjectID, db.IntegrationProps, integration)
return newIntegration.(db.Integration), err
2023-07-03 01:41:13 +02:00
}
2024-02-11 20:52:14 +01:00
func (d *BoltDb) GetIntegrations(projectID int, params db.RetrieveQueryParams) (integrations []db.Integration, err error) {
err = d.getObjects(projectID, db.IntegrationProps, params, nil, &integrations)
return integrations, err
2023-07-03 01:41:13 +02:00
}
2024-02-11 20:52:14 +01:00
func (d *BoltDb) GetIntegration(projectID int, integrationID int) (integration db.Integration, err error) {
err = d.getObject(projectID, db.IntegrationProps, intObjectID(integrationID), &integration)
2023-07-03 01:41:13 +02:00
if err != nil {
return
}
return
}
2024-02-11 20:52:14 +01:00
func (d *BoltDb) UpdateIntegration(integration db.Integration) error {
err := integration.Validate()
2023-07-03 01:41:13 +02:00
if err != nil {
return err
}
2024-02-11 20:52:14 +01:00
return d.updateObject(integration.ProjectID, db.IntegrationProps, integration)
2023-07-03 01:41:13 +02:00
}
2024-02-11 20:52:14 +01:00
func (d *BoltDb) GetIntegrationRefs(projectID int, integrationID int) (db.IntegrationReferrers, error) {
//return d.getObjectRefs(projectID, db.IntegrationProps, integrationID)
return db.IntegrationReferrers{}, nil
2023-07-03 01:41:13 +02:00
}
/*
2024-02-11 20:52:14 +01:00
Integration Extractors
2023-07-03 01:41:13 +02:00
*/
/*
2024-02-11 20:52:14 +01:00
Integration ExtractValue
2023-07-03 01:41:13 +02:00
*/
2024-03-06 15:51:59 +01:00
func (d *BoltDb) GetIntegrationExtractValuesByExtractorID(integrationID int) (values []db.IntegrationExtractValue, err error) {
err = d.getObjects(integrationID, db.IntegrationExtractValueProps, db.RetrieveQueryParams{}, nil, &values)
2023-07-03 01:41:13 +02:00
return values, err
}
2024-03-06 15:51:59 +01:00
func (d *BoltDb) DeleteIntegrationExtractValue(projectID int, valueID int, integrationID int) error {
2024-03-04 14:39:48 +01:00
return d.deleteObject(projectID, db.IntegrationExtractValueProps, intObjectID(valueID), nil)
2023-07-03 01:41:13 +02:00
}
2024-03-06 15:51:59 +01:00
func (d *BoltDb) GetIntegrationMatchersByExtractorID(integrationID int) (matchers []db.IntegrationMatcher, err error) {
err = d.getObjects(integrationID, db.IntegrationMatcherProps, db.RetrieveQueryParams{}, nil, &matchers)
2023-07-03 01:41:13 +02:00
return matchers, err
}
2024-03-04 12:24:47 +01:00
func (d *BoltDb) CreateIntegrationExtractValue(projectId int, value db.IntegrationExtractValue) (db.IntegrationExtractValue, error) {
2023-07-03 01:41:13 +02:00
err := value.Validate()
if err != nil {
2024-02-11 20:52:14 +01:00
return db.IntegrationExtractValue{}, err
2023-07-03 01:41:13 +02:00
}
2024-03-04 14:39:48 +01:00
newValue, err := d.createObject(projectId, db.IntegrationExtractValueProps, value)
2024-02-11 20:52:14 +01:00
return newValue.(db.IntegrationExtractValue), err
2023-07-03 01:41:13 +02:00
}
2024-03-06 15:51:59 +01:00
func (d *BoltDb) GetIntegrationExtractValues(projectID int, params db.RetrieveQueryParams, integrationID int) (values []db.IntegrationExtractValue, err error) {
2024-02-11 20:52:14 +01:00
values = make([]db.IntegrationExtractValue, 0)
var allValues []db.IntegrationExtractValue
2024-01-08 13:56:50 +01:00
err = d.getObjects(projectID, db.IntegrationExtractValueProps, params, nil, &allValues)
2024-01-08 13:56:50 +01:00
if err != nil {
return
}
for _, v := range allValues {
2024-03-06 15:51:59 +01:00
if v.IntegrationID == integrationID {
2024-01-08 13:56:50 +01:00
values = append(values, v)
}
}
return
2023-07-03 01:41:13 +02:00
}
2024-03-06 15:51:59 +01:00
func (d *BoltDb) GetIntegrationExtractValue(projectID int, valueID int, integrationID int) (value db.IntegrationExtractValue, err error) {
2024-03-04 14:39:48 +01:00
err = d.getObject(projectID, db.IntegrationExtractValueProps, intObjectID(valueID), &value)
2023-07-03 01:41:13 +02:00
return value, err
}
2024-03-04 12:24:47 +01:00
func (d *BoltDb) UpdateIntegrationExtractValue(projectID int, integrationExtractValue db.IntegrationExtractValue) error {
2024-02-11 20:52:14 +01:00
err := integrationExtractValue.Validate()
2023-07-03 01:41:13 +02:00
if err != nil {
return err
}
2024-03-04 14:39:48 +01:00
return d.updateObject(projectID, db.IntegrationExtractValueProps, integrationExtractValue)
2023-07-03 01:41:13 +02:00
}
2024-03-06 15:51:59 +01:00
func (d *BoltDb) GetIntegrationExtractValueRefs(projectID int, valueID int, integrationID int) (db.IntegrationExtractorChildReferrers, error) {
2024-03-04 14:39:48 +01:00
return d.getIntegrationExtractorChildrenRefs(projectID, db.IntegrationExtractValueProps, valueID)
2023-07-03 01:41:13 +02:00
}
2024-02-11 20:52:14 +01:00
2023-07-03 01:41:13 +02:00
/*
2024-02-11 20:52:14 +01:00
Integration Matcher
2023-07-03 01:41:13 +02:00
*/
2024-03-04 12:36:24 +01:00
func (d *BoltDb) CreateIntegrationMatcher(projectID int, matcher db.IntegrationMatcher) (db.IntegrationMatcher, error) {
2023-07-03 01:41:13 +02:00
err := matcher.Validate()
if err != nil {
2024-02-11 20:52:14 +01:00
return db.IntegrationMatcher{}, err
2023-07-03 01:41:13 +02:00
}
2024-03-04 14:39:48 +01:00
newMatcher, err := d.createObject(projectID, db.IntegrationMatcherProps, matcher)
2024-02-11 20:52:14 +01:00
return newMatcher.(db.IntegrationMatcher), err
2023-07-03 01:41:13 +02:00
}
2024-03-06 15:51:59 +01:00
func (d *BoltDb) GetIntegrationMatchers(projectID int, params db.RetrieveQueryParams, integrationID int) (matchers []db.IntegrationMatcher, err error) {
2024-02-11 20:52:14 +01:00
matchers = make([]db.IntegrationMatcher, 0)
var allMatchers []db.IntegrationMatcher
2023-07-03 01:41:13 +02:00
2024-03-04 14:39:48 +01:00
err = d.getObjects(projectID, db.IntegrationMatcherProps, db.RetrieveQueryParams{}, nil, &allMatchers)
2023-07-03 01:41:13 +02:00
if err != nil {
return
}
for _, v := range allMatchers {
2024-03-06 15:51:59 +01:00
if v.IntegrationID == integrationID {
2023-07-03 01:41:13 +02:00
matchers = append(matchers, v)
}
}
return
}
2024-03-06 15:51:59 +01:00
func (d *BoltDb) GetIntegrationMatcher(projectID int, matcherID int, integrationID int) (matcher db.IntegrationMatcher, err error) {
2024-02-11 20:52:14 +01:00
var matchers []db.IntegrationMatcher
2024-03-06 15:51:59 +01:00
matchers, err = d.GetIntegrationMatchers(projectID, db.RetrieveQueryParams{}, integrationID)
2023-07-03 01:41:13 +02:00
for _, v := range matchers {
if v.ID == matcherID {
matcher = v
}
}
return
}
2024-03-04 12:36:24 +01:00
func (d *BoltDb) UpdateIntegrationMatcher(projectID int, integrationMatcher db.IntegrationMatcher) error {
2024-02-11 20:52:14 +01:00
err := integrationMatcher.Validate()
2023-07-03 01:41:13 +02:00
if err != nil {
return err
}
2024-03-04 14:39:48 +01:00
return d.updateObject(projectID, db.IntegrationMatcherProps, integrationMatcher)
2023-07-03 01:41:13 +02:00
}
2024-03-06 15:51:59 +01:00
func (d *BoltDb) DeleteIntegrationMatcher(projectID int, matcherID int, integrationID int) error {
2024-03-04 14:39:48 +01:00
return d.deleteObject(projectID, db.IntegrationMatcherProps, intObjectID(matcherID), nil)
2023-07-03 01:41:13 +02:00
}
2024-02-11 20:52:14 +01:00
func (d *BoltDb) DeleteIntegration(projectID int, integrationID int) error {
2024-03-06 15:51:59 +01:00
matchers, err := d.GetIntegrationMatchers(projectID, db.RetrieveQueryParams{}, integrationID)
2023-07-03 01:41:13 +02:00
if err != nil {
return err
}
2024-03-06 15:51:59 +01:00
for m := range matchers {
d.DeleteIntegrationMatcher(projectID, matchers[m].ID, integrationID)
2023-07-03 01:41:13 +02:00
}
2024-02-11 20:52:14 +01:00
return d.deleteObject(projectID, db.IntegrationProps, intObjectID(integrationID), nil)
2023-07-03 01:41:13 +02:00
}
2024-03-06 15:51:59 +01:00
func (d *BoltDb) GetIntegrationMatcherRefs(projectID int, matcherID int, integrationID int) (db.IntegrationExtractorChildReferrers, error) {
2024-03-04 14:39:48 +01:00
return d.getIntegrationExtractorChildrenRefs(projectID, db.IntegrationMatcherProps, matcherID)
2023-07-03 01:41:13 +02:00
}