api

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Event lease configuration constants
	DefaultLeaseDurationSeconds = 300  // 5 minutes
	MaxLeaseDurationSeconds     = 3600 // 1 hour
	MinLeaseDurationSeconds     = 30   // 30 seconds
	DefaultEventLimit           = 100  // default number of events to fetch
	MaxEventLimit               = 1000 // maximum number of events to fetch
	MinEventLimit               = 1    // minimum number of events to fetch
)
View Source
const (
	// ISO8601UTC is the standard time format used across the API
	ISO8601UTC = "2006-01-02T15:04:05Z07:00"
)

Variables

This section is empty.

Functions

func Action

func Action[Req any, T domain.Entity, R any](
	actionFunc func(context.Context, properties.UUID, *Req) (*T, error),
	toResp func(*T) *R,
) http.HandlerFunc

Action handles operations that take an ID and optionally a request body, returning an entity

func ActionWithoutBody

func ActionWithoutBody[T domain.Entity, R any](
	actionFunc func(context.Context, properties.UUID) (*T, error),
	toResp func(*T) *R,
) http.HandlerFunc

ActionWithoutBody handles operations that only need an ID and return an entity

func Command

func Command[Req any](
	commandFunc func(context.Context, properties.UUID, *Req) error,
) http.HandlerFunc

Command handles operations that don't return entities (like status changes)

func CommandWithoutBody

func CommandWithoutBody(
	commandFunc func(context.Context, properties.UUID) error,
) http.HandlerFunc

CommandWithoutBody handles operations that only need an ID and don't return anything

func Create

func Create[Req any, T domain.Entity, R any](
	createFunc func(context.Context, *Req) (*T, error),
	toResp func(*T) *R,
) http.HandlerFunc

Create handles standard create operations that take a request body and return a created entity

func CreateServiceScopeExtractor

func CreateServiceScopeExtractor(
	serviceGroupQuerier domain.ServiceGroupQuerier,
	agentQuerier domain.AgentQuerier,
) middlewares.ObjectScopeExtractor

CreateServiceScopeExtractor creates an extractor that gets a combined scope from the request body by retrieving scopes from both ServiceGroup and Agent

func CreateTokenScopeExtractor

func CreateTokenScopeExtractor() middlewares.ObjectScopeExtractor

CreateTokenScopeExtractor creates an extractor that sets the target scope based on token role

func Delete

func Delete[T domain.Entity](querier domain.BaseEntityQuerier[T], deleteFunc func(context.Context, properties.UUID) error) http.HandlerFunc

Delete handles standard delete operations that take an ID from URL and return a deleted entity

func ErrDomain

func ErrDomain(err error) render.Renderer

func ErrInternal

func ErrInternal(err error) render.Renderer

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrNotFound

func ErrNotFound() render.Renderer

func ErrUnauthenticated

func ErrUnauthenticated() render.Renderer

func ErrUnauthorized

func ErrUnauthorized(err error) render.Renderer

func ErrValidation

func ErrValidation(err domain.ValidationError) render.Renderer

func Get

func Get[T domain.Entity, R any](get func(ctx context.Context, id properties.UUID) (*T, error), toResp func(*T) *R) http.HandlerFunc

Get handles standard get operations that take an ID from URL and return an entity

func List

func List[T domain.Entity, R any](querier domain.BaseEntityQuerier[T], toResp func(*T) *R) http.HandlerFunc

List handles standard list operations that take a querier and a toResp function

func NewMockAuthAdmin

func NewMockAuthAdmin() *auth.Identity

func NewMockAuthAgent

func NewMockAuthAgent() *auth.Identity

func NewMockAuthAgentWithID

func NewMockAuthAgentWithID(agentID properties.UUID) *auth.Identity

NewMockAuthAgentWithID creates a mock agent identity with a specific agent ID

func NewMockAuthConsumer

func NewMockAuthConsumer() *auth.Identity

Legacy function kept for compatibility with existing tests but updated to use RoleParticipant instead of RoleConsumer

func NewMockAuthParticipant

func NewMockAuthParticipant() *auth.Identity

