summaryrefslogtreecommitdiff
path: root/lib/api/pages_domains.rb
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-10-25 15:39:23 +0300
committerLin Jen-Shin <godfat@godfat.org>2017-10-25 15:39:23 +0300
commit47c5ecaff33f49cfdc5fd47f5baff9a13e3d3807 (patch)
tree8352b7ec74351f1324956a4c7c34c32a812816f1 /lib/api/pages_domains.rb
parent188e1c261edf70685a7ea9e4276cd9794f2029c3 (diff)
parente81d74b9253e4a9f48bad0071bf37075bb6a20c5 (diff)
downloadgitlab-ce-use-git-branch-merged.tar.gz
Merge remote-tracking branch 'upstream/master' into use-git-branch-mergeduse-git-branch-merged
* upstream/master: (56 commits) Resolve "Remove overzealous tooltips in projects page tabs" Remove filter icon from search bar Don't rename groups/projects that aren't reserved anymore Memoize GitLab logger to reduce open file descriptors Update groups API documentation Changing the smallest of typos Remove `<script>` and `<template>` from CHANGELOG.md Support `Gitaly::User`'s gl_username field Fix icon color and btn-group alignment of discussion buttons Simple docs fixes Fix button type Changes after review fixed karma tests Removes group_avatar & group_label_subscription from global namespace Fix CSS in load more participants Fix the description of the new branch created by an issue's new branch button Fix a small typo in the delete merged branches documentation spec fixes Remove Sherlock usage from the performance bar moved to eventHub to manage creating new files removed an ID from the CSS ...
Diffstat (limited to 'lib/api/pages_domains.rb')
-rw-r--r--lib/api/pages_domains.rb117
1 files changed, 117 insertions, 0 deletions
diff --git a/lib/api/pages_domains.rb b/lib/api/pages_domains.rb
new file mode 100644
index 00000000000..259f3f34068
--- /dev/null
+++ b/lib/api/pages_domains.rb
@@ -0,0 +1,117 @@
+module API
+ class PagesDomains < Grape::API
+ include PaginationParams
+
+ before do
+ authenticate!
+ require_pages_enabled!
+ end
+
+ after_validation do
+ normalize_params_file_to_string
+ end
+
+ helpers do
+ def find_pages_domain!
+ user_project.pages_domains.find_by(domain: params[:domain]) || not_found!('PagesDomain')
+ end
+
+ def pages_domain
+ @pages_domain ||= find_pages_domain!
+ end
+
+ def normalize_params_file_to_string
+ params.each do |k, v|
+ if v.is_a?(Hash) && v.key?(:tempfile)
+ params[k] = v[:tempfile].to_a.join('')
+ end
+ end
+ end
+ end
+
+ params do
+ requires :id, type: String, desc: 'The ID of a project'
+ end
+ resource :projects, requirements: { id: %r{[^/]+} } do
+ desc 'Get all pages domains' do
+ success Entities::PagesDomain
+ end
+ params do
+ use :pagination
+ end
+ get ":id/pages/domains" do
+ authorize! :read_pages, user_project
+
+ present paginate(user_project.pages_domains.order(:domain)), with: Entities::PagesDomain
+ end
+
+ desc 'Get a single pages domain' do
+ success Entities::PagesDomain
+ end
+ params do
+ requires :domain, type: String, desc: 'The domain'
+ end
+ get ":id/pages/domains/:domain", requirements: { domain: %r{[^/]+} } do
+ authorize! :read_pages, user_project
+
+ present pages_domain, with: Entities::PagesDomain
+ end
+
+ desc 'Create a new pages domain' do
+ success Entities::PagesDomain
+ end
+ params do
+ requires :domain, type: String, desc: 'The domain'
+ optional :certificate, allow_blank: false, types: [File, String], desc: 'The certificate'
+ optional :key, allow_blank: false, types: [File, String], desc: 'The key'
+ all_or_none_of :certificate, :key
+ end
+ post ":id/pages/domains" do
+ authorize! :update_pages, user_project
+
+ pages_domain_params = declared(params, include_parent_namespaces: false)
+ pages_domain = user_project.pages_domains.create(pages_domain_params)
+
+ if pages_domain.persisted?
+ present pages_domain, with: Entities::PagesDomain
+ else
+ render_validation_error!(pages_domain)
+ end
+ end
+
+ desc 'Updates a pages domain'
+ params do
+ requires :domain, type: String, desc: 'The domain'
+ optional :certificate, allow_blank: false, types: [File, String], desc: 'The certificate'
+ optional :key, allow_blank: false, types: [File, String], desc: 'The key'
+ end
+ put ":id/pages/domains/:domain", requirements: { domain: %r{[^/]+} } do
+ authorize! :update_pages, user_project
+
+ pages_domain_params = declared(params, include_parent_namespaces: false)
+
+ # Remove empty private key if certificate is not empty.
+ if pages_domain_params[:certificate] && !pages_domain_params[:key]
+ pages_domain_params.delete(:key)
+ end
+
+ if pages_domain.update(pages_domain_params)
+ present pages_domain, with: Entities::PagesDomain
+ else
+ render_validation_error!(pages_domain)
+ end
+ end
+
+ desc 'Delete a pages domain'
+ params do
+ requires :domain, type: String, desc: 'The domain'
+ end
+ delete ":id/pages/domains/:domain", requirements: { domain: %r{[^/]+} } do
+ authorize! :update_pages, user_project
+
+ status 204
+ pages_domain.destroy
+ end
+ end
+ end
+end