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) GetAllIntegrations() ([]db.Integration, error) {
|
|
|
|
return []db.Integration{}, nil
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|
|
|
|
|
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-02-11 20:52:14 +01:00
|
|
|
newIntegrationExtractor, err := d.createObject(integrationExtractor.IntegrationID, db.IntegrationExtractorProps, integrationExtractor)
|
|
|
|
return newIntegrationExtractor.(db.IntegrationExtractor), err
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|
|
|
|
|
2024-03-04 12:36:24 +01:00
|
|
|
func (d *BoltDb) GetIntegrationExtractors(projectID int, params db.RetrieveQueryParams, integrationID int) ([]db.IntegrationExtractor, error) {
|
2024-02-11 20:52:14 +01:00
|
|
|
var extractors []db.IntegrationExtractor
|
|
|
|
err := d.getObjects(integrationID, db.IntegrationExtractorProps, params, nil, &extractors)
|
2023-07-03 01:41:13 +02:00
|
|
|
|
|
|
|
return extractors, err
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
err := d.getObject(integrationID, 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-02-11 20:52:14 +01:00
|
|
|
return d.updateObject(integrationExtractor.IntegrationID, 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-02-11 20:52:14 +01:00
|
|
|
return d.getIntegrationExtractorRefs(integrationID, 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-02-11 20:52:14 +01:00
|
|
|
return d.deleteObject(extractorID, 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-02-11 20:52:14 +01:00
|
|
|
func (d *BoltDb) GetAllIntegrationMatchers() (matchers []db.IntegrationMatcher, err error) {
|
|
|
|
err = d.getObjects(0, 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 12:24:47 +01:00
|
|
|
d.DeleteIntegrationExtractValue(0, 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 12:36:24 +01:00
|
|
|
d.DeleteIntegrationMatcher(0, 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-02-11 20:52:14 +01:00
|
|
|
newValue, err := d.createObject(value.ExtractorID, db.IntegrationExtractValueProps, value)
|
|
|
|
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-02-11 20:52:14 +01:00
|
|
|
err = d.getObjects(extractorID, db.IntegrationExtractValueProps, db.RetrieveQueryParams{}, 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-02-11 20:52:14 +01:00
|
|
|
func (d *BoltDb) GetAllIntegrationExtractValues() (matchers []db.IntegrationExtractValue, err error) {
|
|
|
|
err = d.getObjects(0, db.IntegrationExtractValueProps, 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) GetIntegrationExtractValue(projectID int, valueID int, extractorID int) (value db.IntegrationExtractValue, err error) {
|
2024-02-11 20:52:14 +01:00
|
|
|
err = d.getObject(extractorID, 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-02-11 20:52:14 +01:00
|
|
|
return d.updateObject(integrationExtractValue.ExtractorID, 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-02-11 20:52:14 +01:00
|
|
|
return d.getIntegrationExtractorChildrenRefs(extractorID, 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-02-11 20:52:14 +01:00
|
|
|
newMatcher, err := d.createObject(matcher.ExtractorID, db.IntegrationMatcherProps, matcher)
|
|
|
|
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-02-11 20:52:14 +01:00
|
|
|
err = d.getObjects(extractorID, 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 12:36:24 +01:00
|
|
|
matchers, err = d.GetIntegrationMatchers(0, 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-02-11 20:52:14 +01:00
|
|
|
return d.updateObject(integrationMatcher.ExtractorID, 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-02-11 20:52:14 +01:00
|
|
|
return d.deleteObject(extractorID, 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 12:36:24 +01:00
|
|
|
extractors, err := d.GetIntegrationExtractors(0, db.RetrieveQueryParams{}, integrationID)
|
2023-07-03 01:41:13 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for extractor := range extractors {
|
2024-03-04 12:36:24 +01:00
|
|
|
d.DeleteIntegrationExtractor(0, 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-02-11 20:52:14 +01:00
|
|
|
return d.getIntegrationExtractorChildrenRefs(extractorID, db.IntegrationMatcherProps, valueID)
|
2023-07-03 01:41:13 +02:00
|
|
|
}
|