Parcourir la source

调整

develop
H Vs il y a 6 mois
Parent
révision
f9d26b93f9
1 fichiers modifiés avec 67 ajouts et 67 suppressions
  1. +67
    -67
      TelpoKafkaConsole.WebApi/Controllers/WeatherForecastController.cs

+ 67
- 67
TelpoKafkaConsole.WebApi/Controllers/WeatherForecastController.cs Voir le fichier

@@ -1,74 +1,74 @@
using Confluent.Kafka;
using Confluent.Kafka.Admin;
using Microsoft.AspNetCore.Mvc;
using TelpoKafkaConsole.Service;
using TelpoKafkaConsole.WebApi.Controllers.Api;
//using Confluent.Kafka;
//using Confluent.Kafka.Admin;
//using Microsoft.AspNetCore.Mvc;
//using TelpoKafkaConsole.Service;
//using TelpoKafkaConsole.WebApi.Controllers.Api;

namespace TelpoKafkaConsole.WebApi.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private readonly KafkaAdminService _servicekafkaAdmin;
//namespace TelpoKafkaConsole.WebApi.Controllers
//{
// [ApiController]
// [Route("[controller]")]
// public class WeatherForecastController : ControllerBase
// {
// private readonly KafkaAdminService _servicekafkaAdmin;

private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
// private static readonly string[] Summaries = new[]
// {
// "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
// };

private readonly ILogger<WeatherForecastController> _logger;
// private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger, KafkaAdminService kafkaAdminService)
{
_logger = logger;
_servicekafkaAdmin = kafkaAdminService;
}
// public WeatherForecastController(ILogger<WeatherForecastController> logger, KafkaAdminService kafkaAdminService)
// {
// _logger = logger;
// _servicekafkaAdmin = kafkaAdminService;
// }

//[HttpGet(Name = "GetWeatherForecast")]
//public IEnumerable<WeatherForecast> Get()
//{
// return Enumerable.Range(1, 5).Select(index => new WeatherForecast
// {
// Date = DateTime.Now.AddDays(index),
// TemperatureC = Random.Shared.Next(-20, 55),
// Summary = Summaries[Random.Shared.Next(Summaries.Length)]
// })
// .ToArray();
//}
//[HttpGet(Name = "GetGroup")]
//public ApiResponse<List<GroupInfo>> GetGroup()
//{
// var group = _servicekafkaAdmin.ListGroups();
// return ApiResponse<List<GroupInfo>>.Success(group);
//}
// //[HttpGet(Name = "GetWeatherForecast")]
// //public IEnumerable<WeatherForecast> Get()
// //{
// // return Enumerable.Range(1, 5).Select(index => new WeatherForecast
// // {
// // Date = DateTime.Now.AddDays(index),
// // TemperatureC = Random.Shared.Next(-20, 55),
// // Summary = Summaries[Random.Shared.Next(Summaries.Length)]
// // })
// // .ToArray();
// //}
// //[HttpGet(Name = "GetGroup")]
// //public ApiResponse<List<GroupInfo>> GetGroup()
// //{
// // var group = _servicekafkaAdmin.ListGroups();
// // return ApiResponse<List<GroupInfo>>.Success(group);
// //}

[HttpGet(Name = "GetGroup")]
public async Task<ApiResponse<string>> GetGroupAsync()
{
// var group = _servicekafkaAdmin.ListGroups();
List<AclBinding> aclBindings = new()
{
new AclBinding()
{
Pattern = new ResourcePattern
{
Type = ResourceType.Broker,
Name = "kafka-cluster",
ResourcePatternType = ResourcePatternType.Literal
},
Entry = new AccessControlEntry
{
Principal = $"User:telpo-consumer",
Host = "*",
Operation = AclOperation.All,
PermissionType = AclPermissionType.Deny
}
}
};
await _servicekafkaAdmin.CreateAclsAsync(aclBindings);
return ApiResponse<string>.Success("ok");
}
}
}
// [HttpGet(Name = "GetGroup")]
// public async Task<ApiResponse<string>> GetGroupAsync()
// {
// // var group = _servicekafkaAdmin.ListGroups();
// List<AclBinding> aclBindings = new()
// {
// new AclBinding()
// {
// Pattern = new ResourcePattern
// {
// Type = ResourceType.Broker,
// Name = "kafka-cluster",
// ResourcePatternType = ResourcePatternType.Literal
// },
// Entry = new AccessControlEntry
// {
// Principal = $"User:telpo-consumer",
// Host = "*",
// Operation = AclOperation.All,
// PermissionType = AclPermissionType.Deny
// }
// }
// };
// await _servicekafkaAdmin.CreateAclsAsync(aclBindings);
// return ApiResponse<string>.Success("ok");
// }
// }
//}

Chargement…
Annuler
Enregistrer