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-03-04 12:36:24 +01:00
|
|
|
func (d *BoltDb) CreateIntegrationExtractor(projectID int, integrationExtractor db.IntegrationExtractor) (db.IntegrationExtractor, error) {
|
2024-02-11 20:52:14 +01:00
|
|
|
err := integrationExtractor.Validate()
|
2023-07-03 01:41:13 +02:00
|
|
|
|
|
|
|
if err != nil {
|
2024-02-11 20:52:14 +01:00
|
|
|
return db.IntegrationExtractor{}, err
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|
|
|
|
|
2024-03-04 14:39:48 +01:00
|
|
|
newIntegrationExtractor, err := d.createObject(projectID, db.IntegrationExtractorProps, integrationExtractor)
|
2024-02-11 20:52:14 +01:00
|
|
|
return newIntegrationExtractor.(db.IntegrationExtractor), err
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|
|
|
|
|
2024-03-04 14:39:48 +01:00
|
|
|
func (d *BoltDb) GetIntegrationExtractors(projectID int, params db.RetrieveQueryParams, integrationID int) (extractors []db.IntegrationExtractor, err error) {
|
|
|
|
var projectExtractors []db.IntegrationExtractor
|
|
|
|
err = d.getObjects(projectID, db.IntegrationExtractorProps, params, nil, &projectExtractors)
|
2023-07-03 01:41:13 +02:00
|
|
|
|
2024-03-04 14:39:48 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
extractors = make([]db.IntegrationExtractor, 0)
|
|
|
|
|
|
|
|
for _, extractor := range projectExtractors {
|
|
|
|
if extractor.IntegrationID == integrationID {
|
|
|
|
extractors = append(extractors, extractor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-04 19:17:40 +01:00
|
|
|
return extractors, err
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|
|
|
|
|
2024-03-04 12:36:24 +01:00
|
|
|
func (d *BoltDb) GetIntegrationExtractor(projectID int, extractorID int, integrationID int) (db.IntegrationExtractor, error) {
|
2024-02-11 20:52:14 +01:00
|
|
|
var extractor db.IntegrationExtractor
|
2024-03-04 14:39:48 +01:00
|
|
|
err := d.getObject(projectID, db.IntegrationExtractorProps, intObjectID(extractorID), &extractor)
|
2023-07-03 01:41:13 +02:00
|
|
|
|
|
|
|
return extractor, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-03-04 12:36:24 +01:00
|
|
|
func (d *BoltDb) UpdateIntegrationExtractor(projectID int, integrationExtractor db.IntegrationExtractor) error {
|
2024-02-11 20:52:14 +01:00
|
|
|
err := integrationExtractor.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.IntegrationExtractorProps, integrationExtractor)
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|
|
|
|
|
2024-03-04 12:36:24 +01:00
|
|
|
func (d *BoltDb) GetIntegrationExtractorRefs(projectID int, extractorID int, integrationID int) (db.IntegrationExtractorReferrers, error) {
|
2024-03-04 14:39:48 +01:00
|
|
|
return d.getIntegrationExtractorRefs(projectID, db.IntegrationExtractorProps, extractorID)
|
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-02-11 20:52:14 +01:00
|
|
|
func (d *BoltDb) GetIntegrationExtractValuesByExtractorID(extractorID int) (values []db.IntegrationExtractValue, err error) {
|
|
|
|
err = d.getObjects(extractorID, db.IntegrationExtractValueProps, db.RetrieveQueryParams{}, nil, &values)
|
2023-07-03 01:41:13 +02:00
|
|
|
return values, err
|
|
|
|
}
|
|
|
|
|
2024-03-04 12:24:47 +01:00
|
|
|
func (d *BoltDb) DeleteIntegrationExtractValue(projectID int, valueID int, extractorID 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-02-11 20:52:14 +01:00
|
|
|
func (d *BoltDb) GetIntegrationMatchersByExtractorID(extractorID int) (matchers []db.IntegrationMatcher, err error) {
|
|
|
|
err = d.getObjects(extractorID, db.IntegrationMatcherProps, db.RetrieveQueryParams{}, nil, &matchers)
|
2023-07-03 01:41:13 +02:00
|
|
|
|
|
|
|
return matchers, err
|
|
|
|
}
|
|
|
|
|
2024-03-04 12:36:24 +01:00
|
|
|
func (d *BoltDb) DeleteIntegrationExtractor(projectID int, extractorID int, integrationID int) error {
|
2024-02-11 20:52:14 +01:00
|
|
|
values, err := d.GetIntegrationExtractValuesByExtractorID(extractorID)
|
2023-07-03 01:41:13 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for value := range values {
|
2024-03-04 14:39:48 +01:00
|
|
|
d.DeleteIntegrationExtractValue(projectID, values[value].ID, extractorID)
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|
|
|
|
|
2024-02-11 20:52:14 +01:00
|
|
|
matchers, err := d.GetIntegrationMatchersByExtractorID(extractorID)
|
2023-07-03 01:41:13 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for matcher := range matchers {
|
2024-03-04 14:39:48 +01:00
|
|
|
d.DeleteIntegrationMatcher(projectID, matchers[matcher].ID, extractorID)
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|
2024-02-11 20:52:14 +01:00
|
|
|
return d.deleteObject(integrationID, db.IntegrationExtractorProps, intObjectID(extractorID), nil)
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|
|
|
|
|
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-04 12:24:47 +01:00
|
|
|
func (d *BoltDb) GetIntegrationExtractValues(projectID int, params db.RetrieveQueryParams, extractorID 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
|
|
|
|
2024-03-04 18:39:15 +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 {
|
|
|
|
if v.ExtractorID == extractorID {
|
|
|
|
values = append(values, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|
|
|
|
|
2024-03-04 12:24:47 +01:00
|
|
|
func (d *BoltDb) GetIntegrationExtractValue(projectID int, valueID int, extractorID 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-04 12:24:47 +01:00
|
|
|
func (d *BoltDb) GetIntegrationExtractValueRefs(projectID int, valueID int, extractorID 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-04 12:36:24 +01:00
|
|
|
func (d *BoltDb) GetIntegrationMatchers(projectID int, params db.RetrieveQueryParams, extractorID 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 {
|
|
|
|
if v.ExtractorID == extractorID {
|
|
|
|
matchers = append(matchers, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-03-04 12:36:24 +01:00
|
|
|
func (d *BoltDb) GetIntegrationMatcher(projectID int, matcherID int, extractorID int) (matcher db.IntegrationMatcher, err error) {
|
2024-02-11 20:52:14 +01:00
|
|
|
var matchers []db.IntegrationMatcher
|
2024-03-04 14:39:48 +01:00
|
|
|
matchers, err = d.GetIntegrationMatchers(projectID, db.RetrieveQueryParams{}, extractorID)
|
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-04 12:36:24 +01:00
|
|
|
func (d *BoltDb) DeleteIntegrationMatcher(projectID int, matcherID int, extractorID 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-04 14:39:48 +01:00
|
|
|
extractors, err := d.GetIntegrationExtractors(projectID, db.RetrieveQueryParams{}, integrationID)
|
2023-07-03 01:41:13 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for extractor := range extractors {
|
2024-03-04 14:39:48 +01:00
|
|
|
d.DeleteIntegrationExtractor(projectID, extractors[extractor].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-04 12:36:24 +01:00
|
|
|
func (d *BoltDb) GetIntegrationMatcherRefs(projectID int, matcherID int, extractorID 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
|
|
|
}
|