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

Add class RestProfile for local maintenance of users' REST parameters. #5463

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
4 changes: 3 additions & 1 deletion tiledb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# The MIT License
#
# Copyright (c) 2017-2024 TileDB, Inc.
# Copyright (c) 2017-2025 TileDB, Inc.
# Copyright (c) 2016 MIT and Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -133,6 +133,7 @@ endif()
set(TILEDB_CORE_SOURCES
${TILEDB_CORE_INCLUDE_DIR}/tiledb/common/memory.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/common/stdx_string.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/common/filesystem/home_directory.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/common/interval/interval.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/common/types/dynamic_typed_datum.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/platform/cert_file.cc
Expand Down Expand Up @@ -279,6 +280,7 @@ set(TILEDB_CORE_SOURCES
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/query/writers/writer_base.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/query_plan/query_plan.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/rest/rest_client.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/rest/rest_profile.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/rtree/rtree.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/serialization/array.cc
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/serialization/array_directory.cc
Expand Down
3 changes: 2 additions & 1 deletion tiledb/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# The MIT License
#
# Copyright (c) 2021-2024 TileDB, Inc.
# Copyright (c) 2021-2025 TileDB, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -43,6 +43,7 @@ add_subdirectory(algorithm)
add_subdirectory(dynamic_memory)
add_subdirectory(evaluator)
add_subdirectory(exception)
add_subdirectory(filesystem)
add_subdirectory(governor)
add_subdirectory(interval)
add_subdirectory(random)
Expand Down
33 changes: 33 additions & 0 deletions tiledb/common/filesystem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# tiledb/common/filesystem/CMakeLists.txt
#
# The MIT License
#
# Copyright (c) 2025 TileDB, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

include(common NO_POLICY_SCOPE)
include(object_library)

commence(object_library home_directory)
this_target_sources(home_directory.cc)
this_target_link_libraries(export)
this_target_object_libraries(baseline)
conclude(object_library)
75 changes: 75 additions & 0 deletions tiledb/common/filesystem/home_directory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @file home_directory.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2025 TileDB, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* This file implements class HomeDirectory and function home_directory().
*/

#include "home_directory.h"

#include <filesystem>
#include <system_error>

namespace tiledb::common::filesystem {

/* ********************************* */
/* API */
/* ********************************* */

std::optional<std::string> home_directory() {
return HomeDirectory().path();
}

/* ********************************* */
/* HomeDirectory */
/* ********************************* */

HomeDirectory::HomeDirectory()
: path_(std::nullopt) {
#ifdef _WIN32
wchar_t home[MAX_PATH];
if (SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, home) == S_OK) {
path_ = home;
}
#else
const char* home = std::getenv("HOME");
if (home != nullptr) {
path_ = home;
}
#endif
// Remove trailing slash, if exists.
if (path_.has_value() && path_.value().back() == '/') {
path_.value().pop_back();
}
}

std::optional<std::string> HomeDirectory::path() {
return path_;
}

} // namespace tiledb::common::filesystem
74 changes: 74 additions & 0 deletions tiledb/common/filesystem/home_directory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @file home_directory.h
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2025 TileDB, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* This file defines class HomeDirectory and function home_directory().
*/

#ifndef TILEDB_HOME_DIRECTORY_H
#define TILEDB_HOME_DIRECTORY_H

#include <optional>
#include <string>

namespace tiledb::common::filesystem {

/** Standalone function which returns the path to user's home directory. */
std::optional<std::string> home_directory();

class HomeDirectory {
public:
/* ********************************* */
/* CONSTRUCTORS & DESTRUCTORS */
/* ********************************* */

/** Constructor. */
HomeDirectory();

/** Destructor. */
~HomeDirectory() = default;

/* ********************************* */
/* API */
/* ********************************* */

/** Return the path of the home directory. */
std::optional<std::string> path();

private:
/* ********************************* */
/* PRIVATE ATTRIBUTES */
/* ********************************* */

/** The path of the home directory. */
std::optional<std::string> path_;
};

} // namespace tiledb::common::filesystem

#endif // TILEDB_HOME_DIRECTORY_H
36 changes: 36 additions & 0 deletions tiledb/common/filesystem/test/compile_home_directory_main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @file compile_home_directory_main.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2025 TileDB, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "../home_directory.h"

using namespace tiledb::common::filesystem;

int main() {
(void)home_directory();
return 0;
}
16 changes: 13 additions & 3 deletions tiledb/sm/rest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# The MIT License
#
# Copyright (c) 2024 TileDB, Inc.
# Copyright (c) 2024-2025 TileDB, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,17 +26,27 @@
include(common NO_POLICY_SCOPE)
include(object_library)

#
# Object library `rest_profile`
#
commence(object_library rest_profile)
this_target_sources(rest_profile.cc)
this_target_object_libraries(config home_directory seedable_global_PRNG)
conclude(object_library)

#
# Object library `rest_client`
#
commence(object_library rest_client)
this_target_sources(rest_client.cc)
this_target_object_libraries(config)
this_target_object_libraries(rest_profile)
conclude(object_library)

#
# Object library `rest_client_remote`
#
# This object library does not link standalone at present. As long as the
# cyclic dependencies in `class RestClient` persist, that won't be possible.
#
#

add_test_subdirectory()
Loading
Loading