Skip to content

Commit

Permalink
merge to main (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
nam20485 authored Oct 20, 2023
2 parents 316885d + 39aa92b commit ef6b728
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 65 deletions.
22 changes: 18 additions & 4 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ name: CMake Build Multi-Platform

on:
push:
branches: [ "development", "main" ]
branches: [ "development", "main", "release" ]
pull_request:
branches: [ "development" ]
workflow_dispatch:
branches: [ "development", "main", "release" ]

permissions:
contents: write
Expand All @@ -20,6 +19,7 @@ env:

jobs:
build:
name: CMake-Multi-Platform-Build
runs-on: ${{ matrix.os }}

strategy:
Expand All @@ -46,8 +46,22 @@ jobs:

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v3

# add problem matchers by compiler
- name: Add Problem Matchers
uses: ammaraskar/msvc-problem-matcher@master
if: matrix.os == 'windows-2022'
- name: Add Problem Matchers
uses: ammaraskar/gcc-problem-matcher@master
if: matrix.os != 'windows-2022'

- name: Install vcpkg Dependencies
run: |
sudo apt update
sudo apt install -y -q --no-install-recommends build-essential tar curl zip unzip
if: matrix.os == 'ubuntu-22.04'

#
# os != windows-2022 (i.e. Linux, MacOS)
#
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ name: "CodeQL"

on:
push:
branches: [ "development", main, release ]
branches: [ "development", "main", "release" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "development" ]
branches: [ "development", "main", "release" ]

env:
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
VCPKG_BINARY_SOURCES: 'clear;x-gha,readwrite'

jobs:
analyze:
name: Analyze
name: CodeQL-Security-Scan
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
name: Docker Build

on:
# push:
# branches: [ "main" ]
#push:
# branches: [ "development", "main", "release" ]
pull_request:
branches: [ "*" ]
branches: [ "development", "main", "release" ]

jobs:

build:
name: Docker-Build

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

# add problem matchers
- name: Add Problem Matchers
uses: ammaraskar/gcc-problem-matcher@master

- name: Build the Docker image
run: docker build . --file Dockerfile_OdbDesignServer --tag odbdesign:${{github.ref_name}}-${{github.run_number}}
9 changes: 8 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ name: Docker Publish

on:
push:
branches: [ "*" ]
branches: [ "development", "main", "release" ]
#pull_request:
# branches: [ "development", "main", "release" ]

env:
# Use docker.io for Docker Hub if empty
Expand All @@ -18,6 +20,7 @@ env:

jobs:
build:
name: Docker-Build-and-Publish

runs-on: ubuntu-latest
permissions:
Expand All @@ -31,6 +34,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

# add problem matchers
- name: Add Problem Matchers
uses: ammaraskar/gcc-problem-matcher@master

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ on:
push:
branches: [ "development", "main", "release" ]
pull_request:
branches: [ "development" ]
schedule:
- cron: '23 4 * * 6'
branches: [ "development", "main", "release" ]

env:
# Path to the CMake build directory.
Expand Down Expand Up @@ -55,7 +53,7 @@ jobs:
run: "& \"${{env.VCPKG_ROOT}}/vcpkg\" install --triplet x64-windows"

- name: CMake Configure
run: cmake --preset x64-release -B ${{ env.build }}
run: cmake --preset x64-release -B ${{ env.build }} -G "Visual Studio 17 2022"

# - name: Configure CMake
# run: cmake -B ${{ env.build }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile_OdbDesignServer
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ COPY --from=build /src/OdbDesign/out/build/linux-release/OdbDesignLib/*.so .
COPY --from=build /src/OdbDesign/out/build/linux-release/Utils/*.so .
COPY --from=build /src/OdbDesign/out/build/linux-release/OdbDesignServer/OdbDesignServer .
COPY --from=build /src/OdbDesign/out/build/linux-release/OdbDesignServer/*.so .
COPY --from=build /src/OdbDesign/out/build/linux-release/*.so .
COPY --from=build /src/OdbDesign/out/build/linux-release/OdbDesignTests/OdbDesignTests .
# copy designs and templates directories
#COPY --from=build /src/OdbDesign/OdbDesignServer/designs ./designs
#COPY --from=build /src/OdbDesign/OdbDesignServer/templates ./templates
Expand Down
8 changes: 4 additions & 4 deletions OdbDesignLib/OdbDesignArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ namespace Odb::Lib

int OdbDesignArgs::port() const
{
return boolArg("port");
return intArg("port", DEFAULT_PORT);
}

bool OdbDesignArgs::useHttps() const
{
return boolArg("use-https");
return boolArg("use-https", DEFAULT_USE_HTTPS);
}

std::string OdbDesignArgs::designsDir() const
{
return stringArg("designs-dir");
return stringArg("designs-dir", DEFAULT_DESIGNS_DIR);
}

std::string OdbDesignArgs::templatesDir() const
{
return stringArg("templates-dir");
return stringArg("templates-dir", DEFAULT_TEMPLATES_DIR);
}
}
9 changes: 5 additions & 4 deletions OdbDesignLib/OdbDesignArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ namespace Odb::Lib
std::string designsDir() const;
std::string templatesDir() const;

// port
// use HTTPS
// designs dir
// templates dir
const int DEFAULT_PORT = 8888;
const bool DEFAULT_USE_HTTPS = false;
const std::string DEFAULT_DESIGNS_DIR = "designs";
const std::string DEFAULT_TEMPLATES_DIR = "templates";

};
}
26 changes: 23 additions & 3 deletions OdbDesignLib/OdbServerAppBase.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "OdbServerAppBase.h"
#include <Logger.h>

using namespace Utils;

Expand All @@ -25,17 +26,36 @@ namespace Odb::Lib
// enable HTTP compression
m_crowApp.use_compression(crow::compression::algorithm::GZIP);

// enable SSL/HTTPS
m_crowApp.ssl_file("ssl/localhost.crt", "ssl/localhost.key");
try
{
if (args().useHttps())
{
// enable SSL/HTTPS
m_crowApp.ssl_file("ssl/localhost.crt", "ssl/localhost.key");
}
}
catch (boost::wrapexcept<boost::system::system_error>& e)
{
// log the error
logexception(e.what());
logerror("SSL was specified but it failed to initialize, exiting...");
return ExitCode::FailedInitSsl;
}

// let subclasses add controller types
add_controllers();

// register all added controllers' routes
register_routes();

// set port to passed-in port or default if none supplied
m_crowApp.port(static_cast<unsigned short>(args().port()));

// set server to use multiple threads
m_crowApp.multithreaded();

// run the Crow server
m_crowApp.port(18080).multithreaded().run();
m_crowApp.run();

// success!
return ExitCode::Success;
Expand Down
68 changes: 53 additions & 15 deletions Utils/CommandLineArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "CommandLineArgs.h"
#include "CommandLineArgs.h"
#include "CommandLineArgs.h"
#include "CommandLineArgs.h"
#include "CommandLineArgs.h"
#include "CommandLineArgs.h"
#include "CommandLineArgs.h"
#include <exception>
#include <stdexcept>
#include "str_trim.h"
Expand All @@ -26,32 +30,62 @@ namespace Utils
parse();
}

bool CommandLineArgs::boolArg(const std::string& name) const
bool CommandLineArgs::boolArg(const std::string& name, bool defaultValue) const
{
auto strB = getArgValue(name);
if (strB.length() == 0) throw std::invalid_argument("Argument not found: " + name);
bool b;
std::istringstream(strB) >> std::boolalpha >> b;
return b;
if (strB.length() > 0)
{
bool b;
std::istringstream(strB) >> std::boolalpha >> b;
return b;
}

return defaultValue;
}

std::string CommandLineArgs::stringArg(const std::string& name) const
std::string CommandLineArgs::stringArg(const std::string& name, const std::string& defaultValue) const
{
return getArgValue(name);
auto str = getArgValue(name);
if (str.length() > 0)
{
return str;
}
return defaultValue;
}

int CommandLineArgs::intArg(const std::string& name) const
int CommandLineArgs::intArg(const std::string& name, int defaultValue) const
{
auto strI = getArgValue(name);
if (strI.length() == 0) throw std::invalid_argument("Argument not found: " + name);
return std::stoi(strI);
if (strI.length() > 0)
{
return std::stoi(strI);
}
return defaultValue;
}

double CommandLineArgs::doubleArg(const std::string& name) const
double CommandLineArgs::doubleArg(const std::string& name, double defaultValue) const
{
auto strD = getArgValue(name);
if (strD.length() == 0) throw std::invalid_argument("Argument not found: " + name);
return std::stod(strD);
if (strD.length() > 0)
{
return std::stod(strD);
}
return defaultValue;
}

std::string CommandLineArgs::executable() const
{
return getArgValue(EXECUTABLE_ARG_NAME);
}

std::filesystem::path CommandLineArgs::executableDirectory() const
{
return std::filesystem::path(executable()).parent_path().string();
}

std::filesystem::path CommandLineArgs::executableName() const
{
return std::filesystem::path(executable()).filename().string();
}

std::string CommandLineArgs::getArgValue(const std::string& name) const
Expand All @@ -68,7 +102,11 @@ namespace Utils
auto& arg = m_vecArguments[i];
if (arg.length() > 0)
{
if (arg[0] == '-' || arg[0] == '/')
if (i == 0)
{
m_mapArguments["executable"] = arg;
}
else if (arg[0] == '-' || arg[0] == '/')
{
Utils::str_ltrim(arg, '-');
Utils::str_ltrim(arg, '/');
Expand Down Expand Up @@ -102,7 +140,7 @@ namespace Utils
//{
// m_mapArguments[arg] = "true";
//}
}
}
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions Utils/CommandLineArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "utils_export.h"
#include <stdexcept>
#include <map>
#include <filesystem>


namespace Utils
Expand All @@ -15,10 +16,14 @@ namespace Utils
CommandLineArgs(int argc, char* argv[]);
CommandLineArgs(const std::vector<std::string>& vecArgv);

bool boolArg(const std::string& name) const;
std::string stringArg(const std::string& name) const;
int intArg(const std::string& name) const;
double doubleArg(const std::string& name) const;
bool boolArg(const std::string& name, bool defaultValue) const;
std::string stringArg(const std::string& name, const std::string& defaultValue) const;
int intArg(const std::string& name, int defaultValue) const;
double doubleArg(const std::string& name, double defaultValue) const;

std::string executable() const;
std::filesystem::path executableDirectory() const;
std::filesystem::path executableName() const;

protected:
std::vector<std::string> m_vecArguments;
Expand All @@ -27,6 +32,8 @@ namespace Utils
std::string getArgValue(const std::string& name) const;

void parse();

const char* EXECUTABLE_ARG_NAME = "executable";

};
}
3 changes: 2 additions & 1 deletion Utils/ExitCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace Utils
enum class ExitCode
{
Success = 0,
FailedInit,
FailedInit = 1,
FailedInitSsl = 2,
UnknownError
};
}
Loading

0 comments on commit ef6b728

Please sign in to comment.