Skip to content

Commit

Permalink
Remove mvc (#316)
Browse files Browse the repository at this point in the history
* Refactoring

---------

Co-authored-by: Boris Ahrens <boris.ahrens@gdata.de>
  • Loading branch information
borisahrens and Boris Ahrens authored Mar 14, 2024
1 parent 50c7665 commit 594ebb3
Show file tree
Hide file tree
Showing 21 changed files with 12 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using JWT.Algorithms;
using Microsoft.AspNetCore.Mvc;
using JWT.Builder;
using JWT.Exceptions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using MalwareSampleExchange.Console.Attributes;
using MalwareSampleExchange.Console.Models;
Expand Down Expand Up @@ -52,7 +45,7 @@ public SampleApiController(ISampleStorageHandler sampleStorageHandler, ILogger<S
/// <param name="token">download</param>
/// <param name="cancellationToken"></param>
[HttpGet]
[Route("downloads/v1/download")]
[Route("v1/download")]
[AllowAnonymous]
[ValidateModelState]
[SwaggerResponse(StatusCodes.Status400BadRequest, "The token is expired.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public TokensApiController(ILogger<TokensApiController> logger, IListRequester l
/// <param name="end">(Default: today's date )</param>
/// <param name="token"></param>
[HttpGet]
[Route("lists/v1/list")]
[Route("v1/list")]
[ValidateModelState]
[SwaggerResponse(StatusCodes.Status400BadRequest, "Start Date has to be before end date")]
[SwaggerResponse(StatusCodes.Status401Unauthorized, "Unauthorized!")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using MalwareSampleExchange.Console.Database;
using MalwareSampleExchange.Console.Models;
using MalwareSampleExchange.Console.SampleStorage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Collections.Generic;
using MalwareSampleExchange.Console.Models;

namespace MalwareSampleExchange.Console.Database;

public interface IPartnerProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace MalwareSampleExchange.Console.Database;

public class MongoMetadataOptions
Expand Down
3 changes: 0 additions & 3 deletions src/MalwareSampleExchange.Console/ListRequester/Hashing.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace MalwareSampleExchange.Console.ListRequester;

public class ListRequesterOptions
Expand Down
4 changes: 0 additions & 4 deletions src/MalwareSampleExchange.Console/LogEvents.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using Microsoft.Extensions.Logging;

#pragma warning disable 1591

namespace MalwareSampleExchange.Console;

public static class LogEvents
{
private static readonly int Id;
//Trace
public static EventId HashListResponse = new(++Id, nameof(HashListResponse));
public static EventId HashListRequest = new(++Id, nameof(HashListRequest));
public static EventId UnknownPartner = new(++Id, nameof(UnknownPartner));
public static EventId TokenExpired = new(++Id, nameof(TokenExpired));
Expand Down
1 change: 0 additions & 1 deletion src/MalwareSampleExchange.Console/Models/Error.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Text;
Expand Down
1 change: 0 additions & 1 deletion src/MalwareSampleExchange.Console/Models/ExportSample.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using MongoDB.Bson.Serialization.Attributes;

namespace MalwareSampleExchange.Console.Models;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using MongoDB.Bson.Serialization.Attributes;

namespace MalwareSampleExchange.Console.Models;

public record RequestExportSample
Expand Down
1 change: 0 additions & 1 deletion src/MalwareSampleExchange.Console/Models/Sample.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json;
Expand Down
1 change: 0 additions & 1 deletion src/MalwareSampleExchange.Console/Models/Token.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using MalwareSampleExchange.Console.AuthHandler;
using MalwareSampleExchange.Console.Database;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace MalwareSampleExchange.Console.Partner;
Expand Down
8 changes: 0 additions & 8 deletions src/MalwareSampleExchange.Console/Partner/PartnerProvider.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using MalwareSampleExchange.Console.Database;
using MalwareSampleExchange.Console.ListRequester;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace MalwareSampleExchange.Console.Database;

public class PartnerProviderOptions
Expand Down
21 changes: 10 additions & 11 deletions src/MalwareSampleExchange.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@
services.AddAuthentication("BasicAuthentication")
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);

//curl -u "gdata:pw" -X GET -k -i 'https://malware-sample-export.processing-orange.ptata.gdata.de/v1/list?start=2022-01-14'
// Add OpenAPI generator
services.AddSwaggerGen(c =>
{
c.EnableAnnotations();
Expand Down Expand Up @@ -127,10 +125,9 @@

var app = builder.Build();


app.UsePrometheusServer(q =>
{
var options = new PrometheusOptions();
var options = new MalwareSampleExchange.Console.PrometheusOptions();
builder.Configuration.GetSection("Prometheus").Bind(options);
q.Port = options.Port;
});
Expand All @@ -144,19 +141,22 @@
q.IgnoreRoutesStartWith = ["/swagger"];
});

app.UseDefaultFiles()
.UseForwardedHeaders()
.UseRouting()
.UseStaticFiles()
.UseSwagger()
.UseSwaggerUI(options =>
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.DocumentTitle = "Malware Sample Exchange - V1";
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Malware Sample Exchange - V1");
});

app.UseForwardedHeaders();
app.UseRouting();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });

if (app.Environment.IsDevelopment())
Expand All @@ -165,4 +165,3 @@
}

app.Run();

Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace MalwareSampleExchange.Console.SampleStorage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace MalwareSampleExchange.Console.SampleStorage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Amazon.S3;
using Amazon.S3.Model;
using Microsoft.AspNetCore.Mvc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace MalwareSampleExchange.Console.SampleStorage;
Expand Down

0 comments on commit 594ebb3

Please sign in to comment.