Skip to content
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
29 changes: 29 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:jammy",

"extensions": [
"ms-vscode.cpptools",
"josetr.cmake-language-support-vscode"
],

"onCreateCommand": "git submodule update --init; sudo apt-get update; sudo apt-get upgrade -y; sudo apt-get install build-essential g++ libssl-dev libcurl4-openssl-dev git apt-transport-https ca-certificates curl gnupg lsb-release jq -y; curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg; echo \"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null; sudo apt-get update; sudo apt-get install docker-ce docker-ce-cli containerd.io -y"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
3 changes: 2 additions & 1 deletion .github/workflows/upgrade-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
name: UML
steps:
- uses: actions/checkout@v2
- name: Export UML
- name: Export UML
continue-on-error: true
uses: docker://rlespinasse/drawio-export:latest
with:
args: -f svg -o ./ docs
Expand Down
38 changes: 37 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
.vscode
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
core

# Vs
.vscode

# Crypto
*.pem
17 changes: 14 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LABEL org.opencontainers.image.source="https://github.com/createstructure/core-c
LABEL org.opencontainers.image.documentation="https://raw.githubusercontent.com/createstructure/core-createstructure/main/docs/README.md"

# Copy the current folder which contains C++ source code to the Docker image under /usr/src
COPY ./bin /usr/src/createstructure
COPY ./ /usr/src/createstructure

# Specify the working directory
WORKDIR /usr/src/createstructure
Expand All @@ -20,8 +20,19 @@ WORKDIR /usr/src/createstructure
RUN apt-get update
RUN apt-get install g++ libssl-dev libcurl4-openssl-dev git -y

# Use GCC to compile the source file
RUN g++ core.cpp -o core -std=c++17 -lcurl -lcrypto
# Use G++ to compile the source file
RUN g++ -Wall ./bin/core.cpp \
./bin/local-libraries/getTemplate.cpp \
./bin/local-libraries/getUploadURL.cpp \
./bin/local-libraries/inputCheck.cpp \
./bin/local-libraries/priority.cpp \
./bin/local-libraries/repo.cpp \
./bin/local-libraries/repoInfoCheck.cpp \
./bin/local-libraries/workload.cpp \
./bin/global-libraries/bin/cryptation.cpp \
./bin/global-libraries/bin/rest.cpp \
./bin/global-libraries/bin/sleep.cpp \
-o core -lcurl -lcrypto

# Setup git
RUN git config --global user.email "help@castellanidavide.it"
Expand Down
50 changes: 50 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# For test only
# sudo apt install build-essential g++ libssl-dev libcurl4-openssl-dev git -y

all:
make compile

createkeys:
openssl genrsa -out private.pem 4096 > /dev/null && chmod +rwx private.pem
openssl rsa -in private.pem -outform PEM -pubout -out public.pem > /dev/null && chmod +rwx public.pem

compile:
g++ -Wall ./bin/core.cpp \
./bin/local-libraries/getTemplate.cpp \
./bin/local-libraries/getUploadURL.cpp \
./bin/local-libraries/inputCheck.cpp \
./bin/local-libraries/priority.cpp \
./bin/local-libraries/repo.cpp \
./bin/local-libraries/repoInfoCheck.cpp \
./bin/local-libraries/workload.cpp \
./bin/global-libraries/bin/cryptation.cpp \
./bin/global-libraries/bin/rest.cpp \
./bin/global-libraries/bin/sleep.cpp \
-o core -lcurl -lcrypto

precompile:
g++ -Wall -c ./bin/core.cpp -o ./bin/core.o
g++ -Wall -c ./bin/local-libraries/getTemplate.cpp -o ./bin/local-libraries/getTemplate.o
g++ -Wall -c ./bin/local-libraries/getUploadURL.cpp -o ./bin/local-libraries/getUploadURL.o
g++ -Wall -c ./bin/local-libraries/inputCheck.cpp -o ./bin/local-libraries/inputCheck.o
g++ -Wall -c ./bin/local-libraries/priority.cpp -o ./bin/local-libraries/priority.o
g++ -Wall -c ./bin/local-libraries/repo.cpp -o ./bin/local-libraries/repo.o
g++ -Wall -c ./bin/local-libraries/repoInfoCheck.cpp -o ./bin/local-libraries/repoInfoCheck.o
g++ -Wall -c ./bin/local-libraries/workload.cpp -o ./bin/local-libraries/workload.o
g++ -Wall -c ./bin/global-libraries/bin/cryptation.cpp -o ./bin/global-libraries/bin/cryptation.o
g++ -Wall -c ./bin/global-libraries/bin/rest.cpp -o ./bin/global-libraries/bin/rest.o
g++ -Wall -c ./bin/global-libraries/bin/sleep.cpp -o ./bin/global-libraries/bin/sleep.o