Updated constructor functions for the participant unification

func ParsePageRequest

func ParsePageRequest(r *http.Request) (*domain.PageReq, error)

func Update

func Update[Req any, T domain.Entity, R any](
	updateFunc func(context.Context, properties.UUID, *Req) (*T, error),
	toResp func(*T) *R,
) http.HandlerFunc

Update handles standard update operations that take an ID from URL and request body

func UpdateWithoutID

func UpdateWithoutID[Req any, T domain.Entity, R any](
	updateFunc func(context.Context, *Req) (*T, error),
	toResp func(*T) *R,
) http.HandlerFunc

UpdateWithoutID handles operations that take only a request body (no ID from URL) and return an entity This is useful for "me" endpoints and similar patterns where the ID comes from auth context

Types

type AgentHandler

type AgentHandler struct {
	// contains filtered or unexported fields
}

func NewAgentHandler

func NewAgentHandler(
	querier domain.AgentQuerier,
	commander domain.AgentCommander,
	authz auth.Authorizer,
) *AgentHandler

func (*AgentHandler) Create

func (h *AgentHandler) Create(ctx context.Context, req *CreateAgentReq) (*domain.Agent, error)

Adapter functions that convert request structs to commander method calls

func (*AgentHandler) GetMe

func (h *AgentHandler) GetMe(w http.ResponseWriter, r *http.Request)

GetMe handles GET /agents/me This endpoint allows agents to retrieve their own information

func (*AgentHandler) Routes

func (h *AgentHandler) Routes() func(r chi.Router)

func (*AgentHandler) Update

Adapter functions that convert request structs to commander method calls

func (*AgentHandler) UpdateStatusMe

func (h *AgentHandler) UpdateStatusMe(ctx context.Context, req *UpdateAgentStatusReq) (*domain.Agent, error)

Adapter functions that convert request structs to commander method calls

type AgentRes

type AgentRes struct {
	ID          properties.UUID    `json:"id"`
	Name        string             `json:"name"`
	Status      domain.AgentStatus `json:"status"`
	ProviderID  properties.UUID    `json:"providerId"`
	AgentTypeID properties.UUID    `json:"agentTypeId"`
	Tags        []string           `json:"tags"`
	Participant *ParticipantRes    `json:"participant,omitempty"`
	AgentType   *AgentTypeRes      `json:"agentType,omitempty"`
	CreatedAt   JSONUTCTime        `json:"createdAt"`
	UpdatedAt   JSONUTCTime        `json:"updatedAt"`
}

AgentRes represents the response body for agent operations

func AgentToRes

func AgentToRes(a *domain.Agent) *AgentRes

AgentToRes converts a domain.Agent to an AgentResponse

type AgentTypeHandler

type AgentTypeHandler struct {
	// contains filtered or unexported fields
}

func NewAgentTypeHandler

func NewAgentTypeHandler(
	querier domain.AgentTypeQuerier,
	authz auth.Authorizer,
) *AgentTypeHandler

func (*AgentTypeHandler) Routes

func (h *AgentTypeHandler) Routes() func(r chi.Router)

Routes returns the router with all agent type routes registered

type AgentTypeRes

type AgentTypeRes struct {
	ID           properties.UUID   `json:"id"`
	Name         string            `json:"name"`
	CreatedAt    JSONUTCTime       `json:"createdAt"`
	UpdatedAt    JSONUTCTime       `json:"updatedAt"`
	ServiceTypes []*ServiceTypeRes `json:"serviceTypes"`
}

AgentTypeRes represents the response body for agent type operations

func AgentTypeToRes

func AgentTypeToRes(at *domain.AgentType) *AgentTypeRes

AgentTypeToRes converts a domain.AgentType to an AgentTypeResponse

type BaseMockQuerier

type BaseMockQuerier[T domain.Entity] struct {
	GetFunc       func(ctx context.Context, id properties.UUID) (*T, error)
	ExistsFunc    func(ctx context.Context, id properties.UUID) (bool, error)
	ListFunc      func(ctx context.Context, authScope *auth.IdentityScope, req *domain.PageReq) (*domain.PageRes[T], error)
	CountFunc     func(ctx context.Context) (int64, error)
	AuthScopeFunc func(ctx context.Context, id properties.UUID) (auth.ObjectScope, error)
}

