Files
teleport/lib/services/bot_instance.go
T
Nick Marais 057b52ff27 feat(machine-id): Bot instances list (web) (#54925)
* Add navigation item

* Add bot instances page

* Populate page info

* Add missing license header

* Update bot instance nav icon

* Reword hint text

* Add active at timestamp tooltip

* Rename active at header

* Remove copy and sort

* Lint and test fixes

* Support backend search term filtering

* Simplify code

* Add search term filter auth tests

* Allow disabling `<Table />` loading indicator

* Rework frontend to use backend paging and filter (remove sort)

* Fix lint (ts)

* Remove unused BotInstances icon

* Add URL state (page and search)

* Use nil-safe getters on protos

* Fix crash on items w/o heartbeat data
2025-05-27 08:01:51 +00:00

81 lines
2.8 KiB
Go

// Teleport
// Copyright (C) 2024 Gravitational, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package services
import (
"context"
"github.com/gravitational/trace"
machineidv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/machineid/v1"
)
// BotInstance is an interface for the BotInstance service.
type BotInstance interface {
// CreateBotInstance
CreateBotInstance(ctx context.Context, botInstance *machineidv1.BotInstance) (*machineidv1.BotInstance, error)
// GetBotInstance
GetBotInstance(ctx context.Context, botName, instanceID string) (*machineidv1.BotInstance, error)
// ListBotInstances
ListBotInstances(ctx context.Context, botName string, pageSize int, lastToken string, search string) ([]*machineidv1.BotInstance, string, error)
// DeleteBotInstance
DeleteBotInstance(ctx context.Context, botName, instanceID string) error
// PatchBotInstance fetches an existing bot instance by bot name and ID,
// then calls `updateFn` to apply any changes before persisting the
// resource.
PatchBotInstance(
ctx context.Context,
botName, instanceID string,
updateFn func(*machineidv1.BotInstance) (*machineidv1.BotInstance, error),
) (*machineidv1.BotInstance, error)
}
// ValidateBotInstance verifies that required fields for a new BotInstance are present
func ValidateBotInstance(b *machineidv1.BotInstance) error {
if b.Spec == nil {
return trace.BadParameter("spec is required")
}
if b.Spec.BotName == "" {
return trace.BadParameter("spec.bot_name is required")
}
if b.Spec.InstanceId == "" {
return trace.BadParameter("spec.instance_id is required")
}
if b.Status == nil {
return trace.BadParameter("status is required")
}
return nil
}
// MarshalBotInstance marshals the BotInstance object into a JSON byte array.
func MarshalBotInstance(object *machineidv1.BotInstance, opts ...MarshalOption) ([]byte, error) {
return MarshalProtoResource(object, opts...)
}
// UnmarshalBotInstance unmarshals the BotInstance object from a JSON byte array.
func UnmarshalBotInstance(data []byte, opts ...MarshalOption) (*machineidv1.BotInstance, error) {
return UnmarshalProtoResource[*machineidv1.BotInstance](data, opts...)
}