protected override async Task <int> Run() { var connection = _connectionFactory.Connect(_connection); // Default will apply the ingest permission var apiKey = await connection.ApiKeys.TemplateAsync(); apiKey.Title = _title; apiKey.InputSettings.AppliedProperties = _properties.Properties .Select(kvp => new InputAppliedPropertyPart { Name = kvp.Key, Value = kvp.Value }) .ToList(); apiKey.InputSettings.UseServerTimestamps = _useServerTimestamps; // If _token is null, a value will be returned when the key is created apiKey.Token = _token; if (_filter != null) { apiKey.InputSettings.Filter = new DescriptiveFilterPart { Filter = (await connection.Expressions.ToStrictAsync(_filter)).StrictExpression, FilterNonStrict = _filter }; } if (_level != null) { apiKey.InputSettings.MinimumLevel = Enum.Parse <LogEventLevel>(LevelMapping.ToFullLevelName(_level)); } apiKey = await connection.ApiKeys.AddAsync(apiKey); if (_token == null && !_output.Json) { Console.WriteLine(apiKey.Token); } else { _output.WriteEntity(apiKey); } return(0); }
protected override async Task <int> Run() { var connection = await TryConnectAsync(); if (connection == null) { return(1); } var apiKey = await connection.ApiKeys.TemplateAsync(); apiKey.Title = _title; apiKey.InputSettings.AppliedProperties = _properties.Properties .Select(kvp => new EventPropertyPart(kvp.Key, kvp.Value)) .ToList(); apiKey.InputSettings.UseServerTimestamps = _useServerTimestamps; // If _token is null, a value will be returned when the key is created apiKey.Token = _token; if (_filter != null) { apiKey.InputSettings.Filter = new DescriptiveFilterPart { Filter = (await connection.Expressions.ToStrictAsync(_filter)).StrictExpression, FilterNonStrict = _filter }; } if (_level != null) { apiKey.InputSettings.MinimumLevel = Enum.Parse <LogEventLevel>(LevelMapping.ToFullLevelName(_level)); } apiKey.AssignedPermissions.Clear(); if (_permissions != null) { foreach (var permission in _permissions) { if (!Enum.TryParse <Permission>(permission, out var p)) { Log.Error("Unrecognized permission {Permission}", permission); return(1); } apiKey.AssignedPermissions.Add(p); } } else { apiKey.AssignedPermissions.Add(Permission.Ingest); } apiKey = await connection.ApiKeys.AddAsync(apiKey); if (_token == null && !_output.Json) { Console.WriteLine(apiKey.Token); } else { _output.WriteEntity(apiKey); } return(0); }