Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mvc #316

Merged
merged 9 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Expand Up @@ -32,7 +31,7 @@
return JsonConvert.SerializeObject(this, Formatting.Indented);
}

public override bool Equals(object obj)

Check warning on line 34 in src/MalwareSampleExchange.Console/Models/Error.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 34 in src/MalwareSampleExchange.Console/Models/Error.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).
{
if (obj is null)
{
Expand All @@ -47,7 +46,7 @@
return obj.GetType() == GetType() && Equals((Error)obj);
}

public bool Equals(Error other)

Check warning on line 49 in src/MalwareSampleExchange.Console/Models/Error.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'other' of 'bool Error.Equals(Error other)' doesn't match implicitly implemented member 'bool IEquatable<Error>.Equals(Error? other)' (possibly because of nullability attributes).

Check warning on line 49 in src/MalwareSampleExchange.Console/Models/Error.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'other' of 'bool Error.Equals(Error other)' doesn't match implicitly implemented member 'bool IEquatable<Error>.Equals(Error? other)' (possibly because of nullability attributes).
{
if (other is null)
{
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 All @@ -25,7 +24,7 @@
return JsonConvert.SerializeObject(this, Formatting.Indented);
}

public override bool Equals(object obj)

Check warning on line 27 in src/MalwareSampleExchange.Console/Models/Sample.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 27 in src/MalwareSampleExchange.Console/Models/Sample.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).
{
if (obj is null)
{
Expand All @@ -40,7 +39,7 @@
return obj.GetType() == GetType() && Equals((Sample)obj);
}

public bool Equals(Sample other)

Check warning on line 42 in src/MalwareSampleExchange.Console/Models/Sample.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'other' of 'bool Sample.Equals(Sample other)' doesn't match implicitly implemented member 'bool IEquatable<Sample>.Equals(Sample? other)' (possibly because of nullability attributes).

Check warning on line 42 in src/MalwareSampleExchange.Console/Models/Sample.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'other' of 'bool Sample.Equals(Sample other)' doesn't match implicitly implemented member 'bool IEquatable<Sample>.Equals(Sample? other)' (possibly because of nullability attributes).
{
if (other is null)
{
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 All @@ -24,7 +23,7 @@
return JsonConvert.SerializeObject(this, Formatting.Indented);
}

public override bool Equals(object obj)

Check warning on line 26 in src/MalwareSampleExchange.Console/Models/Token.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 26 in src/MalwareSampleExchange.Console/Models/Token.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).
{
if (obj is null)
{
Expand All @@ -39,7 +38,7 @@
return obj.GetType() == GetType() && Equals((Token)obj);
}

public bool Equals(Token other)

Check warning on line 41 in src/MalwareSampleExchange.Console/Models/Token.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'other' of 'bool Token.Equals(Token other)' doesn't match implicitly implemented member 'bool IEquatable<Token>.Equals(Token? other)' (possibly because of nullability attributes).

Check warning on line 41 in src/MalwareSampleExchange.Console/Models/Token.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'other' of 'bool Token.Equals(Token other)' doesn't match implicitly implemented member 'bool IEquatable<Token>.Equals(Token? other)' (possibly because of nullability attributes).
{
if (other is null)
{
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 All @@ -27,7 +23,7 @@
ILogger<BasicAuthenticationHandler> logger,
ILoggerFactory loggerFactory,
UrlEncoder encoder,
ISystemClock clock,

Check warning on line 26 in src/MalwareSampleExchange.Console/Partner/BasicAuthenticationHandler.cs

View workflow job for this annotation

GitHub Actions / build

'ISystemClock' is obsolete: 'Use TimeProvider instead.'

Check warning on line 26 in src/MalwareSampleExchange.Console/Partner/BasicAuthenticationHandler.cs

View workflow job for this annotation

GitHub Actions / build

'ISystemClock' is obsolete: 'Use TimeProvider instead.'
IPartnerProvider partnerProvider,
IOptions<UploadOptions> uploadOptions)
: base(options, loggerFactory, encoder, clock)
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
Loading