MCPcopy
hub / github.com/harness/harness / SearchPackagesProxyWrapper

Function SearchPackagesProxyWrapper

registry/app/pkg/base/wrapper.go:183–262  ·  view source on GitHub ↗
(
	ctx context.Context,
	registryDao store.RegistryRepository,
	f func(registry registrytypes.Registry, a pkg.Artifact, limit, offset int) response.Response,
	extractResponseDataFunc func(searchResponse response.Response) ([]interface{}, int64),
	info pkg.PackageArtifactInfo,
	limit int,
	offset int,
)

Source from the content-addressed store, hash-verified

181}
182
183func SearchPackagesProxyWrapper(
184 ctx context.Context,
185 registryDao store.RegistryRepository,
186 f func(registry registrytypes.Registry, a pkg.Artifact, limit, offset int) response.Response,
187 extractResponseDataFunc func(searchResponse response.Response) ([]interface{}, int64),
188 info pkg.PackageArtifactInfo,
189 limit int,
190 offset int,
191) ([]interface{}, int64, error) {
192 requestRepoKey := info.BaseArtifactInfo().RegIdentifier
193
194 // Get all registries (local + proxies) - Z = [x, p1, p2, p3...]
195 registries, skipped, err := filterRegs(ctx, registryDao, requestRepoKey, info, true)
196 if err != nil {
197 return nil, 0, err
198 }
199
200 // Pre-allocate slice for aggregated results (generic interface{})
201 var aggregatedResults []interface{}
202 var totalCount int64
203
204 currentOffset := offset
205 remainingLimit := limit
206
207 // Loop through each registry R in Z
208 for _, registry := range registries {
209 if remainingLimit <= 0 {
210 break
211 }
212
213 log.Ctx(ctx).Info().Msgf("Searching in Registry: %s, Type: %s", registry.Name, registry.Type)
214 art := GetArtifactRegistry(registry)
215 if art == nil {
216 log.Ctx(ctx).Warn().Msgf("No artifact registry found for: %s", registry.Name)
217 continue
218 }
219
220 // 1. Call f with remainingLimit and currentOffset
221 searchResponse := f(registry, art, remainingLimit, currentOffset)
222 if searchResponse.GetError() != nil {
223 log.Ctx(ctx).Warn().Msgf("Search failed for registry %s: %v", registry.Name, searchResponse.GetError())
224 continue
225 }
226
227 // Extract response data using the provided function
228 nativeResults, totalHits := extractResponseDataFunc(searchResponse)
229 resultsSize := len(nativeResults)
230 totalCount += totalHits
231
232 if resultsSize == 0 {
233 continue
234 }
235
236 // 2. Append search results (preserve native types)
237 aggregatedResults = append(aggregatedResults, nativeResults...)
238
239 // 3. Update currentOffset = max(0, currentOffset - registryResults.size)
240 currentOffset = max(0, currentOffset-resultsSize)

Callers 2

SearchPackageV2Method · 0.92
SearchPackageMethod · 0.92

Calls 10

IsEmptyFunction · 0.92
JoinWithSeparatorFunction · 0.92
filterRegsFunction · 0.85
GetArtifactRegistryFunction · 0.85
maxFunction · 0.85
MsgfMethod · 0.80
BaseArtifactInfoMethod · 0.65
InfoMethod · 0.65
WarnMethod · 0.65
GetErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…