]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_token.cc
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) 2016 Red Hat, Inc.
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.
20 #include "common/config.h"
21 #include "common/ceph_argparse.h"
22 #include "common/debug.h"
23 #include "global/global_init.h"
24 #include "include/assert.h"
25 #include "include/str_list.h"
27 #include "rgw_token.h"
30 #define dout_subsys ceph_subsys_rgw
38 RGWToken::token_type type
{RGWToken::TOKEN_NONE
};
39 string access_key
{""};
40 string secret_key
{""};
42 Formatter
* formatter
{nullptr};
45 bool do_encode
{false};
46 bool do_decode
{false};
52 cout
<< "usage: radosgw-token --encode --ttype=<token type> [options...]" << std::endl
;
53 cout
<< "\t(maybe exporting RGW_ACCESS_KEY_ID and RGW_SECRET_ACCESS_KEY)"
55 cout
<< "\t <token type> := ad | ldap" << std::endl
;
57 generic_client_usage();
60 int main(int argc
, char **argv
)
63 vector
<const char*> args
;
64 argv_to_vec(argc
, (const char **)argv
, args
);
67 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
68 CODE_ENVIRONMENT_UTILITY
, 0);
69 common_init_finish(g_ceph_context
);
72 v
= getenv("RGW_ACCESS_KEY_ID");
77 v
= getenv("RGW_SECRET_ACCESS_KEY");
82 for (auto arg_iter
= args
.begin(); arg_iter
!= args
.end();) {
83 if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--access",
86 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--secret",
89 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--ttype",
91 for (const auto& ttype
: {"ad", "ldap"}) {
92 if (boost::iequals(val
, ttype
)) {
93 type
= RGWToken::to_type(val
);
97 } else if (ceph_argparse_flag(args
, arg_iter
, "--encode",
100 } else if (ceph_argparse_flag(args
, arg_iter
, "--decode",
103 } else if (ceph_argparse_flag(args
, arg_iter
, "--verbose",
112 (type
== RGWToken::TOKEN_NONE
)) {
117 formatter
= new JSONFormatter(true /* pretty */);
119 RGWToken
token(type
, access_key
, secret_key
);
121 token
.encode_json(formatter
);
122 std::ostringstream os
;
123 formatter
->flush(os
);
124 string token_str
= os
.str();
126 std::cout
<< "expanded token: " << token_str
<< std::endl
;
128 RGWToken
token2(token_str
);
129 std::cout
<< "decoded expanded token: " << token2
<< std::endl
;
132 std::cout
<< to_base64(token_str
) << std::endl
;