feat(integrations): add alias methods

This commit is contained in:
fiftin 2024-03-07 10:32:25 +01:00
parent 3e052de57f
commit 2c2e7df311
5 changed files with 75 additions and 100 deletions

View File

@ -64,6 +64,13 @@ type IntegrationExtractValue struct {
Variable string `db:"variable" json:"variable"`
}
type IntegrationAlias struct {
ID int `db:"id" json:"id"`
Alias string `db:"alias" json:"alias"`
ProjectID int `db:"project_id" json:"project_id"`
IntegrationID *int `db:"integration_id" json:"integration_id"`
}
type Integration struct {
ID int `db:"id" json:"id"`
Name string `db:"name" json:"name"`

View File

@ -156,6 +156,12 @@ type Store interface {
GetIntegrationMatcherRefs(projectID int, matcherID int, integrationID int) (IntegrationExtractorChildReferrers, error)
DeleteIntegrationMatcher(projectID int, matcherID int, integrationID int) error
CreateIntegrationAlias(alias IntegrationAlias) (IntegrationAlias, error)
GetIntegrationAlias(projectID int, integrationID *int) (IntegrationAlias, error)
GetIntegrationAliasByAlias(alias string) (IntegrationAlias, error)
UpdateIntegrationAlias(alias IntegrationAlias) error
DeleteIntegrationAlias(projectID int, integrationID *int) error
UpdateAccessKey(accessKey AccessKey) error
CreateAccessKey(accessKey AccessKey) (AccessKey, error)
DeleteAccessKey(projectID int, accessKeyID int) error
@ -276,6 +282,12 @@ var IntegrationMatcherProps = ObjectProps{
DefaultSortingColumn: "name",
}
var IntegrationAliasProps = ObjectProps{
TableName: "project__integration_alias",
Type: reflect.TypeOf(IntegrationAlias{}),
PrimaryColumnName: "id",
}
var EnvironmentProps = ObjectProps{
TableName: "project__environment",
Type: reflect.TypeOf(Environment{}),

View File

@ -2,6 +2,7 @@ package bolt
import (
"github.com/ansible-semaphore/semaphore/db"
"reflect"
)
/*
@ -48,28 +49,10 @@ func (d *BoltDb) GetIntegrationRefs(projectID int, integrationID int) (db.Integr
return db.IntegrationReferrers{}, nil
}
/*
Integration Extractors
*/
/*
Integration ExtractValue
*/
func (d *BoltDb) GetIntegrationExtractValuesByExtractorID(integrationID int) (values []db.IntegrationExtractValue, err error) {
err = d.getObjects(integrationID, db.IntegrationExtractValueProps, db.RetrieveQueryParams{}, nil, &values)
return values, err
}
func (d *BoltDb) DeleteIntegrationExtractValue(projectID int, valueID int, integrationID int) error {
return d.deleteObject(projectID, db.IntegrationExtractValueProps, intObjectID(valueID), nil)
}
func (d *BoltDb) GetIntegrationMatchersByExtractorID(integrationID int) (matchers []db.IntegrationMatcher, err error) {
err = d.getObjects(integrationID, db.IntegrationMatcherProps, db.RetrieveQueryParams{}, nil, &matchers)
return matchers, err
}
func (d *BoltDb) CreateIntegrationExtractValue(projectId int, value db.IntegrationExtractValue) (db.IntegrationExtractValue, error) {
err := value.Validate()
@ -195,3 +178,37 @@ func (d *BoltDb) DeleteIntegration(projectID int, integrationID int) error {
func (d *BoltDb) GetIntegrationMatcherRefs(projectID int, matcherID int, integrationID int) (db.IntegrationExtractorChildReferrers, error) {
return d.getIntegrationExtractorChildrenRefs(projectID, db.IntegrationMatcherProps, matcherID)
}
var integrationAliasProps = db.ObjectProps{
TableName: "integration_alias",
Type: reflect.TypeOf(db.IntegrationAlias{}),
PrimaryColumnName: "alias",
}
func (d *BoltDb) CreateIntegrationAlias(alias db.IntegrationAlias) (res db.IntegrationAlias, err error) {
return
}
func (d *BoltDb) GetIntegrationAlias(projectID int, integrationID *int) (res db.IntegrationAlias, err error) {
if integrationID == nil {
projectLevelIntegrationId := -1
integrationID = &projectLevelIntegrationId
}
err = d.getObject(projectID, db.IntegrationAliasProps, intObjectID(*integrationID), &res)
return
}
func (d *BoltDb) GetIntegrationAliasByAlias(alias string) (res db.IntegrationAlias, err error) {
err = d.getObject(-1, integrationAliasProps, strObjectID(alias), &res)
return
}
func (d *BoltDb) UpdateIntegrationAlias(alias db.IntegrationAlias) error {
return nil
}
func (d *BoltDb) DeleteIntegrationAlias(projectID int, integrationID *int) error {
return nil
}

View File

@ -94,87 +94,6 @@ func (d *SqlDb) UpdateIntegration(integration db.Integration) error {
return err
}
func (d *SqlDb) GetIntegrationExtractValuesByExtractorID(integrationID int) (values []db.IntegrationExtractValue, err error) {
var sqlError error
query, args, sqlError := squirrel.Select("v.*").
From("project__integration_extract_value as v").
Where(squirrel.Eq{"integration_id": integrationID}).
OrderBy("v.id").
ToSql()
if sqlError != nil {
return []db.IntegrationExtractValue{}, sqlError
}
err = d.selectOne(&values, query, args...)
return values, err
}
func (d *SqlDb) GetIntegrationMatchersByExtractorID(integrationID int) (matchers []db.IntegrationMatcher, err error) {
var sqlError error
query, args, sqlError := squirrel.Select("m.*").
From("project__integration_matcher as m").
Where(squirrel.Eq{"integration_id": integrationID}).
OrderBy("m.id").
ToSql()
if sqlError != nil {
return []db.IntegrationMatcher{}, sqlError
}
err = d.selectOne(&matchers, query, args...)
return matchers, err
}
//func (d *SqlDb) DeleteIntegrationExtractor(projectID int, integrationID int, integrationID int) error {
// values, err := d.GetIntegrationExtractValuesByExtractorID(integrationID)
// if err != nil && !strings.Contains(err.Error(), "no rows in result set") {
// return err
// }
//
// for value := range values {
//
// err = d.DeleteIntegrationExtractValue(0, values[value].ID, integrationID)
// if err != nil && !strings.Contains(err.Error(), "no rows in result set") {
// log.Error(err)
// return err
// }
// }
//
// matchers, errExtractor := d.GetIntegrationMatchersByExtractorID(integrationID)
// if errExtractor != nil && !strings.Contains(errExtractor.Error(), "no rows in result set") {
// log.Error(errExtractor)
// return errExtractor
// }
//
// for matcher := range matchers {
// err = d.DeleteIntegrationMatcher(0, matchers[matcher].ID, integrationID)
// if err != nil && !strings.Contains(err.Error(), "no rows in result set") {
// log.Error(err)
// return err
// }
// }
//
// return d.deleteObjectByReferencedID(integrationID, db.IntegrationProps, db.IntegrationExtractorProps, integrationID)
//}
//
//func (d *SqlDb) UpdateIntegrationExtractor(projectID int, integrationExtractor db.IntegrationExtractor) error {
// err := integrationExtractor.Validate()
//
// if err != nil {
// return err
// }
//
// _, err = d.exec(
// "update project__integration_extractor set name=? where id=?",
// integrationExtractor.Name,
// integrationExtractor.ID)
//
// return err
//}
func (d *SqlDb) CreateIntegrationExtractValue(projectId int, value db.IntegrationExtractValue) (newValue db.IntegrationExtractValue, err error) {
err = value.Validate()
@ -359,3 +278,23 @@ func (d *SqlDb) UpdateIntegrationMatcher(projectID int, integrationMatcher db.In
return err
}
func (d *SqlDb) CreateIntegrationAlias(alias db.IntegrationAlias) (res db.IntegrationAlias, err error) {
return
}
func (d *SqlDb) GetIntegrationAlias(projectID int, integrationID *int) (res db.IntegrationAlias, err error) {
return
}
func (d *SqlDb) GetIntegrationAliasByAlias(alias string) (res db.IntegrationAlias, err error) {
return
}
func (d *SqlDb) UpdateIntegrationAlias(alias db.IntegrationAlias) error {
return nil
}
func (d *SqlDb) DeleteIntegrationAlias(projectID int, integrationID *int) error {
return nil
}

View File

@ -53,5 +53,5 @@ create table project__integration_alias (
foreign key (`integration_id`) references project__integration(`id`) on delete cascade,
unique (`alias`),
unique (`project_id`)
unique (`project_id`, `integration_id`)
);