public async Task <ConsulResponse> SetTTLTypeStatusAsync(ConsulRequest <StatusRequest> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); return(await _polymath.MakeConsulApiRequest <JToken>(request, "v1/agent/check/update/" + request.RequestData.CheckId, HttpMethod.Put, request.RequestData).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse <AgentServiceModel> > GetConfigAsync(ConsulRequest <string> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); return(await _polymath.MakeConsulApiRequest <AgentServiceModel>(request, "v1/agent/service/" + request.RequestData, HttpMethod.Get).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse <string> > RegisterAsync(ConsulRequest <CheckRequest> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); return(await _polymath.MakeConsulApiRequest <string>(request, "v1/agent/check/register", HttpMethod.Put, request.RequestData).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse> DeregisterAsync(ConsulRequest <string> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); return(await _polymath.MakeConsulApiRequest <JToken>(request, "v1/agent/service/deregister/" + request.RequestData, HttpMethod.Put, request.RequestData).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse <KeyValueData> > ReadAsync(ConsulRequest <ReadKeyValueModel> request) { var resourcePath = "v1/kv/" + request.RequestData.Key.TrimStart('/') + request.RequestData.ToQueryString(); if (request.RequestData.KeysOnly) { var keysResponse = await _polymath.MakeConsulApiRequest <List <string> >(request, resourcePath, HttpMethod.Get).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext); return(keysResponse.Map(() => new KeyValueData { Keys = keysResponse.Data })); } if (request.RequestData.RawResponse) { var rawResponse = await _polymath.MakeConsulApiRequest <string>(request, resourcePath, HttpMethod.Get, rawResponse : true).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext); return(rawResponse.Map(() => new KeyValueData { RawValue = rawResponse.Data })); } var response = await _polymath.MakeConsulApiRequest <List <KeyValueModel> >(request, resourcePath, HttpMethod.Get).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext); return(response.Map(() => new KeyValueData { KeyValueModels = response.Data })); }
public async Task LogoutAsync(ConsulRequest <string> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); await _polymath.MakeConsulApiRequest(request, "v1/acl/logout", HttpMethod.Post, unauthenticated : true, consulToken : request.RequestData).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext); }
private static void RunKeyValueSamples() { output.AppendLine("\n KV Samples \n"); var createKey = new WriteKeyValueModel { Key = Guid.NewGuid().ToString(), Flags = 32, Value = "some-value" }; var createResponse = _consulClient.V1.KeyValue.WriteAsync(new ConsulRequest <WriteKeyValueModel> { RequestData = createKey }).Result; DisplayJson(createResponse); Assert.True(createResponse.Data); var readKeyModel = new ReadKeyValueModel { Key = createKey.Key, }; var readRequest = new ConsulRequest <ReadKeyValueModel> { RequestData = readKeyModel }; var readKeyResponse = _consulClient.V1.KeyValue.ReadAsync(readRequest).Result; DisplayJson(readKeyResponse); Assert.Equal(readKeyModel.Key, readKeyResponse.Data.KeyValueModels[0].Key); readRequest.RequestData.RawResponse = true; var raw = _consulClient.V1.KeyValue.ReadAsync(readRequest).Result; DisplayJson(raw); Assert.Equal(createKey.Value, raw.Data.RawValue); readRequest.RequestData.KeysOnly = true; var keys = _consulClient.V1.KeyValue.ReadAsync(readRequest).Result; DisplayJson(keys); Assert.True(keys.Data.Keys.Count == 1); var deleteResponse = _consulClient.V1.KeyValue.DeleteAsync(new ConsulRequest <DeleteKeyValueModel> { RequestData = new DeleteKeyValueModel { Key = createKey.Key } }).Result; DisplayJson(deleteResponse); Assert.True(deleteResponse.Data); var consulException = Assert.ThrowsAsync <ConsulApiException>(() => _consulClient.V1.KeyValue.ReadAsync(readRequest)).Result; Assert.Equal(HttpStatusCode.NotFound, consulException.HttpStatusCode); }
public async Task <ConsulResponse <AuthResponse> > LoginAsync(ConsulRequest <AuthRequest> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData.AuthMethodName, nameof(request.RequestData.AuthMethodName)); Checker.NotNull(request.RequestData.BearerToken, nameof(request.RequestData.BearerToken)); return(await _polymath.MakeConsulApiRequest <AuthResponse>(request, "v1/acl/login", HttpMethod.Post).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse <MetricsModel> > GetMetricsAsync(ConsulRequest <MetricsRequest> request = null) { var plain = !string.IsNullOrEmpty(request?.RequestData?.Format) && string.Equals(request.RequestData.Format, MetricsFormat.PROMETHEUS, StringComparison.OrdinalIgnoreCase); var qs = plain ? "?format=" + MetricsFormat.PROMETHEUS : string.Empty; return(await _polymath.MakeConsulApiRequest <MetricsModel>(request, "v1/agent/metrics" + qs, HttpMethod.Get, rawResponse : plain).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse> ToggleMaintenanceModeAsync(ConsulRequest <MaintenanceRequest> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); var qs = "?enable=" + (request.RequestData.Mode == MaintenanceMode.Enable ? "true" : "false") + (!string.IsNullOrEmpty(request.RequestData.Reason) ? "&reason=" + WebUtility.UrlEncode(request.RequestData.Reason) : string.Empty); return(await _polymath.MakeConsulApiRequest <JToken>(request, "v1/agent/service/maintenance/" + request.RequestData.ServiceId + qs, HttpMethod.Put).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse> UpdateACLTokenAsync(ConsulRequest <UpdateAgentTokenRequest> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); Checker.NotNull(request.RequestData.TokenType, nameof(request.RequestData.TokenType)); Checker.NotNull(request.RequestData.Token, nameof(request.RequestData.Token)); return(await _polymath.MakeConsulApiRequest <JToken>(request, "v1/agent/token/" + request.RequestData.TokenType, HttpMethod.Put, new { Token = request.RequestData.Token }).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse> ForceLeaveAsync(ConsulRequest <ForceLeaveRequest> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); Checker.NotNull(request.RequestData.NodeName, nameof(request.RequestData.NodeName)); var qs = request.RequestData.Prune ? "?prune" : string.Empty; return(await _polymath.MakeConsulApiRequest <JToken>(request, "v1/agent/force-leave/" + request.RequestData.NodeName + qs, HttpMethod.Put).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse> JoinAsync(ConsulRequest <JoinRequest> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); Checker.NotNull(request.RequestData.AgentAddress, nameof(request.RequestData.AgentAddress)); var qs = "?wan=" + request.RequestData.OverWAN.ToString().ToLowerInvariant(); return(await _polymath.MakeConsulApiRequest <JToken>(request, "v1/agent/join/" + request.RequestData.AgentAddress + qs, HttpMethod.Put).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse <string> > StreamLogAsync(ConsulRequest <StreamLogRequest> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); Checker.NotNull(request.RequestData.LogLevel, nameof(request.RequestData.LogLevel)); var qs = "?loglevel=" + request.RequestData.LogLevel + "&logjson=" + request.RequestData.LogJson.ToString().ToLowerInvariant(); return(await _polymath.MakeConsulApiRequest <string>(request, "v1/agent/monitor" + qs, HttpMethod.Get, rawResponse : true).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse <HealthResponse> > GetHealthAsync(ConsulRequest <HealthRequest> request) { Checker.NotNull(request, nameof(request)); Checker.NotNull(request.RequestData, nameof(request.RequestData)); if (string.IsNullOrEmpty(request.RequestData.ServiceId) && string.IsNullOrEmpty(request.RequestData.ServiceName)) { throw new ArgumentException("Provide one of ServiceId or ServiceName. Both cannot be missing."); } var qs = !string.IsNullOrEmpty(request.RequestData.ServiceId) ? "id/" + request.RequestData.ServiceId : "name/" + request.RequestData.ServiceName; var plain = !string.IsNullOrEmpty(request.RequestData.Format) && request.RequestData.Format.Equals(ContentFormat.TEXT, StringComparison.OrdinalIgnoreCase); qs += (plain ? "?format=text" : string.Empty); var status = HttpStatusCode.OK; if (plain) { var plainText = await _polymath.MakeConsulApiRequest <string>(request, "v1/agent/health/service/" + qs, HttpMethod.Get, rawResponse : true, postResponseFunc : r => { status = r.StatusCode; return(true); }).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext); return(plainText.Map(() => new HealthResponse { StatusCode = status, PlainText = plainText.Data })); } if (!string.IsNullOrEmpty(request.RequestData.ServiceId)) { var service = await _polymath.MakeConsulApiRequest <Dictionary <string, AgentServiceModel> >(request, "v1/agent/health/service/" + qs, HttpMethod.Get, postResponseFunc : r => { status = r.StatusCode; return(true); }).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext); return(service.Map(() => new HealthResponse { StatusCode = status, Statuses = service.Data.ToDictionary(kv => kv.Key, kv => new List <AgentServiceModel> { kv.Value }) })); } var services = await _polymath.MakeConsulApiRequest <Dictionary <string, List <AgentServiceModel> > >(request, "v1/agent/health/service/" + qs, HttpMethod.Get, postResponseFunc : r => { status = r.StatusCode; return(true); }).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext); return(services.Map(() => new HealthResponse { StatusCode = status, Statuses = services.Data })); }
public async Task <ConsulResponse <TransactionResponseModel> > CreateAsync(ConsulRequest <TransactionRequestModel> request) { var status = TransactionStatus.Success; var response = await _polymath.MakeConsulApiRequest <TransactionResponseModel>(request, "v1/txn" + request.RequestData.ToQueryString(), HttpMethod.Put, request.RequestData.Operations, postResponseFunc : httpResponseMessage => { if (httpResponseMessage.StatusCode == System.Net.HttpStatusCode.Conflict) { status = TransactionStatus.Rollback; return(true); } return(false); } ).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext); response.Data.Status = status; return(response); }
private static void RunSnapshotSamples() { output.AppendLine("\n Snapshot Samples \n"); var snapshot = _consulClient.V1.Snapshot.GenerateAsync().Result; DisplayJson(snapshot); Assert.NotNull(snapshot.Data); var restore = new ConsulRequest <SnapshotRestoreModel> { RequestData = new SnapshotRestoreModel { Snapshot = snapshot.Data } }; var restoreResponse = _consulClient.V1.Snapshot.RestoreAsync(restore).Result; DisplayJson(restoreResponse); Assert.NotNull(restoreResponse); }
public async Task <ConsulResponse <List <PolicyModel> > > ListAsync(ConsulRequest request = null) { return(await _polymath.MakeConsulApiRequest <List <PolicyModel> >(request, "v1/acl/policies", HttpMethod.Get).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse> RegisterAsync(ConsulRequest <RegisterRequest> request) { return(await _polymath.MakeConsulApiRequest <JToken>(request, "v1/agent/service/register", HttpMethod.Put, request.RequestData).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
private static void RunAclSamples() { output.AppendLine("\n ACL Samples \n"); var request = new ConsulRequest { ConsistencyMode = ConsistencyMode.consistent, PrettyJsonResponse = true, Wait = "10s" }; var managementTokenResponse = _consulClient.V1.ACL.BootstrapAsync(request).Result; DisplayJson(managementTokenResponse); Assert.NotNull(managementTokenResponse.Data); _managementToken = managementTokenResponse.Data.SecretId; _consulClient = new ConsulClient(new ConsulClientSettings("http://127.0.0.1:8500", _managementToken) { AfterApiResponseAction = r => { var value = ((int)r.StatusCode + "-" + r.StatusCode) + "\n"; var content = r.Content != null ? r.Content.ReadAsStringAsync().Result : string.Empty; output.AppendLine(); output.AppendLine("=============================================================================="); output.AppendLine(); _responseContent = "Actual Consul Server Response: " + value + content; output.AppendLine(_responseContent); output.AppendLine("-------------------------------------"); } }); var consulException = Assert.ThrowsAsync <ConsulApiException>(() => _consulClient.V1.ACL.BootstrapAsync()).Result; Assert.Equal(HttpStatusCode.Forbidden, consulException.HttpStatusCode); var newTokenModel = new TokenRequest { Id = Guid.NewGuid().ToString(), Name = "my-app-token", Rules = "", TokenType = TokenType.client }; var newToken = _consulClient.V1.ACL.LegacyToken.CreateAsync(new ConsulRequest <TokenRequest> { RequestData = newTokenModel }).Result; DisplayJson(newToken); Assert.Equal(newTokenModel.Id, newToken.Data); var updateTokenModel = new TokenRequest { Id = newTokenModel.Id, Name = "updated", Rules = "", TokenType = TokenType.client }; newToken = _consulClient.V1.ACL.LegacyToken.UpdateAsync(new ConsulRequest <TokenRequest> { RequestData = updateTokenModel }).Result; DisplayJson(newToken); Assert.Equal(updateTokenModel.Id, newToken.Data); var readToken = _consulClient.V1.ACL.LegacyToken.ReadAsync(new ConsulRequest <string> { RequestData = updateTokenModel.Id }).Result; DisplayJson(readToken); Assert.Equal(updateTokenModel.Name, readToken.Data[0].Name); var clonedToken = _consulClient.V1.ACL.LegacyToken.CloneAsync(new ConsulRequest <string> { RequestData = readToken.Data[0].Id }).Result; DisplayJson(clonedToken); Assert.NotNull(clonedToken.Data); var list = _consulClient.V1.ACL.LegacyToken.ListAsync().Result; DisplayJson(list); Assert.True(list.Data.Count > 1); var repStatus = _consulClient.V1.ACL.CheckReplicationAsync().Result; DisplayJson(repStatus); Assert.NotNull(repStatus.Data); var del1 = _consulClient.V1.ACL.LegacyToken.DeleteAsync(new ConsulRequest <string> { RequestData = readToken.Data[0].Id }).Result; DisplayJson(del1); var tokens = _consulClient.V1.ACL.LegacyToken.ReadAsync(new ConsulRequest <string> { RequestData = updateTokenModel.Id }).Result; DisplayJson(tokens); Assert.True(tokens.Data.Count == 0); var del2 = _consulClient.V1.ACL.LegacyToken.DeleteAsync(new ConsulRequest <string> { RequestData = clonedToken.Data }).Result; DisplayJson(del2); }
public Task <ConsulResponse <CARootsResponse> > GetCARootsAsync(ConsulRequest request = null) { throw new NotImplementedException(); }
public async Task <ConsulResponse <Dictionary <string, object> > > ReloadConfigAsync(ConsulRequest request = null) { return(await _polymath.MakeConsulApiRequest <Dictionary <string, object> >(request, "v1/agent/reload", HttpMethod.Put).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse <ConfigAndMemberModel> > ReadConfigAsync(ConsulRequest request = null) { return(await _polymath.MakeConsulApiRequest <ConfigAndMemberModel>(request, "v1/agent/self", HttpMethod.Get).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse <List <MemberModel> > > ListMembersAsync(ConsulRequest <ListMemberRequest> request = null) { return(await _polymath.MakeConsulApiRequest <List <MemberModel> >(request, "v1/agent/members" + GetQueryString(request.RequestData), HttpMethod.Get).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public async Task <ConsulResponse <bool> > DeleteAsync(ConsulRequest <DeleteKeyValueModel> request) { var response = await _polymath.MakeConsulApiRequest <string>(request, "v1/kv/" + request.RequestData.Key.TrimStart('/') + request.RequestData.ToQueryString(), HttpMethod.Delete, rawResponse : true).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext); return(response.Map(() => bool.Parse(response.Data))); }
public async Task <ConsulResponse> LeaveAsync(ConsulRequest request = null) { return(await _polymath.MakeConsulApiRequest <JToken>(request, "v1/agent/leave", HttpMethod.Put).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
private static void RunAgentSamples() { output.AppendLine("\n Agent Samples \n"); var members = _consulClient.V1.Agent.ListMembersAsync(new ConsulRequest <ListMemberRequest> { RequestData = new ListMemberRequest { WANMembers = true, Segment = "_all" } }).Result; DisplayJson(members); var configAndMember = _consulClient.V1.Agent.ReadConfigAsync().Result; DisplayJson(configAndMember); var reloadResponse = _consulClient.V1.Agent.ReloadConfigAsync().Result; DisplayJson(reloadResponse); var request = new ConsulRequest <MaintenanceRequest> { RequestData = new MaintenanceRequest { Mode = MaintenanceMode.Enable, Reason = "Yo Yo Ma" } }; var enableMaintenance = _consulClient.V1.Agent.ToggleMaintenanceModeAsync(request).Result; DisplayJson(enableMaintenance); request.RequestData.Mode = MaintenanceMode.Disable; var disableMaintenance = _consulClient.V1.Agent.ToggleMaintenanceModeAsync(request).Result; DisplayJson(disableMaintenance); var metrics = _consulClient.V1.Agent.GetMetricsAsync().Result; DisplayJson(metrics); //var logs = _consulClient.V1.Agent.StreamLogAsync(new ConsulRequest<StreamLogRequest> //{ // RequestData = new StreamLogRequest // { // LogLevel = "info" // } //}).Result; //DisplayJson(logs); var join = _consulClient.V1.Agent.JoinAsync(ConsulRequest.WithData(new JoinRequest { AgentAddress = "127.0.0.1", OverWAN = true })).Result; DisplayJson(join); RunAgentCheckSamples(); }
public async Task <ConsulResponse <Dictionary <string, AgentServiceModel> > > ListAsync(ConsulRequest <string> request = null) { var qs = string.IsNullOrEmpty(request?.RequestData) ? string.Empty : "?filter=" + request.RequestData; return(await _polymath.MakeConsulApiRequest <Dictionary <string, AgentServiceModel> >(request, "v1/agent/services" + qs, HttpMethod.Get).ConfigureAwait(_polymath.ConsulClientSettings.ContinueAsyncTasksOnCapturedContext)); }
public Task <ConsulResponse <ConnectAuthResponse> > AuthorizeAsync(ConsulRequest <ConnectAuthRequest> request) { throw new NotImplementedException(); }
public Task <ConsulResponse <CertificateModel> > GetLeafCertificateAsync(ConsulRequest <string> request) { throw new NotImplementedException(); }