Skip to content

Commit 06b4c4f

Browse files
authored
CCAP-138: Added OneDrive transfer support. (#4)
* Added OpenAPI documentation. * Updated class and module structure to be more accurate. * Added document transfer endpoint with support for url sources and onedrive destinations. * Added reusable response entities. * Added additional documentation for the API.
1 parent 8b51dba commit 06b4c4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1435
-30
lines changed

.github/config/rubocop_linter_action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ versions:
1515
- rubocop: 'latest'
1616
- rubocop-rake: 'latest'
1717
- rubocop-rspec: 'latest'
18+
- rubocop-factory_bot: 'latest'
1819

1920
# Description: RuboCop configuration file path relative to the workspace.
2021
# Valid options: A valid file path inside of the workspace.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Ignore local environment files
22
.env
33
*.env
4+
!sample.env
5+
coverage/
46

57
# Ignore Byebug command history file.
68
.byebug_history

.rspec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--require spec_helper.rb
2+
--color
3+
--format RSpec::Github::Formatter
4+
--format documentation

.rubocop.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
require:
2+
- rubocop-factory_bot
3+
- rubocop-rake
4+
- rubocop-rspec
5+
16
AllCops:
27
NewCops: enable
38
SuggestExtensions: true
9+
10+
# Transient properties get mistaken for associations in FactoryBot.
11+
# See https://github.com/rubocop/rubocop-factory_bot/issues/73
12+
FactoryBot/FactoryAssociationWithStrategy:
13+
Enabled: false
14+
15+
# Count multi-line hashes and arrays in examples as one line.
16+
RSpec/ExampleLength:
17+
CountAsOne:
18+
- array
19+
- hash
20+
21+
Metrics/BlockLength:
22+
AllowedMethods:
23+
# Exclude grape `resource` blocks.
24+
- resource

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ source 'https://rubygems.org'
44

55
gemspec
66

7+
# TODO: Move to gemspec once a new release has been cut.
8+
# See https://github.com/kklimuk/microsoft-graph-client/pull/4
9+
gem 'microsoft-graph-client', git: 'https://github.com/jamesiarmes/microsoft-graph-client.git', branch: 'non-hash-body'
10+
711
group :development do
812
gem 'rake', '~> 13.0'
913
gem 'rubocop', '~> 1.48'

Gemfile.lock

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1+
GIT
2+
remote: https://github.com/jamesiarmes/microsoft-graph-client.git
3+
revision: 206aa96ce1c4073b5c570accf1559af9c2e2e509
4+
branch: non-hash-body
5+
specs:
6+
microsoft-graph-client (0.1.3)
7+
httparty
8+
19
PATH
210
remote: .
311
specs:
412
document-transfer-service (0.1.0)
13+
adal (~> 1.0)
14+
faraday (~> 2.9)
515
grape (~> 2.0)
16+
grape-entity (~> 1.0)
17+
grape-swagger (~> 2.1)
18+
grape-swagger-entity (~> 0.5)
19+
httparty (~> 0.22)
620
rack (~> 3.0)
721
rackup (~> 2.1)
822
statsd-instrument (~> 3.7)
923

1024
GEM
1125
remote: https://rubygems.org/
1226
specs:
13-
activesupport (7.1.3.2)
27+
activesupport (7.1.3.4)
1428
base64
1529
bigdecimal
1630
concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -20,12 +34,17 @@ GEM
2034
minitest (>= 5.1)
2135
mutex_m
2236
tzinfo (~> 2.0)
37+
adal (1.0.0)
38+
jwt (~> 1.5)
39+
nokogiri (~> 1.6)
40+
uri_template (~> 0.7)
2341
ast (2.4.2)
2442
base64 (0.2.0)
2543
bigdecimal (3.1.8)
26-
builder (3.2.4)
27-
concurrent-ruby (1.2.3)
44+
builder (3.3.0)
45+
concurrent-ruby (1.3.1)
2846
connection_pool (2.4.1)
47+
csv (3.3.0)
2948
diff-lcs (1.5.1)
3049
docile (1.4.0)
3150
drb (2.2.1)
@@ -46,29 +65,59 @@ GEM
4665
zeitwerk (~> 2.6)
4766
factory_bot (6.4.6)
4867
activesupport (>= 5.0.0)
68+
faraday (2.9.1)
69+
faraday-net_http (>= 2.0, < 3.2)
70+
faraday-net_http (3.1.0)
71+
net-http
4972
grape (2.0.0)
5073
activesupport (>= 5)
5174
builder
5275
dry-types (>= 1.1)
5376
mustermann-grape (~> 1.0.0)
5477
rack (>= 1.3.0)
5578
rack-accept
79+
grape-entity (1.0.1)
80+
activesupport (>= 3.0.0)
81+
multi_json (>= 1.3.2)
82+
grape-swagger (2.1.0)
83+
grape (>= 1.7, < 3.0)
84+
rack-test (~> 2)
85+
grape-swagger-entity (0.5.4)
86+
grape-entity (~> 1)
87+
grape-swagger (~> 2)
88+
httparty (0.22.0)
89+
csv
90+
mini_mime (>= 1.0.0)
91+
multi_xml (>= 0.5.2)
5692
i18n (1.14.5)
5793
concurrent-ruby (~> 1.0)
5894
json (2.7.2)
95+
jwt (1.5.6)
5996
language_server-protocol (3.17.0.3)
60-
minitest (5.22.3)
97+
mini_mime (1.1.5)
98+
mini_portile2 (2.8.7)
99+
minitest (5.23.1)
100+
multi_json (1.15.0)
101+
multi_xml (0.7.1)
102+
bigdecimal (~> 3.1)
61103
mustermann (3.0.0)
62104
ruby2_keywords (~> 0.0.1)
63105
mustermann-grape (1.0.2)
64106
mustermann (>= 1.0.0)
65107
mutex_m (0.2.0)
108+
net-http (0.4.1)
109+
uri
110+
nokogiri (1.16.5)
111+
mini_portile2 (~> 2.8.2)
112+
racc (~> 1.4)
113+
nokogiri (1.16.5-arm64-darwin)
114+
racc (~> 1.4)
66115
parallel (1.24.0)
67-
parser (3.3.1.0)
116+
parser (3.3.2.0)
68117
ast (~> 2.4.1)
69118
racc
70-
racc (1.7.3)
71-
rack (3.0.10)
119+
racc (1.8.0)
120+
rack (3.0.11)
72121
rack-accept (0.4.5)
73122
rack (>= 0.4)
74123
rack-test (2.1.0)
@@ -78,8 +127,9 @@ GEM
78127
webrick (~> 1.8)
79128
rainbow (3.1.1)
80129
rake (13.2.1)
81-
regexp_parser (2.9.0)
82-
rexml (3.2.6)
130+
regexp_parser (2.9.2)
131+
rexml (3.2.8)
132+
strscan (>= 3.0.9)
83133
rspec (3.13.0)
84134
rspec-core (~> 3.13.0)
85135
rspec-expectations (~> 3.13.0)
@@ -91,11 +141,11 @@ GEM
91141
rspec-support (~> 3.13.0)
92142
rspec-github (2.4.0)
93143
rspec-core (~> 3.0)
94-
rspec-mocks (3.13.0)
144+
rspec-mocks (3.13.1)
95145
diff-lcs (>= 1.2.0, < 2.0)
96146
rspec-support (~> 3.13.0)
97147
rspec-support (3.13.1)
98-
rubocop (1.63.4)
148+
rubocop (1.64.1)
99149
json (~> 2.3)
100150
language_server-protocol (>= 3.17.0)
101151
parallel (~> 1.10)
@@ -114,7 +164,7 @@ GEM
114164
rubocop (~> 1.41)
115165
rubocop-rake (0.6.0)
116166
rubocop (~> 1.0)
117-
rubocop-rspec (2.29.2)
167+
rubocop-rspec (2.30.0)
118168
rubocop (~> 1.40)
119169
rubocop-capybara (~> 2.17)
120170
rubocop-factory_bot (~> 2.22)
@@ -130,11 +180,14 @@ GEM
130180
simplecov-html (0.12.3)
131181
simplecov_json_formatter (0.1.4)
132182
statsd-instrument (3.7.0)
183+
strscan (3.1.0)
133184
tzinfo (2.0.6)
134185
concurrent-ruby (~> 1.0)
135186
unicode-display_width (2.5.0)
187+
uri (0.13.0)
188+
uri_template (0.7.0)
136189
webrick (1.8.1)
137-
zeitwerk (2.6.13)
190+
zeitwerk (2.6.15)
138191

139192
PLATFORMS
140193
arm64-darwin-23
@@ -143,6 +196,7 @@ PLATFORMS
143196
DEPENDENCIES
144197
document-transfer-service!
145198
factory_bot (~> 6.2)
199+
microsoft-graph-client!
146200
rack-test (~> 2.1)
147201
rake (~> 13.0)
148202
rspec (~> 3.12)

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
A microservice to securely transfer documents.
44

5+
## Configuration
6+
7+
The service is configured using a series of environment variables. The actual
8+
variables required will depend on the [source] and [destination] types you wish
9+
to support.
10+
11+
A [sample `.env` file][.env] has been included to help you get started. Simply
12+
copy this file to `.env` and update the values as needed.
13+
14+
Make sure this file is then loaded into your environment before running the
15+
service. This can be done automatically through various shell tools (such as
16+
[Oh My Zsh][omz]), or manually by running the following:
17+
18+
```bash
19+
source .env
20+
```
21+
22+
_Note: Your `.env` file will contain sensitive information. This file is ignored
23+
by git, but it is your responsibility to ensure this file remains safe and
24+
secure._
25+
526
## Running
627

728
### Docker
@@ -35,6 +56,16 @@ bundle exec rackup
3556

3657
The service should now be available at `http://localhost:9292`.
3758

59+
## Usage
60+
61+
See the [API documentation][api] for information on how to interact with the
62+
service.
63+
64+
[.env]: ./sample.env
65+
[api]: ./doc/api.md
66+
[destination]: ./doc/destinations.md
3867
[Dockerfile]: ./Dockerfile
3968
[docker compose]: ./docker-compose.yaml
4069
[Docker Desktop]: https://docs.docker.com/desktop/
70+
[omz]: https://ohmyz.sh/
71+
[source]: ./doc/sources.md

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# frozen_string_literal: true
22

3+
require 'grape-swagger/rake/oapi_tasks'
34
require 'rspec/core/rake_task'
45
require 'rubocop/rake_task'
56

67
task default: %i[spec rubocop]
78

9+
task :environment do # rubocop:disable Rake/Desc
10+
require_relative 'lib/api/api'
11+
end
12+
13+
GrapeSwagger::Rake::OapiTasks.new('::DocumentTransfer::API::API')
14+
815
RuboCop::RakeTask.new(:rubocop) do |task|
916
task.requires << 'rubocop'
1017
end

config.ru

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
require_relative 'lib/api/api'
44

5-
run DocumentService::API
5+
use Rack::RewindableInput::Middleware
6+
7+
run DocumentTransfer::API::API

doc/api.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Document Transfer Service API
2+
3+
Interacting with the Document Transfer Service is done through a RESTful API.
4+
All requests and responses should be in JSON format, unless otherwise indicated.
5+
6+
Full API documentation can be found in the [OpenAPI specification][spec].
7+
8+
## GET /health
9+
10+
A basic health endpoint that will return a 200 status code if the API is
11+
running.
12+
13+
_Note: This endpoint does not require authentication._
14+
15+
Example response:
16+
17+
```json
18+
{ "status": "ok" }
19+
```
20+
21+
## POST /transfer
22+
23+
Initiate a document transfer. This is a synchronous request that will return
24+
once the transfer is complete or a failure occurs.
25+
26+
The required parameters for this request will vary based on the [source] and
27+
[destination] types.
28+
29+
Successful requests will always include a `status` and `destination` field.
30+
Additional fields may be included based on the destination type.
31+
32+
### Example request
33+
34+
```json
35+
{
36+
"source": {
37+
"type": "url",
38+
"url": "https://example.com/document.pdf"
39+
},
40+
"destination": {
41+
"type": "onedrive",
42+
"path": "/document/path"
43+
}
44+
}
45+
```
46+
47+
### Example response:
48+
49+
```json
50+
{
51+
"status": "success",
52+
"destination": "onedrive",
53+
"path": "/document/path/document.pdf"
54+
}
55+
```
56+
57+
[destination]: destinations.md
58+
[source]: sources.md
59+
[spec]: ../openapi.yaml

0 commit comments

Comments
 (0)