docraptor 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.docker_env.list +2 -0
  3. data/.docker_mounts.list +4 -0
  4. data/.generator-revision +1 -1
  5. data/.gitlab-ci.yml +1 -1
  6. data/.openapi-generator/FILES +5 -0
  7. data/.openapi-generator/VERSION +1 -1
  8. data/.openapi-generator-ignore +0 -10
  9. data/.review/generated_files/README.md +6 -5
  10. data/.review/generated_files/docs/AsyncDoc.md +18 -0
  11. data/.review/generated_files/docs/Doc.md +50 -0
  12. data/.review/generated_files/docs/DocApi.md +503 -0
  13. data/.review/generated_files/docs/DocStatus.md +28 -0
  14. data/.review/generated_files/docs/PrinceOptions.md +82 -0
  15. data/.review/generated_files/spec/api/doc_api_spec.rb +112 -0
  16. data/.review/generated_files/spec/api_client_spec.rb +228 -0
  17. data/.review/generated_files/spec/configuration_spec.rb +42 -0
  18. data/.review/generated_files/spec/models/async_doc_spec.rb +34 -0
  19. data/.review/generated_files/spec/models/doc_spec.rb +138 -0
  20. data/.review/generated_files/spec/models/doc_status_spec.rb +64 -0
  21. data/.review/generated_files/spec/models/prince_options_spec.rb +234 -0
  22. data/.review/generated_files/spec/spec_helper.rb +111 -0
  23. data/.runtime-environments +3 -0
  24. data/.travis.yml +2 -5
  25. data/CHANGELOG.md +3 -0
  26. data/README.md +1 -1
  27. data/docraptor.gemspec +1 -1
  28. data/docraptor.yaml +281 -283
  29. data/gemfiles/Gemfile.3.1.lock +72 -0
  30. data/gemfiles/Gemfile.3.2.lock +72 -0
  31. data/gemfiles/Gemfile.3.3.lock +72 -0
  32. data/generator-config.json +1 -1
  33. data/lib/docraptor/api/doc_api.rb +33 -13
  34. data/lib/docraptor/api_client.rb +1 -1
  35. data/lib/docraptor/api_error.rb +2 -1
  36. data/lib/docraptor/configuration.rb +19 -3
  37. data/lib/docraptor/models/async_doc.rb +1 -1
  38. data/lib/docraptor/models/doc.rb +1 -6
  39. data/lib/docraptor/models/doc_status.rb +1 -1
  40. data/lib/docraptor/models/prince_options.rb +49 -10
  41. data/lib/docraptor/version.rb +2 -2
  42. data/lib/docraptor.rb +1 -1
  43. data/script/docker +21 -4
  44. data/script/generate_language +26 -4
  45. data/script/inside_container/test +52 -3
  46. data/script/post_generate_language +1 -3
  47. data/script/release +13 -0
  48. data/test/iframes_default.rb +40 -0
  49. data/test/iframes_false.rb +40 -0
  50. data/test/iframes_true.rb +40 -0
  51. data/test/prince_options.rb +45 -0
  52. data/test/xlsx.rb +6 -2
  53. metadata +32 -6
data/script/docker CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/bin/bash
2
2
  set -e
3
+ [[ "$TRACE" == "true" ]] && set -x
3
4
  cd "$(dirname "$0")/.."
4
5
 
5
6
  OPTIND=1
@@ -24,16 +25,32 @@ if [[ "$image" == "" ]]; then
24
25
  echo "docker image (-i) unset, defaulting to: $image"
25
26
  fi
26
27
 
28
+ if ! docker pull "$image"; then
29
+ echo "Pulling the latest version of ${image} failed, but we'll continue in"
30
+ echo "the hopes that there's a previous version of the container available."
31
+ echo "This probably isn't an issue unless you really want to verify"
32
+ echo "everything works with a :latest container image."
33
+ fi
34
+
27
35
  command="$1"
28
36
 
29
- cache_dir="$(pwd)/tmp/cache_${image}"
30
- mkdir -p "$cache_dir"
37
+ mounts=()
38
+ while IFS=':' read -r source target; do
39
+ # Create the directory if it's not a special/magic path (like for ssh)
40
+ mkdir -p -m 700 "$source" &> /dev/null || true
41
+
42
+ mounts+=(--volume)
43
+ mounts+=("${source}:${target}")
44
+
45
+ # Can't pipe to the while loop because that causes a subshell, which means
46
+ # the variables set in the loop aren't available outside of it.
47
+ done < <(eval echo "\"$(grep -v '^#' .docker_mounts.list)\"")
31
48
 
