예제 #1
0
        /// <summary>
        /// Put is used to write a new value. Only the Key, Flags and Value is 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 write attempt succeeded</returns>
        public WriteResult <bool> Put(KVPair p, WriteOptions q)
        {
            var req = _client.CreateWrite <byte[], bool>(string.Format("/v1/kv/{0}", p.Key), p.Value, q);

            if (p.Flags > 0)
            {
                req.Params["flags"] = p.Flags.ToString();
            }
            return(req.Execute());
        }
예제 #2
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 WriteResult <string> Create(SessionEntry se, WriteOptions q)
        {
            var res = _client.CreateWrite <SessionEntry, SessionCreationResult>("/v1/session/create", se, q).Execute();

            return(new WriteResult <string>()
            {
                RequestTime = res.RequestTime,
                Response = res.Response.ID
            });
        }
예제 #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 WriteResult <string> Fire(UserEvent ue, WriteOptions q)
        {
            var req =
                _client.CreateWrite <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 = req.Execute();
            var ret = new WriteResult <string>()
            {
                RequestTime = res.RequestTime,
                Response    = res.Response.ID
            };

            return(ret);
        }
예제 #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 WriteResult <string> Create(ACLEntry acl, WriteOptions q)
        {
            var res = _client.CreateWrite <ACLEntry, ACLCreationResult>("/v1/acl/create", acl, q).Execute();

            return(new WriteResult <string>()
            {
                RequestTime = res.RequestTime,
                Response = res.Response.ID
            });
        }
예제 #5
0
 /// <summary>
 /// ServiceRegister is used to register a new service with the local agent
 /// </summary>
 /// <param name="serviceID">The service ID</param>
 /// <returns>An empty write result</returns>
 public WriteResult ServiceDeregister(string serviceID)
 {
     return(_client.CreateWrite(string.Format("/v1/agent/service/deregister/{0}", serviceID)).Execute());
 }
예제 #6
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 WriteResult <dynamic> Write(string endpoint, object obj, WriteOptions q)
 {
     return(_client.CreateWrite <object, dynamic>(endpoint, obj, q).Execute());
 }