Skip to content

Commit e759f9e

Browse files
authored
merge to release (#173)
2 parents 7381452 + 5c96608 commit e759f9e

File tree

77 files changed

+9424
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+9424
-421
lines changed

Diff for: .github/workflows/cmake-multi-platform.yml

+33-16
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,40 @@ jobs:
140140
run: cmake --preset ${{matrix.preset}}
141141

142142
- name: CMake Build
143-
run: cmake --build --preset ${{matrix.preset}}
143+
run: cmake --build --preset ${{matrix.preset}}
144144

145-
# - name: CMake Test
146-
# id: cmake-test
147-
# run: ctest --test-dir ./out/build/${{matrix.preset}}/OdbDesignTests --output-log ${{github.workspace}}/testlog.txt --output-junit ${{github.workspace}}/testlog.xml -V
148-
# # let the report step fail the job if it finds failed tests
149-
# continue-on-error: true
145+
- name: Checkout OdbDesign Test Data Repository
146+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
147+
with:
148+
repository: 'nam20485/OdbDesignTestData'
149+
path: 'OdbDesignTestData'
150+
ref: 'main'
151+
token: ${{ secrets.ODBDESIGN_TESTDATA_ACCESS_TOKEN }}
152+
153+
- name : Export ODB_TEST_DATA_DIR
154+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
155+
with:
156+
script: core.exportVariable('ODB_TEST_DATA_DIR', "${{github.workspace}}/OdbDesignTestData/TEST_DATA" || '');
150157

151-
# # report test results
152-
# - name: Report Test Results
153-
# uses: dorny/[email protected]
154-
# if: ${{steps.cmake-test.outcome}} == 'success' || ${{steps.cmake-test.outcome}} == 'failure'
155-
# with:
156-
# name: ${{ matrix.os }}_test-results
157-
# path: ${{github.workspace}}/testlog.xml
158-
# reporter: java-junit
159-
# fail-on-error: true
158+
- name: CMake Test
159+
id: cmake-test
160+
env:
161+
ODB_TEST_DATA_DIR: ${{github.workspace}}/OdbDesignTestData/TEST_DATA
162+
run: ctest --test-dir ./out/build/${{matrix.preset}}/OdbDesignTests --output-log ${{github.workspace}}/testlog.txt --output-junit ${{github.workspace}}/testlog.xml --output-on-failure
163+
# let the report step fail the job if it finds failed tests...
164+
continue-on-error: true
165+
166+
# report test results
167+
- name: Report Test Results
168+
uses: dorny/[email protected]
169+
if: steps.cmake-test.outcome == 'success' || steps.cmake-test.outcome == 'failure'
170+
with:
171+
name: ${{ matrix.os }}_test-results
172+
path: ${{github.workspace}}/testlog.xml
173+
reporter: java-junit
174+
path-replace-backslashes: true
175+
# fail job based on report results
176+
fail-on-error: true
160177

161178
#
162179
# Artifacts
@@ -190,7 +207,7 @@ jobs:
190207
Compress-Archive -Path "${{env.ARTIFACTS_DIR_WIN}}\*.dll","${{env.ARTIFACTS_DIR_WIN}}\*.exe" -DestinationPath "${{env.ARTIFACTS_DIR_WIN}}\artifacts-${{matrix.os}}.zip" -Verbose -Force
191208
192209
- name: Upload Artifacts
193-
uses: actions/upload-artifact@1eb3cb2b3e0f29609092a73eb033bb759a334595 # v4.1.0
210+
uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0
194211
with:
195212
name: ${{ matrix.os }}-artifacts
196213
path: ${{ env.ARTIFACTS_DIR }}/artifacts-${{matrix.os}}.zip

Diff for: .github/workflows/codeql.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747

4848
# Initializes the CodeQL tools for scanning.
4949
- name: Initialize CodeQL
50-
uses: github/codeql-action/init@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
50+
uses: github/codeql-action/init@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
5151
with:
5252
languages: ${{ matrix.language }}
5353
config-file: ${{ github.workspace }}/.github/codeql-config.yml
@@ -78,6 +78,6 @@ jobs:
7878
run: cmake --build --preset linux-release
7979

8080
- name: Perform CodeQL Analysis
81-
uses: github/codeql-action/analyze@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
81+
uses: github/codeql-action/analyze@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
8282
with:
8383
category: "/language:${{matrix.language}}"

Diff for: .github/workflows/dependency-review.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ jobs:
2525
- name: 'Checkout Repository'
2626
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2727
- name: 'Dependency Review'
28-
uses: actions/dependency-review-action@c74b580d73376b7750d3d2a50bfb8adc2c937507 # v3.1.5
28+
uses: actions/dependency-review-action@4901385134134e04cec5fbe5ddfe3b2c5bd5d976 # v4.0.0
2929
with:
3030
comment-summary-in-pr: true

Diff for: .github/workflows/docker-publish.yml

+3-11
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,8 @@ jobs:
4141
- name: Add Problem Matchers
4242
uses: ammaraskar/gcc-problem-matcher@d1fed1fac9e94d30e23b5a82dba4e2963e71d2e7 # master
4343

44-
# # Install the cosign tool except on PR
45-
# # https://github.com/sigstore/cosign-installer
46-
# - name: Install cosign
47-
# if: github.event_name != 'pull_request'
48-
# uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0
49-
# # with:
50-
# # cosign-release: 'v1.13.1'
51-
44+
# Install the cosign tool except on PR
45+
# https://github.com/sigstore/cosign-installer
5246
- name: cosign-installer
5347
if: github.event_name != 'pull_request'
5448
uses: sigstore/cosign-installer@9614fae9e5c5eddabb09f90a270fcb487c9f7149 # v3.3.0
@@ -103,9 +97,7 @@ jobs:
10397
# transparency data even for private images, pass --force to cosign below.
10498
# https://github.com/sigstore/cosign
10599
- name: Sign the published Docker image
106-
if: ${{ github.event_name != 'pull_request' }}
107-
env:
108-
COSIGN_EXPERIMENTAL: "true"
100+
if: ${{ github.event_name != 'pull_request' }}
109101
# This step uses the identity token to provision an ephemeral certificate
110102
# against the sigstore community Fulcio instance.
111103
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push.outputs.digest }}

