mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
feat(integrations): add global alias
This commit is contained in:
parent
4c27e0a70d
commit
8f9b9a74fe
@ -5,6 +5,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
@ -55,7 +56,13 @@ func ReceiveIntegration(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
log.Info(fmt.Sprintf("Receiving Integration from: %s", r.RemoteAddr))
|
||||
|
||||
integrations, err := helpers.Store(r).GetIntegrationsByAlias(integrationAlias)
|
||||
var integrations []db.Integration
|
||||
|
||||
if util.Config.GlobalIntegrationAlias != "" && integrationAlias == util.Config.GlobalIntegrationAlias {
|
||||
integrations, err = helpers.Store(r).GetAllSearchableIntegrations()
|
||||
} else {
|
||||
integrations, err = helpers.Store(r).GetIntegrationsByAlias(integrationAlias)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
@ -64,15 +71,20 @@ func ReceiveIntegration(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
log.Info(fmt.Sprintf("%d integrations found for alias %s", len(integrations), integrationAlias))
|
||||
|
||||
var project db.Project
|
||||
if len(integrations) > 0 {
|
||||
project, err = helpers.Store(r).GetProject(integrations[0].ProjectID)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
projects := make(map[int]db.Project)
|
||||
|
||||
for _, integration := range integrations {
|
||||
|
||||
project, ok := projects[integration.ProjectID]
|
||||
if !ok {
|
||||
project, err = helpers.Store(r).GetProject(integrations[0].ProjectID)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
projects[integration.ProjectID] = project
|
||||
}
|
||||
|
||||
if integration.ProjectID != project.ID {
|
||||
panic("")
|
||||
}
|
||||
|
@ -163,6 +163,7 @@ type Store interface {
|
||||
GetIntegrationAliases(projectID int, integrationID *int) ([]IntegrationAlias, error)
|
||||
GetIntegrationsByAlias(alias string) ([]Integration, error)
|
||||
DeleteIntegrationAlias(projectID int, aliasID int) error
|
||||
GetAllSearchableIntegrations() ([]Integration, error)
|
||||
|
||||
UpdateAccessKey(accessKey AccessKey) error
|
||||
CreateAccessKey(accessKey AccessKey) (AccessKey, error)
|
||||
|
@ -283,3 +283,24 @@ func (d *BoltDb) DeleteIntegrationAlias(projectID int, aliasID int) (err error)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (d *BoltDb) GetAllSearchableIntegrations() (integrations []db.Integration, err error) {
|
||||
integrations = make([]db.Integration, 0)
|
||||
|
||||
projects, err := d.GetAllProjects()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, project := range projects {
|
||||
var projectIntegrations []db.Integration
|
||||
projectIntegrations, err = d.GetIntegrations(project.ID, db.RetrieveQueryParams{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
integrations = append(projectIntegrations)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -113,13 +113,6 @@ func (d *SqlDb) GetIntegrationExtractValues(projectID int, params db.RetrieveQue
|
||||
return values, err
|
||||
}
|
||||
|
||||
func (d *SqlDb) GetAllIntegrationExtractValues() (values []db.IntegrationExtractValue, err error) {
|
||||
var valueObjects interface{}
|
||||
valueObjects, err = d.GetAllObjects(db.IntegrationExtractValueProps)
|
||||
values = valueObjects.([]db.IntegrationExtractValue)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SqlDb) GetIntegrationExtractValue(projectID int, valueID int, integrationID int) (value db.IntegrationExtractValue, err error) {
|
||||
query, args, err := squirrel.Select("v.*").
|
||||
From("project__integration_extract_value as v").
|
||||
@ -210,14 +203,6 @@ func (d *SqlDb) GetIntegrationMatchers(projectID int, params db.RetrieveQueryPar
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SqlDb) GetAllIntegrationMatchers() (matchers []db.IntegrationMatcher, err error) {
|
||||
var matcherObjects interface{}
|
||||
matcherObjects, err = d.GetAllObjects(db.IntegrationMatcherProps)
|
||||
matchers = matcherObjects.([]db.IntegrationMatcher)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SqlDb) GetIntegrationMatcher(projectID int, matcherID int, integrationID int) (matcher db.IntegrationMatcher, err error) {
|
||||
query, args, err := squirrel.Select("m.*").
|
||||
From("project__integration_matcher as m").
|
||||
@ -347,3 +332,19 @@ func (d *SqlDb) GetIntegrationsByAlias(alias string) (res []db.Integration, err
|
||||
func (d *SqlDb) DeleteIntegrationAlias(projectID int, aliasID int) error {
|
||||
return d.deleteObject(projectID, db.IntegrationAliasProps, aliasID)
|
||||
}
|
||||
|
||||
func (d *SqlDb) GetAllSearchableIntegrations() (integrations []db.Integration, err error) {
|
||||
q := squirrel.Select("*").From(db.IntegrationProps.TableName)
|
||||
|
||||
q = q.Where("searchable")
|
||||
|
||||
query, args, err := q.ToSql()
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = d.selectAll(&integrations, query, args...)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -191,6 +191,8 @@ type ConfigType struct {
|
||||
UseRemoteRunner bool `json:"use_remote_runner" env:"SEMAPHORE_USE_REMOTE_RUNNER"`
|
||||
|
||||
Runner RunnerSettings `json:"runner"`
|
||||
|
||||
GlobalIntegrationAlias string `json:"global_integration_alias"`
|
||||
}
|
||||
|
||||
// Config exposes the application configuration storage for use in the application
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
<v-checkbox
|
||||
v-model="integration.searchable"
|
||||
label="Available by project alias"
|
||||
label="Available by project and global alias"
|
||||
@change="updateIntegration()"
|
||||
/>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user