Skip to content

Commit 9f7731e

Browse files
committed
fix: removed duplicate structures from service.go and moved them to pkg/common
Signed-off-by: Ana-Roberta Lisca <ana.kagome@yahoo.com> Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com>
1 parent 6e6ffe8 commit 9f7731e

18 files changed

Lines changed: 707 additions & 721 deletions

File tree

pkg/cli/client.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ func (p *requestsPool) doJob(ctx context.Context, job *httpJob) {
217217
p.outputCh <- stringResult{"", err}
218218
}
219219

220+
verbose := *job.config.verbose
221+
220222
switch header.Get("Content-Type") {
221223
case ispec.MediaTypeImageManifest:
222224
image, err := fetchImageManifestStruct(ctx, job)
@@ -230,7 +232,7 @@ func (p *requestsPool) doJob(ctx context.Context, job *httpJob) {
230232
}
231233
platformStr := getPlatformStr(image.Manifests[0].Platform)
232234

233-
str, err := image.string(*job.config.outputFormat, len(job.imageName), len(job.tagName), len(platformStr))
235+
str, err := image.string(*job.config.outputFormat, len(job.imageName), len(job.tagName), len(platformStr), verbose)
234236
if err != nil {
235237
if isContextDone(ctx) {
236238
return
@@ -258,7 +260,7 @@ func (p *requestsPool) doJob(ctx context.Context, job *httpJob) {
258260

259261
platformStr := getPlatformStr(image.Manifests[0].Platform)
260262

261-
str, err := image.string(*job.config.outputFormat, len(job.imageName), len(job.tagName), len(platformStr))
263+
str, err := image.string(*job.config.outputFormat, len(job.imageName), len(job.tagName), len(platformStr), verbose)
262264
if err != nil {
263265
if isContextDone(ctx) {
264266
return
@@ -300,7 +302,7 @@ func fetchImageIndexStruct(ctx context.Context, job *httpJob) (*imageStruct, err
300302

301303
imageSize := indexSize
302304

303-
manifestList := make([]manifestStruct, 0, len(indexContent.Manifests))
305+
manifestList := make([]common.ManifestSummary, 0, len(indexContent.Manifests))
304306

305307
for _, manifestDescriptor := range indexContent.Manifests {
306308
manifest, err := fetchManifestStruct(ctx, job.imageName, manifestDescriptor.Digest.String(),
@@ -312,7 +314,7 @@ func fetchImageIndexStruct(ctx context.Context, job *httpJob) (*imageStruct, err
312314
imageSize += int64(atoiWithDefault(manifest.Size, 0))
313315

314316
if manifestDescriptor.Platform != nil {
315-
manifest.Platform = platform{
317+
manifest.Platform = common.Platform{
316318
Os: manifestDescriptor.Platform.OS,
317319
Arch: manifestDescriptor.Platform.Architecture,
318320
Variant: manifestDescriptor.Platform.Variant,
@@ -333,7 +335,6 @@ func fetchImageIndexStruct(ctx context.Context, job *httpJob) (*imageStruct, err
333335
Manifests: manifestList,
334336
Size: strconv.FormatInt(imageSize, 10),
335337
IsSigned: isIndexSigned,
336-
verbose: *job.config.verbose,
337338
}, nil
338339
}
339340

@@ -357,18 +358,17 @@ func fetchImageManifestStruct(ctx context.Context, job *httpJob) (*imageStruct,
357358
Tag: job.tagName,
358359
Digest: manifest.Digest,
359360
MediaType: ispec.MediaTypeImageManifest,
360-
Manifests: []manifestStruct{
361+
Manifests: []common.ManifestSummary{
361362
manifest,
362363
},
363364
Size: manifest.Size,
364365
IsSigned: manifest.IsSigned,
365-
verbose: *job.config.verbose,
366366
}, nil
367367
}
368368

369369
func fetchManifestStruct(ctx context.Context, repo, manifestReference string, searchConf searchConfig,
370370
username, password string,
371-
) (manifestStruct, error) {
371+
) (common.ManifestSummary, error) {
372372
manifestResp := ispec.Manifest{}
373373

374374
URL := fmt.Sprintf("%s/v2/%s/manifests/%s",
@@ -378,10 +378,10 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se
378378
*searchConf.verifyTLS, *searchConf.debug, &manifestResp, searchConf.resultWriter)
379379
if err != nil {
380380
if isContextDone(ctx) {
381-
return manifestStruct{}, context.Canceled
381+
return common.ManifestSummary{}, context.Canceled
382382
}
383383

384-
return manifestStruct{}, err
384+
return common.ManifestSummary{}, err
385385
}
386386

387387
manifestDigest := header.Get("docker-content-digest")
@@ -390,10 +390,10 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se
390390
configContent, err := fetchConfig(ctx, repo, configDigest, searchConf, username, password)
391391
if err != nil {
392392
if isContextDone(ctx) {
393-
return manifestStruct{}, context.Canceled
393+
return common.ManifestSummary{}, context.Canceled
394394
}
395395

396-
return manifestStruct{}, err
396+
return common.ManifestSummary{}, err
397397
}
398398

399399
opSys := ""
@@ -420,23 +420,23 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se
420420

421421
manifestSize, err := strconv.ParseInt(header.Get("Content-Length"), 10, 64)
422422
if err != nil {
423-
return manifestStruct{}, err
423+
return common.ManifestSummary{}, err
424424
}
425425

426426
var imageSize int64
427427

428428
imageSize += manifestResp.Config.Size
429429
imageSize += manifestSize
430430

431-
layers := []layer{}
431+
layers := []common.LayerSummary{}
432432

433433
for _, entry := range manifestResp.Layers {
434434
imageSize += entry.Size
435435

436436
layers = append(
437437
layers,
438-
layer{
439-
Size: entry.Size,
438+
common.LayerSummary{
439+
Size: fmt.Sprintf("%v", entry.Size),
440440
Digest: entry.Digest.String(),
441441
},
442442
)
@@ -445,11 +445,11 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se
445445
isSigned := isCosignSigned(ctx, repo, manifestDigest, searchConf, username, password) ||
446446
isNotationSigned(ctx, repo, manifestDigest, searchConf, username, password)
447447

448-
return manifestStruct{
448+
return common.ManifestSummary{
449449
ConfigDigest: configDigest,
450450
Digest: manifestDigest,
451451
Layers: layers,
452-
Platform: platform{Os: opSys, Arch: arch, Variant: variant},
452+
Platform: common.Platform{Os: opSys, Arch: arch, Variant: variant},
453453
Size: strconv.FormatInt(imageSize, 10),
454454
IsSigned: isSigned,
455455
}, nil

pkg/cli/discover.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type schemaList struct {
2525
} `json:"queryType"` //nolint:tagliatelle // graphQL schema
2626
} `json:"__schema"` //nolint:tagliatelle // graphQL schema
2727
} `json:"data"`
28-
Errors []common.ErrorGraphQL `json:"errors"`
28+
Errors []common.ErrorGQL `json:"errors"`
2929
}
3030

3131
func containsGQLQuery(queryList []field, query string) bool {

0 commit comments

Comments
 (0)