Diff for: .github/workflows/docker-scout-scan.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
- name: Analyze for critical and high CVEs
129129
id: docker-scout-cves
130130
# if: ${{ github.event_name != 'pull_request_target' }}
131-
uses: docker/scout-action@b7413c99043c2a9131c0fa39cedaece80f285788 # v1.2.2
131+
uses: docker/scout-action@42a6acc319ac229f86e12bfca3b83de09fb058be # v1.3.0
132132
with:
133133
command: cves,recommendations
134134
image: ${{ steps.meta.outputs.tags }}
@@ -138,14 +138,14 @@ jobs:
138138

139139
- name: Upload SARIF result
140140
id: upload-sarif
141-
uses: github/codeql-action/upload-sarif@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
141+
uses: github/codeql-action/upload-sarif@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
142142
with:
143143
sarif_file: sarif.output.json
144144

145145
- name: Docker Scout Compare to Latest
146146
id: docker-scout
147147
if: ${{ github.event_name == 'pull_request' }}
148-
uses: docker/scout-action@b7413c99043c2a9131c0fa39cedaece80f285788 # v1.2.2
148+
uses: docker/scout-action@42a6acc319ac229f86e12bfca3b83de09fb058be # v1.3.0
149149
with:
150150
command: compare
151151
image: ${{ steps.meta.outputs.tags }}

Diff for: .github/workflows/scorecard.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ jobs:
6161
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
6262
# format to the repository Actions tab.
6363
- name: "Upload artifact"
64-
uses: actions/upload-artifact@1eb3cb2b3e0f29609092a73eb033bb759a334595 # v4.1.0
64+
uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0
6565
with:
6666
name: SARIF file
6767
path: results.sarif
6868
retention-days: 5
6969

7070
# Upload the results to GitHub's code scanning dashboard.
7171
- name: "Upload to code-scanning"
72-
uses: github/codeql-action/upload-sarif@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
72+
uses: github/codeql-action/upload-sarif@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
7373
with:
7474
sarif_file: results.sarif

