Skip to content

Commit d2fe071

Browse files
authored
Add workflow to scan for vulnerable dependencies (#1563)
* Add workflow to scan for vulnerable dependencies * Adapt for breaking change in Consul v1.7.14.8
1 parent 5cd0b82 commit d2fe071

File tree

10 files changed

+60
-16
lines changed

10 files changed

+60
-16
lines changed

.github/workflows/Steeltoe.All.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
branches:
77
- main
88
- '[0-9]+.x'
9-
- 'release/*'
109
pull_request:
1110

1211
concurrency:

.github/workflows/package.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
branches:
77
- main
88
- '[0-9]+.x'
9-
- 'release/*'
109
pull_request:
1110
release:
1211
types:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Scan vulnerable dependencies
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- '[0-9]+.x'
9+
pull_request:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
permissions:
16+
contents: read
17+
18+
env:
19+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
20+
DOTNET_NOLOGO: true
21+
SOLUTION_FILE: 'src/Steeltoe.All.sln'
22+
23+
jobs:
24+
scan:
25+
name: Scan
26+
timeout-minutes: 15
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Setup .NET
31+
uses: actions/setup-dotnet@v4
32+
with:
33+
dotnet-version: |
34+
8.0.*
35+
9.0.*
36+
37+
- name: Git checkout
38+
uses: actions/checkout@v4
39+
40+
- name: Report vulnerable dependencies
41+
run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal /p:NuGetAudit=true /p:NuGetAuditMode=all /p:NuGetAuditLevel=low /p:TreatWarningsAsErrors=True

.github/workflows/sonarcube.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
branches:
77
- main
88
- '[0-9]+.x'
9-
- 'release/*'
109
pull_request:
1110
types: [opened, synchronize, reopened]
1211

.github/workflows/verify-code-style.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
branches:
77
- main
88
- '[0-9]+.x'
9-
- 'release/*'
109
pull_request:
1110

1211
concurrency:

src/Discovery/src/Consul/ConsulDiscoveryClient.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using Consul;
6+
using Consul.Filtering;
67
using Microsoft.Extensions.Logging;
78
using Microsoft.Extensions.Logging.Abstractions;
89
using Microsoft.Extensions.Options;
@@ -130,7 +131,7 @@ public async Task<IList<IServiceInstance>> GetAllInstancesAsync(QueryOptions que
130131

131132
if (options.Enabled)
132133
{
133-
ISet<string> serviceIds = await GetServiceIdsAsync(queryOptions, cancellationToken);
134+
ISet<string> serviceIds = await GetServiceIdsAsync(null, null, queryOptions, cancellationToken);
134135

135136
foreach (string serviceId in serviceIds)
136137
{
@@ -144,22 +145,28 @@ public async Task<IList<IServiceInstance>> GetAllInstancesAsync(QueryOptions que
144145
/// <inheritdoc />
145146
public Task<ISet<string>> GetServiceIdsAsync(CancellationToken cancellationToken)
146147
{
147-
return GetServiceIdsAsync(QueryOptions.Default, cancellationToken);
148+
return GetServiceIdsAsync(null, null, QueryOptions.Default, cancellationToken);
148149
}
149150

150151
/// <summary>
151152
/// Gets all registered service IDs from the Consul catalog.
152153
/// </summary>
154+
/// <param name="dataCenter">
155+
/// Specifies the datacenter to query.
156+
/// </param>
157+
/// <param name="filter">
158+
/// Specifies the expression used to filter the queries results prior to returning the data.
159+
/// </param>
153160
/// <param name="queryOptions">
154-
/// Any Consul query options to use.
161+
/// Options to parameterize the Consul query.
155162
/// </param>
156163
/// <param name="cancellationToken">
157164
/// The token to monitor for cancellation requests.
158165
/// </param>
159166
/// <returns>
160167
/// The list of service IDs.
161168
/// </returns>
162-
public async Task<ISet<string>> GetServiceIdsAsync(QueryOptions queryOptions, CancellationToken cancellationToken)
169+
public async Task<ISet<string>> GetServiceIdsAsync(string? dataCenter, Filter? filter, QueryOptions queryOptions, CancellationToken cancellationToken)
163170
{
164171
ArgumentNullException.ThrowIfNull(queryOptions);
165172

@@ -170,7 +177,7 @@ public async Task<ISet<string>> GetServiceIdsAsync(QueryOptions queryOptions, Ca
170177
return new HashSet<string>();
171178
}
172179

173-
QueryResult<Dictionary<string, string[]>> result = await _client.Catalog.Services(queryOptions, cancellationToken);
180+
QueryResult<Dictionary<string, string[]>> result = await _client.Catalog.Services(dataCenter, filter, queryOptions, cancellationToken);
174181
return result.Response.Keys.ToHashSet();
175182
}
176183

src/Discovery/src/Consul/ConsulHealthContributor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal Task<string> GetLeaderStatusAsync(CancellationToken cancellationToken)
6767

6868
internal async Task<Dictionary<string, string[]>> GetCatalogServicesAsync(CancellationToken cancellationToken)
6969
{
70-
QueryResult<Dictionary<string, string[]>> result = await _client.Catalog.Services(QueryOptions.Default, cancellationToken);
70+
QueryResult<Dictionary<string, string[]>> result = await _client.Catalog.Services(cancellationToken);
7171
return result.Response;
7272
}
7373
}

src/Discovery/src/Consul/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetAllInstancesAsync(Consul.Quer
104104
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetInstancesAsync(string! serviceId, Consul.QueryOptions! queryOptions, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.IList<Steeltoe.Common.Discovery.IServiceInstance!>!>!
105105
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetInstancesAsync(string! serviceId, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.IList<Steeltoe.Common.Discovery.IServiceInstance!>!>!
106106
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetLocalServiceInstance() -> Steeltoe.Common.Discovery.IServiceInstance?
107-
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetServiceIdsAsync(Consul.QueryOptions! queryOptions, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.ISet<string!>!>!
107+
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetServiceIdsAsync(string? dataCenter, Consul.Filtering.Filter? filter, Consul.QueryOptions! queryOptions, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.ISet<string!>!>!
108108
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetServiceIdsAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.ISet<string!>!>!
109109
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.ShutdownAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
110110
Steeltoe.Discovery.Consul.ConsulServiceCollectionExtensions

src/Discovery/test/Consul.Test/Discovery/ConsulDiscoveryClientTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ public async Task GetServicesAsync_ReturnsExpected()
124124
};
125125

126126
var catalogMoq = new Mock<ICatalogEndpoint>();
127-
catalogMoq.Setup(endpoint => endpoint.Services(QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
127+
catalogMoq.Setup(endpoint => endpoint.Services(null, null, QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
128128

129129
var clientMoq = new Mock<IConsulClient>();
130130
clientMoq.Setup(client => client.Catalog).Returns(catalogMoq.Object);
131131

132132
TestOptionsMonitor<ConsulDiscoveryOptions> optionsMonitor = TestOptionsMonitor.Create(options);
133133
var discoveryClient = new ConsulDiscoveryClient(clientMoq.Object, optionsMonitor, NullLoggerFactory.Instance);
134-
ISet<string> serviceIds = await discoveryClient.GetServiceIdsAsync(QueryOptions.Default, TestContext.Current.CancellationToken);
134+
ISet<string> serviceIds = await discoveryClient.GetServiceIdsAsync(TestContext.Current.CancellationToken);
135135

136136
serviceIds.Should().HaveCount(2);
137137
serviceIds.Should().Contain("foo");
@@ -196,7 +196,7 @@ public async Task GetAllInstances_ReturnsExpected()
196196
};
197197

198198
var catalogMoq = new Mock<ICatalogEndpoint>();
199-
catalogMoq.Setup(endpoint => endpoint.Services(QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult1));
199+
catalogMoq.Setup(endpoint => endpoint.Services(null, null, QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult1));
200200

201201
var clientMoq = new Mock<IConsulClient>();
202202
clientMoq.Setup(client => client.Catalog).Returns(catalogMoq.Object);

src/Discovery/test/Consul.Test/Discovery/ConsulHealthContributorTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task GetCatalogServicesAsync_ReturnsExpected()
5050
};
5151

5252
var catalogMoq = new Mock<ICatalogEndpoint>();
53-
catalogMoq.Setup(endpoint => endpoint.Services(QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
53+
catalogMoq.Setup(endpoint => endpoint.Services(It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
5454

5555
var clientMoq = new Mock<IConsulClient>();
5656
clientMoq.Setup(client => client.Catalog).Returns(catalogMoq.Object);
@@ -89,7 +89,7 @@ public async Task Health_ReturnsExpected()
8989
statusMoq.Setup(endpoint => endpoint.Leader(It.IsAny<CancellationToken>())).Returns(Task.FromResult("the-status"));
9090

9191
var catalogMoq = new Mock<ICatalogEndpoint>();
92-
catalogMoq.Setup(endpoint => endpoint.Services(QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
92+
catalogMoq.Setup(endpoint => endpoint.Services(It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
9393

9494
var clientMoq = new Mock<IConsulClient>();
9595
clientMoq.Setup(client => client.Status).Returns(statusMoq.Object);

0 commit comments

Comments
 (0)