Skip to content

Commit ac2ecc7

Browse files
committed
Squashed 'src/SfsClient/sfs-client/' changes from be733af9..44d81dc8
44d81dc8 Using early-return in UrlBuilder::GetQuery() 9e9b27e3 Fixing "Use of string after lifetime ends" 21bf6b98 Adding functional proxy tests 46388eaa Adding a ProxyServer implementation 7a0bfbec Exposing Path and Query via UrlBuilder b2014df3 Adding unit tests for proxy validation cdd840b0 Adding proxy input string support 216210ab Adding required permissions to enable uploading of CodeQL results (#214) fb953d6e Bump github/codeql-action from 2 to 3 (#215) 52af7124 Enabling CodeQL scanning (#211) e555d764 Bump clang-format from 18.1.5 to 19.1.1 (#210) ab8f0e72 Setup: improving build tools installation (#207) git-subtree-dir: src/SfsClient/sfs-client git-subtree-split: 44d81dc8e7614c0be8777db22431e5065aa7a6b8
1 parent d5ae2a9 commit ac2ecc7

File tree

21 files changed

+584
-173
lines changed

21 files changed

+584
-173
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Initialize CodeQL
2+
3+
description: Initializes CodeQL action to be used in build workflows
4+
5+
runs:
6+
using: "composite"
7+
8+
steps:
9+
- name: Initialize CodeQL
10+
uses: github/codeql-action/init@v3
11+
with:
12+
languages: cpp

.github/workflows/main-build-ubuntu.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ on:
55
branches: [ "main" ]
66

77
# Permissions and environment values to be able to update the dependency graph with vcpkg information
8+
# and to enable the writing/uploading of CodeQL scan results
89
permissions:
910
contents: write
11+
security-events: write
1012

1113
env:
1214
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -19,6 +21,9 @@ jobs:
1921
steps:
2022
- uses: actions/checkout@v4
2123

24+
- name: Initialize CodeQL
25+
uses: ./.github/workflows/initialize-codeql
26+
2227
- name: Setup
2328
run: source ./scripts/setup.sh
2429

@@ -36,3 +41,6 @@ jobs:
3641
run: |
3742
./scripts/build.sh --build-type Release
3843
./scripts/test.sh --output-on-failure
44+
45+
- name: Perform CodeQL Analysis
46+
uses: github/codeql-action/analyze@v3

.github/workflows/main-build-windows.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ on:
55
branches: [ "main" ]
66

77
# Permissions and environment values to be able to update the dependency graph with vcpkg information
8+
# and to enable the writing/uploading of CodeQL scan results
89
permissions:
910
contents: write
11+
security-events: write
1012

1113
env:
1214
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -19,12 +21,15 @@ jobs:
1921
steps:
2022
- uses: actions/checkout@v4
2123

24+
- name: Initialize CodeQL
25+
uses: ./.github/workflows/initialize-codeql
26+
2227
- name: Install Winget
2328
uses: ./.github/workflows/install-winget
2429

2530
- name: Setup
2631
shell: pwsh
27-
run: .\scripts\Setup.ps1 -NoBuildTools
32+
run: .\scripts\Setup.ps1
2833

2934
- name: Build and Test (no test overrides)
3035
shell: pwsh
@@ -43,3 +48,6 @@ jobs:
4348
run: |
4449
.\scripts\Build.ps1 -BuildType Release
4550
.\scripts\Test.ps1 -OutputOnFailure
51+
52+
- name: Perform CodeQL Analysis
53+
uses: github/codeql-action/analyze@v3

.github/workflows/pr.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ jobs:
2222
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
2323
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
2424
25+
- name: Initialize CodeQL
26+
uses: ./.github/workflows/initialize-codeql
27+
2528
- name: Install Winget
2629
uses: ./.github/workflows/install-winget
2730

2831
- name: Setup
2932
shell: pwsh
30-
run: .\scripts\Setup.ps1 -NoBuildTools
33+
run: .\scripts\Setup.ps1
3134

3235
- name: Check formatting
3336
shell: pwsh
@@ -45,6 +48,9 @@ jobs:
4548
.\scripts\Build.ps1 -EnableTestOverrides
4649
.\scripts\Test.ps1 -OutputOnFailure
4750
51+
- name: Perform CodeQL Analysis
52+
uses: github/codeql-action/analyze@v3
53+
4854
build-ubuntu:
4955
runs-on: ubuntu-latest
5056

@@ -58,6 +64,9 @@ jobs:
5864
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
5965
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
6066
67+
- name: Initialize CodeQL
68+
uses: ./.github/workflows/initialize-codeql
69+
6170
- name: Setup
6271
run: source ./scripts/setup.sh
6372

@@ -73,3 +82,6 @@ jobs:
7382
run: |
7483
./scripts/build.sh --enable-test-overrides
7584
./scripts/test.sh --output-on-failure
85+
86+
- name: Perform CodeQL Analysis
87+
uses: github/codeql-action/analyze@v3

client/include/sfsclient/RequestParams.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ struct RequestParams
3535
/// @note If not provided, a new CorrelationVector will be generated
3636
std::optional<std::string> baseCV;
3737

38+
/// @brief Proxy setting which can be used to establish connections with the server (optional)
39+
/// @note The string can be a hostname or dotted numerical IP address. It can be suffixed with the port number
40+
/// like :[port], and can be prefixed with [scheme]://. If not provided, no proxy will be used.
41+
std::optional<std::string> proxy;
42+
3843
/// @brief Retry for a web request after a failed attempt. If true, client will retry up to c_maxRetries times
3944
bool retryOnError{true};
4045
};

client/src/details/UrlBuilder.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,31 @@ std::string UrlBuilder::GetUrl() const
6666
return urlPtr;
6767
}
6868

69+
std::string UrlBuilder::GetPath() const
70+
{
71+
CurlCharPtr path;
72+
char* pathPtr = path.get();
73+
THROW_IF_CURL_URL_SETUP_ERROR(curl_url_get(m_handle, CURLUPART_PATH, &pathPtr, 0 /*flags*/));
74+
return pathPtr;
75+
}
76+
77+
std::string UrlBuilder::GetQuery() const
78+
{
79+
CurlCharPtr query;
80+
char* queryPtr = query.get();
81+
const auto queryResult = curl_url_get(m_handle, CURLUPART_QUERY, &queryPtr, 0 /*flags*/);
82+
switch (queryResult)
83+
{
84+
case CURLUE_OK:
85+
return queryPtr;
86+
case CURLUE_NO_QUERY:
87+
return {};
88+
default:
89+
THROW_IF_CURL_URL_SETUP_ERROR(queryResult);
90+
}
91+
return {};
92+
}
93+
6994
UrlBuilder& UrlBuilder::SetScheme(Scheme scheme)
7095
{
7196
switch (scheme)

client/src/details/UrlBuilder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class UrlBuilder
3939

4040
std::string GetUrl() const;
4141

42+
std::string GetPath() const;
43+
std::string GetQuery() const;
44+
4245
/**
4346
* @brief Set the scheme for the URL
4447
* @param scheme The scheme to set for the URL Ex: Https

client/src/details/connection/ConnectionConfig.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ using namespace SFS::details;
1111
ConnectionConfig::ConnectionConfig(const SFS::RequestParams& requestParams)
1212
: maxRetries(requestParams.retryOnError ? c_maxRetries : 0)
1313
, baseCV(requestParams.baseCV)
14+
, proxy(requestParams.proxy)
1415
{
1516
}

client/src/details/connection/ConnectionConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ struct ConnectionConfig
2222

2323
/// @brief The correlation vector to use for requests
2424
std::optional<std::string> baseCV;
25+
26+
/// @brief Proxy setting which can be used to establish connections with the server
27+
std::optional<std::string> proxy;
2528
};
2629
} // namespace details
2730
} // namespace SFS

client/src/details/connection/CurlConnection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ CurlConnection::CurlConnection(const ConnectionConfig& config, const ReportingHa
284284
m_handler,
285285
"Failed to set up curl");
286286

287+
if (config.proxy)
288+
{
289+
THROW_IF_CURL_SETUP_ERROR(curl_easy_setopt(m_handle, CURLOPT_PROXY, config.proxy->c_str()));
290+
}
291+
287292
// TODO #41: Pass AAD token in the header if it is available
288293
// TODO #42: Cert pinning with service
289294
}

0 commit comments

Comments
 (0)