~mathiaz/+junk/ceph-new-pkg-review

« back to all changes in this revision

Viewing changes to src/rgw/rgw_user.h

  • Committer: Mathias Gug
  • Date: 2010-07-29 03:10:42 UTC
  • Revision ID: mathias.gug@canonical.com-20100729031042-n9n8kky962qb4onb
Import ceph_0.21-0ubuntu1 from https://launchpad.net/~clint-fewbar/+archive/ceph/+packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef CEPH_RGW_USER_H
 
2
#define CEPH_RGW_USER_H
 
3
 
 
4
#include <string>
 
5
 
 
6
#include "include/types.h"
 
7
#include "rgw_common.h"
 
8
 
 
9
using namespace std;
 
10
 
 
11
#define USER_INFO_BUCKET_NAME ".users"
 
12
#define USER_INFO_EMAIL_BUCKET_NAME ".users.email"
 
13
#define RGW_USER_ANON_ID "anonymous"
 
14
 
 
15
/**
 
16
 * A string wrapper that includes encode/decode functions
 
17
 * for easily accessing a UID in all forms
 
18
 */
 
19
struct RGWUID
 
20
{
 
21
  string user_id;
 
22
  void encode(bufferlist& bl) const {
 
23
     ::encode(user_id, bl);
 
24
  }
 
25
  void decode(bufferlist::iterator& bl) {
 
26
    ::decode(user_id, bl);
 
27
  }
 
28
};
 
29
WRITE_CLASS_ENCODER(RGWUID)
 
30
 
 
31
/**
 
32
 * Get the info for a user out of storage.
 
33
 * Returns: 0 on success, -ERR# on failure
 
34
 */
 
35
extern int rgw_get_user_info(string user_id, RGWUserInfo& info);
 
36
/**
 
37
 * Get the anonymous (ie, unauthenticated) user info.
 
38
 */
 
39
extern void rgw_get_anon_user(RGWUserInfo& info);
 
40
/**
 
41
 * Save the given user information to storage.
 
42
 * Returns: 0 on success, -ERR# on failure.
 
43
 */
 
44
extern int rgw_store_user_info(RGWUserInfo& info);
 
45
/**
 
46
 * Given an email, finds the user_id associated with it.
 
47
 * returns: 0 on success, -ERR# on failure (including nonexistence)
 
48
 */
 
49
extern int rgw_get_uid_by_email(string& email, string& user_id);
 
50
/**
 
51
 * Given an RGWUserInfo, deletes the user and its bucket ACLs.
 
52
 */
 
53
extern int rgw_delete_user(RGWUserInfo& user);
 
54
/**
 
55
 * Store a list of the user's buckets, with associated functinos.
 
56
 */
 
57
class RGWUserBuckets
 
58
{
 
59
  map<string, RGWObjEnt> buckets;
 
60
 
 
61
public:
 
62
  RGWUserBuckets() {}
 
63
  void encode(bufferlist& bl) const {
 
64
     ::encode(buckets, bl);
 
65
  }
 
66
  void decode(bufferlist::iterator& bl) {
 
67
    ::decode(buckets, bl);
 
68
  }
 
69
  /**
 
70
   * Check if the user owns a bucket by the given name.
 
71
   */
 
72
  bool owns(string& name) {
 
73
    map<string, RGWObjEnt>::iterator iter;
 
74
    iter = buckets.find(name);
 
75
    return (iter != buckets.end());
 
76
  }
 
77
 
 
78
  /**
 
79
   * Add a (created) bucket to the user's bucket list.
 
80
   */
 
81
  void add(RGWObjEnt& bucket) {
 
82
    buckets[bucket.name] = bucket;
 
83
  }
 
84
 
 
85
  /**
 
86
   * Remove a bucket from the user's list by name.
 
87
   */
 
88
  void remove(string& name) {
 
89
    map<string, RGWObjEnt>::iterator iter;
 
90
    iter = buckets.find(name);
 
91
    if (iter != buckets.end()) {
 
92
      buckets.erase(iter);
 
93
    }
 
94
  }
 
95
 
 
96
  /**
 
97
   * Get the user's buckets as a map.
 
98
   */
 
99
  map<string, RGWObjEnt>& get_buckets() { return buckets; }
 
100
};
 
101
WRITE_CLASS_ENCODER(RGWUserBuckets)
 
102
 
 
103
/**
 
104
 * Get all the buckets owned by a user and fill up an RGWUserBuckets with them.
 
105
 * Returns: 0 on success, -ERR# on failure.
 
106
 */
 
107
extern int rgw_get_user_buckets(string user_id, RGWUserBuckets& buckets);
 
108
/**
 
109
 * Store the set of buckets associated with a user.
 
110
 * This completely overwrites any previously-stored list, so be careful!
 
111
 * Returns 0 on success, -ERR# otherwise.
 
112
 */
 
113
extern int rgw_put_user_buckets(string user_id, RGWUserBuckets& buckets);
 
114
 
 
115
#endif