コード例 #1
0
ファイル: ACL.cs プロジェクト: sergeybykov/consuldotnet
        /// <summary>
        /// Info is used to query for information about an ACL token
        /// </summary>
        /// <param name="id">The ACL ID to request information about</param>
        /// <param name="q">Customized query options</param>
        /// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
        /// <returns>A query result containing the ACL entry matching the provided ID, or a query result with a null response if no token matched the provided ID</returns>
        public QueryResult <ACLEntry> Info(string id, QueryOptions q, CancellationToken ct)
        {
            var res = _client.CreateQuery <ACLEntry[]>(string.Format("/v1/acl/info/{0}", id), q).Execute(ct);
            var ret = new QueryResult <ACLEntry>()
            {
                KnownLeader = res.KnownLeader,
                LastContact = res.LastContact,
                LastIndex   = res.LastIndex,
                RequestTime = res.RequestTime
            };

            if (res.Response != null && res.Response.Length > 0)
            {
                ret.Response = res.Response[0];
            }
            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Get is used to lookup a single key
        /// </summary>
        /// <param name="key">The key name</param>
        /// <param name="q">Customized query options</param>
        /// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
        /// <returns>A query result containing the requested key/value pair, or a query result with a null response if the key does not exist</returns>
        public QueryResult <KVPair> Get(string key, QueryOptions q, CancellationToken ct)
        {
            var req = _client.CreateQuery <KVPair[]>(string.Format("/v1/kv/{0}", key), q);
            var res = req.Execute(ct);
            var ret = new QueryResult <KVPair>()
            {
                KnownLeader = res.KnownLeader,
                LastContact = res.LastContact,
                LastIndex   = res.LastIndex,
                RequestTime = res.RequestTime
            };

            if (res.Response != null && res.Response.Length > 0)
            {
                ret.Response = res.Response[0];
            }
            return(ret);
        }
コード例 #3
0
        /// <summary>
        /// List is used to get the most recent events an agent has received. This list can be optionally filtered by the name. This endpoint supports quasi-blocking queries. The index is not monotonic, nor does it provide provide LastContact or KnownLeader.
        /// </summary>
        /// <param name="name">The name of the event to filter for</param>
        /// <param name="q">Customized query options</param>
        /// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
        /// <returns>An array of events</returns>
        public QueryResult <UserEvent[]> List(string name, QueryOptions q, CancellationToken ct)
        {
            var req = _client.CreateQuery <UserEvent[]>("/v1/event/list", q);

            if (!string.IsNullOrEmpty(name))
            {
                req.Params["name"] = name;
            }
            return(req.Execute(ct));
        }
コード例 #4
0
ファイル: Status.cs プロジェクト: sergeybykov/consuldotnet
        /// <summary>
        /// Leader is used to query for a known leader
        /// </summary>
        /// <returns>A write result containing the leader node name</returns>
        public string Leader()
        {
            var res = _client.CreateQuery <string>("/v1/status/leader").Execute();

            return(res.Response);
        }
コード例 #5
0
 /// <summary>
 /// Datacenters is used to query for all the known datacenters
 /// </summary>
 /// <returns>A list of datacenter names</returns>
 public QueryResult <string[]> Datacenters()
 {
     return(_client.CreateQuery <string[]>("/v1/catalog/datacenters").Execute());
 }
コード例 #6
0
 /// <summary>
 /// Self is used to query the agent we are speaking to for information about itself
 /// </summary>
 /// <returns>A somewhat dynamic object representing the various data elements in Self</returns>
 public QueryResult <Dictionary <string, Dictionary <string, dynamic> > > Self()
 {
     return(_client.CreateQuery <Dictionary <string, Dictionary <string, dynamic> > >("/v1/agent/self")
            .Execute());
 }
コード例 #7
0
 /// <summary>
 /// Node is used to query for checks belonging to a given node
 /// </summary>
 /// <param name="node">The node name</param>
 /// <param name="q">Customized query options</param>
 /// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
 /// <returns>A query result containing the health checks matching the provided node ID, or a query result with a null response if no node matched the provided ID</returns>
 public QueryResult <HealthCheck[]> Node(string node, QueryOptions q, CancellationToken ct)
 {
     return
         (_client.CreateQuery <HealthCheck[]>(string.Format("/v1/health/node/{0}", node), q).Execute(ct));
 }
コード例 #8
0
 /// <summary>
 /// Query is used to do a GET request against an endpoint and deserialize the response into an interface using standard Consul conventions.
 /// </summary>
 /// <param name="endpoint">The URL endpoint to access</param>
 /// <param name="q">Custom query options</param>
 /// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
 /// <returns>The data returned by the custom endpoint</returns>
 public QueryResult <dynamic> Query(string endpoint, QueryOptions q, CancellationToken ct)
 {
     return(_client.CreateQuery <dynamic>(endpoint, q).Execute(ct));
 }