├── .env.sample
├── .github
└── workflows
│ ├── pr.yml
│ └── prod.yml
├── .gitignore
├── .rspec
├── Capfile
├── Dockerfile
├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── app
├── assets
│ ├── config
│ │ └── manifest.js
│ ├── images
│ │ └── .keep
│ ├── javascripts
│ │ └── application.js
│ └── stylesheets
│ │ └── application.css
├── channels
│ └── application_cable
│ │ ├── channel.rb
│ │ └── connection.rb
├── controllers
│ ├── application_controller.rb
│ ├── concerns
│ │ └── .keep
│ ├── health_check_controller.rb
│ └── integrations_controller.rb
├── helpers
│ ├── application_helper.rb
│ └── integrations_helper.rb
├── jobs
│ └── application_job.rb
├── lib
│ └── integrations
│ │ ├── aws_s3_integration.rb
│ │ ├── dropbox_integration.rb
│ │ ├── google_drive_integration.rb
│ │ └── webdav_integration.rb
├── mailers
│ └── application_mailer.rb
├── models
│ ├── application_record.rb
│ └── concerns
│ │ └── .keep
└── views
│ ├── application
│ └── index.html.haml
│ ├── integrations
│ ├── form_aws_s3.html.haml
│ ├── form_webdav.html.haml
│ ├── integration_complete.html.haml
│ └── oauth_redirect.html.haml
│ └── layouts
│ ├── application.html.erb
│ ├── mailer.html.erb
│ └── mailer.text.erb
├── bin
├── bundle
├── rails
├── rake
├── setup
├── spring
├── update
└── yarn
├── config.ru
├── config
├── application.rb
├── boot.rb
├── cable.yml
├── database.yml
├── deploy.rb
├── deploy
│ ├── production.rb
│ └── staging.rb
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── application_controller_renderer.rb
│ ├── assets.rb
│ ├── backtrace_silencers.rb
│ ├── cookies_serializer.rb
│ ├── filter_parameter_logging.rb
│ ├── inflections.rb
│ ├── lograge.rb
│ ├── mime_types.rb
│ └── wrap_parameters.rb
├── locales
│ └── en.yml
├── puma.rb
├── routes.rb
├── secrets.yml
└── spring.rb
├── db
└── seeds.rb
├── docker
└── entrypoint.sh
├── log
└── .keep
├── package.json
├── public
├── 404.html
├── 422.html
├── 500.html
├── apple-touch-icon-precomposed.png
├── apple-touch-icon.png
├── favicon.ico
└── robots.txt
├── spec
├── controllers
│ └── integrations_controller_spec.rb
├── rails_helper.rb
└── spec_helper.rb
├── test
├── application_system_test_case.rb
├── controllers
│ └── .keep
├── fixtures
│ ├── .keep
│ └── files
│ │ └── .keep
├── helpers
│ └── .keep
├── integration
│ └── .keep
├── mailers
│ └── .keep
├── models
│ └── .keep
├── system
│ └── .keep
└── test_helper.rb
├── tmp
└── .keep
├── vendor
└── .keep
└── yarn.lock
/.env.sample:
--------------------------------------------------------------------------------
1 | RAILS_ENV=development
2 | HOST=http://localhost:3000
3 |
4 | RAILS_LOG_TO_STDOUT=false
5 |
6 | GOOGLE_CLIENT_SECRETS=
7 |
8 | # NewRelic (Optional)
9 | NEW_RELIC_ENABLED=false
10 | NEW_RELIC_THREAD_PROFILER_ENABLED=false
11 | NEW_RELIC_LICENSE_KEY=
12 | NEW_RELIC_APP_NAME="Filesafe Relay"
13 | NEW_RELIC_BROWSER_MONITORING_AUTO_INSTRUMENT=false
14 |
--------------------------------------------------------------------------------
/.github/workflows/pr.yml:
--------------------------------------------------------------------------------
1 | name: PR
2 |
3 | on:
4 | pull_request:
5 | branches: [ develop ]
6 |
7 | jobs:
8 | test:
9 |
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - uses: actions/checkout@v2
14 | - name: Set up Ruby
15 | uses: ruby/setup-ruby@v1
16 | with:
17 | ruby-version: 2.6
18 | - name: Install libcurl
19 | run: sudo apt-get update --fix-missing && sudo apt-get install libcurl4-openssl-dev
20 | - name: Copy default configuration
21 | run: cp .env.sample .env
22 | - name: Install dependencies
23 | run: bundle install
24 | - name: Run tests
25 | run: bundle exec rspec
26 |
--------------------------------------------------------------------------------
/.github/workflows/prod.yml:
--------------------------------------------------------------------------------
1 | name: Prod
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 |
7 | jobs:
8 | test:
9 |
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - uses: actions/checkout@v2
14 | - name: Set up Ruby
15 | uses: ruby/setup-ruby@v1
16 | with:
17 | ruby-version: 2.6
18 | - name: Install libcurl
19 | run: sudo apt-get update --fix-missing && sudo apt-get install libcurl4-openssl-dev
20 | - name: Copy default configuration
21 | run: cp .env.sample .env
22 | - name: Install dependencies
23 | run: bundle install
24 | - name: Run tests
25 | run: bundle exec rspec
26 |
27 | deploy:
28 | needs: test
29 |
30 | runs-on: ubuntu-latest
31 |
32 | steps:
33 | - uses: actions/checkout@v3
34 |
35 | - name: Login to Docker Hub
36 | uses: docker/login-action@v2
37 | with:
38 | username: ${{ secrets.DOCKER_USERNAME }}
39 | password: ${{ secrets.DOCKER_PASSWORD }}
40 |
41 | - name: Configure AWS credentials
42 | uses: aws-actions/configure-aws-credentials@v3
43 | with:
44 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
45 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
46 | aws-region: us-east-1
47 |
48 | - name: Login to Amazon ECR
49 | id: login-ecr
50 | uses: aws-actions/amazon-ecr-login@v1
51 |
52 | - name: Set up QEMU
53 | uses: docker/setup-qemu-action@master
54 | with:
55 | platforms: all
56 |
57 | - name: Set up Docker Buildx
58 | id: buildx
59 | uses: docker/setup-buildx-action@master
60 |
61 | - name: Publish Docker image
62 | uses: docker/build-push-action@v4
63 | with:
64 | builder: ${{ steps.buildx.outputs.name }}
65 | context: .
66 | file: Dockerfile
67 | platforms: linux/amd64
68 | push: true
69 | tags: |
70 | standardnotes/filesafe-relay:latest
71 | standardnotes/filesafe-relay:${{ github.sha }}
72 | ${{ steps.login-ecr.outputs.registry }}/filesafe-relay:${{ github.sha }}
73 | ${{ steps.login-ecr.outputs.registry }}/filesafe-relay:latest
74 |
75 | - name: Download task definition
76 | run: |
77 | aws ecs describe-task-definition --task-definition filesafe-relay-prod --query taskDefinition > task-definition.json
78 |
79 | - name: Fill in the new image ID in the Amazon ECS task definition
80 | id: task-def
81 | uses: aws-actions/amazon-ecs-render-task-definition@v1
82 | with:
83 | task-definition: task-definition.json
84 | container-name: filesafe-relay-prod
85 | image: ${{ steps.login-ecr.outputs.registry }}/filesafe-relay:${{ github.sha }}
86 |
87 | - name: Deploy Amazon ECS task definition
88 | uses: aws-actions/amazon-ecs-deploy-task-definition@v1
89 | with:
90 | task-definition: ${{ steps.task-def.outputs.task-definition }}
91 | service: filesafe-relay
92 | cluster: prod
93 | wait-for-service-stability: true
94 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 |
10 | # Ignore the default SQLite database.
11 | /db/*.sqlite3
12 | /db/*.sqlite3-journal
13 |
14 | # Ignore all logfiles and tempfiles.
15 | /log/*
16 | /tmp/*
17 | !/log/.keep
18 | !/tmp/.keep
19 |
20 | client_secrets.json
21 |
22 | /node_modules
23 | /yarn-error.log
24 |
25 | .byebug_history
26 |
27 | .ssh
28 | .env
29 | /config/cap.yml
30 | .DS_Store
31 |
--------------------------------------------------------------------------------
/.rspec:
--------------------------------------------------------------------------------
1 | --require spec_helper
2 |
--------------------------------------------------------------------------------
/Capfile:
--------------------------------------------------------------------------------
1 | # Load DSL and set up stages
2 | require "capistrano/setup"
3 |
4 | # Include default deployment tasks
5 | require "capistrano/deploy"
6 |
7 | # Include tasks from other gems included in your Gemfile
8 | #
9 | # For documentation on these, see for example:
10 | #
11 | # https://github.com/capistrano/rvm
12 | # https://github.com/capistrano/rbenv
13 | # https://github.com/capistrano/chruby
14 | # https://github.com/capistrano/bundler
15 | # https://github.com/capistrano/rails
16 | # https://github.com/capistrano/passenger
17 | #
18 | require 'capistrano/rvm'
19 | # require 'capistrano/rbenv'
20 | # require 'capistrano/chruby'
21 | require 'capistrano/bundler'
22 | require 'capistrano/rails/assets'
23 | require 'capistrano/rails/migrations'
24 | require 'capistrano/passenger'
25 | # require 'capistrano/sidekiq'
26 | require 'capistrano/git-submodule-strategy'
27 | # require "whenever/capistrano" # Update crontab on deploy
28 |
29 |
30 | # Load custom tasks from `lib/capistrano/tasks` if you have any defined
31 | Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
32 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ruby:2.6.5-alpine
2 |
3 | ARG UID=1000
4 | ARG GID=1000
5 |
6 | RUN addgroup -S filesafe -g $GID && adduser -D -S filesafe -G filesafe -u $UID
7 |
8 | RUN apk add --update --no-cache \
9 | alpine-sdk \
10 | sqlite-dev \
11 | git \
12 | make \
13 | g++ \
14 | curl-dev \
15 | nodejs \
16 | nodejs-npm \
17 | yarn \
18 | tzdata
19 |
20 | WORKDIR /filesafe-relay
21 |
22 | RUN chown -R $UID:$GID .
23 |
24 | USER filesafe
25 |
26 | COPY --chown=$UID:$GID package.json yarn.lock Gemfile Gemfile.lock /filesafe-relay/
27 |
28 | COPY --chown=$UID:$GID vendor /filesafe-relay/vendor
29 |
30 | RUN yarn install --frozen-lockfile
31 |
32 | RUN gem install bundler && bundle install
33 |
34 | COPY --chown=$UID:$GID . /filesafe-relay
35 |
36 | RUN bundle exec rake assets:precompile
37 |
38 | EXPOSE 3000
39 |
40 | ENTRYPOINT [ "docker/entrypoint.sh" ]
41 |
42 | CMD [ "start" ]
43 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | git_source(:github) do |repo_name|
4 | repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
5 | "https://github.com/#{repo_name}.git"
6 | end
7 |
8 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
9 | gem 'rails', '~> 5.1.5'
10 |
11 | # Use sqlite3 as the database for Active Record
12 | gem 'sqlite3'
13 |
14 | gem 'net_dav'
15 | gem 'curb'
16 |
17 | # Use Puma as the app server
18 | gem 'puma', '~> 3.12'
19 |
20 | # Use SCSS for stylesheets
21 | gem 'sass-rails', '~> 5.0'
22 |
23 | # Use Uglifier as compressor for JavaScript assets
24 | gem 'uglifier', '>= 1.3.0'
25 | gem 'rack-cors', :require => 'rack/cors'
26 | gem 'haml-rails'
27 |
28 | gem "non-stupid-digest-assets"
29 |
30 | gem 'dotenv-rails'
31 | # See https://github.com/rails/execjs#readme for more supported runtimes
32 | # gem 'therubyracer', platforms: :ruby
33 |
34 | gem "dropbox-sdk-v2"
35 | gem "google-api-client"
36 | gem 'aws-sdk-s3', '~> 1'
37 |
38 | # Use Capistrano for deployment
39 | # gem 'capistrano-rails', group: :development
40 |
41 | group :development, :test do
42 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console
43 | gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
44 | # Adds support for Capybara system testing and selenium driver
45 | gem 'capybara', '~> 2.13'
46 | gem 'selenium-webdriver'
47 | end
48 |
49 | group :development do
50 | # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
51 | gem 'web-console', '>= 3.3.0'
52 | gem 'listen', '>= 3.0.5', '< 3.2'
53 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
54 | gem 'spring'
55 | gem 'spring-watcher-listen', '~> 2.0.0'
56 |
57 | gem 'capistrano'
58 | gem 'capistrano-bundler'
59 | gem 'capistrano-passenger', '>= 0.2.0'
60 | gem 'capistrano-rails'
61 | gem 'capistrano-rvm'
62 | gem 'capistrano-sidekiq'
63 | gem 'capistrano-git-submodule-strategy', '~> 0.1.22'
64 | end
65 |
66 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
67 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
68 |
69 |
70 | gem "lograge", "~> 0.11.2"
71 |
72 | gem "rspec-rails", "~> 4.0"
73 |
74 | gem "newrelic_rpm", "~> 7.0"
75 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actioncable (5.1.7)
5 | actionpack (= 5.1.7)
6 | nio4r (~> 2.0)
7 | websocket-driver (~> 0.6.1)
8 | actionmailer (5.1.7)
9 | actionpack (= 5.1.7)
10 | actionview (= 5.1.7)
11 | activejob (= 5.1.7)
12 | mail (~> 2.5, >= 2.5.4)
13 | rails-dom-testing (~> 2.0)
14 | actionpack (5.1.7)
15 | actionview (= 5.1.7)
16 | activesupport (= 5.1.7)
17 | rack (~> 2.0)
18 | rack-test (>= 0.6.3)
19 | rails-dom-testing (~> 2.0)
20 | rails-html-sanitizer (~> 1.0, >= 1.0.2)
21 | actionview (5.1.7)
22 | activesupport (= 5.1.7)
23 | builder (~> 3.1)
24 | erubi (~> 1.4)
25 | rails-dom-testing (~> 2.0)
26 | rails-html-sanitizer (~> 1.0, >= 1.0.3)
27 | activejob (5.1.7)
28 | activesupport (= 5.1.7)
29 | globalid (>= 0.3.6)
30 | activemodel (5.1.7)
31 | activesupport (= 5.1.7)
32 | activerecord (5.1.7)
33 | activemodel (= 5.1.7)
34 | activesupport (= 5.1.7)
35 | arel (~> 8.0)
36 | activesupport (5.1.7)
37 | concurrent-ruby (~> 1.0, >= 1.0.2)
38 | i18n (>= 0.7, < 2)
39 | minitest (~> 5.1)
40 | tzinfo (~> 1.1)
41 | addressable (2.7.0)
42 | public_suffix (>= 2.0.2, < 5.0)
43 | airbrussh (1.4.0)
44 | sshkit (>= 1.6.1, != 1.7.0)
45 | arel (8.0.0)
46 | aws-eventstream (1.1.0)
47 | aws-partitions (1.337.0)
48 | aws-sdk-core (3.103.0)
49 | aws-eventstream (~> 1, >= 1.0.2)
50 | aws-partitions (~> 1, >= 1.239.0)
51 | aws-sigv4 (~> 1.1)
52 | jmespath (~> 1.0)
53 | aws-sdk-kms (1.35.0)
54 | aws-sdk-core (~> 3, >= 3.99.0)
55 | aws-sigv4 (~> 1.1)
56 | aws-sdk-s3 (1.72.0)
57 | aws-sdk-core (~> 3, >= 3.102.1)
58 | aws-sdk-kms (~> 1)
59 | aws-sigv4 (~> 1.1)
60 | aws-sigv4 (1.2.1)
61 | aws-eventstream (~> 1, >= 1.0.2)
62 | bindex (0.8.1)
63 | builder (3.2.4)
64 | byebug (11.1.3)
65 | capistrano (3.6.1)
66 | airbrussh (>= 1.0.0)
67 | capistrano-harrow
68 | i18n
69 | rake (>= 10.0.0)
70 | sshkit (>= 1.9.0)
71 | capistrano-bundler (1.6.0)
72 | capistrano (~> 3.1)
73 | capistrano-git-submodule-strategy (0.1.23)
74 | capistrano (>= 3.1.0, < 3.7)
75 | capistrano-harrow (0.5.3)
76 | capistrano-passenger (0.2.0)
77 | capistrano (~> 3.0)
78 | capistrano-rails (1.5.0)
79 | capistrano (~> 3.1)
80 | capistrano-bundler (~> 1.1)
81 | capistrano-rvm (0.1.2)
82 | capistrano (~> 3.0)
83 | sshkit (~> 1.2)
84 | capistrano-sidekiq (0.10.0)
85 | capistrano
86 | sidekiq (>= 3.4)
87 | capybara (2.18.0)
88 | addressable
89 | mini_mime (>= 0.1.3)
90 | nokogiri (>= 1.3.3)
91 | rack (>= 1.0.0)
92 | rack-test (>= 0.5.4)
93 | xpath (>= 2.0, < 4.0)
94 | childprocess (3.0.0)
95 | concurrent-ruby (1.1.6)
96 | connection_pool (2.2.3)
97 | crass (1.0.6)
98 | curb (0.9.10)
99 | declarative (0.0.20)
100 | declarative-option (0.1.0)
101 | diff-lcs (1.4.4)
102 | domain_name (0.5.20190701)
103 | unf (>= 0.0.5, < 1.0.0)
104 | dotenv (2.7.5)
105 | dotenv-rails (2.7.5)
106 | dotenv (= 2.7.5)
107 | railties (>= 3.2, < 6.1)
108 | dropbox-sdk-v2 (0.0.3)
109 | http (~> 2.0)
110 | erubi (1.9.0)
111 | erubis (2.7.0)
112 | execjs (2.7.0)
113 | faraday (1.0.1)
114 | multipart-post (>= 1.2, < 3)
115 | ffi (1.13.1)
116 | globalid (0.4.2)
117 | activesupport (>= 4.2.0)
118 | google-api-client (0.41.1)
119 | addressable (~> 2.5, >= 2.5.1)
120 | googleauth (~> 0.9)
121 | httpclient (>= 2.8.1, < 3.0)
122 | mini_mime (~> 1.0)
123 | representable (~> 3.0)
124 | retriable (>= 2.0, < 4.0)
125 | signet (~> 0.12)
126 | googleauth (0.13.0)
127 | faraday (>= 0.17.3, < 2.0)
128 | jwt (>= 1.4, < 3.0)
129 | memoist (~> 0.16)
130 | multi_json (~> 1.11)
131 | os (>= 0.9, < 2.0)
132 | signet (~> 0.14)
133 | haml (5.1.2)
134 | temple (>= 0.8.0)
135 | tilt
136 | haml-rails (2.0.1)
137 | actionpack (>= 5.1)
138 | activesupport (>= 5.1)
139 | haml (>= 4.0.6, < 6.0)
140 | html2haml (>= 1.0.1)
141 | railties (>= 5.1)
142 | html2haml (2.2.0)
143 | erubis (~> 2.7.0)
144 | haml (>= 4.0, < 6)
145 | nokogiri (>= 1.6.0)
146 | ruby_parser (~> 3.5)
147 | http (2.2.2)
148 | addressable (~> 2.3)
149 | http-cookie (~> 1.0)
150 | http-form_data (~> 1.0.1)
151 | http_parser.rb (~> 0.6.0)
152 | http-cookie (1.0.3)
153 | domain_name (~> 0.5)
154 | http-form_data (1.0.3)
155 | http_parser.rb (0.6.0)
156 | httpclient (2.8.3)
157 | i18n (1.8.3)
158 | concurrent-ruby (~> 1.0)
159 | jmespath (1.4.0)
160 | jwt (2.2.1)
161 | listen (3.1.5)
162 | rb-fsevent (~> 0.9, >= 0.9.4)
163 | rb-inotify (~> 0.9, >= 0.9.7)
164 | ruby_dep (~> 1.2)
165 | lograge (0.11.2)
166 | actionpack (>= 4)
167 | activesupport (>= 4)
168 | railties (>= 4)
169 | request_store (~> 1.0)
170 | loofah (2.6.0)
171 | crass (~> 1.0.2)
172 | nokogiri (>= 1.5.9)
173 | mail (2.7.1)
174 | mini_mime (>= 0.1.1)
175 | memoist (0.16.2)
176 | method_source (1.0.0)
177 | mini_mime (1.0.2)
178 | mini_portile2 (2.4.0)
179 | minitest (5.14.1)
180 | multi_json (1.14.1)
181 | multipart-post (2.1.1)
182 | net-scp (3.0.0)
183 | net-ssh (>= 2.6.5, < 7.0.0)
184 | net-ssh (6.1.0)
185 | net_dav (0.5.1)
186 | nokogiri
187 | newrelic_rpm (7.0.0)
188 | nio4r (2.5.2)
189 | nokogiri (1.10.9)
190 | mini_portile2 (~> 2.4.0)
191 | non-stupid-digest-assets (1.0.9)
192 | sprockets (>= 2.0)
193 | os (1.1.0)
194 | public_suffix (4.0.6)
195 | puma (3.12.6)
196 | rack (2.2.3)
197 | rack-cors (1.1.1)
198 | rack (>= 2.0.0)
199 | rack-test (1.1.0)
200 | rack (>= 1.0, < 3)
201 | rails (5.1.7)
202 | actioncable (= 5.1.7)
203 | actionmailer (= 5.1.7)
204 | actionpack (= 5.1.7)
205 | actionview (= 5.1.7)
206 | activejob (= 5.1.7)
207 | activemodel (= 5.1.7)
208 | activerecord (= 5.1.7)
209 | activesupport (= 5.1.7)
210 | bundler (>= 1.3.0)
211 | railties (= 5.1.7)
212 | sprockets-rails (>= 2.0.0)
213 | rails-dom-testing (2.0.3)
214 | activesupport (>= 4.2.0)
215 | nokogiri (>= 1.6)
216 | rails-html-sanitizer (1.3.0)
217 | loofah (~> 2.3)
218 | railties (5.1.7)
219 | actionpack (= 5.1.7)
220 | activesupport (= 5.1.7)
221 | method_source
222 | rake (>= 0.8.7)
223 | thor (>= 0.18.1, < 2.0)
224 | rake (13.0.1)
225 | rb-fsevent (0.10.4)
226 | rb-inotify (0.10.1)
227 | ffi (~> 1.0)
228 | redis (4.2.1)
229 | representable (3.0.4)
230 | declarative (< 0.1.0)
231 | declarative-option (< 0.2.0)
232 | uber (< 0.2.0)
233 | request_store (1.5.0)
234 | rack (>= 1.4)
235 | retriable (3.1.2)
236 | rspec-core (3.9.2)
237 | rspec-support (~> 3.9.3)
238 | rspec-expectations (3.9.2)
239 | diff-lcs (>= 1.2.0, < 2.0)
240 | rspec-support (~> 3.9.0)
241 | rspec-mocks (3.9.1)
242 | diff-lcs (>= 1.2.0, < 2.0)
243 | rspec-support (~> 3.9.0)
244 | rspec-rails (4.0.1)
245 | actionpack (>= 4.2)
246 | activesupport (>= 4.2)
247 | railties (>= 4.2)
248 | rspec-core (~> 3.9)
249 | rspec-expectations (~> 3.9)
250 | rspec-mocks (~> 3.9)
251 | rspec-support (~> 3.9)
252 | rspec-support (3.9.3)
253 | ruby_dep (1.5.0)
254 | ruby_parser (3.14.2)
255 | sexp_processor (~> 4.9)
256 | rubyzip (2.3.0)
257 | sass (3.7.4)
258 | sass-listen (~> 4.0.0)
259 | sass-listen (4.0.0)
260 | rb-fsevent (~> 0.9, >= 0.9.4)
261 | rb-inotify (~> 0.9, >= 0.9.7)
262 | sass-rails (5.0.7)
263 | railties (>= 4.0.0, < 6)
264 | sass (~> 3.1)
265 | sprockets (>= 2.8, < 4.0)
266 | sprockets-rails (>= 2.0, < 4.0)
267 | tilt (>= 1.1, < 3)
268 | selenium-webdriver (3.142.7)
269 | childprocess (>= 0.5, < 4.0)
270 | rubyzip (>= 1.2.2)
271 | sexp_processor (4.15.0)
272 | sidekiq (6.1.0)
273 | connection_pool (>= 2.2.2)
274 | rack (~> 2.0)
275 | redis (>= 4.2.0)
276 | signet (0.14.0)
277 | addressable (~> 2.3)
278 | faraday (>= 0.17.3, < 2.0)
279 | jwt (>= 1.5, < 3.0)
280 | multi_json (~> 1.10)
281 | spring (2.1.0)
282 | spring-watcher-listen (2.0.1)
283 | listen (>= 2.7, < 4.0)
284 | spring (>= 1.2, < 3.0)
285 | sprockets (3.7.2)
286 | concurrent-ruby (~> 1.0)
287 | rack (> 1, < 3)
288 | sprockets-rails (3.2.1)
289 | actionpack (>= 4.0)
290 | activesupport (>= 4.0)
291 | sprockets (>= 3.0.0)
292 | sqlite3 (1.4.2)
293 | sshkit (1.21.0)
294 | net-scp (>= 1.1.2)
295 | net-ssh (>= 2.8.0)
296 | temple (0.8.2)
297 | thor (1.0.1)
298 | thread_safe (0.3.6)
299 | tilt (2.0.10)
300 | tzinfo (1.2.7)
301 | thread_safe (~> 0.1)
302 | uber (0.1.0)
303 | uglifier (4.2.0)
304 | execjs (>= 0.3.0, < 3)
305 | unf (0.1.4)
306 | unf_ext
307 | unf_ext (0.0.7.7)
308 | web-console (3.7.0)
309 | actionview (>= 5.0)
310 | activemodel (>= 5.0)
311 | bindex (>= 0.4.0)
312 | railties (>= 5.0)
313 | websocket-driver (0.6.5)
314 | websocket-extensions (>= 0.1.0)
315 | websocket-extensions (0.1.5)
316 | xpath (3.2.0)
317 | nokogiri (~> 1.8)
318 |
319 | PLATFORMS
320 | ruby
321 |
322 | DEPENDENCIES
323 | aws-sdk-s3 (~> 1)
324 | byebug
325 | capistrano
326 | capistrano-bundler
327 | capistrano-git-submodule-strategy (~> 0.1.22)
328 | capistrano-passenger (>= 0.2.0)
329 | capistrano-rails
330 | capistrano-rvm
331 | capistrano-sidekiq
332 | capybara (~> 2.13)
333 | curb
334 | dotenv-rails
335 | dropbox-sdk-v2
336 | google-api-client
337 | haml-rails
338 | listen (>= 3.0.5, < 3.2)
339 | lograge (~> 0.11.2)
340 | net_dav
341 | newrelic_rpm (~> 7.0)
342 | non-stupid-digest-assets
343 | puma (~> 3.12)
344 | rack-cors
345 | rails (~> 5.1.5)
346 | rspec-rails (~> 4.0)
347 | sass-rails (~> 5.0)
348 | selenium-webdriver
349 | spring
350 | spring-watcher-listen (~> 2.0.0)
351 | sqlite3
352 | tzinfo-data
353 | uglifier (>= 1.3.0)
354 | web-console (>= 3.3.0)
355 |
356 | BUNDLED WITH
357 | 1.17.3
358 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Filesafe Relay
2 |
3 | This is the server component that is part of the larger FileSafe system. It deals with relaying files to the proper 3rd party storage provider, such as Dropbox, Google Drive, WebDAV, or AWS S3.
4 |
5 | ## Setting up
6 |
7 | ### Requirements
8 |
9 | #### Google Auth
10 |
11 | This is required for an integration with Google Drive.
12 |
13 | You need to supply the `client_secrets.json` file in the root directory of the project as is required by [Google Auth Library](https://github.com/googleapis/google-auth-library-ruby/tree/584ad57d7d72d9ffa395daa1dde4c48e04ab3c99#example-web). This can be set up [here](https://console.developers.google.com/apis/dashboard).
14 |
15 | As an alternative you can set the `GOOGLE_CLIENT_SECRETS` environment variable in the `.env` file. When running the container, this will create the `client_secrets.json` file with contents of the variable.
16 |
17 | ### Docker
18 |
19 | In order to run the relay server locally, type the following commands:
20 |
21 | ```
22 | cp .env.sample .env
23 | docker build -t filesafe-relay-local .
24 | docker run -d -p 3000:3000 --env-file .env filesafe-relay-local
25 | ```
26 |
27 | ## Contributing
28 |
29 | Feel free to create a pull request, we welcome your enthusiasm!
30 |
31 | ## Support
32 |
33 | Please open a new issue and the Standard Notes team will take a look as soon as we can.
34 |
35 | We are also reachable on our forum, Slack, Reddit, Twitter, and through email:
36 |
37 | - Standard Notes Help and Support: [Get Help](https://standardnotes.org/help)
38 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require_relative 'config/application'
5 |
6 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/app/assets/config/manifest.js:
--------------------------------------------------------------------------------
1 | //= link_tree ../images
2 | //= link_directory ../javascripts .js
3 | //= link_directory ../stylesheets .css
4 |
--------------------------------------------------------------------------------
/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/app/assets/images/.keep
--------------------------------------------------------------------------------
/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
5 | // vendor/assets/javascripts directory can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file. JavaScript code in this file should be added after the last require_* statement.
9 | //
10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require_tree .
14 |
15 | document.addEventListener("DOMContentLoaded", function(event) {
16 |
17 | function copyToClipboard(text) {
18 | if (window.clipboardData && window.clipboardData.setData) {
19 | // IE specific code path to prevent textarea being shown while dialog is visible.
20 | return clipboardData.setData("Text", text);
21 |
22 | } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
23 | var textarea = document.createElement("textarea");
24 | textarea.textContent = text;
25 | textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in MS Edge.
26 | document.body.appendChild(textarea);
27 | textarea.select();
28 | try {
29 | return document.execCommand("copy"); // Security exception may be thrown by some browsers.
30 | } catch (ex) {
31 | console.warn("Copy to clipboard failed.", ex);
32 | return false;
33 | } finally {
34 | document.body.removeChild(textarea);
35 | }
36 | }
37 | }
38 |
39 | var button = document.querySelector("#activation-code-button");
40 | if(button) {
41 | button.onclick = function() {
42 | var codeElement = document.querySelector("#activation-code");
43 | var code = codeElement.innerHTML.trim();
44 | copyToClipboard(code);
45 | button.querySelector(".sk-label").innerHTML = "Copied"
46 | }
47 | }
48 | });
49 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
6 | * vendor/assets/stylesheets directory can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10 | * files in this directory. Styles in this file should be added after the last require_* statement.
11 | * It is generally better to create a new file per style scope.
12 | *
13 | *= require_tree .
14 | *= require_self
15 | */
16 |
17 | @import "stylekit.css";
18 |
19 | .sk-notification {
20 | margin-top: 0.5rem !important;
21 | }
22 |
23 | a:hover {
24 | text-decoration: underline !important;
25 | }
26 |
27 | a, a.sk-button:hover {
28 | text-decoration: none !important;
29 | }
30 |
31 | .select-all {
32 | user-select: all;
33 | }
34 |
35 | #activation-code {
36 | user-select: text !important;
37 | margin: 10px;
38 |
39 | -webkit-user-select: none;
40 | -webkit-touch-callout: none;
41 | -khtml-user-select: none;
42 | -moz-user-select: none;
43 | -ms-user-select: none;
44 | -o-user-select: none;
45 | }
46 |
--------------------------------------------------------------------------------
/app/channels/application_cable/channel.rb:
--------------------------------------------------------------------------------
1 | module ApplicationCable
2 | class Channel < ActionCable::Channel::Base
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/app/channels/application_cable/connection.rb:
--------------------------------------------------------------------------------
1 | module ApplicationCable
2 | class Connection < ActionCable::Connection::Base
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | protect_from_forgery with: :null_session
3 |
4 | def index
5 | @dropbox_link = "/integrations/link?source=dropbox"
6 | @google_drive_link = "/integrations/link?source=google_drive"
7 | @webdav_link = "/integrations/link?source=webdav"
8 | @aws_s3_link = "/integrations/link?source=AWS_S3"
9 | end
10 |
11 | def route_not_found
12 | render :json => {:error => {:message => "Not found."}}, :status => 404
13 | end
14 |
15 | private
16 |
17 | def append_info_to_payload(payload)
18 | super
19 |
20 | unless payload[:status]
21 | return
22 | end
23 |
24 | payload[:level] = 'INFO'
25 | if payload[:status] >= 500
26 | payload[:level] = 'ERROR'
27 | elsif payload[:status] >= 400
28 | payload[:level] = 'WARN'
29 | end
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/app/controllers/health_check_controller.rb:
--------------------------------------------------------------------------------
1 | class HealthCheckController < ApplicationController
2 | def index
3 | render :plain => "OK"
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/app/controllers/integrations_controller.rb:
--------------------------------------------------------------------------------
1 | class IntegrationsController < ApplicationController
2 | # http://localhost:3020/integrations/link?source=dropbox
3 |
4 | before_action {
5 | integration_name = get_integration_name_from_params
6 | if integration_name
7 | if integration_name == "dropbox"
8 | @integration = DropboxIntegration.new(:authorization => params[:authorization])
9 | elsif integration_name == "google_drive"
10 | @integration = GoogleDriveIntegration.new(:authorization => params[:authorization])
11 | elsif integration_name == "webdav"
12 | @integration = WebdavIntegration.new(:authorization => params[:authorization])
13 | elsif integration_name === "AWS_S3"
14 | @integration = AwsS3Integration.new(:authorization => params[:authorization])
15 | end
16 | end
17 | }
18 |
19 | def get_integration_name_from_params
20 | if params[:metadata]
21 | params[:metadata][:source]
22 | elsif params[:source] || session[:source]
23 | params[:source] || session[:source]
24 | end
25 | end
26 |
27 | def link
28 | integration_name = params[:source]
29 | session[:source] = integration_name
30 | if @integration.type == "oauth"
31 | url = @integration.authorization_link(auth_redirect_url)
32 | redirect_to url
33 | elsif @integration.type == "form"
34 | render action: "form_#{integration_name.downcase}"
35 | end
36 | end
37 |
38 | def submit_form
39 | @code = Base64.encode64(params[:auth_data].to_json)
40 |
41 | redirect_to controller: 'integrations', action: 'integration_complete', authorization: @code, source: get_integration_name_from_params
42 | end
43 |
44 | def save_item
45 | metadata = @integration.save_item(
46 | name: params[:file][:name],
47 | item: params[:file][:item],
48 | auth_params: params[:file][:auth_params]
49 | )
50 |
51 | metadata[:source] = get_integration_name_from_params
52 |
53 | render json: { metadata: metadata }
54 | rescue StandardError => e
55 | Rails.logger.error "Could not save item: #{e.message}"
56 |
57 | render(
58 | json: {
59 | error: {
60 | message: 'Could not save item. Please verify your integration.'
61 | }
62 | },
63 | status: :bad_request
64 | )
65 | end
66 |
67 | def download_item
68 | metadata = params[:metadata]
69 | body, file_name = @integration.download_item(metadata)
70 | send_data body, filename: file_name
71 | rescue StandardError => e
72 | Rails.logger.error "Could not download item: #{e.message}"
73 |
74 | render(
75 | json: {
76 | error: {
77 | message: 'Could not retrieve item. Please verify your integration.'
78 | }
79 | },
80 | status: :bad_request
81 | )
82 | end
83 |
84 | def delete_item
85 | metadata = params[:metadata]
86 | @integration.delete_item(metadata)
87 |
88 | head :no_content
89 | rescue StandardError => e
90 | Rails.logger.error "Could not delete item: #{e.message}"
91 |
92 | render(
93 | json: {
94 | error: {
95 | message: 'Could not delete item. Please verify your integration.'
96 | }
97 | },
98 | status: :bad_request
99 | )
100 | end
101 |
102 | def oauth_redirect
103 | @integration_name = session[:source]
104 | begin
105 | @authorization = @integration.finalize_authorization(params, auth_redirect_url)
106 | if @authorization.is_a?(Hash) && @authorization[:error]
107 | @error = @authorization[:error]
108 | else
109 | redirect_to controller: "integrations", action: 'integration_complete', authorization: @authorization, source: @integration_name
110 | end
111 | rescue StandardError => e
112 | @error = e
113 | end
114 | end
115 |
116 | def integration_complete
117 | @authorization = params[:authorization]
118 | @source = params[:source]
119 |
120 | integration = {
121 | source: @source,
122 | authorization: @authorization,
123 | relayUrl: ENV['HOST']
124 | }
125 |
126 | # Remove whitespace
127 | @code = Base64.encode64(integration.to_json).gsub(/[[:space:]]/, '')
128 | end
129 |
130 | private
131 |
132 | def auth_redirect_url
133 | "#{ENV['HOST']}/integrations/oauth-redirect"
134 | end
135 | end
136 |
--------------------------------------------------------------------------------
/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/helpers/integrations_helper.rb:
--------------------------------------------------------------------------------
1 | module IntegrationsHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/jobs/application_job.rb:
--------------------------------------------------------------------------------
1 | class ApplicationJob < ActiveJob::Base
2 | end
3 |
--------------------------------------------------------------------------------
/app/lib/integrations/aws_s3_integration.rb:
--------------------------------------------------------------------------------
1 | require 'aws-sdk-s3'
2 |
3 | class AwsS3Integration
4 | def initialize(params = {})
5 | if params[:authorization]
6 | @auth_params = JSON.parse(Base64.decode64(params[:authorization]))
7 | end
8 | end
9 |
10 | def type
11 | return "form"
12 | end
13 |
14 | def save_item(params)
15 | Rails.logger.info 'Saving file to S3'
16 |
17 | payload = { items: [params[:item]] }
18 | payload['auth_params'] = params[:auth_params]
19 |
20 | obj_key = "FileSafe/#{params[:name]}"
21 |
22 | bucket.object(obj_key).put(body: JSON.pretty_generate(payload.as_json))
23 |
24 | { obj_key: obj_key }
25 | end
26 |
27 | def download_item(metadata = {})
28 | file = bucket.object(metadata[:obj_key]).get
29 | return file.body.string, metadata[:obj_key]
30 | end
31 |
32 | def delete_item(metadata)
33 | bucket.object(metadata[:obj_key]).delete
34 | end
35 |
36 | def bucket
37 | @bucket ||= begin
38 | s3 = Aws::S3::Resource.new({
39 | region: @auth_params["region"],
40 | credentials: Aws::Credentials.new(@auth_params["key"], @auth_params["secret"])
41 | })
42 | s3.bucket(@auth_params["bucket"])
43 | end
44 | end
45 | end
46 |
--------------------------------------------------------------------------------
/app/lib/integrations/dropbox_integration.rb:
--------------------------------------------------------------------------------
1 | require 'dropbox'
2 |
3 | class DropboxIntegration
4 | FILE_READ_CHUNK_SIZE_BYTES = 512_000
5 |
6 | def initialize(params = {})
7 | @token = params[:authorization]
8 | end
9 |
10 | def type
11 | return "oauth"
12 | end
13 |
14 | def authorization_link(redirect_url)
15 | endpoint = "https://www.dropbox.com/1/oauth2/authorize"
16 | params = "client_id=#{ENV["DROPBOX_CLIENT_ID"]}&response_type=code&redirect_uri=" + redirect_url
17 | return "#{endpoint}?#{params}"
18 | end
19 |
20 | def finalize_authorization(params, redirect_url)
21 | code = params[:code]
22 |
23 | result = get_access_key(code, redirect_url)
24 | if result[:error]
25 | return {:error => result[:error]}
26 | else
27 | return result[:token]
28 | end
29 | end
30 |
31 | def save_item(params)
32 | Rails.logger.info 'Saving file to Dropbox'
33 |
34 | payload = { items: [params[:item]] }
35 | payload['auth_params'] = params[:auth_params]
36 |
37 | tmp_file = Tempfile.new(SecureRandom.hex)
38 | tmp_file.write(JSON.pretty_generate(payload.as_json))
39 | tmp_file.rewind
40 |
41 | dropbox_upload_session_cursor = dropbox.start_upload_session('')
42 |
43 | File.open(tmp_file.path) do |file|
44 | dropbox.append_upload_session(
45 | dropbox_upload_session_cursor,
46 | file.read(FILE_READ_CHUNK_SIZE_BYTES)
47 | ) until file.eof?
48 | end
49 |
50 | metadata = dropbox.finish_upload_session(
51 | dropbox_upload_session_cursor,
52 | "/#{params[:name]}",
53 | '',
54 | mode: 'overwrite'
55 | )
56 |
57 | tmp_file.close
58 | tmp_file.unlink
59 |
60 | { file_path: metadata.path_lower }
61 | end
62 |
63 | def download_item(metadata)
64 | file, body = dropbox.download("#{metadata[:file_path]}")
65 | return body.to_s, file.name
66 | end
67 |
68 | def delete_item(metadata)
69 | dropbox.delete(metadata[:file_path])
70 | end
71 |
72 | private
73 |
74 | def dropbox
75 | return @dropbox if @dropbox
76 |
77 | @dropbox = Dropbox::Client.new(@token)
78 | end
79 |
80 | def get_access_key(auth_code, redirect)
81 | url = "https://api.dropboxapi.com/1/oauth2/token"
82 | request_params = {
83 | :code => auth_code,
84 | :grant_type => "authorization_code",
85 | :client_id => ENV["DROPBOX_CLIENT_ID"],
86 | :client_secret => ENV["DROPBOX_CLIENT_SECRET"],
87 | :redirect_uri => "#{redirect}"
88 | }
89 |
90 | resp = HTTP.headers(content_type: 'application/json').post(url, :params => request_params)
91 |
92 | if resp.code != 200
93 | @error = "Unable to authenticate. Please try again."
94 | return {:error => @error}
95 | else
96 | data = JSON.parse(resp.to_s)
97 | dropbox_token = data["access_token"]
98 | return {:token => dropbox_token}
99 | end
100 | end
101 |
102 | end
103 |
--------------------------------------------------------------------------------
/app/lib/integrations/google_drive_integration.rb:
--------------------------------------------------------------------------------
1 | class GoogleDriveIntegration
2 |
3 | require 'google/apis/drive_v3'
4 | require 'google/api_client/client_secrets'
5 |
6 | def initialize(params = {})
7 | @token = params[:authorization]
8 | end
9 |
10 | def type
11 | return "oauth"
12 | end
13 |
14 | def authorization_link(redirect_url)
15 | client_secrets = Google::APIClient::ClientSecrets.load
16 | _auth_client = client_secrets.to_authorization
17 | _auth_client.update!(
18 | :scope => 'https://www.googleapis.com/auth/drive.file',
19 | :redirect_uri => redirect_url
20 | )
21 |
22 | return _auth_client.authorization_uri.to_s
23 | end
24 |
25 | def finalize_authorization(params, redirect_url)
26 | auth_code = params[:code]
27 | client_secrets = Google::APIClient::ClientSecrets.load
28 | auth_client = client_secrets.to_authorization
29 | auth_client.update!(
30 | :scope => 'https://www.googleapis.com/auth/drive.file',
31 | :redirect_uri => redirect_url
32 | )
33 | auth_client.code = auth_code
34 |
35 | begin
36 | auth_client.fetch_access_token!
37 | secret_hash = auth_client.as_json.slice("expiry", "refresh_token", "access_token")
38 | if secret_hash["refresh_token"] == nil
39 | return {:error => {:message => 'You have already authorized this application. In order to re-configure, go to https://myaccount.google.com/permissions and remove access to "Standard Notes".'}}
40 | else
41 | secret_hash[:expires_at] = auth_client.expires_at
42 | secret_base64 = Base64.encode64(secret_hash.to_json)
43 | return secret_base64
44 | end
45 | rescue StandardError => e
46 | return {:error => {:message => e.message}}
47 | end
48 | end
49 |
50 | def find_or_create_folder(folder_name)
51 | folder_mime = "application/vnd.google-apps.folder"
52 | folder_search = nil
53 | begin
54 | folder_search = drive.list_files(q: "mimeType='#{folder_mime}' and name='#{folder_name}'")
55 | rescue StandardError => _e
56 | return
57 | end
58 |
59 | if folder_search.files.length > 0
60 | folder = folder_search.files[0]
61 | else
62 | folder_data = {
63 | name: folder_name,
64 | mime_type: folder_mime
65 | }
66 | folder = drive.create_file(folder_data, fields: 'id')
67 | end
68 |
69 | return folder
70 | end
71 |
72 | def save_item(params)
73 | Rails.logger.info 'Saving file to Google Drive'
74 |
75 | payload = { items: [params[:item]] }
76 | payload['auth_params'] = params[:auth_params]
77 |
78 | tmp = Tempfile.new(SecureRandom.hex)
79 | tmp.write(JSON.pretty_generate(payload.as_json))
80 | tmp.rewind
81 |
82 | folder = find_or_create_folder('FileSafe')
83 |
84 | file = drive.create_file(
85 | { name: params[:name], parents: [folder.id] },
86 | upload_source: tmp.path,
87 | content_type: 'application/json'
88 | )
89 |
90 | { file_id: file.id }
91 | end
92 |
93 | def download_item(metadata)
94 | file_id = metadata[:file_id]
95 | path = "/tmp/gdrive-tmp-#{file_id}"
96 | # Actually downloda file
97 | drive.get_file("#{file_id}", download_dest: path)
98 | body = File.read(path)
99 | # Get metadata
100 | file = drive.get_file("#{file_id}")
101 | return body, file.name
102 | end
103 |
104 | def delete_item(metadata)
105 | file_id = metadata[:file_id]
106 | drive.delete_file("#{file_id}")
107 | end
108 |
109 | private
110 |
111 | def drive
112 | return @drive if @drive
113 |
114 | client_secrets = Google::APIClient::ClientSecrets.load
115 | client_params = client_secrets.to_authorization.as_json
116 | secret_hash = JSON.parse(Base64.decode64(@token))
117 | client_params.merge!(secret_hash)
118 | auth_client = Signet::OAuth2::Client.new(client_params)
119 |
120 | @drive = Google::Apis::DriveV3::DriveService.new
121 | @drive.authorization = auth_client
122 |
123 | return @drive
124 | end
125 |
126 | end
127 |
--------------------------------------------------------------------------------
/app/lib/integrations/webdav_integration.rb:
--------------------------------------------------------------------------------
1 | class WebdavIntegration
2 | require 'net/dav'
3 |
4 | def initialize(params = {})
5 | if params[:authorization]
6 | @auth_params = JSON.parse(Base64.decode64(params[:authorization]))
7 | end
8 | end
9 |
10 | def type
11 | return "form"
12 | end
13 |
14 | def save_item(params)
15 | Rails.logger.info 'Saving file to WebDAV'
16 |
17 | payload = { items: [params[:item]] }
18 | payload['auth_params'] = params[:auth_params]
19 |
20 | file_path = params[:name]
21 | dir = @auth_params['dir']
22 | file_path = "#{dir}/#{params[:name]}" if dir&.length&.positive?
23 |
24 | file_path = URI::encode(file_path)
25 | dav.put_string(file_path, JSON.pretty_generate(payload.as_json))
26 |
27 | { file_path: file_path }
28 | end
29 |
30 | def download_item(metadata = {})
31 | body = nil, filename = nil
32 | self.dav.find(metadata[:file_path]) do |item|
33 | body = item.content
34 | filename = metadata[:file_path]
35 | end
36 |
37 | return body, filename
38 | end
39 |
40 | def delete_item(metadata)
41 | self.dav.delete(metadata[:file_path])
42 | end
43 |
44 | def dav
45 | return @dav if @dav
46 | @dav = Net::DAV.new(@auth_params["server"])
47 | @dav.verify_server = false
48 | @dav.credentials(@auth_params["username"], @auth_params["password"])
49 | return @dav
50 | end
51 |
52 | end
53 |
--------------------------------------------------------------------------------
/app/mailers/application_mailer.rb:
--------------------------------------------------------------------------------
1 | class ApplicationMailer < ActionMailer::Base
2 | default from: 'from@example.com'
3 | layout 'mailer'
4 | end
5 |
--------------------------------------------------------------------------------
/app/models/application_record.rb:
--------------------------------------------------------------------------------
1 | class ApplicationRecord < ActiveRecord::Base
2 | self.abstract_class = true
3 | end
4 |
--------------------------------------------------------------------------------
/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/app/models/concerns/.keep
--------------------------------------------------------------------------------
/app/views/application/index.html.haml:
--------------------------------------------------------------------------------
1 | .sk-panel-section
2 | .sk-button-group
3 | %a.sk-button.info{"href" => "#{@dropbox_link}", "target" => "_blank"}
4 | .sk-label Dropbox
5 |
6 | %a.sk-button.success{"href" => "#{@google_drive_link}", "target" => "_blank"}
7 | .sk-label Google Drive
8 |
9 | %a.sk-button.warning{"href" => "#{@webdav_link}"}
10 | .sk-label WebDAV
11 |
12 | %a.sk-button.neutral{"href" => "#{@aws_s3_link}"}
13 | .sk-label AWS S3
14 |
--------------------------------------------------------------------------------
/app/views/integrations/form_aws_s3.html.haml:
--------------------------------------------------------------------------------
1 | .sk-panel-section
2 | .sk-panel-form
3 | = form_tag({controller: "integrations", :action => "submit_form"}, :method => "post") do
4 | = fields_for :auth_data do |ad|
5 | = ad.text_field :region, :placeholder => "Region, e.g., eu-central-1", :required => true, :class => "sk-input contrast"
6 | = ad.text_field :bucket, :placeholder => "S3 Bucket", :required => true, :class => "sk-input contrast"
7 | = ad.text_field :key, :placeholder => "Access Key ID", :required => true, :class => "sk-input contrast"
8 | = ad.password_field :secret, :placeholder => "Access Key Secret", :required => true, :class => "sk-input contrast"
9 | .sk-panel-row
10 | = submit_tag "Submit", :class => "sk-button info "
11 | .sk-panel-row
12 | %h4
13 | Guide:
14 | %a{"href" => "https://github.com/standardnotes/docs/wiki/How-to-configure-Amazon-S3-with-Standard-Notes-FileSafe", "target" => "_blank"}
15 | How to configure Amazon S3 with Standard Notes FileSafe →
16 |
--------------------------------------------------------------------------------
/app/views/integrations/form_webdav.html.haml:
--------------------------------------------------------------------------------
1 | .sk-panel-section
2 | .sk-panel-form
3 | = form_tag({controller: "integrations", :action => "submit_form"}, :method => "post") do
4 | = fields_for :auth_data do |ad|
5 | = ad.text_field :server, :placeholder => "Server", :required => true, :class => "sk-input contrast"
6 | = ad.text_field :username, :placeholder => "Username", :required => true, :class => "sk-input contrast"
7 | = ad.password_field :password, :placeholder => "Password", :required => true, :class => "sk-input contrast"
8 | = ad.text_field :dir, :placeholder => "Directory (optional; make sure exists. i.e 'FileSafe/files')", :class => "sk-input contrast"
9 | .sk-panel-row
10 | = submit_tag "Submit", :class => "sk-button info "
11 |
--------------------------------------------------------------------------------
/app/views/integrations/integration_complete.html.haml:
--------------------------------------------------------------------------------
1 | .sk-panel-section
2 | .sk-panel-row
3 | .sk-panel-column
4 | Your #{@integration_name || "integration"} is complete.
5 | Copy the code below, and return to Standard Notes to paste the code into the FileSafe extension.
6 | .sk-panel-row
7 | %h2.title.sk-panel-row Integration Code
8 | .sk-notification.info.dashed
9 | #activation-code.center-text.select-all.wrap.info-contrast
10 | #{@code}
11 | #activation-code-button.sk-button.info
12 | .sk-label Copy Code
13 |
--------------------------------------------------------------------------------
/app/views/integrations/oauth_redirect.html.haml:
--------------------------------------------------------------------------------
1 | .sk-panel-section
2 | .sk-panel-row
3 | .danger An error occured: #{@error[:message].html_safe}
4 |
--------------------------------------------------------------------------------
/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | FileSafe Integrations
5 |
6 |
7 |
8 | <%= csrf_meta_tags %>
9 |
10 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
11 | <%= javascript_include_tag 'application' %>
12 |
13 |
14 |
15 |
16 |
19 |
20 |
21 | <%= yield %>
22 |
23 |
24 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/views/layouts/mailer.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/views/layouts/mailer.text.erb:
--------------------------------------------------------------------------------
1 | <%= yield %>
2 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | APP_PATH = File.expand_path('../config/application', __dir__)
8 | require_relative '../config/boot'
9 | require 'rails/commands'
10 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | require_relative '../config/boot'
8 | require 'rake'
9 | Rake.application.run
10 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'pathname'
3 | require 'fileutils'
4 | include FileUtils
5 |
6 | # path to your application root.
7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8 |
9 | def system!(*args)
10 | system(*args) || abort("\n== Command #{args} failed ==")
11 | end
12 |
13 | chdir APP_ROOT do
14 | # This script is a starting point to setup your application.
15 | # Add necessary setup steps to this file.
16 |
17 | puts '== Installing dependencies =='
18 | system! 'gem install bundler --conservative'
19 | system('bundle check') || system!('bundle install')
20 |
21 | # Install JavaScript dependencies if using Yarn
22 | # system('bin/yarn')
23 |
24 |
25 | # puts "\n== Copying sample files =="
26 | # unless File.exist?('config/database.yml')
27 | # cp 'config/database.yml.sample', 'config/database.yml'
28 | # end
29 |
30 | puts "\n== Preparing database =="
31 | system! 'bin/rails db:setup'
32 |
33 | puts "\n== Removing old logs and tempfiles =="
34 | system! 'bin/rails log:clear tmp:clear'
35 |
36 | puts "\n== Restarting application server =="
37 | system! 'bin/rails restart'
38 | end
39 |
--------------------------------------------------------------------------------
/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require 'rubygems'
8 | require 'bundler'
9 |
10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11 | spring = lockfile.specs.detect { |spec| spec.name == "spring" }
12 | if spring
13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
14 | gem 'spring', spring.version
15 | require 'spring/binstub'
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/bin/update:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'pathname'
3 | require 'fileutils'
4 | include FileUtils
5 |
6 | # path to your application root.
7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8 |
9 | def system!(*args)
10 | system(*args) || abort("\n== Command #{args} failed ==")
11 | end
12 |
13 | chdir APP_ROOT do
14 | # This script is a way to update your development environment automatically.
15 | # Add necessary update steps to this file.
16 |
17 | puts '== Installing dependencies =='
18 | system! 'gem install bundler --conservative'
19 | system('bundle check') || system!('bundle install')
20 |
21 | puts "\n== Updating database =="
22 | system! 'bin/rails db:migrate'
23 |
24 | puts "\n== Removing old logs and tempfiles =="
25 | system! 'bin/rails log:clear tmp:clear'
26 |
27 | puts "\n== Restarting application server =="
28 | system! 'bin/rails restart'
29 | end
30 |
--------------------------------------------------------------------------------
/bin/yarn:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | VENDOR_PATH = File.expand_path('..', __dir__)
3 | Dir.chdir(VENDOR_PATH) do
4 | begin
5 | exec "yarnpkg #{ARGV.join(" ")}"
6 | rescue Errno::ENOENT
7 | $stderr.puts "Yarn executable was not detected in the system."
8 | $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9 | exit 1
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require_relative 'config/environment'
4 |
5 | run Rails.application
6 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require_relative 'boot'
2 |
3 | require 'rails/all'
4 |
5 | # Require the gems listed in Gemfile, including any gems
6 | # you've limited to :test, :development, or :production.
7 | Bundler.require(*Rails.groups)
8 |
9 | module FilevaultRelay
10 | class Application < Rails::Application
11 | # Initialize configuration defaults for originally generated Rails version.
12 | config.load_defaults 5.1
13 |
14 | config.autoload_paths += Dir["#{config.root}/app/lib/**/*"]
15 |
16 | # Cross-Origin Resource Sharing (CORS) for Rack compatible web applications.
17 | config.middleware.insert_before 0, Rack::Cors do
18 | allow do
19 | origins '*'
20 | resource '*', :headers => :any, :methods => [:get, :post, :put, :patch, :delete, :options], :expose => ['Access-Token', 'Client', 'UID']
21 | end
22 | end
23 |
24 | # Settings in config/environments/* take precedence over those specified here.
25 | # Application configuration should go into files in config/initializers
26 | # -- all .rb files in that directory are automatically loaded.
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2 |
3 | require 'bundler/setup' # Set up gems listed in the Gemfile.
4 |
--------------------------------------------------------------------------------
/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: async
3 |
4 | test:
5 | adapter: async
6 |
7 | production:
8 | adapter: redis
9 | url: redis://localhost:6379/1
10 | channel_prefix: filevault-relay_production
11 |
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: db/development.sqlite3
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: db/test.sqlite3
22 |
23 | production:
24 | <<: *default
25 | database: db/production.sqlite3
26 |
--------------------------------------------------------------------------------
/config/deploy.rb:
--------------------------------------------------------------------------------
1 | CAP_CONFIG = YAML.load_file("config/cap.yml")
2 |
3 | # config valid only for current version of Capistrano
4 | lock '3.6.1'
5 |
6 | set :application, 'filesafe-relay'
7 | set :repo_url, CAP_CONFIG["default"]["repo_url"]
8 |
9 | # Default branch is :master
10 | # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
11 |
12 | # Default deploy_to directory is /var/www/my_app_name
13 | # set :deploy_to, '/var/www/my_app_name'
14 |
15 | # Default value for :scm is :git
16 | set :scm, :git
17 | set :deploy_via, :remote_cache
18 | set :git_strategy, Capistrano::Git::SubmoduleStrategy
19 |
20 | # Default value for :format is :airbrussh.
21 | # set :format, :airbrussh
22 |
23 | # You can configure the Airbrussh format using :format_options.
24 | # These are the defaults.
25 | # set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto
26 |
27 | # Default value for :pty is false
28 | # set :pty, true
29 |
30 | # Default value for :linked_files is []
31 | # set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
32 | set :linked_files, fetch(:linked_files, []).push('.env', 'client_secrets.json')
33 |
34 | # Default value for linked_dirs is []
35 | # set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system')
36 | set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system', 'public/uploads')
37 |
38 | # Default value for keep_releases is 5
39 | # set :keep_releases, 5
40 |
41 | set :rvm_ruby_version, '2.3.0'
42 |
43 | namespace :deploy do
44 |
45 | after :restart, :clear_cache do
46 | on roles(:web), in: :groups, limit: 3, wait: 5 do
47 | # Here we can do anything such as:
48 | within release_path do
49 |
50 | end
51 | end
52 | end
53 | end
54 |
55 | set :ssh_options, {
56 | keys: %W( #{CAP_CONFIG['default']['key_path']} ),
57 | forward_agent: false,
58 | auth_methods: %w(publickey)
59 | }
60 |
--------------------------------------------------------------------------------
/config/deploy/production.rb:
--------------------------------------------------------------------------------
1 | # server-based syntax
2 | # ======================
3 | # Defines a single server with a list of roles and multiple properties.
4 | # You can define all roles on a single server, or split them:
5 |
6 | # server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
7 | # server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
8 | # server 'db.example.com', user: 'deploy', roles: %w{db}
9 |
10 | server CAP_CONFIG['production']['server'], user: CAP_CONFIG['production']['user'], roles: %w{app db web}
11 |
12 | set :deploy_to, CAP_CONFIG['production']['deploy_to']
13 |
14 | # role-based syntax
15 | # ==================
16 |
17 | # Defines a role with one or multiple servers. The primary server in each
18 | # group is considered to be the first unless any hosts have the primary
19 | # property set. Specify the username and a domain or IP for the server.
20 | # Don't use `:all`, it's a meta role.
21 |
22 | # role :app, %w{deploy@example.com}, my_property: :my_value
23 | # role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
24 | # role :db, %w{deploy@example.com}
25 |
26 |
27 |
28 | # Configuration
29 | # =============
30 | # You can set any configuration variable like in config/deploy.rb
31 | # These variables are then only loaded and set in this stage.
32 | # For available Capistrano configuration variables see the documentation page.
33 | # http://capistranorb.com/documentation/getting-started/configuration/
34 | # Feel free to add new variables to customise your setup.
35 |
36 |
37 |
38 | # Custom SSH Options
39 | # ==================
40 | # You may pass any option but keep in mind that net/ssh understands a
41 | # limited set of options, consult the Net::SSH documentation.
42 | # http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
43 | #
44 | # Global options
45 | # --------------
46 | # set :ssh_options, {
47 | # keys: %w(/home/rlisowski/.ssh/id_rsa),
48 | # forward_agent: false,
49 | # auth_methods: %w(password)
50 | # }
51 | #
52 | # The server-based syntax can be used to override options:
53 | # ------------------------------------
54 | # server 'example.com',
55 | # user: 'user_name',
56 | # roles: %w{web app},
57 | # ssh_options: {
58 | # user: 'user_name', # overrides user setting above
59 | # keys: %w(/home/user_name/.ssh/id_rsa),
60 | # forward_agent: false,
61 | # auth_methods: %w(publickey password)
62 | # # password: 'please use keys'
63 | # }
64 |
--------------------------------------------------------------------------------
/config/deploy/staging.rb:
--------------------------------------------------------------------------------
1 | # server-based syntax
2 | # ======================
3 | # Defines a single server with a list of roles and multiple properties.
4 | # You can define all roles on a single server, or split them:
5 |
6 | # server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
7 | # server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
8 | # server 'db.example.com', user: 'deploy', roles: %w{db}
9 |
10 | server CAP_CONFIG['staging']['server'], user: CAP_CONFIG['staging']['user'], roles: %w{app db web}
11 |
12 | set :branch, CAP_CONFIG['staging']['branch']
13 |
14 | set :deploy_to, CAP_CONFIG['staging']['deploy_to']
15 |
16 | # role-based syntax
17 | # ==================
18 |
19 | # Defines a role with one or multiple servers. The primary server in each
20 | # group is considered to be the first unless any hosts have the primary
21 | # property set. Specify the username and a domain or IP for the server.
22 | # Don't use `:all`, it's a meta role.
23 |
24 | # role :app, %w{deploy@example.com}, my_property: :my_value
25 | # role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
26 | # role :db, %w{deploy@example.com}
27 |
28 |
29 |
30 | # Configuration
31 | # =============
32 | # You can set any configuration variable like in config/deploy.rb
33 | # These variables are then only loaded and set in this stage.
34 | # For available Capistrano configuration variables see the documentation page.
35 | # http://capistranorb.com/documentation/getting-started/configuration/
36 | # Feel free to add new variables to customise your setup.
37 |
38 |
39 |
40 | # Custom SSH Options
41 | # ==================
42 | # You may pass any option but keep in mind that net/ssh understands a
43 | # limited set of options, consult the Net::SSH documentation.
44 | # http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
45 | #
46 | # Global options
47 | # --------------
48 | # set :ssh_options, {
49 | # keys: %w(/home/rlisowski/.ssh/id_rsa),
50 | # forward_agent: false,
51 | # auth_methods: %w(password)
52 | # }
53 | #
54 | # The server-based syntax can be used to override options:
55 | # ------------------------------------
56 | # server 'example.com',
57 | # user: 'user_name',
58 | # roles: %w{web app},
59 | # ssh_options: {
60 | # user: 'user_name', # overrides user setting above
61 | # keys: %w(/home/user_name/.ssh/id_rsa),
62 | # forward_agent: false,
63 | # auth_methods: %w(publickey password)
64 | # # password: 'please use keys'
65 | # }
66 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require_relative 'application'
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Do not eager load code on boot.
10 | config.eager_load = true
11 |
12 | MAX_LOG_MEGABYTES = 50
13 | config.logger = ActiveSupport::Logger.new(config.paths['log'].first, 1, MAX_LOG_MEGABYTES * 1024 * 1024)
14 |
15 | if ENV["RAILS_LOG_TO_STDOUT"].present?
16 | config.logger = ActiveSupport::Logger.new(STDOUT)
17 | end
18 |
19 | config.colorize_logging = false
20 |
21 | # Show full error reports.
22 | config.consider_all_requests_local = true
23 |
24 | # Enable/disable caching. By default caching is disabled.
25 | if Rails.root.join('tmp/caching-dev.txt').exist?
26 | config.action_controller.perform_caching = true
27 |
28 | config.cache_store = :memory_store
29 | config.public_file_server.headers = {
30 | 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
31 | }
32 | else
33 | config.action_controller.perform_caching = false
34 |
35 | config.cache_store = :null_store
36 | end
37 |
38 | # Don't care if the mailer can't send.
39 | config.action_mailer.raise_delivery_errors = false
40 |
41 | config.action_mailer.perform_caching = false
42 |
43 | # Print deprecation notices to the Rails logger.
44 | config.active_support.deprecation = :log
45 |
46 | # Raise an error on page load if there are pending migrations.
47 | config.active_record.migration_error = :page_load
48 |
49 | # Debug mode disables concatenation and preprocessing of assets.
50 | # This option may cause significant delays in view rendering with a large
51 | # number of complex assets.
52 | config.assets.debug = true
53 |
54 | # Suppress logger output for asset requests.
55 | config.assets.logger = false
56 | config.assets.quiet = true
57 |
58 | # Raises error for missing translations
59 | # config.action_view.raise_on_missing_translations = true
60 |
61 | # Use an evented file watcher to asynchronously detect changes in source code,
62 | # routes, locales, etc. This feature depends on the listen gem.
63 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker
64 | end
65 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both threaded web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | MAX_LOG_MEGABYTES = 50
14 | config.logger = ActiveSupport::Logger.new(config.paths['log'].first, 1, MAX_LOG_MEGABYTES * 1024 * 1024)
15 |
16 | if ENV["RAILS_LOG_TO_STDOUT"].present?
17 | config.logger = ActiveSupport::Logger.new(STDOUT)
18 | end
19 |
20 | config.colorize_logging = false
21 |
22 | # Full error reports are disabled and caching is turned on.
23 | config.consider_all_requests_local = false
24 | config.action_controller.perform_caching = true
25 |
26 | # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
27 | # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
28 | # `config/secrets.yml.key`.
29 | config.read_encrypted_secrets = true
30 |
31 | # Disable serving static files from the `/public` folder by default since
32 | # Apache or NGINX already handles this.
33 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
34 |
35 | # Compress JavaScripts and CSS.
36 | config.assets.js_compressor = :uglifier
37 | # config.assets.css_compressor = :sass
38 |
39 | # Do not fallback to assets pipeline if a precompiled asset is missed.
40 | config.assets.compile = false
41 |
42 | config.assets.logger = false
43 | config.assets.quiet = true
44 |
45 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
46 |
47 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
48 | # config.action_controller.asset_host = 'http://assets.example.com'
49 |
50 | # Specifies the header that your server uses for sending files.
51 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
52 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
53 |
54 | # Mount Action Cable outside main process or domain
55 | # config.action_cable.mount_path = nil
56 | # config.action_cable.url = 'wss://example.com/cable'
57 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
58 |
59 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
60 | # config.force_ssl = true
61 |
62 | # Use the lowest log level to ensure availability of diagnostic information
63 | # when problems arise.
64 | config.log_level = :info
65 |
66 | # Prepend all log lines with the following tags.
67 | config.log_tags = [ :request_id ]
68 |
69 | # Use a different cache store in production.
70 | # config.cache_store = :mem_cache_store
71 |
72 | # Use a real queuing backend for Active Job (and separate queues per environment)
73 | # config.active_job.queue_adapter = :resque
74 | # config.active_job.queue_name_prefix = "filevault-relay_#{Rails.env}"
75 | config.action_mailer.perform_caching = false
76 |
77 | # Ignore bad email addresses and do not raise email delivery errors.
78 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
79 | # config.action_mailer.raise_delivery_errors = false
80 |
81 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
82 | # the I18n.default_locale when a translation cannot be found).
83 | config.i18n.fallbacks = true
84 |
85 | # Send deprecation notices to registered listeners.
86 | config.active_support.deprecation = :notify
87 |
88 | # Use a different logger for distributed setups.
89 | # require 'syslog/logger'
90 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
91 |
92 | # Do not dump schema after migrations.
93 | config.active_record.dump_schema_after_migration = false
94 | end
95 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Configure public file server for tests with Cache-Control for performance.
16 | config.public_file_server.enabled = true
17 | config.public_file_server.headers = {
18 | 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
19 | }
20 |
21 | # Show full error reports and disable caching.
22 | config.consider_all_requests_local = true
23 | config.action_controller.perform_caching = false
24 |
25 | # Raise exceptions instead of rendering exception templates.
26 | config.action_dispatch.show_exceptions = false
27 |
28 | # Disable request forgery protection in test environment.
29 | config.action_controller.allow_forgery_protection = false
30 | config.action_mailer.perform_caching = false
31 |
32 | # Tell Action Mailer not to deliver emails to the real world.
33 | # The :test delivery method accumulates sent emails in the
34 | # ActionMailer::Base.deliveries array.
35 | config.action_mailer.delivery_method = :test
36 |
37 | # Print deprecation notices to the stderr.
38 | config.active_support.deprecation = :stderr
39 |
40 | # Raises error for missing translations
41 | # config.action_view.raise_on_missing_translations = true
42 | end
43 |
--------------------------------------------------------------------------------
/config/initializers/application_controller_renderer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # ActiveSupport::Reloader.to_prepare do
4 | # ApplicationController.renderer.defaults.merge!(
5 | # http_host: 'example.org',
6 | # https: false
7 | # )
8 | # end
9 |
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path.
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 | # Add Yarn node_modules folder to the asset load path.
9 | Rails.application.config.assets.paths << Rails.root.join('node_modules/sn-stylekit/dist')
10 |
11 | # Precompile additional assets.
12 | # application.js, application.css, and all non-JS/CSS in the app/assets
13 | # folder are already added.
14 | # Rails.application.config.assets.precompile += %w( admin.js admin.css )
15 |
16 | Rails.application.config.assets.precompile += %w( stylekit.css )
17 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Specify a serializer for the signed and encrypted cookie jars.
4 | # Valid options are :json, :marshal, and :hybrid.
5 | Rails.application.config.action_dispatch.cookies_serializer = :json
6 |
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password, :file]
5 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/config/initializers/lograge.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | config.lograge.enabled = true
3 | config.lograge.ignore_actions = ['HealthCheckController#index']
4 | end
5 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json]
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # The following keys must be escaped otherwise they will not be retrieved by
20 | # the default I18n backend:
21 | #
22 | # true, false, on, off, yes, no
23 | #
24 | # Instead, surround them with single quotes.
25 | #
26 | # en:
27 | # 'true': 'foo'
28 | #
29 | # To learn more, please read the Rails Internationalization guide
30 | # available at http://guides.rubyonrails.org/i18n.html.
31 |
32 | en:
33 | hello: "Hello world"
34 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | # Puma can serve each request in a thread from an internal thread pool.
2 | # The `threads` method setting takes two numbers: a minimum and maximum.
3 | # Any libraries that use thread pools should be configured to match
4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
5 | # and maximum; this matches the default thread size of Active Record.
6 | #
7 | threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8 | threads threads_count, threads_count
9 |
10 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
11 | #
12 | port ENV.fetch("PORT") { 3000 }
13 |
14 | # Specifies the `environment` that Puma will run in.
15 | #
16 | environment ENV.fetch("RAILS_ENV") { "development" }
17 |
18 | # Specifies the number of `workers` to boot in clustered mode.
19 | # Workers are forked webserver processes. If using threads and workers together
20 | # the concurrency of the application would be max `threads` * `workers`.
21 | # Workers do not work on JRuby or Windows (both of which do not support
22 | # processes).
23 | #
24 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
25 |
26 | # Use the `preload_app!` method when specifying a `workers` number.
27 | # This directive tells Puma to first boot the application and load code
28 | # before forking the application. This takes advantage of Copy On Write
29 | # process behavior so workers use less memory. If you use this option
30 | # you need to make sure to reconnect any threads in the `on_worker_boot`
31 | # block.
32 | #
33 | # preload_app!
34 |
35 | # If you are preloading your application and using Active Record, it's
36 | # recommended that you close any connections to the database before workers
37 | # are forked to prevent connection leakage.
38 | #
39 | # before_fork do
40 | # ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
41 | # end
42 |
43 | # The code in the `on_worker_boot` will be called if you are using
44 | # clustered mode by specifying a number of `workers`. After each worker
45 | # process is booted, this block will be run. If you are using the `preload_app!`
46 | # option, you will want to use this block to reconnect to any threads
47 | # or connections that may have been created at application boot, as Ruby
48 | # cannot share connections between processes.
49 | #
50 | # on_worker_boot do
51 | # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
52 | # end
53 | #
54 |
55 | # Allow puma to be restarted by `rails restart` command.
56 | plugin :tmp_restart
57 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
3 |
4 | get "integrations/link" => "integrations#link"
5 | get "integrations/oauth-redirect" => "integrations#oauth_redirect"
6 | get "integrations/integration_complete" => "integrations#integration_complete"
7 | post "integrations/submit_form"
8 |
9 | post "integrations/save-item" => "integrations#save_item"
10 | post "integrations/download-item" => "integrations#download_item"
11 | post "integrations/delete-item" => "integrations#delete_item"
12 |
13 | get "/healthcheck" => "health_check#index"
14 |
15 | get '*unmatched_route', to: 'application#route_not_found'
16 |
17 | root "application#index"
18 | end
19 |
--------------------------------------------------------------------------------
/config/secrets.yml:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key is used for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 |
6 | # Make sure the secret is at least 30 characters and all random,
7 | # no regular words or you'll be exposed to dictionary attacks.
8 | # You can use `rails secret` to generate a secure secret key.
9 |
10 | # Make sure the secrets in this file are kept private
11 | # if you're sharing your code publicly.
12 |
13 | # Shared secrets are available across all environments.
14 |
15 | # shared:
16 | # api_key: a1B2c3D4e5F6
17 |
18 | # Environmental secrets are only available for that specific environment.
19 |
20 | development:
21 | secret_key_base: 4a9482a86e23d994a76974cd087814c0a6e6073ad2fbe4aa3ac3e9fdd8844d6f3c9d897bbcc2ed208db1983875ebadd634e9fc5353c7cba7bb2640be0a62932e
22 |
23 | test:
24 | secret_key_base: e485fddba9ae12cffcffe348fde003e44177e7bd08d563ed9f87f223b1f6ecc19fb059303a755b9b46d44eacb77857cc1bc93f7c82b1ca0c83f9c3fd4b4f0387
25 |
26 | # Do not keep production secrets in the unencrypted secrets file.
27 | # Instead, either read values from the environment.
28 | # Or, use `bin/rails secrets:setup` to configure encrypted secrets
29 | # and move the `production:` environment over there.
30 |
31 | production:
32 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
33 |
--------------------------------------------------------------------------------
/config/spring.rb:
--------------------------------------------------------------------------------
1 | %w(
2 | .ruby-version
3 | .rbenv-vars
4 | tmp/restart.txt
5 | tmp/caching-dev.txt
6 | ).each { |path| Spring.watch(path) }
7 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7 | # Character.create(name: 'Luke', movie: movies.first)
8 |
--------------------------------------------------------------------------------
/docker/entrypoint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | case "$1" in
5 | 'start' )
6 | rm -f /filesafe-relay/tmp/pids/server.pid
7 | [ ! -z "$GOOGLE_CLIENT_SECRETS" ] && echo "$GOOGLE_CLIENT_SECRETS" > /filesafe-relay/client_secrets.json
8 | bundle exec rails server -b 0.0.0.0
9 | ;;
10 |
11 | * )
12 | echo "Unknown command"
13 | ;;
14 | esac
15 |
16 | exec "$@"
17 |
--------------------------------------------------------------------------------
/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/log/.keep
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "filevault-relay",
3 | "private": true,
4 | "dependencies": {
5 | "sn-stylekit": "2.0.22"
6 | },
7 | "description": "This README would normally document whatever steps are necessary to get the application up and running.",
8 | "version": "1.0.0",
9 | "main": "index.js",
10 | "directories": {
11 | "lib": "lib",
12 | "test": "test"
13 | },
14 | "scripts": {
15 | "test": "echo \"Error: no test specified\" && exit 1"
16 | },
17 | "repository": {
18 | "type": "git",
19 | "url": "git+https://github.com/standardnotes/filevault-relay.git"
20 | },
21 | "author": "",
22 | "license": "ISC",
23 | "bugs": {
24 | "url": "https://github.com/standardnotes/filevault-relay/issues"
25 | },
26 | "homepage": "https://github.com/standardnotes/filevault-relay#readme"
27 | }
28 |
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
The change you wanted was rejected (422)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The change you wanted was rejected.
62 |
Maybe you tried to change something you didn't have access to.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
We're sorry, but something went wrong (500)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
We're sorry, but something went wrong.
62 |
63 |
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/public/apple-touch-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/public/apple-touch-icon-precomposed.png
--------------------------------------------------------------------------------
/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/public/apple-touch-icon.png
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/public/favicon.ico
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 | Disallow: /
--------------------------------------------------------------------------------
/spec/controllers/integrations_controller_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'rails_helper'
4 |
5 | RSpec.describe IntegrationsController, type: :controller do
6 | describe 'download_failure' do
7 | it 'should signal integration failure' do
8 | post :download_item
9 |
10 | expect(response).to have_http_status(:bad_request)
11 | expect(response.headers['Content-Type']).to eq(
12 | 'application/json; charset=utf-8'
13 | )
14 |
15 | parsed_response_body = JSON.parse(response.body)
16 |
17 | expect(parsed_response_body).to_not be_nil
18 | expect(parsed_response_body['error']).to_not be_nil
19 | expect(parsed_response_body['error']['message']).to eq(
20 | 'Could not retrieve item. Please verify your integration.'
21 | )
22 | end
23 | end
24 |
25 | describe 'save_failure' do
26 | it 'should signal integration failure' do
27 | post :save_item
28 |
29 | expect(response).to have_http_status(:bad_request)
30 | expect(response.headers['Content-Type']).to eq(
31 | 'application/json; charset=utf-8'
32 | )
33 |
34 | parsed_response_body = JSON.parse(response.body)
35 |
36 | expect(parsed_response_body).to_not be_nil
37 | expect(parsed_response_body['error']).to_not be_nil
38 | expect(parsed_response_body['error']['message']).to eq(
39 | 'Could not save item. Please verify your integration.'
40 | )
41 | end
42 | end
43 |
44 | describe 'delete_failure' do
45 | it 'should signal integration failure' do
46 | post :delete_item
47 |
48 | expect(response).to have_http_status(:bad_request)
49 | expect(response.headers['Content-Type']).to eq(
50 | 'application/json; charset=utf-8'
51 | )
52 |
53 | parsed_response_body = JSON.parse(response.body)
54 |
55 | expect(parsed_response_body).to_not be_nil
56 | expect(parsed_response_body['error']).to_not be_nil
57 | expect(parsed_response_body['error']['message']).to eq(
58 | 'Could not delete item. Please verify your integration.'
59 | )
60 | end
61 | end
62 | end
63 |
--------------------------------------------------------------------------------
/spec/rails_helper.rb:
--------------------------------------------------------------------------------
1 | # This file is copied to spec/ when you run 'rails generate rspec:install'
2 | require 'spec_helper'
3 | ENV['RAILS_ENV'] ||= 'test'
4 | require File.expand_path('../config/environment', __dir__)
5 | # Prevent database truncation if the environment is production
6 | abort("The Rails environment is running in production mode!") if Rails.env.production?
7 | require 'rspec/rails'
8 | # Add additional requires below this line. Rails is not loaded until this point!
9 |
10 | # Requires supporting ruby files with custom matchers and macros, etc, in
11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12 | # run as spec files by default. This means that files in spec/support that end
13 | # in _spec.rb will both be required and run as specs, causing the specs to be
14 | # run twice. It is recommended that you do not name files matching this glob to
15 | # end with _spec.rb. You can configure this pattern with the --pattern
16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17 | #
18 | # The following line is provided for convenience purposes. It has the downside
19 | # of increasing the boot-up time by auto-requiring all files in the support
20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually
21 | # require only the support files necessary.
22 | #
23 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
24 |
25 | # Checks for pending migrations and applies them before tests are run.
26 | # If you are not using ActiveRecord, you can remove these lines.
27 | # begin
28 | # ActiveRecord::Migration.maintain_test_schema!
29 | # rescue ActiveRecord::PendingMigrationError => e
30 | # puts e.to_s.strip
31 | # exit 1
32 | # end
33 | RSpec.configure do |config|
34 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
35 | config.fixture_path = "#{::Rails.root}/spec/fixtures"
36 |
37 | # If you're not using ActiveRecord, or you'd prefer not to run each of your
38 | # examples within a transaction, remove the following line or assign false
39 | # instead of true.
40 | config.use_transactional_fixtures = false
41 |
42 | # You can uncomment this line to turn off ActiveRecord support entirely.
43 | # config.use_active_record = false
44 |
45 | # RSpec Rails can automatically mix in different behaviours to your tests
46 | # based on their file location, for example enabling you to call `get` and
47 | # `post` in specs under `spec/controllers`.
48 | #
49 | # You can disable this behaviour by removing the line below, and instead
50 | # explicitly tag your specs with their type, e.g.:
51 | #
52 | # RSpec.describe UsersController, type: :controller do
53 | # # ...
54 | # end
55 | #
56 | # The different available types are documented in the features, such as in
57 | # https://relishapp.com/rspec/rspec-rails/docs
58 | config.infer_spec_type_from_file_location!
59 |
60 | # Filter lines from Rails gems in backtraces.
61 | config.filter_rails_from_backtrace!
62 | # arbitrary gems may also be filtered via:
63 | # config.filter_gems_from_backtrace("gem name")
64 | end
65 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3 | # The generated `.rspec` file contains `--require spec_helper` which will cause
4 | # this file to always be loaded, without a need to explicitly require it in any
5 | # files.
6 | #
7 | # Given that it is always loaded, you are encouraged to keep this file as
8 | # light-weight as possible. Requiring heavyweight dependencies from this file
9 | # will add to the boot time of your test suite on EVERY test run, even for an
10 | # individual file that may not need all of that loaded. Instead, consider making
11 | # a separate helper file that requires the additional dependencies and performs
12 | # the additional setup, and require it from the spec files that actually need
13 | # it.
14 | #
15 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16 | RSpec.configure do |config|
17 | # rspec-expectations config goes here. You can use an alternate
18 | # assertion/expectation library such as wrong or the stdlib/minitest
19 | # assertions if you prefer.
20 | config.expect_with :rspec do |expectations|
21 | # This option will default to `true` in RSpec 4. It makes the `description`
22 | # and `failure_message` of custom matchers include text for helper methods
23 | # defined using `chain`, e.g.:
24 | # be_bigger_than(2).and_smaller_than(4).description
25 | # # => "be bigger than 2 and smaller than 4"
26 | # ...rather than:
27 | # # => "be bigger than 2"
28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29 | end
30 |
31 | # rspec-mocks config goes here. You can use an alternate test double
32 | # library (such as bogus or mocha) by changing the `mock_with` option here.
33 | config.mock_with :rspec do |mocks|
34 | # Prevents you from mocking or stubbing a method that does not exist on
35 | # a real object. This is generally recommended, and will default to
36 | # `true` in RSpec 4.
37 | mocks.verify_partial_doubles = true
38 | end
39 |
40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41 | # have no way to turn it off -- the option exists only for backwards
42 | # compatibility in RSpec 3). It causes shared context metadata to be
43 | # inherited by the metadata hash of host groups and examples, rather than
44 | # triggering implicit auto-inclusion in groups with matching metadata.
45 | config.shared_context_metadata_behavior = :apply_to_host_groups
46 |
47 | # The settings below are suggested to provide a good initial experience
48 | # with RSpec, but feel free to customize to your heart's content.
49 | =begin
50 | # This allows you to limit a spec run to individual examples or groups
51 | # you care about by tagging them with `:focus` metadata. When nothing
52 | # is tagged with `:focus`, all examples get run. RSpec also provides
53 | # aliases for `it`, `describe`, and `context` that include `:focus`
54 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55 | config.filter_run_when_matching :focus
56 |
57 | # Allows RSpec to persist some state between runs in order to support
58 | # the `--only-failures` and `--next-failure` CLI options. We recommend
59 | # you configure your source control system to ignore this file.
60 | config.example_status_persistence_file_path = "spec/examples.txt"
61 |
62 | # Limits the available syntax to the non-monkey patched syntax that is
63 | # recommended. For more details, see:
64 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67 | config.disable_monkey_patching!
68 |
69 | # Many RSpec users commonly either run the entire suite or an individual
70 | # file, and it's useful to allow more verbose output when running an
71 | # individual spec file.
72 | if config.files_to_run.one?
73 | # Use the documentation formatter for detailed output,
74 | # unless a formatter has already been configured
75 | # (e.g. via a command-line flag).
76 | config.default_formatter = "doc"
77 | end
78 |
79 | # Print the 10 slowest examples and example groups at the
80 | # end of the spec run, to help surface which specs are running
81 | # particularly slow.
82 | config.profile_examples = 10
83 |
84 | # Run specs in random order to surface order dependencies. If you find an
85 | # order dependency and want to debug it, you can fix the order by providing
86 | # the seed, which is printed after each run.
87 | # --seed 1234
88 | config.order = :random
89 |
90 | # Seed global randomization in this process using the `--seed` CLI option.
91 | # Setting this allows you to use `--seed` to deterministically reproduce
92 | # test failures related to randomization by passing the same `--seed` value
93 | # as the one that triggered the failure.
94 | Kernel.srand config.seed
95 | =end
96 | end
97 |
--------------------------------------------------------------------------------
/test/application_system_test_case.rb:
--------------------------------------------------------------------------------
1 | require "test_helper"
2 |
3 | class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
4 | driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
5 | end
6 |
--------------------------------------------------------------------------------
/test/controllers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/test/controllers/.keep
--------------------------------------------------------------------------------
/test/fixtures/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/test/fixtures/.keep
--------------------------------------------------------------------------------
/test/fixtures/files/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/test/fixtures/files/.keep
--------------------------------------------------------------------------------
/test/helpers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/test/helpers/.keep
--------------------------------------------------------------------------------
/test/integration/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/test/integration/.keep
--------------------------------------------------------------------------------
/test/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/test/mailers/.keep
--------------------------------------------------------------------------------
/test/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/test/models/.keep
--------------------------------------------------------------------------------
/test/system/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/test/system/.keep
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | ENV['RAILS_ENV'] ||= 'test'
2 | require File.expand_path('../../config/environment', __FILE__)
3 | require 'rails/test_help'
4 |
5 | class ActiveSupport::TestCase
6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7 | fixtures :all
8 |
9 | # Add more helper methods to be used by all tests here...
10 | end
11 |
--------------------------------------------------------------------------------
/tmp/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/tmp/.keep
--------------------------------------------------------------------------------
/vendor/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/standardnotes/filesafe-relay/95df6ced3fb9fe08c65083ea8e72e82c28455287/vendor/.keep
--------------------------------------------------------------------------------
/yarn.lock:
--------------------------------------------------------------------------------
1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2 | # yarn lockfile v1
3 |
4 |
5 | sn-stylekit@2.0.22:
6 | version "2.0.22"
7 | resolved "https://registry.yarnpkg.com/sn-stylekit/-/sn-stylekit-2.0.22.tgz#1ead6ed7ab6e2f4dd12759dc82b88d88d10d877e"
8 | integrity sha512-35BZbKCQQoYunmFMrMGA7OP7gkGoBJvNixfwlPXu7ep/ZhC+8NShrs7m+zYEvToZJG3Hc/709UgrzbgMYEz6FA==
9 |
--------------------------------------------------------------------------------