Diff for: OdbDesignLib/App/BasicRequestAuthentication.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "BasicRequestAuthentication.h"
2+
#include <string>
3+
4+
namespace Odb::Lib::App
5+
{
6+
crow::response BasicRequestAuthentication::AuthenticateRequest(const crow::request& req)
7+
{
8+
const auto& authHeader = req.get_header_value("Authorization");
9+
if (authHeader.empty()) return crow::response(401, "Unauthorized");
10+
11+
auto authValue = authHeader.substr(6);
12+
if (authValue.empty()) return crow::response(401, "Unauthorized");
13+
14+
auto authValueDecoded = crow::utility::base64decode(authValue, authValue.size());
15+
if (authValueDecoded.empty()) return crow::response(401, "Unauthorized");
16+
17+
auto seperatorPos = authValueDecoded.find(':');
18+
if (seperatorPos == std::string::npos) return crow::response(401, "Unauthorized");
19+
20+
auto username = authValueDecoded.substr(0, seperatorPos);
21+
auto password = authValueDecoded.substr(seperatorPos + 1);
22+
23+
//if (! VerifyCredentials(username, password)) return crow::response(403, "Invalid username or password");
24+
auto resp = VerifyCredentials(username, password);
25+
return resp;
26+
}
27+
28+
crow::response BasicRequestAuthentication::VerifyCredentials(const std::string& username, const std::string& password)
29+
{
30+
// 500 - Internal Server Error
31+
auto validUsername = std::getenv(USERNAME_ENV_NAME);
32+
if (validUsername == nullptr) return crow::response(500, "Server failed retrieving credentials");
33+
34+
auto validPassword = std::getenv(PASSWORD_ENV_NAME);
35+
if (validPassword == nullptr) return crow::response(500, "Server failed retrieving credentials");
36+
37+
// 403 - Forbidden
38+
if (username != validUsername ||
39+
password != validPassword)
40+
{
41+
return crow::response(403, "Invalid username or password");
42+
}
43+
44+
// 200 Authorized!
45+
return crow::response(200, "Authorized");
46+
}
47+
}

Diff for: OdbDesignLib/App/BasicRequestAuthentication.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include "IRequestAuthentication.h"
4+
#include "../odbdesign_export.h"
5+
6+
namespace Odb::Lib::App
7+
{
8+
class ODBDESIGN_EXPORT BasicRequestAuthentication : public IRequestAuthentication
9+
{
10+
public:
11+
//BasicRequestAuthentication()
12+
//{
13+
//}
14+
15+
// Inherited via IRequestAuthentication
16+
crow::response AuthenticateRequest(const crow::request& req) override;
17+
18+
private:
19+
20+
crow::response VerifyCredentials(const std::string& username, const std::string& password);
21+
22+
const inline static char USERNAME_ENV_NAME[] = "ODBDESIGN_SERVER_REQUEST_USERNAME";
23+
const inline static char PASSWORD_ENV_NAME[] = "ODBDESIGN_SERVER_REQUEST_PASSWORD";
24+
25+
};
26+
}

Diff for: OdbDesignLib/App/IOdbServerApp.h

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "IOdbApp.h"
44
#include "../odbdesign_export.h"
5+
#include "IRequestAuthentication.h"
56