32
49
  set -x
33
- docker run --pull=always -it --rm \
50
+ docker run -it --rm \
34
51
  --env-file .docker_env.list \
35
52
  --env RUNTIME_ENV="${image}" \
36
53
  --mount type=bind,source="$(pwd)",target=/app \
37
- --mount type=bind,source="${cache_dir}",target=/app/tmp/cache \
54
+ "${mounts[@]}" \
38
55
  "$image" \
39
56
  "$command"
@@ -1,5 +1,6 @@
1
1
  #!/bin/bash
2
2
  set -e
3
+ [[ "$TRACE" == "true" ]] && set -x
3
4
  cd "$(dirname "$0")/.."
4
5
 
5
6
  LANGUAGE="$(cat .generator-language-identifier)"
@@ -22,10 +23,18 @@ fi
22
23
  echo "Facilitating generated content review"
23
24
  tmp_dir=".review/tmp"
24
25
  review_root=".review/generated_files"
26
+ # Clear the tmp_dir, where we'll temporarily store our files so they aren't
27
+ # overwritten by the generated files.
25
28
  rm -rf "$tmp_dir"
26
29
  (cd "$review_root" && find . -type f) | while read file_path; do
27
- mkdir -p "$(dirname "${tmp_dir}/$file_path")"
28
- mv -v "$file_path" "${tmp_dir}/$file_path"
30
+ # Move our file out of the way so it doesn't get overwritten by the generated
31
+ # file, but only if the file exists. Some files, like the generated docs and
32
+ # tests, aren't useful to users to we generally remove them, but we still
33
+ # want to facilitate review of these generated files.
34
+ if [ -e "$file_path" ]; then
35
+ mkdir -p "$(dirname "${tmp_dir}/$file_path")"
36
+ mv -v "$file_path" "${tmp_dir}/$file_path"
37
+ fi
29
38
  done
30
39
 
31
40
  ./script/swagger generate \
@@ -41,6 +50,19 @@ fi
41
50
  # See .review/README.md
42
51
  echo "Facilitating generated content review"
43
52
  (cd "$review_root" && find . -type f) | while read file_path; do
44
- mv -v "$file_path" "$review_root/$file_path"
45
- mv -v "${tmp_dir}/$file_path" "$file_path"
53
+ # Update $review_root to match the generated files.
54
+ if [ -e "$file_path" ]; then
55
+ # Move the newly generated file into the review directory so we'll be able to
56
+ # see it in the diff.
57
+ mv -v "$file_path" "$review_root/$file_path"
58
+ else
59
+ # If the file doesn't exist, then it was removed by the generator, so we
60
+ # should remove it from the review directory as well.
61
+ rm -v "$review_root/$file_path"
62
+ fi
63
+ # If we temporarily stored a file (meaning it existed before the generation)
64
+ # then move it back into place.
65
+ if [ -e "${tmp_dir}/$file_path" ]; then
66
+ mv -v "${tmp_dir}/$file_path" "$file_path"
67
+ fi
46
68
  done
@@ -2,6 +2,9 @@
2
2
  set -e
3
3
  cd "$(dirname "$0")/../.."
4
4
 
5
+ apt update
6
+ apt install poppler-utils -y
7
+
5
8
  # check dependencies
6
9
  ruby -v > /dev/null || (echo "ruby must be installed"; exit 1)
7
10
 
@@ -24,15 +27,61 @@ fi
24
27
 
25
28
  cd test
26
29
 
30
+
31
+ green() {
32
+ tput bold # bold text
33
+ tput setaf 2 # green text
34
+ echo -n "$@"
35
+ tput sgr0 # reset to default text
36
+ }
37
+ red() {
38
+ tput bold # bold text
39
+ tput setaf 1 # red text
40
+ echo -n "$@"
41
+ tput sgr0 # reset to default text
42
+ }
43
+
44
+
45
+ key_relative_path="tmp/.docraptor_key"
46
+ key_path="../$key_relative_path"
47
+
27
48
  # runs a test file with PASS/FAIL message
