Skip to content

Commit

Permalink
log warning if local items have conflicting names
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Jan 10, 2025
1 parent 866b0ad commit 28c0f0d
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 146 deletions.
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/clihub/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func ListItems(out io.Writer, wantColor string, itemTypes []string, items map[st
continue
}

listHubItemTable(out, wantColor, "\n"+strings.ToUpper(itemType), items[itemType])
listHubItemTable(out, wantColor, strings.ToUpper(itemType), items[itemType])

Check warning on line 66 in cmd/crowdsec-cli/clihub/items.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/clihub/items.go#L66

Added line #L66 was not covered by tests

nothingToDisplay = false
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cwhub/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (h *Hub) Update(ctx context.Context, indexProvider IndexProvider, withConte
return nil
}

// addItem adds an item to the hub. It silently replaces an existing item with the same type and name.
func (h *Hub) addItem(item *Item) {
if h.items[item.Type] == nil {
h.items[item.Type] = make(map[string]*Item)
Expand Down
3 changes: 2 additions & 1 deletion pkg/cwhub/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type ItemState struct {
LocalVersion string `json:"local_version,omitempty" yaml:"local_version,omitempty"`
LocalHash string `json:"local_hash,omitempty" yaml:"local_hash,omitempty"`
Installed bool `json:"installed"`
local bool
Downloaded bool `json:"downloaded"`
UpToDate bool `json:"up_to_date"`
Tainted bool `json:"tainted"`
Expand All @@ -20,7 +21,7 @@ type ItemState struct {

// IsLocal returns true if the item has been create by a user (not downloaded from the hub).
func (s *ItemState) IsLocal() bool {
return s.Installed && !s.Downloaded
return s.local
}

// Text returns the status of the item as a string (eg. "enabled,update-available").
Expand Down
1 change: 1 addition & 0 deletions pkg/cwhub/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestItemStateText(t *testing.T) {
ItemState{
Installed: true,
UpToDate: false,
local: true,
Tainted: false,
Downloaded: false,
},
Expand Down
Loading

0 comments on commit 28c0f0d

Please sign in to comment.