link:
g++ -Wall ./bin/core.o \
./bin/local-libraries/getTemplate.o \
./bin/local-libraries/getUploadURL.o \
./bin/local-libraries/inputCheck.o \
./bin/local-libraries/priority.o \
./bin/local-libraries/repo.o \
./bin/local-libraries/repoInfoCheck.o \
./bin/local-libraries/workload.o \
./bin/global-libraries/bin/cryptation.o \
./bin/global-libraries/bin/rest.o \
./bin/global-libraries/bin/sleep.o \
-o core -lcurl -lcrypto
14 changes: 9 additions & 5 deletions bin/core.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Dependencies
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include "global-libraries/bin/json.hpp"
#include "global-libraries/bin/rest.hpp"
#include "global-libraries/bin/sleep.hpp"
Expand Down Expand Up @@ -32,6 +33,7 @@ int main(int argc, char *argv[])
// Function viariable(s)
json inputs;
string path;
bool byArg = false;

#ifdef DEBUG
cout << "argc: " << argc << endl;
Expand All @@ -40,11 +42,13 @@ int main(int argc, char *argv[])
#endif // DEBUG

// Save the given input data
if (argc == 2)
if (argc == 2 && json::accept(string(argv[1])))
{
inputs = json::parse(string(argv[1]));
inputs = json::parse(string(argv[1]));
byArg = true;
}
else

if (!byArg)
{
#ifdef DEBUG
system("ls /etc/auth");
Expand Down Expand Up @@ -112,7 +116,7 @@ int main(int argc, char *argv[])
#ifdef DEBUG
cout << "Doing nothing: " << workloadData.dump(4) << endl;
#endif // DEBUG
Sleep::sleep(1);
Sleep::sleep(3);
break;
}

Expand Down
134 changes: 134 additions & 0 deletions bin/local-libraries/getTemplate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* @file gettemplateURL.cpp
*
* @brief Library for getting template URL.
*
* @author Castellani Davide (@DavideC03)
*/

// Dependencies
#include "getTemplate.hpp"

// Definitions
// #define DEBUG

/**
* @brief Constructor
*
* @param repoInfo Json object containing the repository information
*/
GetTemplate::GetTemplate(json repoInfo)
{
// Get the data
GetTemplate::username = repoInfo["username"].get<string>();
GetTemplate::token = repoInfo["token"].get<string>();
GetTemplate::data = RepoInfoCheck::sanitize(repoInfo["answers"]);
}

/**
* @brief Get the template
*
* @return string The template URL
*/
string GetTemplate::get()
{
string templateURL(GetTemplate::data["template"].get<string>());

templateURL = GetTemplate::ending(templateURL, "-template");
replace(templateURL.begin(), templateURL.end(), ' ', '-');

#ifdef DEBUG
cout << "Given template request: " << templateURL << endl;
#endif // DEBUG

try
{
if (templateURL.find("/") != string::npos)
{
// External template
json response = Rest::jsonRequest(
Rest::GITHUB_REST_API + "repos/" + templateURL,
GetTemplate::token,
NULL,
false);
#ifdef DEBUG
cout << "Response: " << response.dump(4) << endl;
#endif // DEBUG
assert(response["private"].get<bool>());
return "https://" +
GetTemplate::username +
":" +
GetTemplate::token +
"@github.com/" +
templateURL;
}
else
{
// Internal template
json response = Rest::jsonRequest(
Rest::GITHUB_REST_API + "repos/createstructure/" + templateURL,
GetTemplate::token,
NULL,
false);
assert(!response["private"].get<bool>());
return "https://" +
GetTemplate::username +
":" +
GetTemplate::token +
"@github.com/createstructure/" +
templateURL;
}
}
catch (...)
{
// If the template doesn't exist or there is an error
return "https://github.com/createstructure/default-template";
}
}

/**
* @brief Get if "original" ends with "ending"
*
* @param original The string to evaluate
* @param ending The "end" string
* @return True if "original" ends with "ending", False otherwise
*/
bool GetTemplate::hasEnding(string original, string ending)
{
if (original.length() >= ending.length())
{
return (0 == original.compare(original.length() - ending.length(), ending.length(), ending));
}
else
{
return false;
}
}

/**
* @brief Add a string to the end of a string
*
* @param original The original string
* @param ending The string to add
*
* @return string The original string with the ending
*/
string GetTemplate::ending(string original, string ending)
{
if (GetTemplate::hasEnding(original, ending))
return original;
else
return original + ending;
}

/**
* @brief Get the template
*
* @return The template URL
*/
string GetTemplate::get(json repoInfo)
{
return GetTemplate(repoInfo).get();
}

#undef DEBUG
Loading