garm/workers/websocket/events/params.go
Gabriel Adrian Samfira 6c46cf9be1 Add API, CLI and web UI integration for objects
This change adds the API endpoints, the CLI commands and the web UI elements
needed to manage objects in GARMs internal storage.

This storage system is meant to be used to distribute the garm-agent and as a
single source of truth for provider binaries, when we will add the ability for GARM
to scale out.

Potentially, we can also use this in air gapped systems to distribute the runner binaries
for forges that don't have their own internal storage system (like GHES).

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2025-10-08 22:22:58 +03:00

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, common.FileObjectEntityType:
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
}