67
namespace Odb::Lib::App
78
{
@@ -11,6 +12,8 @@ namespace Odb::Lib::App
1112
virtual ~IOdbServerApp() {}
1213

1314
virtual CrowApp& crow_app() = 0;
15+
virtual IRequestAuthentication& request_auth() = 0;
16+
virtual void request_auth(std::unique_ptr<IRequestAuthentication> requestAuthentication) = 0;
1417

1518
protected:
1619
IOdbServerApp() = default;

Diff for: OdbDesignLib/App/IRequestAuthentication.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "IRequestAuthentication.h"
2+
3+
namespace Odb::Lib::App
4+
{
5+
6+
}

Diff for: OdbDesignLib/App/IRequestAuthentication.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include "../odbdesign_export.h"
4+
#include "crow_win.h"
5+
6+
namespace Odb::Lib::App
7+
{
8+
class ODBDESIGN_EXPORT IRequestAuthentication
9+
{
10+
public:
11+
virtual crow::response AuthenticateRequest(const crow::request& req) = 0;
12+
13+
protected:
14+
// pure virtual interface
15+
IRequestAuthentication() = default;
16+
17+
};
18+
}

Diff for: OdbDesignLib/App/OdbServerAppBase.cpp

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "OdbServerAppBase.h"
2+
#include "OdbServerAppBase.h"
23
#include "Logger.h"
34

45
using namespace Utils;
@@ -7,8 +8,20 @@ using namespace std::filesystem;
78
namespace Odb::Lib::App
89
{
910
OdbServerAppBase::OdbServerAppBase(int argc, char* argv[])
10-
: OdbAppBase(argc, argv)
11+
: OdbAppBase(argc, argv)
12+
{
13+
}
14+
15+
bool OdbServerAppBase::preServerRun()
1116
{
17+
// override in extended class to configure server or run custom code
18+
return true;
19+
}
20+
21+
bool OdbServerAppBase::postServerRun()
22+
{
23+
// override in extended class to cleanup server or run custom code
24+
return true;
1225
}
1326

1427
OdbServerAppBase::~OdbServerAppBase()
@@ -70,9 +83,13 @@ namespace Odb::Lib::App
7083
// set server to use multiple threads
7184
m_crowApp.multithreaded();
7285

86+
if (!preServerRun()) return ExitCode::PreServerRunFailed;
87+
7388
// run the Crow server
7489
m_crowApp.run();
7590

91+
if (!postServerRun()) return ExitCode::PostServerRunFailed;
92+
7693
// success!
7794
return ExitCode::Success;
7895
}
@@ -82,6 +99,16 @@ namespace Odb::Lib::App
8299
return m_crowApp;
83100
}
84101

102+
IRequestAuthentication& OdbServerAppBase::request_auth()
103+
{
104+
return *m_pRequestAuthentication;
105+
}
106+
107+
void OdbServerAppBase::request_auth(std::unique_ptr<IRequestAuthentication> pRequestAuthentication)
108+
{
109+
m_pRequestAuthentication = std::move(pRequestAuthentication);
110+
}
111+
85112
void OdbServerAppBase::register_routes()
86113
{
87114
for (const auto& pController : m_vecControllers)

Diff for: OdbDesignLib/App/OdbServerAppBase.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,38 @@
44
#include "OdbAppBase.h"
55
#include "RouteController.h"
66
#include "../odbdesign_export.h"
7+
#include "IRequestAuthentication.h"
8+
#include "BasicRequestAuthentication.h"
79

810
namespace Odb::Lib::App
911
{
1012
class ODBDESIGN_EXPORT OdbServerAppBase : public OdbAppBase, public IOdbServerApp
1113
{
12-
public:
13-
OdbServerAppBase(int argc, char* argv[]);
14+
public:
1415
virtual ~OdbServerAppBase();
1516

1617
CrowApp& crow_app() override;
1718

19+
IRequestAuthentication& request_auth() override;
20+
void request_auth(std::unique_ptr<IRequestAuthentication> pRequestAuthentication) override;
21+
1822
Utils::ExitCode Run() override;
1923

2024
protected:
25+
OdbServerAppBase(int argc, char* argv[]);
26+
2127
RouteController::Vector m_vecControllers;
2228

2329
// implement in subclasses to add route controllers
2430
virtual void add_controllers() = 0;
2531

32+
virtual bool preServerRun();
33+
virtual bool postServerRun();
34+
2635
private:
2736
CrowApp m_crowApp;
2837
//crow::SimpleApp m_crowApp;
38+
std::unique_ptr<IRequestAuthentication> m_pRequestAuthentication;
2939

3040
void register_routes();
3141

Diff for: OdbDesignLib/App/RouteController.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ namespace Odb::Lib::App
1111
void RouteController::register_route_handler(std::string route, TRouteHandlerFunction handler)
1212
{
1313
m_serverApp.crow_app().route_dynamic(std::move(route))
14-
([handler](const crow::request& req)
14+
([/*&,*/ handler](const crow::request& req)
1515
{
16+
//// authenticate request before sending to handler
17+
//auto authResp = m_serverApp.request_auth().AuthenticateRequest(req);
18+
//if (authResp.code != crow::status::OK)
19+
//{
20+
// return authResp;
21+
//}
22+
1623
return handler(req);
1724
});
1825

0 commit comments

Comments
 (0)