Skip to content

harden entrygroups #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions entry_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

func (e *entryGroups) get(containerID string) (*avahi.EntryGroup, func(), error) {
commit := func() {
defer e.mutex.Unlock()

Check warning on line 28 in entry_groups.go

View check run for this annotation

Codecov / codecov/patch

entry_groups.go#L27-L28

Added lines #L27 - L28 were not covered by tests
empty, err := e.groups[containerID].IsEmpty()
if err != nil {
log.Logf(log.PriErr, "checking whether Avahi entry group is empty: %v", err)
Expand All @@ -35,18 +37,18 @@
log.Logf(log.PriErr, "error committing: %v", err)
}
}

e.mutex.Unlock()
}

e.mutex.Lock()
if _, ok := e.groups[containerID]; !ok {
eg, err := e.avahiServer.EntryGroupNew()
entryGroup, err := e.avahiServer.EntryGroupNew()

Check warning on line 44 in entry_groups.go

View check run for this annotation

Codecov / codecov/patch

entry_groups.go#L44

Added line #L44 was not covered by tests
if err != nil {
return nil, commit, fmt.Errorf("error creating new entry group: %w", err)
e.mutex.Unlock()

return nil, func() {}, fmt.Errorf("error creating new entry group: %w", err)

Check warning on line 48 in entry_groups.go

View check run for this annotation

Codecov / codecov/patch

entry_groups.go#L46-L48

Added lines #L46 - L48 were not covered by tests
}

e.groups[containerID] = eg
e.groups[containerID] = entryGroup

Check warning on line 51 in entry_groups.go

View check run for this annotation

Codecov / codecov/patch

entry_groups.go#L51

Added line #L51 was not covered by tests
}

return e.groups[containerID], commit, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c Container) Services() map[string]uint16 {
continue
}

//nolint:mnd,gomnd
//nolint:mnd
if portNumber > 65535 {
log.Logf(log.PriErr, "Port number %d is too large", portNumber)

Expand Down
6 changes: 3 additions & 3 deletions internal/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"os"
"testing"

"github.com/docker/docker/api/types"
docker_container "github.com/docker/docker/api/types/container"
"ldddns.arnested.dk/internal/container"
)

func containerJSON() (*types.ContainerJSON, error) {
func containerJSON() (*docker_container.InspectResponse, error) {
jsonFile, err := os.Open("../../testdata/container.json")
if err != nil {
return nil, fmt.Errorf("opening JSON test data: %w", err)
Expand All @@ -25,7 +25,7 @@ func containerJSON() (*types.ContainerJSON, error) {
}

// we initialize our Users array
var containerJSON *types.ContainerJSON
var containerJSON *docker_container.InspectResponse

err = json.Unmarshal(byteValue, &containerJSON)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/hostname/hostname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"os"
"testing"

"github.com/docker/docker/api/types"
docker_container "github.com/docker/docker/api/types/container"
"ldddns.arnested.dk/internal/container"
"ldddns.arnested.dk/internal/hostname"
)

func containerJSON() (*types.ContainerJSON, error) {
func containerJSON() (*docker_container.InspectResponse, error) {
jsonFile, err := os.Open("../../testdata/container.json")
if err != nil {
return nil, fmt.Errorf("opening JSON test data: %w", err)
Expand All @@ -26,7 +26,7 @@ func containerJSON() (*types.ContainerJSON, error) {
}

// we initialize our Users array
var containerJSON *types.ContainerJSON
var containerJSON *docker_container.InspectResponse

err = json.Unmarshal(byteValue, &containerJSON)
if err != nil {
Expand Down