-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: felipecruz91 <[email protected]>
- Loading branch information
1 parent
21141f3
commit 6f7be4c
Showing
2 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package mocks | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/atomist-skills/go-skill" | ||
"github.com/atomist-skills/go-skill/policy/types" | ||
) | ||
|
||
const ( | ||
ImageDetailsQueryName = "image-details-by-digest" | ||
|
||
ImageDetailsQuery = ` | ||
query ($context: Context!, $digest: String!, $platform: ImagePlatform!) { | ||
imageDetailsByDigest( | ||
context: $context | ||
digest: $digest | ||
platform: $platform | ||
) { | ||
digest | ||
baseImage { | ||
digest | ||
repository { | ||
hostName | ||
repoName | ||
} | ||
tags { | ||
name | ||
current | ||
} | ||
} | ||
baseImageTag { | ||
name | ||
current | ||
} | ||
} | ||
} | ||
` | ||
) | ||
|
||
type ( | ||
GqlImagePlatform struct { | ||
Architecture string `json:"architecture"` | ||
Os string `json:"os"` | ||
Variant string `json:"variant,omitempty"` | ||
} | ||
|
||
Repository struct { | ||
HostName string `json:"hostName" edn:"hostName"` | ||
RepoName string `json:"repoName" edn:"repoName"` | ||
} | ||
|
||
Tag struct { | ||
Name string `json:"name" edn:"name"` | ||
Current bool `json:"current" edn:"current"` | ||
} | ||
|
||
BaseImage struct { | ||
Digest string `json:"digest" edn:"digest"` | ||
Repository Repository `json:"repository" edn:"repository"` | ||
Tags []Tag `json:"tags" edn:"tags"` | ||
} | ||
|
||
ImageDetailsByDigest struct { | ||
Digest string `json:"digest" edn:"digest"` | ||
BaseImage *BaseImage `json:"baseImage" edn:"baseImage"` | ||
BaseImageTag *Tag `json:"baseImageTag" edn:"baseImageTag"` | ||
} | ||
|
||
ImageDetailsByDigestResponse struct { | ||
ImageDetailsByDigest *ImageDetailsByDigest `json:"imageDetailsByDigest" edn:"imageDetailsByDigest"` | ||
} | ||
) | ||
|
||
func MockImageDetailsByDigest(ctx context.Context, req skill.RequestContext, sb *types.SBOM) (ImageDetailsByDigestResponse, error) { | ||
req.Log.Info("Building local evaluation mocks for image details by digest") | ||
|
||
var tags []Tag | ||
for _, t := range sb.Source.Image.Details.Tags { | ||
tags = append(tags, Tag{ | ||
Name: t.Name, | ||
Current: t.Current, | ||
}) | ||
} | ||
|
||
repo := parseFromReference(sb.Source.Provenance.BaseImage.Name) | ||
|
||
return ImageDetailsByDigestResponse{ | ||
ImageDetailsByDigest: &ImageDetailsByDigest{ | ||
Digest: sb.Source.Image.Digest, | ||
BaseImage: &BaseImage{ | ||
Digest: sb.Source.Provenance.BaseImage.Digest, | ||
Repository: Repository{ | ||
HostName: repo.Host, | ||
RepoName: repo.Repository, | ||
}, | ||
Tags: tags, | ||
}, | ||
}, | ||
}, nil | ||
} |