BaseMockQuerier provides common mock implementations for BaseEntityQuerier methods

func (*BaseMockQuerier[T]) AuthScope

func (m *BaseMockQuerier[T]) AuthScope(ctx context.Context, id properties.UUID) (auth.ObjectScope, error)

AuthScope returns the authorization scope for the entity

func (*BaseMockQuerier[T]) Count

func (m *BaseMockQuerier[T]) Count(ctx context.Context) (int64, error)

Count returns the number of entities

func (*BaseMockQuerier[T]) Exists

func (m *BaseMockQuerier[T]) Exists(ctx context.Context, id properties.UUID) (bool, error)

Exists checks if an entity with the given ID exists

func (*BaseMockQuerier[T]) Get

func (m *BaseMockQuerier[T]) Get(ctx context.Context, id properties.UUID) (*T, error)

Get retrieves an entity by ID

func (*BaseMockQuerier[T]) List

func (m *BaseMockQuerier[T]) List(ctx context.Context, authScope *auth.IdentityScope, req *domain.PageReq) (*domain.PageRes[T], error)

List retrieves a list of entities based on the provided filters

type BaseMockRepository

type BaseMockRepository[T domain.Entity] struct {
	BaseMockQuerier[T]
	CreateFunc func(ctx context.Context, entity *T) error
	SaveFunc   func(ctx context.Context, entity *T) error
	DeleteFunc func(ctx context.Context, id properties.UUID) error
}

BaseMockRepository provides common mock implementations for BaseEntityRepository methods

func (*BaseMockRepository[T]) Create

func (m *BaseMockRepository[T]) Create(ctx context.Context, entity *T) error

Create creates a new entity

func (*BaseMockRepository[T]) Delete

func (m *BaseMockRepository[T]) Delete(ctx context.Context, id properties.UUID) error

Delete removes an entity by ID

func (*BaseMockRepository[T]) Save

func (m *BaseMockRepository[T]) Save(ctx context.Context, entity *T) error

Save updates an existing entity

type CompleteJobReq

type CompleteJobReq struct {
	Resources  *properties.JSON `json:"resources"`
	ExternalID *string          `json:"externalID"`
}

type CreateAgentReq

type CreateAgentReq struct {
	Name        string          `json:"name"`
	ProviderID  properties.UUID `json:"providerId"`
	AgentTypeID properties.UUID `json:"agentTypeId"`
	Tags        []string        `json:"tags"`
}

func (CreateAgentReq) ObjectScope

func (r CreateAgentReq) ObjectScope() (auth.ObjectScope, error)

auth.ObjectScope implements auth.ObjectScopeProvider interface

type CreateMetricEntryReq

type CreateMetricEntryReq struct {
	ServiceID    *properties.UUID `json:"serviceId,omitempty"`
	ExternalID   *string          `json:"externalId,omitempty"`
	ResourceID   string           `json:"resourceId"`
	Value        float64          `json:"value"`
	TypeName     string           `json:"typeName"`
	MetricTypeID properties.UUID  `json:"metricTypeId"`
	EntityType   string           `json:"entityType"`
	EntityID     properties.UUID  `json:"entityId"`
	Timestamp    time.Time        `json:"timestamp"`
}

type CreateMetricTypeReq

type CreateMetricTypeReq struct {
	Name       string                  `json:"name"`
	EntityType domain.MetricEntityType `json:"entityType"`
}

type CreateParticipantReq

type CreateParticipantReq struct {
	Name   string                   `json:"name"`
	Status domain.ParticipantStatus `json:"status"`
}

type CreateServiceGroupReq

type CreateServiceGroupReq struct {
	Name       string          `json:"name"`
	ConsumerID properties.UUID `json:"consumerId"`
}

func (CreateServiceGroupReq) ObjectScope

