1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "include/types.h"
16 #include "msg/msg_types.h"
17 #include "include/rados/librados.hpp"
18 #include "include/utime.h"
20 using namespace librados
;
22 #include "cls/otp/cls_otp_ops.h"
23 #include "cls/otp/cls_otp_client.h"
25 #include "common/random_string.h" /* for gen_rand_alphanumeric */
31 void OTP::create(librados::ObjectWriteOperation
*rados_op
,
32 const otp_info_t
& config
) {
33 cls_otp_set_otp_op op
;
34 op
.entries
.push_back(config
);
37 rados_op
->exec("otp", "otp_set", in
);
40 void OTP::set(librados::ObjectWriteOperation
*rados_op
,
41 const list
<otp_info_t
>& entries
) {
42 cls_otp_set_otp_op op
;
46 rados_op
->exec("otp", "otp_set", in
);
49 void OTP::remove(librados::ObjectWriteOperation
*rados_op
,
51 cls_otp_remove_otp_op op
;
55 rados_op
->exec("otp", "otp_remove", in
);
58 int OTP::check(CephContext
*cct
, librados::IoCtx
& ioctx
, const string
& oid
,
59 const string
& id
, const string
& val
, otp_check_t
*result
) {
60 cls_otp_check_otp_op op
;
64 op
.token
= gen_rand_alphanumeric(cct
, TOKEN_LEN
);
69 int r
= ioctx
.exec(oid
, "otp", "otp_check", in
, out
);
74 cls_otp_get_result_op op2
;
79 r
= ioctx
.exec(oid
, "otp", "otp_get_result", in
, out
);
84 auto iter
= out
.cbegin();
85 cls_otp_get_result_reply ret
;
88 } catch (buffer::error
& err
) {
97 int OTP::get(librados::ObjectReadOperation
*rop
,
98 librados::IoCtx
& ioctx
, const string
& oid
,
99 const list
<string
> *ids
, bool get_all
, list
<otp_info_t
> *result
) {
100 librados::ObjectReadOperation _rop
;
104 cls_otp_get_otp_op op
;
108 op
.get_all
= get_all
;
113 rop
->exec("otp", "otp_get", in
, &out
, &op_ret
);
114 int r
= ioctx
.operate(oid
, rop
, nullptr);
122 cls_otp_get_otp_reply ret
;
123 auto iter
= out
.cbegin();
126 } catch (buffer::error
& err
) {
130 *result
= ret
.found_entries
;;
135 int OTP::get(librados::ObjectReadOperation
*op
,
136 librados::IoCtx
& ioctx
, const string
& oid
,
137 const string
& id
, otp_info_t
*result
) {
138 list
<string
> ids
{ id
};
139 list
<otp_info_t
> ret
;
141 int r
= get(op
, ioctx
, oid
, &ids
, false, &ret
);
148 *result
= ret
.front();
153 int OTP::get_all(librados::ObjectReadOperation
*op
, librados::IoCtx
& ioctx
, const string
& oid
,
154 list
<otp_info_t
> *result
) {
155 return get(op
, ioctx
, oid
, nullptr, true, result
);
158 int OTP::get_current_time(librados::IoCtx
& ioctx
, const string
& oid
,
159 ceph::real_time
*result
) {
160 cls_otp_get_current_time_op op
;
165 ObjectReadOperation rop
;
166 rop
.exec("otp", "get_current_time", in
, &out
, &op_ret
);
167 int r
= ioctx
.operate(oid
, &rop
, nullptr);
175 cls_otp_get_current_time_reply ret
;
176 auto iter
= out
.cbegin();
179 } catch (buffer::error
& err
) {