summaryrefslogtreecommitdiffstats
path: root/src/rgw/services/svc_otp.cc
blob: fc386ae72359f214ab0daeabecad3e3f3c015282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp

#include "svc_otp.h"
#include "svc_zone.h"
#include "svc_meta.h"
#include "svc_meta_be_sobj.h"

#include "rgw/rgw_zone.h"

#define dout_subsys ceph_subsys_rgw

class RGW_MB_Handler_Module_OTP : public RGWSI_MBSObj_Handler_Module {
  RGWSI_Zone *zone_svc;
  string prefix;
public:
  RGW_MB_Handler_Module_OTP(RGWSI_Zone *_zone_svc) : RGWSI_MBSObj_Handler_Module("otp"),
                                                     zone_svc(_zone_svc) {}

  void get_pool_and_oid(const string& key, rgw_pool *pool, string *oid) override {
    if (pool) {
      *pool = zone_svc->get_zone_params().otp_pool;
    }

    if (oid) {
      *oid = key;
    }
  }

  const string& get_oid_prefix() override {
    return prefix;
  }

  bool is_valid_oid(const string& oid) override {
    return true;
  }

  string key_to_oid(const string& key) override {
    return key;
  }

  string oid_to_key(const string& oid) override {
    return oid;
  }
};

RGWSI_OTP::RGWSI_OTP(CephContext *cct): RGWServiceInstance(cct) {
}

RGWSI_OTP::~RGWSI_OTP() {
}

void RGWSI_OTP::init(RGWSI_Zone *_zone_svc,
                        RGWSI_Meta *_meta_svc,
                        RGWSI_MetaBackend *_meta_be_svc)
{
  svc.otp = this;
  svc.zone = _zone_svc;
  svc.meta = _meta_svc;
  svc.meta_be = _meta_be_svc;
}

int RGWSI_OTP::do_start(optional_yield, const DoutPrefixProvider *dpp)
{
  /* create first backend handler for bucket entrypoints */

  RGWSI_MetaBackend_Handler *_otp_be_handler;

  int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_OTP, &_otp_be_handler);
  if (r < 0) {
    ldout(ctx(), 0) << "ERROR: failed to create be handler: r=" << r << dendl;
    return r;
  }

  be_handler = _otp_be_handler;

  RGWSI_MetaBackend_Handler_OTP *otp_be_handler = static_cast<RGWSI_MetaBackend_Handler_OTP *>(_otp_be_handler);

  auto otp_be_module = new RGW_MB_Handler_Module_OTP(svc.zone);
  be_module.reset(otp_be_module);
  otp_be_handler->set_module(otp_be_module);

  return 0;
}

int RGWSI_OTP::read_all(RGWSI_OTP_BE_Ctx& ctx,
                        const string& key,
                        otp_devices_list_t *devices,
                        real_time *pmtime,
                        RGWObjVersionTracker *objv_tracker,
                        optional_yield y, const DoutPrefixProvider *dpp)
{
  RGWSI_MBOTP_GetParams params;
  params.pdevices = devices;
  params.pmtime = pmtime;

  int ret = svc.meta_be->get_entry(ctx.get(), key, params, objv_tracker, y, dpp);
  if (ret < 0) {
    return ret;
  }

  return 0;
}

int RGWSI_OTP::read_all(RGWSI_OTP_BE_Ctx& ctx,
                        const rgw_user& uid,
                        otp_devices_list_t *devices,
                        real_time *pmtime,
                        RGWObjVersionTracker *objv_tracker,
                        optional_yield y,
                        const DoutPrefixProvider *dpp)
{
  return read_all(ctx,
                  uid.to_str(),
                  devices,
                  pmtime,
                  objv_tracker,
                  y,
                  dpp);
}

int RGWSI_OTP::store_all(const DoutPrefixProvider *dpp, 
                         RGWSI_OTP_BE_Ctx& ctx,
                         const string& key,
                         const otp_devices_list_t& devices,
                         real_time mtime,
                         RGWObjVersionTracker *objv_tracker,
                         optional_yield y)
{
  RGWSI_MBOTP_PutParams params;
  params.mtime = mtime;
  params.devices = devices;

  int ret = svc.meta_be->put_entry(dpp, ctx.get(), key, params, objv_tracker, y);
  if (ret < 0) {
    return ret;
  }

  return 0;
}

int RGWSI_OTP::store_all(const DoutPrefixProvider *dpp, 
                         RGWSI_OTP_BE_Ctx& ctx,
                         const rgw_user& uid,
                         const otp_devices_list_t& devices,
                         real_time mtime,
                         RGWObjVersionTracker *objv_tracker,
                         optional_yield y)
{
  return store_all(dpp, ctx,
                   uid.to_str(),
                   devices,
                   mtime,
                   objv_tracker,
                   y);
}

int RGWSI_OTP::remove_all(const DoutPrefixProvider *dpp, 
                          RGWSI_OTP_BE_Ctx& ctx,
                          const string& key,
                          RGWObjVersionTracker *objv_tracker,
                          optional_yield y)
{
  RGWSI_MBOTP_RemoveParams params;

  int ret = svc.meta_be->remove_entry(dpp, ctx.get(), key, params, objv_tracker, y);
  if (ret < 0) {
    return ret;
  }

  return 0;
}

int RGWSI_OTP::remove_all(const DoutPrefixProvider *dpp, 
                          RGWSI_OTP_BE_Ctx& ctx,
                          const rgw_user& uid,
                          RGWObjVersionTracker *objv_tracker,
                          optional_yield y)
{
  return remove_all(dpp,ctx,
                    uid.to_str(),
                    objv_tracker,
                    y);
}