28
49
  run_test() {
29
- ruby $1 && echo "PASS $1" || (echo "FAIL $1"; exit 1)
50
+ test_success="true"
51
+ test_name="$1 ${2:-(without $key_relative_path)}"
52
+ if [[ "$DOCRAPTOR_KEY" == "" ]] && [ -f "$key_path" ]; then
53
+ (
54
+ export DOCRAPTOR_KEY="$(cat "$key_path")"
55
+ run_test $1 "(with $key_relative_path)"
56
+ ) || test_success="false"
57
+ fi
58
+
59
+ if ruby $1; then
60
+ echo "$(green PASS) $test_name"
61
+ else
62
+ test_success="false"
63
+ echo "$(red FAIL) $test_name"
64
+ fi
65
+
66
+ if [ $test_success == "true" ]; then
67
+ return 0
68
+ else
69
+ return 1
70
+ fi
30
71
  }
31
72
 
73
+ success="true"
74
+
32
75
  if [ "$1" == "" ]; then
33
76
  for test in $(ls *.rb); do
34
- run_test $test
77
+ run_test $test || success="false"
35
78
  done
36
79
  else
37
- run_test $1.rb
80
+ run_test $1.rb || success="false"
81
+ fi
82
+
83
+ if [ $success == "true" ]; then
84
+ exit 0
85
+ else
86
+ exit 1
38
87
  fi
@@ -1,10 +1,8 @@
1
1
  #!/bin/bash
2
2
  set -e
3
+ [[ "$TRACE" == "true" ]] && set -x
3
4
  cd "$(dirname "$0")/.."
4
5
 
5
- echo "Removing unnecessary generated specs..."
6
- rm -r spec
7
-
8
6
  echo "Removing trailing whitespace..."
9
7
  find lib -name "*.rb" -type f -exec sed -E -i '' 's/[[:space:]]+$//g' {} +
10
8
 
