Skip to content

Commit f3a4671

Browse files
committed
feat: support new upload features
1 parent 475ebfe commit f3a4671

File tree

6 files changed

+223
-15
lines changed

6 files changed

+223
-15
lines changed

ChangeLog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
## NEXT
44

5-
* support new maintenance endpoint.
5+
* support REST API 1.5.1 feaures:
6+
* support new maintenance endpoint.
7+
* support new upload features.
8+
* new `GetUploadFileById` to download an upload file.
69

710
## 1.3.0 (2022-12-30)
811

Fossology.Rest.Dotnet.Model/TriggerInfo.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ---------------------------------------------------------------------------
22
// <copyright file="TriggerInfo.cs" company="Tethys">
3-
// Copyright (C) 2019-2020 T. Graf
3+
// Copyright (C) 2019-2023 T. Graf
44
// </copyright>
55
//
66
// Licensed under the MIT License.
@@ -45,6 +45,12 @@ public class TriggerInfo
4545
"reuse_group": 0,
4646
"reuse_main": true,
4747
"reuse_enhanced": true
48+
},
49+
"scancode": {
50+
"license": true,
51+
"copyright": true,
52+
"email": true,
53+
"url": true
4854
}
4955
}
5056
*/
@@ -67,6 +73,12 @@ public class TriggerInfo
6773
[JsonProperty("reuse")]
6874
public ReuseInfo Reuse { get; set; }
6975

76+
/// <summary>
77+
/// Gets or sets the ScanCode settings.
78+
/// </summary>
79+
[JsonProperty("scancode")]
80+
public ScanCodeInfo Scancode { get; set; }
81+
7082
/// <summary>
7183
/// Initializes a new instance of the <see cref="TriggerInfo"/> class.
7284
/// </summary>
@@ -75,6 +87,7 @@ public TriggerInfo()
7587
this.Analysis = new Analysis();
7688
this.Decider = new DeciderInfo();
7789
this.Reuse = new ReuseInfo();
90+
this.Scancode = new ScanCodeInfo();
7891
} // TriggerInfo()
7992
} // TriggerInfo
8093
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="UploadInformationFile.cs" company="Tethys">
3+
// Copyright (C) 2019-2023 T. Graf
4+
// </copyright>
5+
//
6+
// Licensed under the MIT License.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied.
13+
// ---------------------------------------------------------------------------
14+
15+
namespace Fossology.Rest.Dotnet.Model
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// Fossology upload information for files.
21+
/// </summary>
22+
public class UploadInformationFile
23+
{
24+
// IMPORTANT: not 'location' information required at the moment
25+
26+
/// <summary>
27+
/// Gets or sets the scan options.
28+
/// </summary>
29+
[JsonProperty("scanOptions")]
30+
public TriggerInfo ScanOptions { get; set; }
31+
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="UploadInformationFile" /> class.
34+
/// </summary>
35+
public UploadInformationFile()
36+
{
37+
this.ScanOptions = new TriggerInfo();
38+
} // UploadInformationFile()
39+
} // UploadInformationFile
40+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="UploadInformationUrl.cs" company="Tethys">
3+
// Copyright (C) 2019-2023 T. Graf
4+
// </copyright>
5+
//
6+
// Licensed under the MIT License.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied.
13+
// ---------------------------------------------------------------------------
14+
15+
namespace Fossology.Rest.Dotnet.Model
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// Fossology version information.
21+
/// </summary>
22+
/// <remarks>
23+
/// <code>
24+
/// {
25+
/// "location" : {
26+
/// "url": "string",
27+
/// "name": "string",
28+
/// "accept": "string",
29+
/// "reject": "string",
30+
/// "maxRecursionDepth": 0
31+
/// }
32+
/// </code>
33+
/// </remarks>
34+
public class UploadInformationUrl
35+
{
36+
/// <summary>
37+
/// Gets or sets the upload location.
38+
/// </summary>
39+
[JsonProperty("location")]
40+
public UrlUpload Location { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the scan options.
44+
/// </summary>
45+
[JsonProperty("scanOptions")]
46+
public TriggerInfo ScanOptions { get; set; }
47+
48+
/// <summary>
49+
/// Initializes a new instance of the <see cref="UploadInformationUrl" /> class.
50+
/// </summary>
51+
/// <param name="scanOptions">The scan options.</param>
52+
public UploadInformationUrl(TriggerInfo scanOptions = null)
53+
{
54+
this.Location = new UrlUpload();
55+
this.ScanOptions = scanOptions;
56+
} // UploadInformationUrl()
57+
} // UploadInformation
58+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="UploadInformationVcs.cs" company="Tethys">
3+
// Copyright (C) 2019-2023 T. Graf
4+
// </copyright>
5+
//
6+
// Licensed under the MIT License.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied.
13+
// ---------------------------------------------------------------------------
14+
15+
namespace Fossology.Rest.Dotnet.Model
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// Fossology version information.
21+
/// </summary>
22+
/// <remarks>
23+
/// <code>
24+
/// {
25+
/// "location" : {
26+
/// "vcsType": "string",
27+
/// "vcsUrl": "string",
28+
/// "vcsBranch": string,
29+
/// "vcsName": "string",
30+
/// "vcsUsername": "string",
31+
/// "vcsPassword": "string",
32+
/// }
33+
/// }
34+
/// </code>
35+
/// </remarks>
36+
public class UploadInformationVcs
37+
{
38+
/// <summary>
39+
/// Gets or sets the upload location.
40+
/// </summary>
41+
[JsonProperty("location")]
42+
public VcsUpload Location { get; set; }
43+
44+
/// <summary>
45+
/// Gets or sets the scan options.
46+
/// </summary>
47+
[JsonProperty("scanOptions")]
48+
public TriggerInfo ScanOptions { get; set; }
49+
50+
/// <summary>
51+
/// Initializes a new instance of the <see cref="UploadInformationVcs" /> class.
52+
/// </summary>
53+
/// <param name="scanOptions">The scan options.</param>
54+
public UploadInformationVcs(TriggerInfo scanOptions = null)
55+
{
56+
this.Location = new VcsUpload();
57+
this.ScanOptions = scanOptions;
58+
} // UploadInformationVcs()
59+
} // UploadInformationVcs
60+
}

