Semaphore/db/bolt/integrations_alias.go

79 lines
1.8 KiB
Go
Raw Normal View History

2024-12-15 08:32:19 +01:00
package bolt
import (
"github.com/semaphoreui/semaphore/db"
"reflect"
)
var integrationAliasProps = db.ObjectProps{
TableName: "integration_alias",
Type: reflect.TypeOf(db.IntegrationAlias{}),
PrimaryColumnName: "alias",
}
func (d *BoltDb) GetIntegrationAliases(projectID int, integrationID *int) (res []db.IntegrationAlias, err error) {
err = d.integrationAlias.getAliases(projectID, func(i interface{}) bool {
2024-12-15 08:32:19 +01:00
alias := i.(db.IntegrationAlias)
if alias.IntegrationID == nil && integrationID == nil {
return true
} else if alias.IntegrationID != nil && integrationID != nil {
return *alias.IntegrationID == *integrationID
}
return false
}, &res)
return
}
func (d *BoltDb) GetIntegrationsByAlias(alias string) (res []db.Integration, err error) {
var aliasObj db.IntegrationAlias
err = d.integrationAlias.getPublicAlias(alias, &aliasObj)
2024-12-15 08:32:19 +01:00
if err != nil {
return
}
if aliasObj.IntegrationID == nil {
err = d.getObjects(aliasObj.ProjectID, db.IntegrationProps, db.RetrieveQueryParams{}, func(i interface{}) bool {
integration := i.(db.Integration)
return integration.Searchable
}, &res)
if err != nil {
return
}
} else {
var integration db.Integration
integration, err = d.GetIntegration(aliasObj.ProjectID, *aliasObj.IntegrationID)
if err != nil {
return
}
res = append(res, integration)
}
return
}
func (d *BoltDb) CreateIntegrationAlias(alias db.IntegrationAlias) (res db.IntegrationAlias, err error) {
newAlias, err := d.integrationAlias.createAlias(alias)
2024-12-15 08:32:19 +01:00
if err != nil {
return
}
res = newAlias.(db.IntegrationAlias)
return
}
func (d *BoltDb) DeleteIntegrationAlias(projectID int, aliasID int) (err error) {
err = d.integrationAlias.deleteIntegrationAlias(projectID, aliasID)
2024-12-15 08:32:19 +01:00
return
}