]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_cls.h
80674a286bcf3c5230cbe2d926ca9653208ab4e4
[ceph.git] / ceph / src / rgw / services / svc_cls.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2019 Red Hat, Inc.
8 *
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
13 *
14 */
15
16
17 #pragma once
18
19 #include "cls/otp/cls_otp_types.h"
20 #include "cls/log/cls_log_types.h"
21
22 #include "rgw/rgw_service.h"
23
24 #include "svc_rados.h"
25
26
27 class RGWSI_Cls : public RGWServiceInstance
28 {
29 RGWSI_Zone *zone_svc{nullptr};
30 RGWSI_RADOS *rados_svc{nullptr};
31
32 class ClsSubService : public RGWServiceInstance {
33 friend class RGWSI_Cls;
34
35 RGWSI_Cls *cls_svc{nullptr};
36 RGWSI_Zone *zone_svc{nullptr};
37 RGWSI_RADOS *rados_svc{nullptr};
38
39 void init(RGWSI_Cls *_cls_svc, RGWSI_Zone *_zone_svc, RGWSI_RADOS *_rados_svc) {
40 cls_svc = _cls_svc;
41 zone_svc = _cls_svc->zone_svc;
42 rados_svc = _cls_svc->rados_svc;
43 }
44
45 public:
46 ClsSubService(CephContext *cct) : RGWServiceInstance(cct) {}
47 };
48
49 public:
50 class MFA : public ClsSubService {
51 int get_mfa_obj(const rgw_user& user, std::optional<RGWSI_RADOS::Obj> *obj);
52 int get_mfa_ref(const rgw_user& user, rgw_rados_ref *ref);
53
54 void prepare_mfa_write(librados::ObjectWriteOperation *op,
55 RGWObjVersionTracker *objv_tracker,
56 const ceph::real_time& mtime);
57
58 public:
59 MFA(CephContext *cct): ClsSubService(cct) {}
60
61 string get_mfa_oid(const rgw_user& user) {
62 return string("user:") + user.to_str();
63 }
64
65 int check_mfa(const rgw_user& user, const string& otp_id, const string& pin, optional_yield y);
66 int create_mfa(const rgw_user& user, const rados::cls::otp::otp_info_t& config,
67 RGWObjVersionTracker *objv_tracker, const ceph::real_time& mtime, optional_yield y);
68 int remove_mfa(const rgw_user& user, const string& id,
69 RGWObjVersionTracker *objv_tracker,
70 const ceph::real_time& mtime,
71 optional_yield y);
72 int get_mfa(const rgw_user& user, const string& id, rados::cls::otp::otp_info_t *result, optional_yield y);
73 int list_mfa(const rgw_user& user, list<rados::cls::otp::otp_info_t> *result, optional_yield y);
74 int otp_get_current_time(const rgw_user& user, ceph::real_time *result, optional_yield y);
75 int set_mfa(const string& oid, const list<rados::cls::otp::otp_info_t>& entries,
76 bool reset_obj, RGWObjVersionTracker *objv_tracker,
77 const real_time& mtime, optional_yield y);
78 int list_mfa(const string& oid, list<rados::cls::otp::otp_info_t> *result,
79 RGWObjVersionTracker *objv_tracker, ceph::real_time *pmtime, optional_yield y);
80 } mfa;
81
82 class TimeLog : public ClsSubService {
83 int init_obj(const string& oid, RGWSI_RADOS::Obj& obj);
84 public:
85 TimeLog(CephContext *cct): ClsSubService(cct) {}
86
87 void prepare_entry(cls_log_entry& entry,
88 const real_time& ut,
89 const string& section,
90 const string& key,
91 bufferlist& bl);
92 int add(const string& oid,
93 const real_time& ut,
94 const string& section,
95 const string& key,
96 bufferlist& bl,
97 optional_yield y);
98 int add(const string& oid,
99 std::list<cls_log_entry>& entries,
100 librados::AioCompletion *completion,
101 bool monotonic_inc,
102 optional_yield y);
103 int list(const string& oid,
104 const real_time& start_time,
105 const real_time& end_time,
106 int max_entries, list<cls_log_entry>& entries,
107 const string& marker,
108 string *out_marker,
109 bool *truncated,
110 optional_yield y);
111 int info(const string& oid,
112 cls_log_header *header,
113 optional_yield y);
114 int info_async(RGWSI_RADOS::Obj& obj,
115 const string& oid,
116 cls_log_header *header,
117 librados::AioCompletion *completion);
118 int trim(const string& oid,
119 const real_time& start_time,
120 const real_time& end_time,
121 const string& from_marker,
122 const string& to_marker,
123 librados::AioCompletion *completion,
124 optional_yield y);
125 } timelog;
126
127 class Lock : public ClsSubService {
128 int init_obj(const string& oid, RGWSI_RADOS::Obj& obj);
129 public:
130 Lock(CephContext *cct): ClsSubService(cct) {}
131 int lock_exclusive(const rgw_pool& pool,
132 const string& oid,
133 timespan& duration,
134 string& zone_id,
135 string& owner_id,
136 std::optional<string> lock_name = std::nullopt);
137 int unlock(const rgw_pool& pool,
138 const string& oid,
139 string& zone_id,
140 string& owner_id,
141 std::optional<string> lock_name = std::nullopt);
142 } lock;
143
144 RGWSI_Cls(CephContext *cct): RGWServiceInstance(cct), mfa(cct), timelog(cct), lock(cct) {}
145
146 void init(RGWSI_Zone *_zone_svc, RGWSI_RADOS *_rados_svc) {
147 rados_svc = _rados_svc;
148 zone_svc = _zone_svc;
149
150 mfa.init(this, zone_svc, rados_svc);
151 timelog.init(this, zone_svc, rados_svc);
152 lock.init(this, zone_svc, rados_svc);
153 }
154
155 int do_start(optional_yield) override;
156 };
157