MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / ListNetworks

Method ListNetworks

server-source-code/internal/store/docker.go:669–726  ·  view source on GitHub ↗

ListNetworks returns networks with host info.

(ctx context.Context, params NetworkListParams)

Source from the content-addressed store, hash-verified

667
668// ListNetworks returns networks with host info.
669func (s *DockerStore) ListNetworks(ctx context.Context, params NetworkListParams) ([]NetworkWithHost, int, error) {
670 d := s.db.DB(ctx)
671 skip, take := validatePagination(params.Page, params.Limit, 10000)
672
673 arg := db.ListNetworksParams{Limit: safeconv.ClampToInt32(take), Offset: safeconv.ClampToInt32(skip)}
674 if params.Driver != "" {
675 arg.Driver = &params.Driver
676 }
677 if params.Search != "" {
678 arg.Search = &params.Search
679 }
680
681 countArg := db.CountNetworksParams{}
682 if params.Driver != "" {
683 countArg.Driver = &params.Driver
684 }
685 if params.Search != "" {
686 countArg.Search = &params.Search
687 }
688
689 total, err := d.Queries.CountNetworks(ctx, countArg)
690 if err != nil {
691 return nil, 0, err
692 }
693
694 networks, err := d.Queries.ListNetworks(ctx, arg)
695 if err != nil {
696 return nil, 0, err
697 }
698
699 if len(networks) == 0 {
700 return []NetworkWithHost{}, int(total), nil
701 }
702
703 hostIDs := make([]string, len(networks))
704 for i := range networks {
705 hostIDs[i] = networks[i].HostID
706 }
707
708 hosts, err := d.Queries.GetDockerHostsMinimalByIDs(ctx, hostIDs)
709 if err != nil {
710 return nil, 0, err
711 }
712 hostMap := make(map[string]*HostInfo)
713 for i := range hosts {
714 h := dockerHostRowToHostInfo(hosts[i])
715 hostMap[h.ID] = h
716 }
717
718 out := make([]NetworkWithHost, len(networks))
719 for i := range networks {
720 out[i] = NetworkWithHost{
721 DockerNetwork: dbDockerNetworkToModel(networks[i]),
722 Hosts: hostMap[networks[i].HostID],
723 }
724 }
725 return out, int(total), nil
726}

Callers

nothing calls this directly

Calls 7

validatePaginationFunction · 0.85
dockerHostRowToHostInfoFunction · 0.85
dbDockerNetworkToModelFunction · 0.85
DBMethod · 0.65
CountNetworksMethod · 0.65
ListNetworksMethod · 0.65

Tested by

no test coverage detected