Skip to content

Commit

Permalink
feat(inv): add IsHostEnrolled method to Store interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhop committed May 17, 2024
1 parent 4c923fd commit 32f70fe
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions internal/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type Store interface {

// Enrollment and runtime/metadata checks
IsEnrolled() bool
IsHostEnrolled(host string) bool
GetInventoryPath() string
GetHostname() string

Expand Down Expand Up @@ -219,21 +220,22 @@ func (i *Inventory) Reload(ctx context.Context, logger *slog.Logger) {
metricMangoInventoryInfo.With(metricMangoInventoryInfoLabels).Set(1)
}

// IsEnrolled returns if the hostname of the system is defined in the
// inventory, or if the hostname of the system matches any group match
// parameters
func (i *Inventory) IsEnrolled() bool {
if _, found := i.GetHost(i.hostname); found {
// IsHostEnrolled returns if the provided hostname of the system is defined in
// the inventory, or if the provided hostname of the system matches any group
// match parameters
func (i *Inventory) IsHostEnrolled(host string) bool {
if _, found := i.GetHost(host); found {
return true
}

for _, group := range i.groups {
if group.IsHostEnrolled(i.hostname) {
return true
}
}
return len(i.GetGroupsForHost(host)) > 0
}

return false
// IsEnrolled returns if the hostname of the system is defined in the
// inventory, or if the hostname of the system matches any group match
// parameters
func (i *Inventory) IsEnrolled() bool {
return i.IsHostEnrolled(i.hostname)
}

// GetDirectives returns a copy of the inventory's slice of Directive
Expand Down

0 comments on commit 32f70fe

Please sign in to comment.