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 bucket size to advanced options #57

Merged
merged 3 commits into from
Sep 5, 2024
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
7 changes: 5 additions & 2 deletions src/lib/cloudfuse/child_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
SOFTWARE
*/

#include <cstdint>
#include <string>

struct processReturn
Expand All @@ -38,12 +39,14 @@ class CloudfuseMngr
processReturn dryRun(const std::string passphrase);
processReturn mount(const std::string passphrase);
processReturn genS3Config(const std::string accessKeyId, const std::string secretAccessKey,
const std::string endpoint, const std::string bucketName, const std::string passphrase);
const std::string endpoint, const std::string bucketName, const uint64_t bucketSizeMb,
const std::string passphrase);
#elif defined(__linux__) || defined(__APPLE__)
processReturn dryRun(const std::string accessKeyId, const std::string secretAccessKey,
const std::string passphrase);
processReturn mount(const std::string accessKeyId, const std::string secretAccessKey, const std::string passphrase);
processReturn genS3Config(const std::string endpoint, const std::string bucketName, const std::string passphrase);
processReturn genS3Config(const std::string endpoint, const std::string bucketName, const uint64_t bucketSizeMb,
const std::string passphrase);
#endif
std::string getMountDir();
std::string getFileCacheDir();
Expand Down
9 changes: 6 additions & 3 deletions src/lib/cloudfuse/child_process_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CloudfuseMngr::CloudfuseMngr()
{
std::string systemName = getSystemName();
// NOTE: increment the version number when the config template changes
templateVersionString = "template-version: 0.1";
templateVersionString = "template-version: 0.2";
std::string config_template = templateVersionString + R"(
allow-other: true
logging:
Expand All @@ -64,6 +64,7 @@ allow-other: true
negative-entry-expiration-sec: 1800
ignore-open-flags: true
network-share: true
display-capacity-mb: { DISPLAY_CAPACITY }

file_cache:
path: { 0 }
Expand Down Expand Up @@ -173,7 +174,7 @@ processReturn CloudfuseMngr::spawnProcess(char *const argv[], char *const envp[]
}

processReturn CloudfuseMngr::genS3Config(const std::string endpoint, const std::string bucketName,
const std::string passphrase)
const uint64_t bucketSizeMb, const std::string passphrase)
{
const std::string configArg = "--config-file=" + templateFile;
const std::string outputArg = "--output-file=" + configFile;
Expand All @@ -189,7 +190,9 @@ processReturn CloudfuseMngr::genS3Config(const std::string endpoint, const std::

const std::string bucketNameEnv = "BUCKET_NAME=" + bucketName;
const std::string endpointEnv = "ENDPOINT=" + endpoint;
char *const envp[] = {const_cast<char *>(bucketNameEnv.c_str()), const_cast<char *>(endpointEnv.c_str()), NULL};
const std::string bucketSizeEnv = "DISPLAY_CAPACITY=" + std::to_string(bucketSizeMb);
char *const envp[] = {const_cast<char *>(bucketNameEnv.c_str()), const_cast<char *>(endpointEnv.c_str()),
const_cast<char *>(bucketSizeEnv.c_str()), NULL};

return spawnProcess(argv, envp);
}
Expand Down
10 changes: 6 additions & 4 deletions src/lib/cloudfuse/child_process_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CloudfuseMngr::CloudfuseMngr()
{
std::string systemName = getSystemName();
// NOTE: increment the version number when the config template changes
templateVersionString = "template-version: 0.1";
templateVersionString = "template-version: 0.2";
std::string config_template = templateVersionString + R"(
allow-other: true
logging:
Expand All @@ -90,6 +90,7 @@ allow-other: true
negative-entry-expiration-sec: 1800
ignore-open-flags: true
network-share: true
display-capacity-mb: { DISPLAY_CAPACITY }

file_cache:
path: { 0 }
Expand Down Expand Up @@ -262,16 +263,17 @@ processReturn CloudfuseMngr::spawnProcess(wchar_t *argv, std::wstring envp)

processReturn CloudfuseMngr::genS3Config(const std::string accessKeyId, const std::string secretAccessKey,
const std::string endpoint, const std::string bucketName,
const std::string passphrase)
const uint64_t bucketSizeMb, const std::string passphrase)
{
const std::string argv = "cloudfuse gen-config --config-file=" + templateFile + " --output-file=" + configFile +
" --temp-path=" + fileCacheDir + " --passphrase=" + passphrase;
const std::string aws_access_key_id_env = "AWS_ACCESS_KEY_ID=" + accessKeyId;
const std::string aws_secret_access_key_env = "AWS_SECRET_ACCESS_KEY=" + secretAccessKey;
const std::string endpoint_env = "ENDPOINT=" + endpoint;
const std::string bucket_name_env = "BUCKET_NAME=" + bucketName;
const std::string envp =
aws_access_key_id_env + '\0' + aws_secret_access_key_env + '\0' + endpoint_env + '\0' + bucket_name_env + '\0';
const std::string bucket_size_env = "DISPLAY_CAPACITY=" + std::to_string(bucketSizeMb);
const std::string envp = aws_access_key_id_env + '\0' + aws_secret_access_key_env + '\0' + endpoint_env + '\0' +
bucket_name_env + '\0' + bucket_size_env + '\0';

const std::wstring wargv = std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>().from_bytes(argv);
const std::wstring wenvp = std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>().from_bytes(envp);
Expand Down
22 changes: 20 additions & 2 deletions src/plugin/settings/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@
{
return true;
}
// bucket capacity
if (m_prevSettings[kBucketSizeTextFieldId] != newValues[kBucketSizeTextFieldId])
{
return true;
}
}
// nothing we care about changed
return false;
Expand All @@ -257,11 +262,22 @@
std::string secretKey = values[kSecretKeyPasswordFieldId];
std::string endpointUrl = kDefaultEndpoint;
std::string bucketName = "";
uint64_t bucketCapacityGB = kDefaultBucketSizeGb;
if (!credentialsOnly)
{
endpointUrl = values[kEndpointUrlTextFieldId];
bucketName = values[kBucketNameTextFieldId]; // The default empty string will cause cloudfuse
// to select first available bucket
try
{
bucketCapacityGB = std::stoi(values[kBucketSizeTextFieldId]);

Check warning on line 273 in src/plugin/settings/engine.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

implicit conversion changes signedness: 'int' to 'uint64_t' (aka 'unsigned long') [-Wsign-conversion]

Check warning on line 273 in src/plugin/settings/engine.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

implicit conversion changes signedness: 'int' to 'uint64_t' (aka 'unsigned long') [-Wsign-conversion]

Check warning on line 273 in src/plugin/settings/engine.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, Release, clang)

implicit conversion changes signedness: 'int' to 'uint64_t' (aka 'unsigned long') [-Wsign-conversion]

Check warning on line 273 in src/plugin/settings/engine.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, Release, clang)

implicit conversion changes signedness: 'int' to 'uint64_t' (aka 'unsigned long') [-Wsign-conversion]

Check warning on line 273 in src/plugin/settings/engine.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, Release, clang)

