Skip to content

opentdf-client: Publish opentdf client cpp recipe #9119

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

Merged
merged 23 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4146050
Add openTDF/client-cpp
Jan 27, 2022
79a6472
Make package naming consistent
Jan 27, 2022
2bf4a77
Update current release to 0.2.12 to fix conan-center build fail
Jan 31, 2022
77ae2ea
Add 0.2.12 placeholder to conandata.yml
Jan 31, 2022
d78636e
Improve placeholder
Jan 31, 2022
8e398cf
Fix GSL version in conanfile
Jan 31, 2022
54b2a7e
Revert to zipfile-based source fetch
Jan 31, 2022
6f2a818
Add options
Jan 31, 2022
aa3be28
Specify destination directory in source fetch
Jan 31, 2022
541fedb
Fix package reference to GSL
Jan 31, 2022
16faa25
Add compiler min version checks
Jan 31, 2022
98f53d1
Import exception to avoid error
Jan 31, 2022
af8aada
Update recipes/opentdf-client/all/CMakeLists.txt
patmantru Feb 2, 2022
bbd4ea7
Update recipes/opentdf-client/all/conanfile.py
patmantru Feb 2, 2022
366ba6c
Update recipes/opentdf-client/all/conanfile.py
patmantru Feb 2, 2022
3db61d4
Update recipes/opentdf-client/all/conanfile.py
patmantru Feb 2, 2022
ec71d03
Update recipes/opentdf-client/all/conanfile.py
patmantru Feb 2, 2022
0d440f2
Update recipes/opentdf-client/all/test_package/conanfile.py
patmantru Feb 2, 2022
15b5f42
Update recipes/opentdf-client/all/test_package/conanfile.py
patmantru Feb 2, 2022
6f6f03f
Update recipes/opentdf-client/all/test_package/test_package.cpp
patmantru Feb 2, 2022
bc5a92e
Update recipes/opentdf-client/all/test_package/CMakeLists.txt
patmantru Feb 2, 2022
01efb8d
Fixes after incorporating code review changes
Feb 2, 2022
1880a59
Fixes after incorporating code review changes
Feb 2, 2022
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
9 changes: 9 additions & 0 deletions recipes/opentdf-client/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.1)
project(opentdf-client)

set(CMAKE_CXX_STANDARD 14)

include(${CMAKE_SOURCE_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/opentdf-client/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.2.12":
url: https://github.com/opentdf/client-cpp/archive/refs/tags/0.2.12.zip
sha256: "eb717e7587e2330666373ab670c1ed79eb3459de0a6d08aea9632ac69881f4e0"
99 changes: 99 additions & 0 deletions recipes/opentdf-client/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.40.0"


class OpenTDFConan(ConanFile):
name = "opentdf-client"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.virtru.com"
topics = ("opentdf", "opentdf-client", "tdf", "virtru")
description = "openTDF core c++ client library for creating and accessing TDF protected data"
license = "MIT"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {"build_python": [True, False], "fPIC": [True, False]}
default_options = {"build_python": False, "fPIC": True}
exports_sources = ["CMakeLists.txt"]

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _minimum_cpp_standard(self):
return 14

@property
def _minimum_compilers_version(self):
return {
"Visual Studio": "17",
"gcc": "9",
"clang": "12",
"apple-clang": "12.0.0",
}

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, self._minimum_cpp_standard)
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if not min_version:
self.output.warn("{} recipe lacks information about the {} compiler support.".format(
self.name, self.settings.compiler))
else:
if tools.Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration("{} requires C++{} support. The current compiler {} {} does not support it.".format(
self.name, self._minimum_cpp_standard, self.settings.compiler, self.settings.compiler.version))

def requirements(self):
self.requires("openssl/1.1.1l@")
self.requires("boost/1.76.0@")
self.requires("libiconv/1.16@")
self.requires("zlib/1.2.11@")
self.requires("ms-gsl/2.1.0@")
self.requires("libxml2/2.9.10@")
self.requires("libarchive/3.5.1@")
self.requires("nlohmann_json/3.10.4@")
self.requires("jwt-cpp/0.4.0@")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def source(self):
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake.install()
self.copy("*", dst="lib", src=os.path.join(self._source_subfolder,"tdf-lib-cpp/lib"))
self.copy("*", dst="include", src=os.path.join(self._source_subfolder,"tdf-lib-cpp/include"))
self.copy("LICENSE", dst="licenses", src=os.path.join(self._source_subfolder,"tdf-lib-cpp"))

# TODO - this only advertises the static lib, add dynamic lib also
def package_info(self):
self.cpp_info.components["libopentdf"].libs = ["opentdf_static"]
self.cpp_info.components["libopentdf"].names["cmake_find_package"] = "opentdf-client"
self.cpp_info.components["libopentdf"].names["cmake_find_package_multi"] = "opentdf-client"
self.cpp_info.components["libopentdf"].names["pkg_config"] = "opentdf-client"
self.cpp_info.components["libopentdf"].requires = ["openssl::openssl", "boost::boost", "libiconv::libiconv", "zlib::zlib", "ms-gsl::ms-gsl", "libxml2::libxml2", "libarchive::libarchive", "jwt-cpp::jwt-cpp", "nlohmann_json::nlohmann_json"]

12 changes: 12 additions & 0 deletions recipes/opentdf-client/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

set(CMAKE_CXX_STANDARD 17)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(opentdf-client CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} opentdf-client::opentdf-client)
16 changes: 16 additions & 0 deletions recipes/opentdf-client/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conans import ConanFile, CMake, tools
import os

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
26 changes: 26 additions & 0 deletions recipes/opentdf-client/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#include "nanotdf_client.h"

using namespace virtru;

const char *sender_private_key = "-----BEGIN PRIVATE KEY-----\n" \
"MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgi/Qr/jF1vkvCtVRn\n" \
"JH25ie37emp8icaowPqgIkFvQgihRANCAARlujKGIcl2ibpir9JKycCnjLZG5Ald\n" \
"6G4o6B340ejGV2XWyyARligEcCCXXeHDe/cfBQm/ODavaNUuZoxp130L\n" \
"-----END PRIVATE KEY-----";

const char *recipient_public_key = "-----BEGIN PUBLIC KEY-----\n" \
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE2SU1P4ECFK4V3/Yxx29qgwqbiC9z\n" \
"K4pt21P3DnZBJufh62/bNYhQkL3VQ9oM13FvcKpbIf6Hi83ry0O2vmE5mQ==\n" \
"-----END PUBLIC KEY-----";

int main(int argc, char **argv) {

NanoTDFClient nano_tdf_client("https://your-eas-url.here", "[email protected]");

nano_tdf_client.setDecrypterPublicKey(recipient_public_key);

nano_tdf_client.setSignerPrivateKey(sender_private_key, EllipticCurve::SECP256R1);

return 0;
}
3 changes: 3 additions & 0 deletions recipes/opentdf-client/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.2.12":
folder: all