diff --git a/api/integration.go b/api/integration.go index e9cf2ac9..faae4fd7 100644 --- a/api/integration.go +++ b/api/integration.go @@ -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("") } diff --git a/db/Store.go b/db/Store.go index 2eae653d..e759f6b8 100644 --- a/db/Store.go +++ b/db/Store.go @@ -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) diff --git a/db/bolt/integrations.go b/db/bolt/integrations.go index ce254fd5..af8873d5 100644 --- a/db/bolt/integrations.go +++ b/db/bolt/integrations.go @@ -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 +} diff --git a/db/sql/integration.go b/db/sql/integration.go index 39935c61..5bc4e5eb 100644 --- a/db/sql/integration.go +++ b/db/sql/integration.go @@ -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 +} diff --git a/util/config.go b/util/config.go index 93424c42..7217ab8b 100644 --- a/util/config.go +++ b/util/config.go @@ -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 diff --git a/web/src/views/project/IntegrationExtractor.vue b/web/src/views/project/IntegrationExtractor.vue index b09b59a7..1e9258d2 100644 --- a/web/src/views/project/IntegrationExtractor.vue +++ b/web/src/views/project/IntegrationExtractor.vue @@ -21,7 +21,7 @@