func (r CreateServiceGroupReq) ObjectScope() (auth.ObjectScope, error)

type CreateServiceReq

type CreateServiceReq struct {
	GroupID       properties.UUID  `json:"groupId"`
	AgentID       *properties.UUID `json:"agentId,omitempty"`
	ServiceTypeID properties.UUID  `json:"serviceTypeId"`
	AgentTags     []string         `json:"agentTags,omitempty"`
	Name          string           `json:"name"`
	Properties    properties.JSON  `json:"properties"`
}

CreateServiceReq represents the request to create a service

type CreateTokenReq

type CreateTokenReq struct {
	Name     string           `json:"name"`
	Role     auth.Role        `json:"role"`
	ScopeID  *properties.UUID `json:"scopeId,omitempty"`
	AgentID  *properties.UUID `json:"agentId,omitempty"`
	ExpireAt *time.Time       `json:"expireAt,omitempty"` // Match the original field name in tests
}

CreateTokenReq represents a request to create a new token

type ErrRes

type ErrRes struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	ErrorText  string `json:"error,omitempty"` // application-level error message
}

ErrRes represents an error response

func (*ErrRes) Render

func (e *ErrRes) Render(w http.ResponseWriter, r *http.Request) error

type EventAckReq

type EventAckReq struct {
	SubscriberID               string `json:"subscriberId"`
	InstanceID                 string `json:"instanceId"`
	LastEventSequenceProcessed int64  `json:"lastEventSequenceProcessed"`
}

EventAckReq represents the request body for event acknowledgement

func (*EventAckReq) Bind

func (req *EventAckReq) Bind(r *http.Request) error

Bind implements the render.Binder interface for EventAckRequest

type EventAckRes

type EventAckRes struct {
	LastEventSequenceProcessed int64 `json:"lastEventSequenceProcessed"`
}

EventAckRes represents the response body for event acknowledgement

type EventHandler

type EventHandler struct {
	// contains filtered or unexported fields
}

func NewEventHandler

func NewEventHandler(
	querier domain.EventQuerier,
	eventSubscriptionCommander domain.EventSubscriptionCommander,
	authz auth.Authorizer,
) *EventHandler

func (*EventHandler) Acknowledge

func (h *EventHandler) Acknowledge(w http.ResponseWriter, r *http.Request)

func (*EventHandler) Lease

func (h *EventHandler) Lease(w http.ResponseWriter, r *http.Request)

func (*EventHandler) Routes

func (h *EventHandler) Routes() func(r chi.Router)

Routes returns the router with all event entry routes registered

type EventLeaseReq

type EventLeaseReq struct {
	SubscriberID         string `json:"subscriberId" validate:"required"`
	InstanceID           string `json:"instanceId" validate:"required"`
	LeaseDurationSeconds *int   `json:"leaseDurationSeconds,omitempty"`
	Limit                *int   `json:"limit,omitempty"`
}

EventLeaseReq represents the request body for event lease operations

func (*EventLeaseReq) Bind

func (req *EventLeaseReq) Bind(r *http.Request) error

Bind implements the render.Binder interface for EventLeaseRequest

type EventLeaseRes

type EventLeaseRes struct {
	Events                     []EventRes  `json:"events"`
	LeaseExpiresAt             JSONUTCTime `json:"leaseExpiresAt"`
	LastEventSequenceProcessed int64       `json:"lastEventSequenceProcessed"`
}

EventLeaseRes represents the response body for event lease operations

type EventRes

type EventRes struct {
	ID             properties.UUID      `json:"id"`
	SequenceNumber int64                `json:"sequenceNumber"`
	InitiatorType  domain.InitiatorType `json:"initiatorType"`
	InitiatorID    string               `json:"initiatorId"`
	Type           domain.EventType     `json:"type"`
	Properties     properties.JSON      `json:"properties"`
	ProviderID     *properties.UUID     `json:"providerId,omitempty"`
	AgentID        *properties.UUID     `json:"agentId,omitempty"`
	ConsumerID     *properties.UUID     `json:"consumerId,omitempty"`
	CreatedAt      JSONUTCTime          `json:"createdAt"`
	UpdatedAt      JSONUTCTime          `json:"updatedAt"`
}