implicit conversion changes signedness: 'int' to 'uint64_t' (aka 'unsigned long') [-Wsign-conversion]
}
catch (std::invalid_argument &e)
{
NX_PRINT << "Bad input for bucket capacity: " << values[kBucketSizeTextFieldId];
// revert to default - write back to settings so user can see value reset
values[kBucketSizeTextFieldId] = std::to_string(kDefaultBucketSizeGb);
}
}
std::string mountDir = m_cfManager.getMountDir();
std::string fileCacheDir = m_cfManager.getFileCacheDir();
Expand Down Expand Up @@ -342,9 +358,11 @@
}
NX_PRINT << "spawning process from genS3Config";
#if defined(__linux__)
const processReturn dryGenConfig = m_cfManager.genS3Config(endpointUrl, bucketName, m_passphrase);
const processReturn dryGenConfig =
m_cfManager.genS3Config(endpointUrl, bucketName, bucketCapacityGB * 1024, m_passphrase);
#elif defined(_WIN32)
const processReturn dryGenConfig = m_cfManager.genS3Config(keyId, secretKey, endpointUrl, bucketName, m_passphrase);
const processReturn dryGenConfig =
m_cfManager.genS3Config(keyId, secretKey, endpointUrl, bucketName, bucketCapacityGB * 1024, m_passphrase);
#endif
if (dryGenConfig.errCode != 0)
{
Expand Down
16 changes: 16 additions & 0 deletions src/plugin/settings/settings_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once

#include <cstdint>
#include <string>

namespace settings
Expand Down Expand Up @@ -53,6 +54,8 @@
static const std::string kEndpointUrlTextFieldId = "endpointUrl";
static const std::string kDefaultEndpoint = "https://s3.us-east-1.lyvecloud.seagate.com";
static const std::string kBucketNameTextFieldId = "bucketName";
static const std::string kBucketSizeTextFieldId = "bucketCapacity";
static const uint64_t kDefaultBucketSizeGb = 1024;
static const std::string kAdvancedGroupBox = R"json(
{
"type": "GroupBox",
Expand Down Expand Up @@ -80,6 +83,19 @@
"defaultValue": "",
"validationErrorMessage": "Bucket name can only contain lowercase letters, numbers, dashes, and dots.",
"validationRegex": "^[-.a-z0-9]*$"
},
{
"type": "SpinBox",
"name": ")json" + kBucketSizeTextFieldId +
R"json(",
"caption": "Backup Storage Limit (in GB)",
"description": "Maximum data this server should back up - default is )json" +
std::to_string(kDefaultBucketSizeGb) +
R"json(GB",
"defaultValue": )json" + std::to_string(kDefaultBucketSizeGb) +
R"json(,
"minValue": 1,
"maxValue": 1000000000
}
]
})json";
Expand All @@ -96,7 +112,7 @@
kCredentialGroupBox + (credentialsOnly ? "" : ("," + kAdvancedGroupBox + "," + kPluginWebsiteLink));

// top-level settings model
static const std::string kEngineSettingsModel = /*suppress newline*/ 1 + R"json(

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]

Check warning on line 115 in src/plugin/settings/settings_model.h

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, Release, clang)

adding 'int' to a string does not append to the string [-Wstring-plus-int]
{
"type": "Settings",
"items":
Expand Down
Loading