data/script/release ADDED
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+ set -e
3
+ [[ "$TRACE" == "true" ]] && set -x
4
+ cd "$(dirname "$0")/.."
5
+
6
+
7
+ if [[ "$INSIDE_DOCKER" != "true" ]]; then
8
+ git config --local user.email "$(git config --get user.email)"
9
+ exec script/docker "/app/script/$(basename "$0")"
10
+ fi
11
+
12
+ public_remote="$(git remote -v | grep -i 'git@github.com:DocRaptor/docraptor-ruby.git' | head -n 1 | cut -f1)"
13
+ rake "release[${public_remote}]"
@@ -0,0 +1,40 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+
4
+ DocRaptor.configure do |dr|
5
+ dr.username = ENV["DOCRAPTOR_KEY"] || "YOUR_API_KEY_HERE"
6
+ # dr.debugging = true
7
+ end
8
+
9
+ # TODO: Remove once pipeline 10 is public. At that point the try it out user
10
+ # will be able to use the iframes option, so this test will pass.
11
+ unless ENV["DOCRAPTOR_KEY"]
12
+ puts "Skipping #{$0} because DOCRAPTOR_KEY is not set."
13
+ exit(0)
14
+ end
15
+
16
+ $docraptor = DocRaptor::DocApi.new
17
+
18
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
19
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
20
+ output_payload = $docraptor.create_doc(
21
+ test: true,
22
+ document_content: <<~HTML,
23
+ <html><body>
24
+ <p>Baseline text</p>
25
+ <iframe src="https://docraptor-test-harness.herokuapp.com/public/index.html"></iframe>
26
+ </body></html>
27
+ HTML
28
+ name: output_file,
29
+ document_type: "pdf",
30
+ pipeline: "10",
31
+ # prince_options: { iframes: true },
32
+ )
33
+
34
+ File.write(output_file, output_payload)
35
+ output_type = `file -b #{output_file}`
36
+
37
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
38
+
39
+ text = `pdftotext #{output_file} -`
40
+ raise "Output shouldn't load iframe" if text !~ /Test/
@@ -0,0 +1,40 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+
4
+ DocRaptor.configure do |dr|
5
+ dr.username = ENV["DOCRAPTOR_KEY"] || "YOUR_API_KEY_HERE"
6
+ # dr.debugging = true
7
+ end
8
+
9
+ # TODO: Remove once pipeline 10 is public. At that point the try it out user
10
+ # will be able to use the iframes option, so this test will pass.
11
+ unless ENV["DOCRAPTOR_KEY"]
12
+ puts "Skipping #{$0} because DOCRAPTOR_KEY is not set."
13
+ exit(0)
14
+ end
15
+
16
+ $docraptor = DocRaptor::DocApi.new
17
+
18
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
19
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
20
+ output_payload = $docraptor.create_doc(
21
+ test: true,
22
+ document_content: <<~HTML,
23
+ <html><body>
24
+ <p>Baseline text</p>
25
+ <iframe src="https://docraptor-test-harness.herokuapp.com/public/index.html"></iframe>
26
+ </body></html>
27
+ HTML
28
+ name: output_file,
29
+ document_type: "pdf",
30
+ pipeline: "10",
31
+ prince_options: { iframes: false },
32
+ )
33
+
34
+ File.write(output_file, output_payload)
35
+ output_type = `file -b #{output_file}`
36
+
37
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
38
+
39
+ text = `pdftotext #{output_file} -`
40
+ raise "Output shouldn't load iframe" if text =~ /Test/
@@ -0,0 +1,40 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+
4
+ DocRaptor.configure do |dr|
5
+ dr.username = ENV["DOCRAPTOR_KEY"] || "YOUR_API_KEY_HERE"
6
+ # dr.debugging = true
7
+ end
8
+
9
+ # TODO: Remove once pipeline 10 is public. At that point the try it out user
10
+ # will be able to use the iframes option, so this test will pass.
11
+ unless ENV["DOCRAPTOR_KEY"]
12
+ puts "Skipping #{$0} because DOCRAPTOR_KEY is not set."
13
+ exit(0)
14
+ end
15
+
16
+ $docraptor = DocRaptor::DocApi.new
17
+
18
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
19
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
20
+ output_payload = $docraptor.create_doc(
21
+ test: true,
22
+ document_content: <<~HTML,
23
+ <html><body>
24
+ <p>Baseline text</p>
25
+ <iframe src="https://docraptor-test-harness.herokuapp.com/public/index.html"></iframe>
26
+ </body></html>
27
+ HTML
28
+ name: output_file,
29
+ document_type: "pdf",
30
+ pipeline: "10",
31
+ prince_options: { iframes: true },
32
+ )
33
+
34
+ File.write(output_file, output_payload)
35
+ output_type = `file -b #{output_file}`
36
+
37
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
38
+
39
+ text = `pdftotext #{output_file} -`
40
+ raise "Output shouldn't load iframe" if text !~ /Test/
@@ -0,0 +1,45 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+
4
+ DocRaptor.configure do |dr|
5
+ dr.username = "YOUR_API_KEY_HERE"
6
+ # dr.debugging = true
7
+ end
8
+
9
+ $docraptor = DocRaptor::DocApi.new
10
+
11
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
12
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
13
+
14
+ # Verify the test works as expected by confirming that this url will fail
15
+ # without prince_options[insecure]=true.
16
+ begin
17
+ $docraptor.create_doc(
18
+ test: true,
19
+ document_url: "https://expired.badssl.com/",
20
+ name: output_file,
21
+ document_type: "pdf",
22
+ )
23
+ rescue DocRaptor::ApiError => ex
24
+ expected_message = "SSL Error downloading document content from supplied url.";
25
+ if ex.message !~ /#{expected_message}/
26
+ raise "Wrong exception, expected: #{expected_message}, got: #{ex.message}"
27
+ end
28
+ end
29
+
30
+ # Verify prince_options works by testing a url that will fail without
31
+ # prince_options[insecure]=true.
32
+ output_payload = $docraptor.create_doc(
33
+ test: true,
34
+ document_url: "https://expired.badssl.com/",
35
+ name: output_file,
36
+ document_type: "pdf",
37
+ prince_options: {
38
+ insecure: true,
39
+ }
40
+ )
41
+
42
+ File.write(output_file, output_payload)
43
+ output_type = `file -b #{output_file}`
44
+
45
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
data/test/xlsx.rb CHANGED
@@ -21,7 +21,11 @@ output_payload = $docraptor.create_doc(
21
21
  File.write(output_file, output_payload)
22
22
  output_type = `file -b #{output_file}`
23
23
 
24
- # Older version of `file` only recognize it as a zip file
25
- if !output_type.start_with?("Microsoft OOXML") && !output_type.start_with?("Zip")
24
+ acceptable_output_types = [
25
+ "Microsoft Excel 2007+", # Newest versions of `file`
26
+ "Microsoft OOXML", # Older versions of `file`
27
+ "Zip archive data, at least v2.0 to extract", # Even older versions of `file`
28
+ ]
29
+ if !acceptable_output_types.include?(output_type.strip)
26
30
  raise "Output was not an XLSX: #{output_type.inspect}"
27
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docraptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Expected Behavior
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-15 00:00:00.000000000 Z
11
+ date: 2023-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -58,6 +58,7 @@ extensions: []
58
58
  extra_rdoc_files: []
59
59
  files:
60
60
  - ".docker_env.list"
61
+ - ".docker_mounts.list"
61
62
  - ".generator-language-identifier"
62
63
  - ".generator-revision"
63
64
  - ".github/pull_request_template.txt"
@@ -69,6 +70,19 @@ files:
69
70
  - ".review/README.md"
70
71
  - ".review/generated_files/.gitignore"
71
72
  - ".review/generated_files/README.md"
73
+ - ".review/generated_files/docs/AsyncDoc.md"
74
+ - ".review/generated_files/docs/Doc.md"
75
+ - ".review/generated_files/docs/DocApi.md"
76
+ - ".review/generated_files/docs/DocStatus.md"
77
+ - ".review/generated_files/docs/PrinceOptions.md"
78
+ - ".review/generated_files/spec/api/doc_api_spec.rb"
79
+ - ".review/generated_files/spec/api_client_spec.rb"
80
+ - ".review/generated_files/spec/configuration_spec.rb"
81
+ - ".review/generated_files/spec/models/async_doc_spec.rb"
82
+ - ".review/generated_files/spec/models/doc_spec.rb"
83
+ - ".review/generated_files/spec/models/doc_status_spec.rb"
84
+ - ".review/generated_files/spec/models/prince_options_spec.rb"
85
+ - ".review/generated_files/spec/spec_helper.rb"
72
86
  - ".rspec"
73
87
  - ".rubocop.yml"
74
88
  - ".runtime-environments"
@@ -88,6 +102,9 @@ files:
88
102
  - gemfiles/Gemfile.2.6.lock
89
103
  - gemfiles/Gemfile.2.7.lock
90
104
  - gemfiles/Gemfile.3.0.lock
105
+ - gemfiles/Gemfile.3.1.lock
106
+ - gemfiles/Gemfile.3.2.lock
107
+ - gemfiles/Gemfile.3.3.lock
91
108
  - generator-config.json
92
109
  - lib/docraptor.rb
93
110
  - lib/docraptor/api/doc_api.rb
@@ -107,6 +124,7 @@ files:
107
124
  - script/inside_container/README.md
108
125
  - script/inside_container/test
109
126
  - script/post_generate_language
127
+ - script/release
110
128
  - script/setup
111
129
  - script/swagger
112
130
  - script/test
@@ -115,15 +133,19 @@ files:
115
133
  - test/expire_hosted.rb
116
134
  - test/hosted_async.rb
117
135
  - test/hosted_sync.rb
136
+ - test/iframes_default.rb
137
+ - test/iframes_false.rb
138
+ - test/iframes_true.rb
118
139
  - test/invalid_async.rb
119
140
  - test/invalid_sync.rb
141
+ - test/prince_options.rb
120
142
  - test/sync.rb
121
143
  - test/xlsx.rb
122
144
  homepage: https://github.com/docraptor/docraptor-ruby
123
145
  licenses:
124
146
  - MIT
125
147
  metadata: {}
126
- post_install_message:
148
+ post_install_message:
127
149
  rdoc_options: []
128
150
  require_paths:
129
151
  - lib
@@ -138,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
160
  - !ruby/object:Gem::Version
139
161
  version: '0'
140
162
  requirements: []
141
- rubygems_version: 3.2.33
142
- signing_key:
163
+ rubygems_version: 3.5.0.dev
164
+ signing_key:
143
165
  specification_version: 4
144
166
  summary: A wrapper for the DocRaptor HTML to PDF/XLS service.
145
167
  test_files:
@@ -147,7 +169,11 @@ test_files:
147
169
  - test/expire_hosted.rb
148
170
  - test/hosted_async.rb
149
171
  - test/hosted_sync.rb
172
+ - test/iframes_default.rb
173
+ - test/iframes_false.rb
174
+ - test/iframes_true.rb
150
175
  - test/invalid_async.rb
151
176
  - test/invalid_sync.rb
177
+ - test/prince_options.rb
152
178
  - test/sync.rb
153
179
  - test/xlsx.rb