Exemple #1
0
        private static Permission ToPermission(Authpb.Permission perm)
        {
            ByteSequence key      = ByteSequence.from(perm.Key);
            ByteSequence rangeEnd = ByteSequence.from(perm.RangeEnd);

            Permission.Type type;
            switch (perm.PermType)
            {
            case Authpb.Permission.Types.Type.Read:
                type = Permission.Type.READ;
                break;

            case Authpb.Permission.Types.Type.Write:
                type = Permission.Type.WRITE;
                break;

            case Authpb.Permission.Types.Type.Readwrite:
                type = Permission.Type.READWRITE;
                break;

            default:
                type = Permission.Type.UNRECOGNIZED;
                break;
            }

            return(new Permission(type, key, rangeEnd));
        }
        public void Put(string key, string value)
        {
            ByteSequence bkey   = ByteSequence.from(key, Encoding.UTF8);
            ByteSequence bvalue = ByteSequence.from(value, Encoding.UTF8);

            client.GetKVClient().Put(bkey, bvalue);
        }
        public string Get(string key)
        {
            ByteSequence    bkey      = ByteSequence.from(key, Encoding.UTF8);
            List <KeyValue> keyValues = client.GetKVClient().Get(bkey).GetKvs();

            if (keyValues.Count > 0)
            {
                return(keyValues[0].GetValue().ToString());
            }
            return(null);
        }
        /**
         * Gets the range end of the given prefix.
         *
         * <p>The range end is the key plus one (e.g., "aa"+1 == "ab", "a\xff"+1 == "b").
         *
         * @param prefix the given prefix
         * @return the range end of the given prefix
         */
        public static ByteSequence PrefixEndOf(ByteSequence prefix)
        {
            byte[] endKey = (byte[])prefix.getBytes().Clone();
            for (int i = endKey.Length - 1; i >= 0; i--)
            {
                if (endKey[i] < 0xff)
                {
                    endKey[i] = (byte)(endKey[i] + 1);
                    byte[] dest = new byte[endKey.Length - i - 1];
                    Array.Copy(endKey, i + 1, dest, 0, dest.Length);
                    return(ByteSequence.from(dest));
                }
            }

            return(ByteSequence.from(NO_PREFIX_END));
        }
 /**
  * Keys is the list of keys attached to this lease.
  */
 public List <ByteSequence> getKeys()
 {
     lock (lock_obj)
     {
         if (keys == null)
         {
             var kkeys = GetResponse().Keys;
             List <ByteSequence> list = new List <ByteSequence>(kkeys.Count);
             foreach (var k in kkeys)
             {
                 list.Add(ByteSequence.from(k));
             }
             keys = list;
         }
     }
     return(keys);
 }
        public void Delete(string key)
        {
            ByteSequence bkey = ByteSequence.from(key, Encoding.UTF8);

            client.GetKVClient().Delete(bkey);
        }
 /**
  * key is a key that will exist on etcd for the duration that the Lock caller
  * owns the lock. Users should not modify this key or the lock may exhibit
  * undefined behavior.
  */
 public ByteSequence GetKey()
 {
     return(ByteSequence.from(GetResponse().Key));
 }