EventRes represents the response body for event entry operations

func EventToRes

func EventToRes(ae *domain.Event) *EventRes

EventToRes converts a domain.Event to an EventResponse

type FailJobReq

type FailJobReq struct {
	ErrorMessage string `json:"errorMessage"`
}

type JSONUTCTime

type JSONUTCTime time.Time

JSONUTCTime is an UTC marshaled time

func (JSONUTCTime) MarshalJSON

func (t JSONUTCTime) MarshalJSON() ([]byte, error)

func (*JSONUTCTime) UnmarshalJSON

func (t *JSONUTCTime) UnmarshalJSON(data []byte) error

type JobHandler

type JobHandler struct {
	// contains filtered or unexported fields
}

JobHandler handles HTTP requests for jobs

func NewJobHandler

func NewJobHandler(
	querier domain.JobQuerier,
	commander domain.JobCommander,
	authz auth.Authorizer,
) *JobHandler

NewJobHandler creates a new JobHandler

func (*JobHandler) Complete

func (h *JobHandler) Complete(ctx context.Context, id properties.UUID, req *CompleteJobReq) error

Adapter functions for standard handlers

func (*JobHandler) Fail

func (h *JobHandler) Fail(ctx context.Context, id properties.UUID, req *FailJobReq) error

func (*JobHandler) Pending

func (h *JobHandler) Pending(w http.ResponseWriter, r *http.Request)

Pending handles GET /jobs/pending

func (*JobHandler) Routes

func (h *JobHandler) Routes() func(r chi.Router)

Routes returns the router for job endpoints

type JobRes

type JobRes struct {
	ID           properties.UUID      `json:"id"`
	ProviderID   properties.UUID      `json:"providerId"`
	ConsumerID   properties.UUID      `json:"consumerId"`
	AgentID      properties.UUID      `json:"agentId"`
	ServiceID    properties.UUID      `json:"serviceId"`
	Action       domain.ServiceAction `json:"action"`
	Status       domain.JobStatus     `json:"status"`
	Priority     int                  `json:"priority"`
	ErrorMessage string               `json:"errorMessage,omitempty"`
	ClaimedAt    *JSONUTCTime         `json:"claimedAt,omitempty"`
	CompletedAt  *JSONUTCTime         `json:"completedAt,omitempty"`
	CreatedAt    JSONUTCTime          `json:"createdAt"`
	UpdatedAt    JSONUTCTime          `json:"updatedAt"`
	Service      *ServiceRes          `json:"service,omitempty"`
}

JobRes represents the response for a job

func JobToRes

func JobToRes(job *domain.Job) *JobRes

JobToRes converts a job entity to a response

type MetricEntryHandler

type MetricEntryHandler struct {
	// contains filtered or unexported fields
}

func NewMetricEntryHandler

func NewMetricEntryHandler(
	querier domain.MetricEntryQuerier,
	serviceQuerier domain.ServiceQuerier,
	commander domain.MetricEntryCommander,
	authz auth.Authorizer,
) *MetricEntryHandler

func (*MetricEntryHandler) Create

func (*MetricEntryHandler) Routes

func (h *MetricEntryHandler) Routes() func(r chi.Router)

Routes returns the router with all metric entry routes registered

type MetricEntryRes

type MetricEntryRes struct {
	ID         properties.UUID `json:"id"`
	ProviderID properties.UUID `json:"providerId"`
	ConsumerID properties.UUID `json:"consumerId"`
	AgentID    properties.UUID `json:"agentId"`
	ServiceID  properties.UUID `json:"serviceId"`
	ResourceID string          `json:"resourceId"`
	Value      float64         `json:"value"`
	TypeID     string          `json:"typeId"`
	CreatedAt  JSONUTCTime     `json:"createdAt"`
	UpdatedAt  JSONUTCTime     `json:"updatedAt"`
	Agent      *AgentRes       `json:"agent,omitempty"`
	Service    *ServiceRes     `json:"service,omitempty"`
	Type       *MetricTypeRes  `json:"type,omitempty"`
}

