Ejemplo n.º 1
0
Archivo: KV.cs Proyecto: stulzq/NConsul
        /// <summary>
        /// Acquire is used for a lock acquisition operation. The Key, Flags, Value and Session are respected.
        /// </summary>
        /// <param name="p">The key/value pair to store in Consul</param>
        /// <param name="q">Customized write options</param>
        /// <returns>A write result indicating if the acquisition attempt succeeded</returns>
        public Task <WriteResult <bool> > Acquire(KVPair p, WriteOptions q, CancellationToken ct = default(CancellationToken))
        {
            p.Validate();
            var req = _client.Put <byte[], bool>(string.Format("/v1/kv/{0}", p.Key.TrimStart('/')), p.Value, q);

            if (p.Flags > 0)
            {
                req.Params["flags"] = p.Flags.ToString();
            }
            req.Params["acquire"] = p.Session;
            return(req.Execute(ct));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// KeyringUse is used to change the active gossip encryption key
 /// </summary>
 public Task <WriteResult> KeyringUse(string key, WriteOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Put("/v1/operator/keyring", new KeyringRequest()
     {
         Key = key
     }, q).Execute(ct));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Fire is used to fire a new user event. Only the Name, Payload and Filters are respected. This returns the ID or an associated error. Cross DC requests are supported.
        /// </summary>
        /// <param name="ue">A User Event definition</param>
        /// <param name="q">Customized write options</param>
        /// <returns></returns>
        public async Task <WriteResult <string> > Fire(UserEvent ue, WriteOptions q, CancellationToken ct = default(CancellationToken))
        {
            var req = _client.Put <byte[], EventCreationResult>(string.Format("/v1/event/fire/{0}", ue.Name), ue.Payload, q);

            if (!string.IsNullOrEmpty(ue.NodeFilter))
            {
                req.Params["node"] = ue.NodeFilter;
            }
            if (!string.IsNullOrEmpty(ue.ServiceFilter))
            {
                req.Params["service"] = ue.ServiceFilter;
            }
            if (!string.IsNullOrEmpty(ue.TagFilter))
            {
                req.Params["tag"] = ue.TagFilter;
            }
            var res = await req.Execute(ct).ConfigureAwait(false);

            return(new WriteResult <string>(res, res.Response.ID));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create is used to generate a new token with the given parameters
        /// </summary>
        /// <param name="acl">The ACL entry to create</param>
        /// <param name="q">Customized write options</param>
        /// <returns>A write result containing the newly created ACL token</returns>
        public async Task <WriteResult <string> > Create(ACLEntry acl, WriteOptions q, CancellationToken ct = default(CancellationToken))
        {
            var res = await _client.Put <ACLEntry, ACLCreationResult>("/v1/acl/create", acl, q).Execute(ct).ConfigureAwait(false);

            return(new WriteResult <string>(res, res.Response.ID));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Register a new catalog item
 /// </summary>
 /// <param name="reg">A catalog registration</param>
 /// <param name="q">Customized write options</param>
 /// <returns>An empty write result</returns>
 public Task <WriteResult> Register(CatalogRegistration reg, WriteOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Put("/v1/catalog/register", reg, q).Execute(ct));
 }
Ejemplo n.º 6
0
 public Task <WriteResult> Update(PreparedQueryDefinition query, WriteOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Put(string.Format("/v1/query/{0}", query.ID), query, q).Execute(ct));
 }
Ejemplo n.º 7
0
 public Task <WriteResult> Restore(Stream s, WriteOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Put("/v1/snapshot", s, q).Execute(ct));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Create makes a new session. Providing a session entry can customize the session. It can also be null to use defaults.
        /// </summary>
        /// <param name="se">The SessionEntry options to use</param>
        /// <param name="q">Customized write options</param>
        /// <returns>A write result containing the new session ID</returns>
        public async Task <WriteResult <string> > Create(SessionEntry se, WriteOptions q, CancellationToken ct = default(CancellationToken))
        {
            var res = await _client.Put <SessionEntry, SessionCreationResult>("/v1/session/create", se, q).Execute(ct).ConfigureAwait(false);

            return(new WriteResult <string>(res, res.Response.ID));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Write is used to do a PUT request against an endpoint and serialize/deserialized using the standard Consul conventions.
 /// </summary>
 /// <param name="endpoint">The URL endpoint to access</param>
 /// <param name="obj">The object to serialize and send to the endpoint. Must be able to be JSON serialized, or be an object of type byte[], which is sent without serialzation.</param>
 /// <param name="q">Custom write options</param>
 /// <returns>The data returned by the custom endpoint in response to the write request</returns>
 public Task <WriteResult <dynamic> > Write(string endpoint, object obj, WriteOptions q, CancellationToken ct = default(CancellationToken))
 {
     return(_client.Put <object, dynamic>(endpoint, obj, q).Execute(ct));
 }