Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for serving the static assets in a report #140

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

bcspragu
Copy link
Collaborator

This PR adds a new /report/<analysis ID> endpoint that serves a report. Importantly, this is a server endpoint, our Nuxt client knows nothing about it.

That means to test it locally, you go to localhost:8081/report/<analysis ID>, and when deployed, it'll be https://pacta-api.dev.rmi.siliconally.dev/report/<analysis ID> IIRC. Since we share cookies between *.dev.rmi.siliconally.dev, this works fine.

The main thing missing from this PR is authz, which will be the next thing I do.

@bcspragu bcspragu requested a review from gbdubs January 13, 2024 06:35
NoTxn(context.Context) db.Tx

AnalysisArtifactsForAnalysis(tx db.Tx, id pacta.AnalysisID) ([]*pacta.AnalysisArtifact, error)
Blobs(tx db.Tx, ids []pacta.BlobID) (map[pacta.BlobID]*pacta.Blob, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're planning this for the next PR, if so great, but we'll need to generate Audit Logs here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, will do

s.logger.Error("path had no UUID prefix", zap.String("analysis_artifact_id", string(a.ID)), zap.String("blob_uri", uri), zap.String("blob_path", path))
continue
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One piece I don't love about this approach is that if N = number of assets in a given report, we read back N rows 2*N times to serve the report. I get that this is still linear in the # of DB calls made, it just seems really duplicative, since the returns for each of these DB calls is identical. I can't think of a simple way of sidestepping this property, but I don't love it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also didn't like that and considered doing a dumb in-mem cache of analysis ID -> artifacts, but the cardinality is low (e.g. 10-20 artifacts), and the loading speed isn't a problem. Can revisit if it becomes an issue.

return
}

func fileTypeToMIME(ft pacta.FileType) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is one good reason to have FT saved!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! As discussed, I'll update the parent PR to store unknown as 'unknown'

@bcspragu bcspragu force-pushed the brandon/serve-report branch from e2d50a5 to 41fedbc Compare January 16, 2024 02:48
This PR adds a new `/report/<analysis ID>` endpoint that serves a report. Importantly, this is a _server_ endpoint, our Nuxt client knows nothing about it.

That means to test it locally, you go to `localhost:8081/report/<analysis ID>`, and when deployed, it'll be `https://pacta-api.dev.rmi.siliconally.dev/report/<analysis ID>` IIRC. Since we share cookies between `*.dev.rmi.siliconally.dev`, this works fine.

The main thing missing from this PR is authz, which will be the next thing I do.
@bcspragu bcspragu force-pushed the brandon/serve-report branch from 41fedbc to 23940d7 Compare January 16, 2024 02:51
@bcspragu bcspragu changed the base branch from brandon/create-report to main January 16, 2024 02:51
@bcspragu bcspragu merged commit 6ccd470 into main Jan 16, 2024
2 checks passed
@bcspragu bcspragu deleted the brandon/serve-report branch January 16, 2024 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants