* Add template api endpoints Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Added template bypass Pools and scale sets will automatically migrate to the new template system for runner install scripts. If a pool or a scale set cannot be migrate, it is left alone. It is expected that users set a runner install template manually for scenarios we don't yet have a template for (windows on gitea for example). Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Integrate templates with pool create/update Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Add webapp integration with templates Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Add unit tests Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Populate all relevant context fields Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Update dependencies Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Fix lint Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Validate uint Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Add CLI template management Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Some editor improvements and bugfixes Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Fix scale set return values post create Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Fix template websocket events filter Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> --------- Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
// Copyright 2025 Cloudbase Solutions SRL
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
// not use this file except in compliance with the License. You may obtain
|
|
// a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
// License for the specific language governing permissions and limitations
|
|
// under the License.
|
|
package events
|
|
|
|
import (
|
|
"github.com/cloudbase/garm/database/common"
|
|
)
|
|
|
|
type Filter struct {
|
|
Operations []common.OperationType `json:"operations,omitempty" jsonschema:"title=operations,description=A list of operations to filter on,enum=create,enum=update,enum=delete"`
|
|
EntityType common.DatabaseEntityType `json:"entity-type,omitempty" jsonschema:"title=entity type,description=The type of entity to filter on,enum=repository,enum=organization,enum=enterprise,enum=pool,enum=user,enum=instance,enum=job,enum=controller,enum=github_credentials,enum=github_endpoint"`
|
|
}
|
|
|
|
func (f Filter) Validate() error {
|
|
switch f.EntityType {
|
|
case common.RepositoryEntityType, common.OrganizationEntityType, common.EnterpriseEntityType,
|
|
common.PoolEntityType, common.UserEntityType, common.InstanceEntityType,
|
|
common.JobEntityType, common.ControllerEntityType, common.GithubCredentialsEntityType,
|
|
common.GiteaCredentialsEntityType, common.ScaleSetEntityType, common.GithubEndpointEntityType,
|
|
common.TemplateEntityType:
|
|
default:
|
|
return common.ErrInvalidEntityType
|
|
}
|
|
|
|
for _, op := range f.Operations {
|
|
switch op {
|
|
case common.CreateOperation, common.UpdateOperation, common.DeleteOperation:
|
|
default:
|
|
return common.ErrInvalidOperationType
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type Options struct {
|
|
SendEverything bool `json:"send-everything,omitempty" jsonschema:"title=send everything, description=send all events,default=false"`
|
|
Filters []Filter `json:"filters,omitempty" jsonschema:"title=filters,description=A list of filters to apply to the events. This is ignored when send-everything is true"`
|
|
}
|
|
|
|
func (o Options) Validate() error {
|
|
if o.SendEverything {
|
|
return nil
|
|
}
|
|
if len(o.Filters) == 0 {
|
|
return common.ErrNoFiltersProvided
|
|
}
|
|
for _, f := range o.Filters {
|
|
if err := f.Validate(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|