diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-09-09 13:27:11 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-09-09 13:27:11 +0000 |
commit | cbb35ea882cdc40c09f7f6cd44bca8d72e506092 (patch) | |
tree | 0f83b09e3ff1e4f75977d17762be2fbd7f0bf5b8 /lib | |
parent | 2bf5a1ace2b9e6d7beeb794c4c7fa9af6552ef5a (diff) | |
parent | 477ba2b3465736cdccfb6cb6a36f78447942e310 (diff) | |
download | gitlab-ce-cbb35ea882cdc40c09f7f6cd44bca8d72e506092.tar.gz |
Merge branch '61927-skeleton-pages-internal-api' into 'master'
Add skeleton Pages internal API
See merge request gitlab-org/gitlab-ce!32732
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/internal/pages.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/pages.rb | 17 |
3 files changed, 44 insertions, 1 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index 88d411e22a9..3bf16dc41d2 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -119,6 +119,7 @@ module API mount ::API::GroupVariables mount ::API::ImportGithub mount ::API::Internal::Base + mount ::API::Internal::Pages mount ::API::Issues mount ::API::JobArtifacts mount ::API::Jobs diff --git a/lib/api/internal/pages.rb b/lib/api/internal/pages.rb new file mode 100644 index 00000000000..6ea048bde03 --- /dev/null +++ b/lib/api/internal/pages.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module API + # Pages Internal API + module Internal + class Pages < Grape::API + before do + not_found! unless Feature.enabled?(:pages_internal_api) + authenticate_gitlab_pages_request! + end + + helpers do + def authenticate_gitlab_pages_request! + unauthorized! unless Gitlab::Pages.verify_api_request(headers) + end + end + + namespace 'internal' do + namespace 'pages' do + get "/" do + status :ok + end + end + end + end + end +end diff --git a/lib/gitlab/pages.rb b/lib/gitlab/pages.rb index 16df0700b08..4899b1d3234 100644 --- a/lib/gitlab/pages.rb +++ b/lib/gitlab/pages.rb @@ -1,7 +1,22 @@ # frozen_string_literal: true module Gitlab - module Pages + class Pages VERSION = File.read(Rails.root.join("GITLAB_PAGES_VERSION")).strip.freeze + INTERNAL_API_REQUEST_HEADER = 'Gitlab-Pages-Api-Request'.freeze + + include JwtAuthenticatable + + class << self + def verify_api_request(request_headers) + decode_jwt_for_issuer('gitlab-pages', request_headers[INTERNAL_API_REQUEST_HEADER]) + rescue JWT::DecodeError + false + end + + def secret_path + Gitlab.config.pages.secret_file + end + end end end |