MetricEntryRes represents the response body for metric entry operations

func MetricEntryToRes

func MetricEntryToRes(me *domain.MetricEntry) *MetricEntryRes

MetricEntryToRes converts a domain.MetricEntry to a MetricEntryResponse

type MetricTypeHandler

type MetricTypeHandler struct {
	// contains filtered or unexported fields
}

func NewMetricTypeHandler

func NewMetricTypeHandler(
	querier domain.MetricTypeQuerier,
	commander domain.MetricTypeCommander,
	authz auth.Authorizer,
) *MetricTypeHandler

func (*MetricTypeHandler) Create

func (*MetricTypeHandler) Routes

func (h *MetricTypeHandler) Routes() func(r chi.Router)

Routes returns the router with all metric type routes registered

func (*MetricTypeHandler) Update

type MetricTypeRes

type MetricTypeRes struct {
	ID         properties.UUID         `json:"id"`
	Name       string                  `json:"name"`
	EntityType domain.MetricEntityType `json:"entityType"`
	CreatedAt  JSONUTCTime             `json:"createdAt"`
	UpdatedAt  JSONUTCTime             `json:"updatedAt"`
}

MetricTypeRes represents the response body for metric type operations

func MetricTypeToRes

func MetricTypeToRes(mt *domain.MetricType) *MetricTypeRes

MetricTypeToRes converts a domain.MetricType to a MetricTypeResponse

type MockAuthorizer

type MockAuthorizer struct {
	ShouldSucceed bool
}

func (*MockAuthorizer) Authorize

func (m *MockAuthorizer) Authorize(identity *auth.Identity, action auth.Action, object auth.ObjectType, scope auth.ObjectScope) error

type PageRes

type PageRes[T any] struct {
	Items       []*T  `json:"items"`
	TotalItems  int64 `json:"totalItems"`
	TotalPages  int   `json:"totalPages"`
	CurrentPage int   `json:"currentPage"`
	HasNext     bool  `json:"hasNext"`
	HasPrev     bool  `json:"hasPrev"`
}

PageRes represents a generic paginated response

func NewPageResponse

func NewPageResponse[E any, R any](result *domain.PageRes[E], conv func(*E) *R) *PageRes[R]

NewPageResponse creates a new PaginatedResponse from a domain.PaginatedResult

type ParticipantHandler

type ParticipantHandler struct {
	// contains filtered or unexported fields
}

func NewParticipantHandler

func NewParticipantHandler(
	querier domain.ParticipantQuerier,
	commander domain.ParticipantCommander,
	authz auth.Authorizer,
) *ParticipantHandler

func (*ParticipantHandler) Create

func (*ParticipantHandler) Routes

func (h *ParticipantHandler) Routes() func(r chi.Router)

Routes returns the router with all participant routes registered

func (*ParticipantHandler) Update

type ParticipantRes

type ParticipantRes struct {
	ID        properties.UUID          `json:"id"`
	Name      string                   `json:"name"`
	Status    domain.ParticipantStatus `json:"status"`
	CreatedAt JSONUTCTime              `json:"createdAt"`
	UpdatedAt JSONUTCTime              `json:"updatedAt"`
}

ParticipantRes represents the response body for participant operations

func ParticipantToRes

func ParticipantToRes(p *domain.Participant) *ParticipantRes

ParticipantToRes converts a domain.Participant to a ParticipantResponse

type ServiceActionReq

type ServiceActionReq struct {
	Action string `json:"action"`
}

ServiceActionReq represents a status transition request

type ServiceGroupHandler

type ServiceGroupHandler struct {
	// contains filtered or unexported fields
}

func NewServiceGroupHandler

func NewServiceGroupHandler(
	querier domain.ServiceGroupQuerier,
	commander domain.ServiceGroupCommander,
	authz auth.Authorizer,
) *ServiceGroupHandler

func (*ServiceGroupHandler) Create

Adapter functions that convert request structs to commander method calls

