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 encrypt route #496

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

vidschofelix
Copy link

First time even touching go. Implemented encryption of PDFs for qpdf and pdfcpu. Pdftk also supports encrypting, but behaviour was weird, so i dropped it for now.

Api description was extended, but no tests so far, because i have no idea how they work in go.

Please give feedback :)

Copy link
Collaborator

@gulien gulien left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! 😄

Don't forget to run make fmt.

You should also update some routes to offer the possibility to encrypt the resulting PDFs:

@@ -38,6 +38,9 @@ type PDFEngine interface {

// Convert converts the given PDF to a specific PDF format.
Convert(ctx context.Context, logger *zap.Logger, format, inputPath, outputPath string) error

//Encrypt one or more PDF Files with given passwords.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
//Encrypt one or more PDF Files with given passwords.
// Encrypt encrypts the given PDF.

pkg/modules/pdfengines/routes.go Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Merging #496 (094fc8e) into main (d8f3f85) will decrease coverage by 2.51%.
The diff coverage is 42.85%.

@@            Coverage Diff             @@
##             main     #496      +/-   ##
==========================================
- Coverage   93.77%   91.25%   -2.52%     
==========================================
  Files          35       36       +1     
  Lines        3050     3203     +153     
==========================================
+ Hits         2860     2923      +63     
- Misses        121      204      +83     
- Partials       69       76       +7     
Impacted Files Coverage Δ
pkg/gotenberg/mocks.go 85.71% <0.00%> (-14.29%) ⬇️
pkg/modules/libreoffice/pdfengine/pdfengine.go 92.85% <0.00%> (-7.15%) ⬇️
pkg/modules/pdfcpu/pdfcpu.go 66.66% <0.00%> (-33.34%) ⬇️
pkg/modules/pdfengines/multi.go 68.75% <0.00%> (-31.25%) ⬇️
pkg/modules/pdftk/pdftk.go 91.48% <0.00%> (-4.07%) ⬇️
pkg/modules/qpdf/qpdf.go 69.23% <0.00%> (-26.52%) ⬇️
pkg/modules/pdfengines/routes.go 75.47% <16.12%> (-24.53%) ⬇️
pkg/modules/chromium/chromium.go 91.92% <75.75%> (-1.11%) ⬇️
pkg/modules/chromium/stream.go 79.16% <79.16%> (ø)
pkg/modules/pdfengines/pdfengines.go 97.50% <100.00%> (+0.03%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vidschofelix
Copy link
Author

regarding the routes: is it possible (or a good idea) to pass the multiPDFEngines to the chrome/libre routes? not sure atm how to access the encrypt parts from within the chrome/libre routes

@gulien
Copy link
Collaborator

gulien commented Sep 14, 2022

Both the Chromium and LibreOffice modules have a PDFEngine:

For the Chromium module, you should update the convertURL method (it is used by other methods): https://github.com/gotenberg/gotenberg/blob/main/pkg/modules/chromium/routes.go#L327.

For the LibreOffice module, you should update the convertRoute method https://github.com/gotenberg/gotenberg/blob/main/pkg/modules/libreoffice/routes.go#L16.

Also, it seems the following packages do not have all required tests (I suspect most of them being "stupid" test but still):

Capture d’écran 2022-09-14 à 14 02 43

add encryption to all routes
tests
@vidschofelix
Copy link
Author

So i added encryption to every route that handles PDFs (all chromium, libreoffice and pdfengine). Restructured the openapi.yaml a little bit, so it's easier to maintain. Tested all routes locally. I hope i got all the tests, but it's hard to tell them all apart :D

@stale
Copy link

stale bot commented Nov 26, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Nov 26, 2022
@gulien gulien removed the wontfix This will not be worked on label Nov 28, 2022
@vidschofelix
Copy link
Author

any feedback?

@gulien
Copy link
Collaborator

gulien commented Nov 29, 2022

Hello @vidschofelix,

Sorry for the delay, but I don’t have enough time to properly review it.

There are many implementations available, so finding the correct interface for all modules is not straightforward.

Also, having an encrypt method will trigger a need for a decrypt route.

I keep this PR open until I find some time to work on it.

@vidschofelix
Copy link
Author

Ok, thank you :).

@gomespauloho
Copy link

It's a very useful feature, I hope I can use it soon.

@stale
Copy link

stale bot commented Mar 14, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Mar 14, 2023
@gulien gulien removed the wontfix This will not be worked on label Mar 14, 2023
@gulien gulien added enhancement New feature or request pdf-engines labels Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pdf-engines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants