Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SfsClient update 1.1.0 for proxy support #5052

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/SfsClient/SfsClient.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>TurnOffAllWarnings</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
Expand All @@ -257,7 +257,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
Expand All @@ -274,7 +274,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'">
<ClCompile>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
Expand All @@ -294,7 +294,7 @@
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>$(ProjectDir)sfs-client\client\include\sfsclient;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
Expand All @@ -304,7 +304,7 @@
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>$(ProjectDir)sfs-client\client\include\sfsclient;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand All @@ -315,7 +315,7 @@
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";NDEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";NDEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>$(ProjectDir)sfs-client\client\include\sfsclient;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
Expand All @@ -325,7 +325,7 @@
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";NDEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";NDEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>$(ProjectDir)sfs-client\client\include\sfsclient;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand All @@ -336,7 +336,7 @@
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";NDEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";NDEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>$(ProjectDir)sfs-client\client\include\sfsclient;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
Expand All @@ -346,7 +346,7 @@
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";NDEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";NDEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>$(ProjectDir)sfs-client\client\include\sfsclient;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand All @@ -357,7 +357,7 @@
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";_DEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";_DEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>TurnOffAllWarnings</WarningLevel>
<AdditionalIncludeDirectories>$(ProjectDir)sfs-client\client\include\sfsclient;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
Expand All @@ -367,7 +367,7 @@
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";_DEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";_DEBUG;%(PreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>TurnOffAllWarnings</WarningLevel>
<AdditionalIncludeDirectories>$(ProjectDir)sfs-client\client\include\sfsclient;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
Expand All @@ -377,7 +377,7 @@
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.0.0";_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CURL_STATICLIB;GUID_WINDOWS;SFS_VERSION="1.1.0";_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>TurnOffAllWarnings</WarningLevel>
<AdditionalIncludeDirectories>$(ProjectDir)sfs-client\client\include\sfsclient;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
Expand Down
9 changes: 7 additions & 2 deletions src/SfsClient/readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
## SfsClient

Do not change code under the sfs-client directory; it contains sfs-client source code from commit [be733af](https://github.com/microsoft/sfs-client/commits/be733af).
It is created using git subtree command:
Do not change code under the sfs-client directory; it contains sfs-client source code from release 1.1.0 (https://github.com/microsoft/sfs-client/releases/tag/1.1.0).
It was initially created using git subtree command:
```
git subtree add --prefix=src/SfsClient/sfs-client https://github.com/microsoft/sfs-client.git be733af9e5c8e9227f2018ff618800bf08a31180 --squash
```
Then updated to release 1.1.0 using:
```
git subtree pull -P src/SfsClient/sfs-client https://github.com/microsoft/sfs-client 1.1.0 --squash
```


### Update
To update, run the following command, then update the above commit for reference. 'master' can be replaced with the appropriate commit spec as desired.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Initialize CodeQL

description: Initializes CodeQL action to be used in build workflows

runs:
using: "composite"

steps:
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ on:
branches: [ "main" ]

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

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -19,6 +21,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Initialize CodeQL
uses: ./.github/workflows/initialize-codeql

- name: Setup
run: source ./scripts/setup.sh

Expand All @@ -36,3 +41,6 @@ jobs:
run: |
./scripts/build.sh --build-type Release
./scripts/test.sh --output-on-failure

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ on:
branches: [ "main" ]

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

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -19,12 +21,15 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Initialize CodeQL
uses: ./.github/workflows/initialize-codeql

- name: Install Winget
uses: ./.github/workflows/install-winget

- name: Setup
shell: pwsh
run: .\scripts\Setup.ps1 -NoBuildTools
run: .\scripts\Setup.ps1

- name: Build and Test (no test overrides)
shell: pwsh
Expand All @@ -43,3 +48,6 @@ jobs:
run: |
.\scripts\Build.ps1 -BuildType Release
.\scripts\Test.ps1 -OutputOnFailure

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
14 changes: 13 additions & 1 deletion src/SfsClient/sfs-client/.github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ jobs:
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

- name: Initialize CodeQL
uses: ./.github/workflows/initialize-codeql

- name: Install Winget
uses: ./.github/workflows/install-winget

- name: Setup
shell: pwsh
run: .\scripts\Setup.ps1 -NoBuildTools
run: .\scripts\Setup.ps1

- name: Check formatting
shell: pwsh
Expand All @@ -45,6 +48,9 @@ jobs:
.\scripts\Build.ps1 -EnableTestOverrides
.\scripts\Test.ps1 -OutputOnFailure

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

build-ubuntu:
runs-on: ubuntu-latest

Expand All @@ -58,6 +64,9 @@ jobs:
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

- name: Initialize CodeQL
uses: ./.github/workflows/initialize-codeql

- name: Setup
run: source ./scripts/setup.sh

Expand All @@ -73,3 +82,6 @@ jobs:
run: |
./scripts/build.sh --enable-test-overrides
./scripts/test.sh --output-on-failure

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion src/SfsClient/sfs-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ endif()
# 1. MAJOR version when you make incompatible API changes
# 2. MINOR version when you add functionality in a backward compatible manner
# 3. PATCH version when you make backward compatible bug fixes
set(SFS_LIBRARY_VERSION "1.0.0")
set(SFS_LIBRARY_VERSION "1.1.0")

project(
sfsclient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ struct RequestParams
/// @note If not provided, a new CorrelationVector will be generated
std::optional<std::string> baseCV;

/// @brief Proxy setting which can be used to establish connections with the server (optional)
/// @note The string can be a hostname or dotted numerical IP address. It can be suffixed with the port number
/// like :[port], and can be prefixed with [scheme]://. If not provided, no proxy will be used.
std::optional<std::string> proxy;

/// @brief Retry for a web request after a failed attempt. If true, client will retry up to c_maxRetries times
bool retryOnError{true};
};
Expand Down
25 changes: 25 additions & 0 deletions src/SfsClient/sfs-client/client/src/details/UrlBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ std::string UrlBuilder::GetUrl() const
return urlPtr;
}

std::string UrlBuilder::GetPath() const
{
CurlCharPtr path;
char* pathPtr = path.get();
THROW_IF_CURL_URL_SETUP_ERROR(curl_url_get(m_handle, CURLUPART_PATH, &pathPtr, 0 /*flags*/));
return pathPtr;
}

std::string UrlBuilder::GetQuery() const
{
CurlCharPtr query;
char* queryPtr = query.get();
const auto queryResult = curl_url_get(m_handle, CURLUPART_QUERY, &queryPtr, 0 /*flags*/);
switch (queryResult)
{
case CURLUE_OK:
return queryPtr;
case CURLUE_NO_QUERY:
return {};
default:
THROW_IF_CURL_URL_SETUP_ERROR(queryResult);
}
return {};
}

UrlBuilder& UrlBuilder::SetScheme(Scheme scheme)
{
switch (scheme)
Expand Down
3 changes: 3 additions & 0 deletions src/SfsClient/sfs-client/client/src/details/UrlBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class UrlBuilder

std::string GetUrl() const;

std::string GetPath() const;
std::string GetQuery() const;

/**
* @brief Set the scheme for the URL
* @param scheme The scheme to set for the URL Ex: Https
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ using namespace SFS::details;
ConnectionConfig::ConnectionConfig(const SFS::RequestParams& requestParams)
: maxRetries(requestParams.retryOnError ? c_maxRetries : 0)
, baseCV(requestParams.baseCV)
, proxy(requestParams.proxy)
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ struct ConnectionConfig

/// @brief The correlation vector to use for requests
std::optional<std::string> baseCV;

/// @brief Proxy setting which can be used to establish connections with the server
std::optional<std::string> proxy;
};
} // namespace details
} // namespace SFS
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ CurlConnection::CurlConnection(const ConnectionConfig& config, const ReportingHa
m_handler,
"Failed to set up curl");

if (config.proxy)
{
THROW_IF_CURL_SETUP_ERROR(curl_easy_setopt(m_handle, CURLOPT_PROXY, config.proxy->c_str()));
}

// TODO #41: Pass AAD token in the header if it is available
// TODO #42: Cert pinning with service
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@

#include "ContentType.h"

#include "../ErrorHandling.h"
#include "../ReportingHandler.h"
#include "Result.h"

using namespace SFS;
using namespace SFS::details;

namespace
{
std::string ToString(ContentType type)
std::string SFS::details::ToString(ContentType type)
{
switch (type)
{
Expand All @@ -24,15 +17,3 @@ std::string ToString(ContentType type)
return "Unknown";
}
}
} // namespace

void SFS::details::ValidateContentType(ContentType currentType,
ContentType expectedType,
const ReportingHandler& handler)
{
THROW_CODE_IF_LOG(Result::ServiceUnexpectedContentType,
currentType != expectedType,
handler,
"Unexpected content type [" + ::ToString(currentType) +
"] returned by the service does not match the expected [" + ::ToString(expectedType) + "]");
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

#pragma once

#include <string>

namespace SFS::details
{
class ReportingHandler;

enum class ContentType
{
Generic,
App,
};

void ValidateContentType(ContentType currentType, ContentType expectedType, const ReportingHandler& handler);
std::string ToString(ContentType type);
} // namespace SFS::details
Loading
Loading