Skip to content

Commit 55a34c2

Browse files
committed
feat: new method GetInfo()
1 parent 64ce1c0 commit 55a34c2

File tree

6 files changed

+233
-4
lines changed

6 files changed

+233
-4
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* have `FossologyClient` to be a partial class for better overview.
88
* new method GetGroupList().
99
* add support for groups for all methods where it did not yet exist.
10+
* new method GetInfo().
1011

1112
## 1.1.0 (2020-06-25)
1213
* supports FOSSology REST API v1.0.16 (FOSSology 3.8.0 built @ 2020/06/19).
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="AppInfo.cs" company="Tethys">
3+
// Copyright (C) 2022 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 application information.
21+
/// </summary>
22+
public class AppInfo
23+
{
24+
/// <summary>
25+
/// Gets or sets the name.
26+
/// </summary>
27+
[JsonProperty("name")]
28+
public string Name { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the description.
32+
/// </summary>
33+
[JsonProperty("description")]
34+
public string Description { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets the version.
38+
/// </summary>
39+
[JsonProperty("version")]
40+
public string Version { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the contact information.
44+
/// </summary>
45+
[JsonProperty("contact")]
46+
public string Contact { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets the Fossology license information.
50+
/// </summary>
51+
[JsonProperty("license")]
52+
public FossologyLicense FossologyLicense { get; set; }
53+
54+
/// <summary>
55+
/// Gets or sets the Fossology information.
56+
/// </summary>
57+
[JsonProperty("fossology")]
58+
public FossologyInfo FossologyInfo { get; set; }
59+
60+
/// <inheritdoc />
61+
public override string ToString()
62+
{
63+
return $"{this.Name}, {this.Version}";
64+
}
65+
} // AppInfo
66+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="FossologyInfo.cs" company="Tethys">
3+
// Copyright (C) 2022 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 information.
21+
/// </summary>
22+
public class FossologyInfo
23+
{
24+
/// <summary>
25+
/// Gets or sets the version.
26+
/// </summary>
27+
[JsonProperty("version")]
28+
public string Version { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the branch name.
32+
/// </summary>
33+
[JsonProperty("branchName")]
34+
public string BranchName { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets the commit hash.
38+
/// </summary>
39+
[JsonProperty("commitHash")]
40+
public string CommitHash { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the commit date.
44+
/// </summary>
45+
[JsonProperty("commitDate")]
46+
public string CommitDate { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets the build date.
50+
/// </summary>
51+
[JsonProperty("buildDate")]
52+
public string BuildDate { get; set; }
53+
54+
/// <inheritdoc />
55+
public override string ToString()
56+
{
57+
return $"{this.Version}, {this.BranchName}, parent={this.CommitHash}, {this.CommitDate}, {this.BuildDate}";
58+
}
59+
} // FossologyInfo
60+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="FossologyLicense.cs" company="Tethys">
3+
// Copyright (C) 2022 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 license information.
21+
/// </summary>
22+
public class FossologyLicense
23+
{
24+
/// <summary>
25+
/// Gets or sets the name.
26+
/// </summary>
27+
[JsonProperty("name")]
28+
public string Name { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the url.
32+
/// </summary>
33+
[JsonProperty("url")]
34+
public string Url { get; set; }
35+
36+
/// <inheritdoc />
37+
public override string ToString()
38+
{
39+
return $"{this.Name}, {this.Url}";
40+
}
41+
} // FossologyLicense
42+
}

Fossology.Rest.Dotnet.Test/FossologyClientTest.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ namespace Fossology.Rest.Dotnet.Test
2828
using Tethys.Logging.Console;
2929

3030
// NOTE:
31-
// If you just run all tests, a number of them will fail.
32-
// This is just because the test will be run in random order ... and if
33-
// for example a folder has not yet been created it will be impossible to delete it.
31+
// 1. Prior to running test, valid token information needs to be provided.
32+
// 2. If you just run all tests, a number of them will fail.
33+
// This is just because the test will be run in random order ... and if
34+
// for example a folder has not yet been created it will be impossible to delete it.
3435

3536
/// <summary>
3637
/// Unit test class.
@@ -48,7 +49,7 @@ public class FossologyClientTest
4849
/// <summary>
4950
/// The access token.
5051
/// </summary>
51-
private const string Token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDc0NzUxOTksIm5iZiI6MTY0NzEyOTYwMCwianRpIjoiTWk0eiIsInNjb3BlIjoid3JpdGUifQ.AKflkhB4194sjPAxMrse3kyBAeMdnGjtQzZZGsYRqMI";
52+
private const string Token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDc1NjE1OTksIm5iZiI6MTY0NzIxNjAwMCwianRpIjoiTWk0eiIsInNjb3BlIjoid3JpdGUifQ.VoBawVZLVEBUs75EEN39L_ml7ZuQhRsJVTWxtxGC26I";
5253

5354
/// <summary>
5455
/// The filename of a test package.
@@ -708,6 +709,21 @@ public void TestGetHealth()
708709
Assert.AreEqual("OK", actual.Database.Status);
709710
}
710711

712+
/// <summary>
713+
/// Unit test.
714+
/// </summary>
715+
[TestMethod]
716+
public void TestGetInfo()
717+
{
718+
var client = new FossologyClient(LocalUrl, Token);
719+
var actual = client.GetInfo();
720+
Assert.IsNotNull(actual);
721+
Assert.AreEqual("FOSSology API", actual.Name);
722+
Assert.AreEqual("[email protected]", actual.Contact);
723+
Assert.AreEqual("GPL-2.0-only", actual.FossologyLicense.Name);
724+
Assert.AreEqual("master", actual.FossologyInfo.BranchName);
725+
}
726+
711727
/// <summary>
712728
/// Unit test.
713729
/// </summary>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="FossologyClientInfo.cs" company="Tethys">
3+
// Copyright (C) 2022 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
16+
{
17+
using Fossology.Rest.Dotnet.Model;
18+
19+
using Newtonsoft.Json;
20+
21+
/// <summary>
22+
/// Client for the SW360 REST API.
23+
/// </summary>
24+
public partial class FossologyClient
25+
{
26+
/// <summary>
27+
/// Gets the Fossology information.
28+
/// </summary>
29+
/// <returns><see cref="AppInfo"/>.</returns>
30+
public AppInfo GetInfo()
31+
{
32+
Log.Debug($"Getting Fossology info...");
33+
34+
var result = this.api.Get(this.Url + "/info");
35+
var info = JsonConvert.DeserializeObject<AppInfo>(
36+
result.Content,
37+
new JsonSerializerSettings
38+
{
39+
NullValueHandling = NullValueHandling.Ignore,
40+
});
41+
return info;
42+
} // GetInfo()
43+
} // FossologyClient
44+
}

0 commit comments

Comments
 (0)