]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/src/http/api_docs.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / seastar / src / http / api_docs.cc
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 /*
19 * Copyright 2015 Cloudius Systems
20 */
21
22 #include <seastar/http/api_docs.hh>
23 #include <seastar/http/handlers.hh>
24 #include <seastar/json/formatter.hh>
25 #include <seastar/http/transformers.hh>
26 #include <seastar/core/fstream.hh>
27 #include <seastar/core/seastar.hh>
28 #include <seastar/http/transformers.hh>
29 #include <seastar/core/loop.hh>
30
31 using namespace std;
32
33 namespace seastar {
34
35 namespace httpd {
36
37 const sstring api_registry_builder_base::DEFAULT_PATH = "/api-doc";
38 const sstring api_registry_builder_base::DEFAULT_DIR = ".";
39
40 doc_entry get_file_reader(sstring file_name) {
41 return [file_name] (output_stream<char>& os) {
42 return open_file_dma(file_name, open_flags::ro).then([&os] (file f) mutable {
43 return do_with(input_stream<char>(make_file_input_stream(std::move(f))), [&os](input_stream<char>& is) {
44 return copy(is, os).then([&is] {
45 return is.close();
46 });
47 });
48 });
49 };
50 }
51
52 future<> api_docs_20::write(output_stream<char>&& os, std::unique_ptr<request> req) {
53 return do_with(output_stream<char>(_transform.transform(std::move(req), "", std::move(os))), [this] (output_stream<char>& os) {
54 return do_for_each(_apis, [&os](doc_entry& api) {
55 return api(os);
56 }).then([&os] {
57 return os.write("},\"definitions\": {");
58 }).then([this, &os] {
59 return do_for_each(_definitions, [&os](doc_entry& api) {
60 return api(os);
61 });
62 }).then([&os] {
63 return os.write("}}");
64 }).then([&os] {
65 return os.flush();
66 }).finally([&os] {
67 return os.close();
68 });
69 });
70 }
71
72 }
73
74 }