Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
AUTHENTICATION_REQUIRED=

AWS_REGION=us-east-2

ENVELOPE_DOWNLOADS_BUCKET=envelope-downloads
Expand Down
6 changes: 6 additions & 0 deletions app/api/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
module API
# Main base class that defines all API versions
class Base < Grape::API
helpers CommunityHelpers

insert_after Grape::Middleware::Formatter, Grape::Middleware::Logger, {
logger: MR.logger,
filter: Class.new do
Expand All @@ -14,6 +16,10 @@ def filter(opts)
end.new
}

before do
authenticate! unless request.path == '/swagger.json'
end

mount API::V1::Base
mount API::V2::Base
end
Expand Down
5 changes: 5 additions & 0 deletions app/api/helpers/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ def test_response
end

def authenticate!
auth_required = ActiveRecord::Type::Boolean.new.deserialize(
ENV.fetch('AUTHENTICATION_REQUIRED', nil)
)

return if !auth_required && request.request_method == 'GET'
return if current_user

json_error!(['Invalid token'], nil, 401)
Expand Down
14 changes: 7 additions & 7 deletions lib/swagger_docs/sections/envelopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Envelopes # rubocop:todo Metrics/ModuleLength, Style/Documentation
key :produces, ['application/json']
key :tags, ['Envelopes']

security
# security

parameter community_name
parameter metadata_only
Expand All @@ -37,7 +37,7 @@ module Envelopes # rubocop:todo Metrics/ModuleLength, Style/Documentation
key :produces, ['application/json']
key :tags, ['Envelopes']

security
# security

parameter community_name
parameter published_by(required: true)
Expand Down Expand Up @@ -96,7 +96,7 @@ module Envelopes # rubocop:todo Metrics/ModuleLength, Style/Documentation
key :produces, ['application/json']
key :tags, ['Envelopes']

security
# security

parameter community_name
parameter name: :after,
Expand Down Expand Up @@ -137,7 +137,7 @@ module Envelopes # rubocop:todo Metrics/ModuleLength, Style/Documentation
key :produces, ['application/json']
key :tags, ['Envelopes']

security
# security

parameter community_name

Expand All @@ -155,7 +155,7 @@ module Envelopes # rubocop:todo Metrics/ModuleLength, Style/Documentation
key :produces, ['application/json']
key :tags, ['Envelopes']

security
# security

parameter community_name
parameter envelope_id
Expand All @@ -175,7 +175,7 @@ module Envelopes # rubocop:todo Metrics/ModuleLength, Style/Documentation
key :produces, ['application/json']
key :tags, ['Envelopes']

security
# security

parameter community_name
parameter envelope_id
Expand All @@ -195,7 +195,7 @@ module Envelopes # rubocop:todo Metrics/ModuleLength, Style/Documentation
key :produces, ['application/json']
key :tags, ['Envelopes']

security
# security

parameter community_name
parameter envelope_id
Expand Down
8 changes: 4 additions & 4 deletions lib/swagger_docs/sections/general.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module General # rubocop:todo Style/Documentation
key :produces, ['application/json']
key :tags, ['General']

security
# security

response 200 do
key :description, 'API root'
Expand All @@ -28,7 +28,7 @@ module General # rubocop:todo Style/Documentation
key :produces, ['application/json']
key :tags, ['General']

security
# security

response 200 do
key :description, 'General info about this API node'
Expand All @@ -44,7 +44,7 @@ module General # rubocop:todo Style/Documentation
key :produces, ['text/html']
key :tags, ['General']

security
# security

response 200, description: 'shows the README rendered in HTML'
end
Expand All @@ -57,7 +57,7 @@ module General # rubocop:todo Style/Documentation
key :produces, ['application/json']
key :tags, ['General']

security
# security

response 200 do
key :description, 'Retrieve a new ctid'
Expand Down
4 changes: 2 additions & 2 deletions lib/swagger_docs/sections/graphs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Graphs # rubocop:todo Style/Documentation
key :produces, ['application/json']
key :tags, ['Graphs']

security
# security

parameter community_name

Expand Down Expand Up @@ -58,7 +58,7 @@ module Graphs # rubocop:todo Style/Documentation
key :produces, ['application/json']
key :tags, ['Graphs']

security
# security

parameter community_name
parameter resource_id
Expand Down
4 changes: 2 additions & 2 deletions lib/swagger_docs/sections/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ module Resources # rubocop:todo Metrics/ModuleLength, Style/Documentation
key :consumes, ['application/json']
key :tags, ['Resources']

security
# security

parameter community_name

Expand Down Expand Up @@ -199,7 +199,7 @@ module Resources # rubocop:todo Metrics/ModuleLength, Style/Documentation
key :produces, ['application/json']
key :tags, ['Resources']

security
# security

parameter community_name
parameter resource_id
Expand Down
8 changes: 3 additions & 5 deletions lib/swagger_docs/sections/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module MetadataRegistry
class SwaggerDocs
module Sections
# rubocop:todo Style/Documentation
# rubocop:todo Metrics/ModuleLength
module Search # rubocop:todo Style/Documentation, Metrics/ModuleLength
module Search # rubocop:todo Style/Documentation
# rubocop:enable Style/Documentation
extend ActiveSupport::Concern

Expand Down Expand Up @@ -87,7 +86,7 @@ module Search # rubocop:todo Style/Documentation, Metrics/ModuleLength
key :produces, ['application/json']
key :tags, ['Search']

security
# security

parameter community_name
parameters_for_search
Expand All @@ -109,7 +108,7 @@ module Search # rubocop:todo Style/Documentation, Metrics/ModuleLength
key :produces, ['application/json']
key :tags, ['Search']

security
# security

parameter community_name
parameter resource_type(_in: :path)
Expand All @@ -126,7 +125,6 @@ module Search # rubocop:todo Style/Documentation, Metrics/ModuleLength
end
end
end
# rubocop:enable Metrics/ModuleLength
end
end
end
Loading