6 import memcacheConstants
11 """Decorate a function with code to authenticate based on 1-3
12 additional arguments."""
14 def g(*args, **kwargs):
16 spec = inspect.getargspec(f)
18 defaults = len(spec.defaults) if spec.defaults else 0
22 print >> sys.stderr, ("Error: too few arguments - command "
23 "expected a minimum of %s but was passed "
25 % (min - 1, len(args) - 1, list(args[1:])))
28 if spec.varargs is None:
30 print >> sys.stderr, ("Error: too many arguments - command "
31 "expected a maximum of %s but was passed "
33 % (max - 1, len(args) - 1, list(args[1:])))
36 bucket = kwargs.pop('bucketName', None) or 'default'
37 username = kwargs.pop('username', None) or bucket
38 password = kwargs.pop('password', None) or ''
42 mc.sasl_auth_plain(username, password)
43 except mc_bin_client.MemcachedError:
44 print ("Authentication error for user:{0} bucket:{1}"
45 .format(username, bucket))
48 mc.hello("{0} {1}".format(os.path.split(sys.argv[0])[1],
49 os.getenv("EP_ENGINE_VERSION",
52 if kwargs.pop('allBuckets', None):
53 buckets = mc.list_buckets()
54 for bucket in buckets:
58 mc.bucket_select(bucket)
60 elif bucket is not None:
61 mc.bucket_select(bucket)
65 except mc_bin_client.ErrorEaccess:
66 print ("No access to bucket:{} - permission denied "
67 "or bucket does not exist.".format(bucket))
74 def get_authed_clitool():
77 c.addFlag('-a', 'allBuckets', 'iterate over all buckets')
78 c.addOption('-b', 'bucketName', 'the bucket to get stats from (Default: default)')
79 c.addOption('-u', 'username', 'the user as which to authenticate (Default: bucketName)')
80 c.addOption('-p', 'password', 'the password for the bucket if one exists')