-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
address #332, make the pdf consumer play well with the rest of the bu…
…ild system
- Loading branch information
1 parent
7078b4b
commit a5b58fc
Showing
6 changed files
with
369 additions
and
79 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
FROM golang:latest | ||
FROM golang:1.22-bookworm | ||
|
||
WORKDIR /playwright | ||
RUN go mod init github.com/smithy-security/pdf-consumer && \ | ||
go get -u github.com/playwright-community/playwright-go && \ | ||
go run github.com/playwright-community/playwright-go/cmd/playwright@latest install --with-deps | ||
# Install playwright cli with right version for later use | ||
RUN go install github.com/playwright-community/playwright-go/cmd/[email protected] && \ | ||
apt-get update && apt-get install -y ca-certificates tzdata &&\ | ||
playwright install chromium --with-deps | ||
|
||
ENV PATH="${PATH}:/go/pkg/mod/github.com/playwright-community" | ||
COPY components/consumers/pdf/pdf /playwright/pdf | ||
COPY components/consumers/pdf/default.html /playwright/default.html | ||
ENTRYPOINT ["/playwright/pdf"] | ||
COPY components/consumers/pdf/linux/amd64/pdf /application/pdf | ||
COPY components/consumers/pdf/default.html /application/default.html | ||
WORKDIR /application | ||
ENTRYPOINT ["/application/pdf"] |
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,22 @@ | ||
.PHONY: container publish | ||
|
||
CONTAINER_REPO= | ||
SMITHY_VERSION= | ||
SOURCE_CODE_REPO= | ||
PRODUCER_AGGREGATOR_BASE_IMAGE=$(shell test -e .custom_image && cat .custom_image || echo "scratch") | ||
|
||
DOCKER=docker | ||
|
||
container: | ||
$(eval workdir:=$(shell mktemp -d /tmp/pdf.XXXXXX)) | ||
mkdir -p ${workdir}/components/consumers && \ | ||
cp -r ../../../bin/components/consumers/pdf ${workdir}/components/consumers && \ | ||
cp default.html ${workdir}/components/consumers/pdf && \ | ||
$(DOCKER) build --tag $(CONTAINER_REPO)/components/consumers/pdf:$(SMITHY_VERSION) \ | ||
--file Dockerfile \ | ||
$$([ "${SOURCE_CODE_REPO}" != "" ] && echo "--label=org.opencontainers.image.source=${SOURCE_CODE_REPO}" ) \ | ||
${workdir} 1>&2 && \ | ||
rm -rf ${workdir} | ||
|
||
publish: | ||
$(DOCKER) push $(CONTAINER_REPO)/components/consumers/pdf:$(SMITHY_VERSION) 1>&2 |
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,62 @@ | ||
// Package main of the pdf consumer implements a simple consumer for | ||
// applying a go-template to a smithy scan, converting the result to pdf and then | ||
// uploading the result to the S3 bucket passed as an argument | ||
// the consumer expects the environment variables | ||
// AWS_ACCESS_KEY_ID | ||
// AWS_SECRET_ACCESS_KEY | ||
// to be set along with the "bucket" and "region" arguments to be passed | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
v1 "github.com/smithy-security/smithy/api/proto/v1" | ||
|
||
playwright "github.com/smithy-security/smithy/pkg/playwright/mock" | ||
s3mock "github.com/smithy-security/smithy/pkg/s3/mock" | ||
"github.com/smithy-security/smithy/pkg/testdata" | ||
) | ||
|
||
func Test_run(t *testing.T) { | ||
mockClient, err := playwright.NewMockClient() | ||
require.NoError(t, err) | ||
|
||
pdfCalled := false | ||
expected := []byte("this is a pdf") | ||
mockClient.GetPDFOfPageCallBack = func(s1, s2 string) ([]byte, error) { | ||
pdfCalled = true | ||
return expected, nil | ||
} | ||
|
||
mockS3Client, err := s3mock.NewMockClient("") | ||
require.NoError(t, err) | ||
s3Called := false | ||
mockS3Client.UpsertCallback = func(s1, s2 string, b []byte) error { | ||
s3Called = true | ||
return nil | ||
} | ||
|
||
err = run([]v1.EnrichedLaunchToolResponse{testdata.EnrichedLaunchToolResponse}, mockClient, mockS3Client) | ||
require.NoError(t, err) | ||
require.True(t, pdfCalled) | ||
require.True(t, s3Called) | ||
|
||
} | ||
|
||
func Test_buildPdf(t *testing.T) { | ||
mockClient, err := playwright.NewMockClient() | ||
require.NoError(t, err) | ||
|
||
called := false | ||
expected := []byte("this is a pdf") | ||
mockClient.GetPDFOfPageCallBack = func(s1, s2 string) ([]byte, error) { | ||
called = true | ||
return expected, nil | ||
} | ||
_, result, err := buildPdf([]v1.EnrichedLaunchToolResponse{testdata.EnrichedLaunchToolResponse}, mockClient) | ||
require.NoError(t, err) | ||
require.Equal(t, called, true) | ||
require.Equal(t, result, expected) | ||
} |
Oops, something went wrong.