func (*ServiceGroupHandler) Routes

func (h *ServiceGroupHandler) Routes() func(r chi.Router)

Routes returns the router with all service group routes registered

func (*ServiceGroupHandler) Update

Adapter functions that convert request structs to commander method calls

type ServiceGroupRes

type ServiceGroupRes struct {
	ID         properties.UUID `json:"id"`
	Name       string          `json:"name"`
	ConsumerID properties.UUID `json:"consumerId"`
	CreatedAt  JSONUTCTime     `json:"createdAt"`
	UpdatedAt  JSONUTCTime     `json:"updatedAt"`
}

ServiceGroupRes represents the response body for service group operations

func ServiceGroupToRes

func ServiceGroupToRes(sg *domain.ServiceGroup) *ServiceGroupRes

ServiceGroupToRes converts a domain.ServiceGroup to a ServiceGroupResponse

type ServiceHandler

type ServiceHandler struct {
	// contains filtered or unexported fields
}

func NewServiceHandler

func NewServiceHandler(
	querier domain.ServiceQuerier,
	agentQuerier domain.AgentQuerier,
	serviceGroupQuerier domain.ServiceGroupQuerier,
	commander domain.ServiceCommander,
	authz auth.Authorizer,
) *ServiceHandler

func (*ServiceHandler) Create

func (h *ServiceHandler) Create(w http.ResponseWriter, r *http.Request)

Create handles service creation with custom logic for agent selection

func (*ServiceHandler) Delete

func (h *ServiceHandler) Delete(ctx context.Context, id properties.UUID) error

func (*ServiceHandler) Retry

func (h *ServiceHandler) Retry(ctx context.Context, id properties.UUID) error

func (*ServiceHandler) Routes

func (h *ServiceHandler) Routes() func(r chi.Router)

Routes returns the router with all service routes registered

func (*ServiceHandler) Start

func (h *ServiceHandler) Start(ctx context.Context, id properties.UUID) error

func (*ServiceHandler) Stop

func (*ServiceHandler) Update

Adapter functions for standard handlers

type ServiceRes

type ServiceRes struct {
	ID                properties.UUID       `json:"id"`
	ProviderID        properties.UUID       `json:"providerId"`
	ConsumerID        properties.UUID       `json:"consumerId"`
	AgentID           properties.UUID       `json:"agentId"`
	ServiceTypeID     properties.UUID       `json:"serviceTypeId"`
	GroupID           properties.UUID       `json:"groupId"`
	ExternalID        *string               `json:"externalId,omitempty"`
	Name              string                `json:"name"`
	CurrentStatus     domain.ServiceStatus  `json:"currentStatus"`
	TargetStatus      *domain.ServiceStatus `json:"targetStatus,omitempty"`
	FailedAction      *domain.ServiceAction `json:"failedAction,omitempty"`
	ErrorMessage      *string               `json:"errorMessage,omitempty"`
	RetryCount        int                   `json:"retryCount,omitempty"`
	CurrentProperties *properties.JSON      `json:"currentProperties,omitempty"`
	TargetProperties  *properties.JSON      `json:"targetProperties,omitempty"`
	Resources         *properties.JSON      `json:"resources,omitempty"`
	CreatedAt         JSONUTCTime           `json:"createdAt"`
	UpdatedAt         JSONUTCTime           `json:"updatedAt"`
}

ServiceRes represents the response body for service operations

func ServiceToRes

func ServiceToRes(s *domain.Service) *ServiceRes

ServiceToRes converts a domain.Service to a ServiceResponse

type ServiceTypeHandler

type ServiceTypeHandler struct {
	// contains filtered or unexported fields
}

func NewServiceTypeHandler

func NewServiceTypeHandler(
	querier domain.ServiceTypeQuerier,
	authz auth.Authorizer,
) *ServiceTypeHandler

func (*ServiceTypeHandler) Routes

func (h *ServiceTypeHandler) Routes() func(r chi.Router)

Routes returns the router with all service type routes registered

func (*ServiceTypeHandler) Validate

func (h *ServiceTypeHandler) Validate(w http.ResponseWriter, r *http.Request)