Fossology.Rest.Dotnet.Test/FossologyClientTest.cs

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ---------------------------------------------------------------------------
22
// <copyright file="FossologyClientTest.cs" company="Tethys">
3-
// Copyright (C) 2019-2022 T. Graf
3+
// Copyright (C) 2019-2023 T. Graf
44
// </copyright>
55
//
66
// Licensed under the MIT License.
@@ -325,10 +325,10 @@ public void TestUploadPackageFromUrl()
325325
var folderId = EnsureTestFolderExists();
326326

327327
var client = new FossologyClient(LocalUrl, Token);
328-
var details = new UrlUpload();
329-
details.Name = "Tethys.xml_v1.0.0.zip";
330-
details.Url = "https://github.com/tngraf/Tethys.Xml/archive/v1.0.0.zip";
331-
details.MaxRecursionDepth = 0;
328+
var details = new UploadInformationUrl();
329+
details.Location.Name = "Tethys.xml_v1.0.0.zip";
330+
details.Location.Url = "https://github.com/tngraf/Tethys.Xml/archive/v1.0.0.zip";
331+
details.Location.MaxRecursionDepth = 0;
332332

333333
var result = client.UploadPackageFromUrl(folderId, details);
334334
Assert.IsNotNull(result);
@@ -346,13 +346,13 @@ public void TestUploadPackageFromVcs()
346346
var folderId = EnsureTestFolderExists();
347347

348348
var client = new FossologyClient(LocalUrl, Token);
349-
var details = new VcsUpload();
350-
details.VcsName = "Tethys.Logging";
351-
details.VcsUrl = "https://github.com/tngraf/Tethys.Logging.git";
352-
details.VcsBranch = "master";
353-
details.VcsType = "git";
354-
details.VcsUsername = "xxx";
355-
details.VcsPassword = "xxx";
349+
var details = new UploadInformationVcs();
350+
details.Location.VcsName = "Tethys.Logging";
351+
details.Location.VcsUrl = "https://github.com/tngraf/Tethys.Logging.git";
352+
details.Location.VcsBranch = "master";
353+
details.Location.VcsType = "git";
354+
details.Location.VcsUsername = "xxx";
355+
details.Location.VcsPassword = "xxx";
356356

357357
var result = client.UploadPackageFromVcs(folderId, details);
358358
Assert.IsNotNull(result);
@@ -463,6 +463,40 @@ public void TestDeleteUpload()
463463
Assert.AreEqual(202, result.Code);
464464
}
465465

466+
/// <summary>
467+
/// Unit test.
468+
/// </summary>
469+
[TestMethod]
470+
[ExpectedException(typeof(FossologyApiException))]
471+
public void TestGetUploadFileById_DoesNotExist()
472+
{
473+
var client = new FossologyClient(LocalUrl, Token);
474+
var result = client.GetUploadFileById(123456789, "TestFile.dat");
475+
}
476+
477+
/// <summary>
478+
/// Unit test.
479+
/// </summary>
480+
[TestMethod]
481+
public void TestGetUploadFileById()
482+
{
483+
var id = FindUpload(PackageName2);
484+
if (id < 0)
485+
{
486+
this.TestUploadPackageFromUrl();
487+
// ugly but required: wait some time until report is available
488+
Thread.Sleep(3000);
489+
id = FindUpload(PackageName2);
490+
} // if
491+
492+
var client = new FossologyClient(LocalUrl, Token);
493+
Debug.WriteLine($"Upload id = {id}");
494+
495+
var result = client.GetUploadFileById(id, "TestFile.dat");
496+
Assert.IsNotNull(result);
497+
Assert.AreEqual(200, result.Code);
498+
}
499+
466500
/// <summary>
467501
/// Unit test.
468502
/// </summary>
@@ -1124,7 +1158,7 @@ private static int TriggerReportGeneration(int uploadId)
11241158
Assert.AreEqual("INFO", result.Type);
11251159
Assert.AreEqual(201, result.Code);
11261160

1127-
var text = result.Message[(result.Message.LastIndexOf('/') + 1)..];
1161+
var text = result.Message[(result.Message.LastIndexOf('/') + 1) ..];
11281162
return int.Parse(text);
11291163
}
11301164

0 commit comments

Comments
 (0)