Skip to content

Commit

Permalink
Add bucket size to advanced options
Browse files Browse the repository at this point in the history
  • Loading branch information
foodprocessor committed Aug 30, 2024
1 parent 79f63e5 commit fc7a793
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/lib/cloudfuse/child_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,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,

Check failure on line 47 in src/lib/cloudfuse/child_process.h

View workflow job for this annotation

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

‘uint64_t’ does not name a type

Check failure on line 47 in src/lib/cloudfuse/child_process.h

View workflow job for this annotation

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

‘uint64_t’ does not name a type

Check failure on line 47 in src/lib/cloudfuse/child_process.h

View workflow job for this annotation

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

unknown type name 'uint64_t'

Check failure on line 47 in src/lib/cloudfuse/child_process.h

View workflow job for this annotation

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

unknown type name 'uint64_t'
const std::string passphrase);
#endif
std::string getMountDir();
std::string getFileCacheDir();
Expand Down
7 changes: 5 additions & 2 deletions src/lib/cloudfuse/child_process_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 177 in src/lib/cloudfuse/child_process_linux.cpp

View workflow job for this annotation

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

‘uint64_t’ does not name a type

Check failure on line 177 in src/lib/cloudfuse/child_process_linux.cpp

View workflow job for this annotation

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

unknown type name 'uint64_t'
{
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
8 changes: 5 additions & 3 deletions src/lib/cloudfuse/child_process_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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=" + 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 @@ bool Engine::settingsChanged()
{
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 @@ nx::sdk::Error Engine::validateMount()
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-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::sdk::Error Engine::validateMount()
}
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
15 changes: 15 additions & 0 deletions src/plugin/settings/settings_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ static const std::string kCredentialGroupBox = R"json(
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 +82,19 @@ static const std::string kAdvancedGroupBox = R"json(
"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 Down

0 comments on commit fc7a793

Please sign in to comment.