type ServiceTypeRes

type ServiceTypeRes struct {
	ID             properties.UUID      `json:"id"`
	Name           string               `json:"name"`
	PropertySchema *schema.CustomSchema `json:"propertySchema,omitempty"`
	CreatedAt      JSONUTCTime          `json:"createdAt"`
	UpdatedAt      JSONUTCTime          `json:"updatedAt"`
}

ServiceTypeRes represents the response body for service type operations

func ServiceTypeToRes

func ServiceTypeToRes(st *domain.ServiceType) *ServiceTypeRes

ServiceTypeToRes converts a domain.ServiceType to a ServiceTypeResponse

type TokenHandler

type TokenHandler struct {
	// contains filtered or unexported fields
}

func NewTokenHandler

func NewTokenHandler(
	querier domain.TokenQuerier,
	commander domain.TokenCommander,
	agentQuerier domain.AgentQuerier,
	authz auth.Authorizer,
) *TokenHandler

func (*TokenHandler) Create

func (h *TokenHandler) Create(ctx context.Context, req *CreateTokenReq) (*domain.Token, error)

func (*TokenHandler) Routes

func (h *TokenHandler) Routes() func(r chi.Router)

Routes returns the router with all token routes registered

func (*TokenHandler) Update

type TokenRes

type TokenRes struct {
	ID            properties.UUID  `json:"id"`
	Name          string           `json:"name"`
	Role          auth.Role        `json:"role"`
	ExpireAt      JSONUTCTime      `json:"expireAt"`
	ParticipantID *properties.UUID `json:"participantId,omitempty"`
	AgentID       *properties.UUID `json:"agentId,omitempty"`
	CreatedAt     JSONUTCTime      `json:"createdAt"`
	UpdatedAt     JSONUTCTime      `json:"updatedAt"`
	Value         string           `json:"value,omitempty"`
}

TokenRes represents the response body for token operations

func TokenToRes

func TokenToRes(t *domain.Token) *TokenRes

TokenToRes converts a domain.Token to a TokenResponse

type UpdateAgentReq

type UpdateAgentReq struct {
	Name   *string             `json:"name"`
	Status *domain.AgentStatus `json:"status"`
	Tags   *[]string           `json:"tags"`
}

type UpdateAgentStatusReq

type UpdateAgentStatusReq struct {
	Status domain.AgentStatus `json:"status"`
}

type UpdateMetricTypeReq

type UpdateMetricTypeReq struct {
	Name *string `json:"name"`
}

type UpdateParticipantReq

type UpdateParticipantReq struct {
	Name   *string                   `json:"name"`
	Status *domain.ParticipantStatus `json:"status"`
}

type UpdateServiceGroupReq

type UpdateServiceGroupReq struct {
	Name *string `json:"name"`
}

type UpdateServiceReq

type UpdateServiceReq struct {
	Name       *string          `json:"name,omitempty"`
	Properties *properties.JSON `json:"properties,omitempty"`
}

UpdateServiceReq represents the request to update a service

type UpdateTokenReq

type UpdateTokenReq struct {
	Name     *string    `json:"name,omitempty"`
	ExpireAt *time.Time `json:"expireAt,omitempty"`
}

UpdateTokenReq represents a request to update a token

type ValidateReq

type ValidateReq struct {
	Properties map[string]any `json:"properties"`
}

ValidateReq represents the request body for property validation

type ValidateRes

type ValidateRes struct {
	Valid  bool                     `json:"valid"`
	Errors []schema.ValidationError `json:"errors,omitempty"`
}

ValidateRes represents the response body for property validation

type ValidationErrRes

type ValidationErrRes struct {
	Err            error                          `json:"-"` // low-level runtime error
	HTTPStatusCode int                            `json:"-"` // http response status code
	StatusText     string                         `json:"status"`
	Valid          bool                           `json:"valid"`
	Errors         []domain.ValidationErrorDetail `json:"errors"`
}

ValidationErrRes represents a validation error response with detailed errors

func (*ValidationErrRes) Render

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL