Coverage Report

Created: 2026-06-11 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/trafficserver/include/mgmt/rpc/jsonrpc/Context.h
Line
Count
Source
1
/**
2
  @section license License
3
4
  Licensed to the Apache Software Foundation (ASF) under one
5
  or more contributor license agreements.  See the NOTICE file
6
  distributed with this work for additional information
7
  regarding copyright ownership.  The ASF licenses this file
8
  to you under the Apache License, Version 2.0 (the
9
  "License"); you may not use this file except in compliance
10
  with the License.  You may obtain a copy of the License at
11
12
  http://www.apache.org/licenses/LICENSE-2.0
13
14
  Unless required by applicable law or agreed to in writing, software
15
  distributed under the License is distributed on an "AS IS" BASIS,
16
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
  See the License for the specific language governing permissions and
18
  limitations under the License.
19
*/
20
#pragma once
21
22
#include <vector>
23
#include <functional>
24
#include <string_view>
25
26
#include "tsutil/ts_errata.h"
27
#include "ts/apidefs.h"
28
#include "mgmt/rpc/handlers/common/ErrorUtils.h"
29
30
namespace rpc
31
{
32
constexpr bool RESTRICTED_API{true};
33
constexpr bool NON_RESTRICTED_API{false};
34
///
35
/// @brief RPC call context class.
36
///
37
/// This class is used to carry information from the transport logic to the rpc invocation logic, the transport may need to block
38
/// some rpc handlers from being executed which at the time of finish ups reading the raw message is yet too early to know the
39
/// actual handler.
40
///
41
class Context
42
{
43
  using checker_cb = std::function<void(TSRPCHandlerOptions const &, swoc::Errata &)>;
44
  /// @brief Internal class to hold the permission checker part.
45
  struct Auth {
46
    /// Checks for permissions. This function checks for every registered permission checker.
47
    ///
48
    /// @param options Registered handler options.
49
    /// @return swoc::Errata The errata will be filled by each of the registered checkers, if there was any issue validating the
50
    ///                    call, then the errata reflects that.
51
    swoc::Errata is_blocked(TSRPCHandlerOptions const &options) const;
52
53
    /// Add permission checkers.
54
    template <typename F>
55
    void
56
    add_checker(F &&f)
57
    {
58
      _checkers.emplace_back(std::forward<F>(f));
59
    }
60
61
  private:
62
    std::vector<checker_cb> _checkers; ///< cb collection.
63
  } _auth;
64
65
public:
66
  Auth &
67
  get_auth()
68
0
  {
69
0
    return _auth;
70
0
  }
71
  Auth const &
72
  get_auth() const
73
0
  {
74
0
    return _auth;
75
0
  }
76
};
77
} // namespace rpc