Documentation
¶
Overview ¶
Package helper provides helper functions for mapping between domain models and API models.
Index ¶
- Constants
- Variables
- type Mapper
- func (mapper *Mapper) MapAPIToAgent(apiAgent *v1.Agent) *agentmodel.Agent
- func (mapper *Mapper) MapAPIToAgentGroup(apiAgentGroup *v1.AgentGroup) *agentmodel.AgentGroup
- func (mapper *Mapper) MapAPIToAgentPackage(apiModel *v1.AgentPackage) *agentmodel.AgentPackage
- func (mapper *Mapper) MapAPIToAgentRemoteConfig(api *v1.AgentRemoteConfig) *agentmodel.AgentRemoteConfig
- func (mapper *Mapper) MapAPIToCertificate(api *v1.Certificate) *agentmodel.Certificate
- func (mapper *Mapper) MapAPIToNamespace(apiModel *v1.Namespace) *agentmodel.Namespace
- func (mapper *Mapper) MapAPIToRoleBinding(apiRB *v1.RoleBinding) *usermodel.RoleBinding
- func (mapper *Mapper) MapAgentGroupToAPI(domainAgentGroup *agentmodel.AgentGroup) *v1.AgentGroup
- func (mapper *Mapper) MapAgentPackageToAPI(agentPackage *agentmodel.AgentPackage) *v1.AgentPackage
- func (mapper *Mapper) MapAgentRemoteConfigToAPI(domain *agentmodel.AgentRemoteConfig) *v1.AgentRemoteConfig
- func (mapper *Mapper) MapAgentToAPI(agent *agentmodel.Agent) *v1.Agent
- func (mapper *Mapper) MapCertificateToAPI(domain *agentmodel.Certificate) *v1.Certificate
- func (mapper *Mapper) MapNamespaceToAPI(namespace *agentmodel.Namespace) *v1.Namespace
- func (mapper *Mapper) MapRoleBindingToAPI(domain *usermodel.RoleBinding) *v1.RoleBinding
- func (mapper *Mapper) MapRoleToAPI(domain *usermodel.Role) *v1.Role
- func (mapper *Mapper) MapUserToAPI(domain *usermodel.User) *v1.User
- type UUIDPage
Constants ¶
const ( // TextJSON is the content type for JSON. TextJSON = "text/json" // TextYAML is the content type for YAML. TextYAML = "text/yaml" // Empty is the content type for empty. // Empty content type is treated as YAML by default. // Due to spec miss, old otel-collector sends empty content type even though it should be YAML. Empty = "" )
Variables ¶
var ErrInvalidContinueToken = errors.New("invalid continue token")
ErrInvalidContinueToken is returned when a continue token cannot be parsed as a valid offset into an in-memory slice page.
Functions ¶
This section is empty.
Types ¶
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
Mapper is a struct that provides methods to map between domain models and API models.
The injected clock is consulted for time-sensitive derivations (e.g. evaluating heartbeat-staleness for the Agent.Connected API field). Tests using mapped output for assertions can pass a fake clock for deterministic results.
connectionStaleness controls how long after an agent's LastReportedAt the API still treats it as connected. Operators tuning the OpAMP heartbeat interval should pass a value at least 2-3× their interval.
func NewMapper ¶
func NewMapper(clk clock.PassiveClock, connectionStaleness time.Duration) *Mapper
NewMapper creates a new instance of Mapper. A nil clock falls back to k8s.io/utils/clock.RealClock so a misconfigured call site never crashes at MapAgentToAPI time — better to be visibly wrong than silently nil. A non-positive connectionStaleness falls back to agentmodel.DefaultConnectionStaleness.
func (*Mapper) MapAPIToAgent ¶
func (mapper *Mapper) MapAPIToAgent(apiAgent *v1.Agent) *agentmodel.Agent
MapAPIToAgent maps an API model Agent to a domain model Agent.
func (*Mapper) MapAPIToAgentGroup ¶
func (mapper *Mapper) MapAPIToAgentGroup(apiAgentGroup *v1.AgentGroup) *agentmodel.AgentGroup
MapAPIToAgentGroup maps an API model AgentGroup to a domain model AgentGroup.
func (*Mapper) MapAPIToAgentPackage ¶
func (mapper *Mapper) MapAPIToAgentPackage(apiModel *v1.AgentPackage) *agentmodel.AgentPackage
MapAPIToAgentPackage maps an API model AgentPackage to a domain model AgentPackage.
func (*Mapper) MapAPIToAgentRemoteConfig ¶
func (mapper *Mapper) MapAPIToAgentRemoteConfig( api *v1.AgentRemoteConfig, ) *agentmodel.AgentRemoteConfig
MapAPIToAgentRemoteConfig maps an API model AgentRemoteConfig to a domain model.
func (*Mapper) MapAPIToCertificate ¶
func (mapper *Mapper) MapAPIToCertificate(api *v1.Certificate) *agentmodel.Certificate
MapAPIToCertificate maps an API model Certificate to a domain model Certificate.
func (*Mapper) MapAPIToNamespace ¶
func (mapper *Mapper) MapAPIToNamespace( apiModel *v1.Namespace, ) *agentmodel.Namespace
MapAPIToNamespace maps an API Namespace to a domain Namespace.
func (*Mapper) MapAPIToRoleBinding ¶
func (mapper *Mapper) MapAPIToRoleBinding(apiRB *v1.RoleBinding) *usermodel.RoleBinding
MapAPIToRoleBinding maps an API model RoleBinding to a domain model RoleBinding.
func (*Mapper) MapAgentGroupToAPI ¶
func (mapper *Mapper) MapAgentGroupToAPI(domainAgentGroup *agentmodel.AgentGroup) *v1.AgentGroup
MapAgentGroupToAPI maps a domain model AgentGroup to an API model AgentGroup.
func (*Mapper) MapAgentPackageToAPI ¶
func (mapper *Mapper) MapAgentPackageToAPI(agentPackage *agentmodel.AgentPackage) *v1.AgentPackage
MapAgentPackageToAPI maps a domain model AgentPackage to an API model AgentPackage.
func (*Mapper) MapAgentRemoteConfigToAPI ¶
func (mapper *Mapper) MapAgentRemoteConfigToAPI( domain *agentmodel.AgentRemoteConfig, ) *v1.AgentRemoteConfig
MapAgentRemoteConfigToAPI maps a domain model AgentRemoteConfig to an API model.
func (*Mapper) MapAgentToAPI ¶
func (mapper *Mapper) MapAgentToAPI(agent *agentmodel.Agent) *v1.Agent
MapAgentToAPI maps a domain model Agent to an API model Agent.
func (*Mapper) MapCertificateToAPI ¶
func (mapper *Mapper) MapCertificateToAPI(domain *agentmodel.Certificate) *v1.Certificate
MapCertificateToAPI maps a domain model Certificate to an API model Certificate.
func (*Mapper) MapNamespaceToAPI ¶
func (mapper *Mapper) MapNamespaceToAPI( namespace *agentmodel.Namespace, ) *v1.Namespace
MapNamespaceToAPI maps a domain Namespace to an API Namespace.
func (*Mapper) MapRoleBindingToAPI ¶
func (mapper *Mapper) MapRoleBindingToAPI(domain *usermodel.RoleBinding) *v1.RoleBinding
MapRoleBindingToAPI maps a domain model RoleBinding to an API model RoleBinding.
func (*Mapper) MapRoleToAPI ¶
MapRoleToAPI maps a domain model Role to an API model Role.
type UUIDPage ¶
type UUIDPage struct {
// Items are the UUIDs on this page.
Items []uuid.UUID
// Continue is the token to pass to fetch the next page, or empty when this
// is the last page.
Continue string
// RemainingItemCount is how many items follow this page.
RemainingItemCount int64
}
UUIDPage is one page of a paginated UUID slice, plus the cursor needed to resume after it.
func PaginateUUIDs ¶
PaginateUUIDs slices an ordered UUID collection into a single page using the offset-based cursor carried in options.Continue. It is the building block for paginating an aggregate's associated-agent list (e.g. a host's agents), where the full ordered set is already in memory.
The continue token is the start offset of the next page (an integer). A zero or negative Limit returns the whole remainder in one page.