Skip to content

Commit cd6db87

Browse files
refactor: update vaas dotnet example version to 8.0.0
1 parent 6e05a47 commit cd6db87

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed
Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Vaas;
22
using Vaas.Authentication;
3+
using Vaas.Options;
34

45
namespace VaasExample;
56

@@ -27,7 +28,7 @@ public static async Task Main(string[] args)
2728

2829
private static async Task FileScan()
2930
{
30-
var vaas = await CreateVaasAndConnect();
31+
var vaas = CreateVaas();
3132
var file = Environment.GetEnvironmentVariable("SCAN_PATH") ?? string.Empty;
3233
var verdict = await vaas.ForFileAsync(file, CancellationToken.None);
3334

@@ -36,54 +37,48 @@ private static async Task FileScan()
3637

3738
private static async Task HashsumScan()
3839
{
39-
var vaas = await CreateVaasAndConnect();
40+
var vaas = CreateVaas();
4041
var verdict = await vaas.ForSha256Async(new ChecksumSha256("275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f"), CancellationToken.None);
4142

4243
Console.WriteLine($"{verdict.Sha256} is detected as {verdict.Verdict}");
4344
}
4445

4546
private static async Task UrlScan()
4647
{
47-
var vaas = await CreateVaasAndConnect();
48+
var vaas = CreateVaas();
4849

4950
var uri = new Uri("https://secure.eicar.org/eicar.com.txt");
5051
var verdict = await vaas.ForUrlAsync(uri, CancellationToken.None);
5152

5253
Console.WriteLine($"{verdict.Sha256} is detected as {verdict.Verdict}");
5354
}
5455

55-
private static async Task<IVaas> CreateVaasAndConnect()
56+
private static IVaas CreateVaas()
5657
{
57-
5858
// If you got a username and password from us, you can use the GrantType.Password like this
5959
// You may use self registration and create a new username and password for the
6060
// Credentials by yourself like the example above on https://vaas.gdata.de/login
61-
var vaas = VaasFactory.Create(new VaasOptions
62-
{
63-
Url = VaasUrl,
64-
TokenUrl = TokenUrl,
65-
Credentials = new TokenRequest
66-
{
67-
GrantType = GrantType.Password,
68-
ClientId = ClientIdForResourceOwnerPasswordGrant,
69-
UserName = UserName,
70-
Password = Password
71-
}
72-
});
73-
61+
var authenticator = new ResourceOwnerPasswordGrantAuthenticator(
62+
ClientIdForResourceOwnerPasswordGrant,
63+
UserName,
64+
Password,
65+
TokenUrl
66+
);
7467
// // Else if you got a client id and client secret from us, you should use the GrantType.ClientCredentials like this
75-
// var vaas = VaasFactory.Create(new VaasOptions()
76-
// {
77-
// Url = VaasUrl,
78-
// TokenUrl = TokenUrl,
79-
// Credentials = new TokenRequest
80-
// {
81-
// GrantType = GrantType.ClientCredentials,
82-
// ClientId = ClientId,
83-
// ClientSecret = ClientSecret
84-
// }
85-
// });
86-
await vaas.Connect(CancellationToken.None);
87-
return vaas;
68+
// var authenticator = new ClientCredentialsGrantAuthenticator(
69+
// ClientId,
70+
// ClientSecret,
71+
// TokenUrl
72+
// );
73+
74+
var options = new VaasOptions
75+
{
76+
UseCache = true,
77+
UseHashLookup = true,
78+
VaasUrl = VaasUrl,
79+
Timeout = TimeSpan.FromSeconds(300)
80+
};
81+
82+
return VaasFactory.Create(authenticator, options);
8883
}
8984
}

dotnet/examples/VaasExample/VaasExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="GDataCyberDefense.Vaas" Version="7.6.3" />
12+
<PackageReference Include="GDataCyberDefense.Vaas" Version="8.0.0" />
1313
</ItemGroup>
1414

1515
</Project>

0 commit comments

Comments
 (0)