2009-10-30 17:09:35 +00:00
|
|
|
#ifndef __RGW_USER_H
|
|
|
|
#define __RGW_USER_H
|
2009-06-26 20:15:18 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "include/types.h"
|
2009-08-07 17:26:07 +00:00
|
|
|
#include "rgw_common.h"
|
2009-06-26 20:15:18 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#define USER_INFO_BUCKET_NAME ".users"
|
2009-07-03 01:42:12 +00:00
|
|
|
#define USER_INFO_EMAIL_BUCKET_NAME ".users.email"
|
2009-08-07 17:46:29 +00:00
|
|
|
#define RGW_USER_ANON_ID "anonymous"
|
2009-07-02 19:05:46 +00:00
|
|
|
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* A string wrapper that includes encode/decode functions
|
|
|
|
* for easily accessing a UID in all forms
|
|
|
|
*/
|
2009-08-07 17:46:29 +00:00
|
|
|
struct RGWUID
|
2009-07-03 01:42:12 +00:00
|
|
|
{
|
|
|
|
string user_id;
|
|
|
|
void encode(bufferlist& bl) const {
|
|
|
|
::encode(user_id, bl);
|
|
|
|
}
|
|
|
|
void decode(bufferlist::iterator& bl) {
|
|
|
|
::decode(user_id, bl);
|
|
|
|
}
|
|
|
|
};
|
2009-08-07 17:46:29 +00:00
|
|
|
WRITE_CLASS_ENCODER(RGWUID)
|
2009-07-03 01:42:12 +00:00
|
|
|
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Get the info for a user out of storage.
|
|
|
|
* Returns: 0 on success, -ERR# on failure
|
|
|
|
*/
|
2009-08-07 17:46:29 +00:00
|
|
|
extern int rgw_get_user_info(string user_id, RGWUserInfo& info);
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Get the anonymous (ie, unauthenticated) user info.
|
|
|
|
*/
|
2009-08-07 17:46:29 +00:00
|
|
|
extern void rgw_get_anon_user(RGWUserInfo& info);
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Save the given user information to storage.
|
|
|
|
* Returns: 0 on success, -ERR# on failure.
|
|
|
|
*/
|
2009-08-07 17:46:29 +00:00
|
|
|
extern int rgw_store_user_info(RGWUserInfo& info);
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Given an email, finds the user_id associated with it.
|
|
|
|
* returns: 0 on success, -ERR# on failure (including nonexistence)
|
|
|
|
*/
|
2009-08-07 17:46:29 +00:00
|
|
|
extern int rgw_get_uid_by_email(string& email, string& user_id);
|
2010-04-02 23:25:00 +00:00
|
|
|
/**
|
|
|
|
* Given an RGWUserInfo, deletes the user and its bucket ACLs.
|
|
|
|
*/
|
|
|
|
extern int rgw_delete_user(RGWUserInfo& user);
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Store a list of the user's buckets, with associated functinos.
|
|
|
|
*/
|
2009-08-07 17:46:29 +00:00
|
|
|
class RGWUserBuckets
|
2009-07-01 21:34:59 +00:00
|
|
|
{
|
2009-08-07 17:46:29 +00:00
|
|
|
map<string, RGWObjEnt> buckets;
|
2009-07-01 21:34:59 +00:00
|
|
|
|
|
|
|
public:
|
2009-08-07 17:46:29 +00:00
|
|
|
RGWUserBuckets() {}
|
2009-07-01 21:34:59 +00:00
|
|
|
void encode(bufferlist& bl) const {
|
|
|
|
::encode(buckets, bl);
|
|
|
|
}
|
|
|
|
void decode(bufferlist::iterator& bl) {
|
|
|
|
::decode(buckets, bl);
|
|
|
|
}
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Check if the user owns a bucket by the given name.
|
|
|
|
*/
|
2009-07-01 21:34:59 +00:00
|
|
|
bool owns(string& name) {
|
2009-08-07 17:46:29 +00:00
|
|
|
map<string, RGWObjEnt>::iterator iter;
|
2009-07-01 21:34:59 +00:00
|
|
|
iter = buckets.find(name);
|
|
|
|
return (iter != buckets.end());
|
|
|
|
}
|
|
|
|
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Add a (created) bucket to the user's bucket list.
|
|
|
|
*/
|
2009-08-07 17:46:29 +00:00
|
|
|
void add(RGWObjEnt& bucket) {
|
2009-07-01 21:34:59 +00:00
|
|
|
buckets[bucket.name] = bucket;
|
|
|
|
}
|
|
|
|
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Remove a bucket from the user's list by name.
|
|
|
|
*/
|
2009-07-01 21:34:59 +00:00
|
|
|
void remove(string& name) {
|
2009-08-07 17:46:29 +00:00
|
|
|
map<string, RGWObjEnt>::iterator iter;
|
2009-07-01 21:34:59 +00:00
|
|
|
iter = buckets.find(name);
|
|
|
|
if (iter != buckets.end()) {
|
|
|
|
buckets.erase(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Get the user's buckets as a map.
|
|
|
|
*/
|
2009-08-07 17:46:29 +00:00
|
|
|
map<string, RGWObjEnt>& get_buckets() { return buckets; }
|
2009-07-01 21:34:59 +00:00
|
|
|
};
|
2009-08-07 17:46:29 +00:00
|
|
|
WRITE_CLASS_ENCODER(RGWUserBuckets)
|
2009-07-01 21:34:59 +00:00
|
|
|
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Get all the buckets owned by a user and fill up an RGWUserBuckets with them.
|
|
|
|
* Returns: 0 on success, -ERR# on failure.
|
|
|
|
*/
|
2009-08-07 17:46:29 +00:00
|
|
|
extern int rgw_get_user_buckets(string user_id, RGWUserBuckets& buckets);
|
2010-03-11 22:49:27 +00:00
|
|
|
/**
|
|
|
|
* Store the set of buckets associated with a user.
|
|
|
|
* This completely overwrites any previously-stored list, so be careful!
|
|
|
|
* Returns 0 on success, -ERR# otherwise.
|
|
|
|
*/
|
2009-08-07 17:46:29 +00:00
|
|
|
extern int rgw_put_user_buckets(string user_id, RGWUserBuckets& buckets);
|
2009-07-01 21:34:59 +00:00
|
|
|
|
2009-06-26 20:15:18 +00:00
|
|
|
#endif
|