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"
22 using namespace librados
;
24 #include "cls/otp/cls_otp_ops.h"
25 #include "cls/otp/cls_otp_client.h"
27 #include "common/random_string.h" /* for gen_rand_alphanumeric */
33 void OTP::create(librados::ObjectWriteOperation
*rados_op
,
34 const otp_info_t
& config
) {
35 cls_otp_set_otp_op op
;
36 op
.entries
.push_back(config
);
39 rados_op
->exec("otp", "otp_set", in
);
42 void OTP::set(librados::ObjectWriteOperation
*rados_op
,
43 const list
<otp_info_t
>& entries
) {
44 cls_otp_set_otp_op op
;
48 rados_op
->exec("otp", "otp_set", in
);
51 void OTP::remove(librados::ObjectWriteOperation
*rados_op
,
53 cls_otp_remove_otp_op op
;
57 rados_op
->exec("otp", "otp_remove", in
);
60 int OTP::check(CephContext
*cct
, librados::IoCtx
& ioctx
, const string
& oid
,
61 const string
& id
, const string
& val
, otp_check_t
*result
) {
62 cls_otp_check_otp_op op
;
66 op
.token
= gen_rand_alphanumeric(cct
, TOKEN_LEN
);
71 int r
= ioctx
.exec(oid
, "otp", "otp_check", in
, out
);
76 cls_otp_get_result_op op2
;
81 r
= ioctx
.exec(oid
, "otp", "otp_get_result", in
, out
);
86 auto iter
= out
.cbegin();
87 cls_otp_get_result_reply ret
;
90 } catch (ceph::buffer::error
& err
) {
99 int OTP::get(librados::ObjectReadOperation
*rop
,
100 librados::IoCtx
& ioctx
, const string
& oid
,
101 const list
<string
> *ids
, bool get_all
, list
<otp_info_t
> *result
) {
102 librados::ObjectReadOperation _rop
;
106 cls_otp_get_otp_op op
;
110 op
.get_all
= get_all
;
115 rop
->exec("otp", "otp_get", in
, &out
, &op_ret
);
116 int r
= ioctx
.operate(oid
, rop
, nullptr);
124 cls_otp_get_otp_reply ret
;
125 auto iter
= out
.cbegin();
128 } catch (ceph::buffer::error
& err
) {
132 *result
= ret
.found_entries
;;
137 int OTP::get(librados::ObjectReadOperation
*op
,
138 librados::IoCtx
& ioctx
, const string
& oid
,
139 const string
& id
, otp_info_t
*result
) {
140 list
<string
> ids
{ id
};
141 list
<otp_info_t
> ret
;
143 int r
= get(op
, ioctx
, oid
, &ids
, false, &ret
);
150 *result
= ret
.front();
155 int OTP::get_all(librados::ObjectReadOperation
*op
, librados::IoCtx
& ioctx
, const string
& oid
,
156 list
<otp_info_t
> *result
) {
157 return get(op
, ioctx
, oid
, nullptr, true, result
);
160 int OTP::get_current_time(librados::IoCtx
& ioctx
, const string
& oid
,
161 ceph::real_time
*result
) {
162 cls_otp_get_current_time_op op
;
167 ObjectReadOperation rop
;
168 rop
.exec("otp", "get_current_time", in
, &out
, &op_ret
);
169 int r
= ioctx
.operate(oid
, &rop
, nullptr);
177 cls_otp_get_current_time_reply ret
;
178 auto iter
= out
.cbegin();
181 } catch (ceph::buffer::error
& err
) {