Skip to content

Commit

Permalink
log warning if local items have conflicting names (#3399)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc authored Jan 13, 2025
1 parent e9c1ed0 commit 5df5684
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 158 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])

nothingToDisplay = false
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/crowdsec-cli/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ cscli dashboard setup -l 0.0.0.0 -p 443 --password <password>
if err = cli.chownDatabase(dockerGroup.Gid); err != nil {
return err
}
mb, err := metabase.SetupMetabase(cli.cfg().API.Server.DbConfig, metabaseListenAddress, metabaseListenPort, metabaseUser, metabasePassword, metabaseDBPath, dockerGroup.Gid, metabaseContainerID, metabaseImage, metabaseContainerEnvironmentVariables)
mb, err := metabase.SetupMetabase(cli.cfg().API.Server.DbConfig, metabaseListenAddress,
metabaseListenPort, metabaseUser, metabasePassword, metabaseDBPath, dockerGroup.Gid,
metabaseContainerID, metabaseImage, metabaseContainerEnvironmentVariables)
if err != nil {
return err
}
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
11 changes: 6 additions & 5 deletions pkg/cwhub/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
// ItemState is used to keep the local state (i.e. at runtime) of an item.
// This data is not stored in the index, but is displayed with "cscli ... inspect".
type ItemState struct {
LocalPath string `json:"local_path,omitempty" yaml:"local_path,omitempty"`
LocalVersion string `json:"local_version,omitempty" yaml:"local_version,omitempty"`
LocalHash string `json:"local_hash,omitempty" yaml:"local_hash,omitempty"`
Installed bool `json:"installed"`
LocalPath string `json:"local_path,omitempty" yaml:"local_path,omitempty"`
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 5df5684

Please sign in to comment.