Skip to content

Commit

Permalink
convert the pdf consumer into the new SDK
Browse files Browse the repository at this point in the history
add the instance ID to the report name

formatting

formatting

fix tests
  • Loading branch information
dlicheva committed Jan 24, 2025
1 parent 42d477e commit cbb672d
Show file tree
Hide file tree
Showing 17 changed files with 1,012 additions and 1,131 deletions.
12 changes: 11 additions & 1 deletion new-components/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
reporter:
json-logger-reporter:
build:
context: .
dockerfile: Dockerfile
Expand All @@ -12,6 +12,16 @@ services:
depends_on:
enricher:
condition: service_completed_successfully
pdf-reporter:
build:
context: reporters/pdf
dockerfile: Dockerfile
platform: linux/amd64
env_file:
- reporters/pdf/.env
depends_on:
enricher:
condition: service_completed_successfully
enricher:
build:
context: .
Expand Down
9 changes: 9 additions & 0 deletions new-components/reporters/pdf/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SMITHY_INSTANCE_ID=8d719c1c-c569-4078-87b3-4951bd4012ee
SMITHY_LOG_LEVEL=debug
AWS_ACCESS_KEY_ID=''
AWS_SECRET_ACCESS_KEY=''
BUCKET_NAME='pdf-consumer-test'
BUCKET_REGION='eu-north-1'
SKIP_S3_UPLOAD=false
SMITHY_STORE_TYPE=postgresql
SMITHY_REMOTE_STORE_POSTGRES_DSN="postgresql://smithy:smithy1234@findings-db:5432/findings-db?sslmode=disable&connect_timeout=10"
20 changes: 20 additions & 0 deletions new-components/reporters/pdf/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.23.3 AS builder
COPY . /workdir
WORKDIR /workdir
# Install Playwright CLI with the correct version
RUN go install github.com/playwright-community/playwright-go/cmd/[email protected]
# Build your Go application
RUN GOOS=linux GOARCH=amd64 go build -o /bin/reporter cmd/main.go

# Stage 3: Final image
FROM ubuntu:22.04

COPY --from=builder /bin/reporter /
COPY --from=builder /go/ /go/

RUN apt-get update
RUN apt-get install -y ca-certificates tzdata
RUN ./go/bin/playwright install chromium --with-deps
RUN rm -rf /var/lib/apt/lists/*

CMD ["/reporter"]
39 changes: 39 additions & 0 deletions new-components/reporters/pdf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# PDF

This component implements
a [reporter](https://github.com/smithy-security/smithy/blob/main/sdk/component/component.go)
that prints vulnerability findings into a PDF and uploads it to an AWS
S3 bucket.

## Environment variables

The component uses environment variables for configuration.

It requires the component
environment variables defined
[here](https://github.com/smithy-security/smithy/blob/main/sdk/README.md#component)
as the following:

| Environment Variable | Type | Required | Default | Description |
|-----------------------|--------|----------|---------|----------------------------------------------------------------------|
| AWS\_ACCESS\_KEY\_ID | string | yes | - | Your S3 access key ID for a user that has write access to the bucket |
| AWS\_SECRET\_ACCESS\_KEY | string | yes | - | Your S3 access key for a user that has write access to the bucket |
| BUCKET\_NAME | string | yes | - | Your S3 bucket name, e.g. "test-bucket" |
| BUCKET\_REGION | string | yes | - | Your S3 bucket region, e.g. "us-west-1" |

On AWS, you will need a new IAM user with programmatic access and
with write permissions for your S3 bucket.

## How to run

Execute:

```shell
docker-compose up --build --force-recreate --remove-orphans
```

Then shutdown with:

```shell
docker-compose down --rmi all
```
40 changes: 40 additions & 0 deletions new-components/reporters/pdf/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"context"
"log"
"time"

"github.com/go-errors/errors"

"github.com/smithy-security/smithy/new-components/reporters/pdf/internal/reporter"
"github.com/smithy-security/smithy/sdk/component"
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

if err := Main(ctx); err != nil {
log.Fatalf("unexpected error: %v", err)
}
}

func Main(ctx context.Context, opts ...component.RunnerOption) error {
conf, err := reporter.NewConf(nil)
if err != nil {
return errors.Errorf("could not create new configuration: %w", err)
}

opts = append(opts, component.RunnerWithComponentName("pdf"))

if err := component.RunReporter(
ctx,
reporter.NewReporter(conf),
opts...,
); err != nil {
return errors.Errorf("could not run reporter: %w", err)
}

return nil
}
11 changes: 11 additions & 0 deletions new-components/reporters/pdf/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
reporter:
build:
context: .
dockerfile: Dockerfile
args:
- COMPONENT_PATH=reporters/pdf
- COMPONENT_BINARY_SOURCE_PATH=cmd/main.go
platform: linux/amd64
env_file:
- .env
Loading

0 comments on commit cbb672d

Please sign in to comment.