diff --git a/src/lib/cloudfuse/child_process.h b/src/lib/cloudfuse/child_process.h index 45c5565..59a0b3a 100644 --- a/src/lib/cloudfuse/child_process.h +++ b/src/lib/cloudfuse/child_process.h @@ -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, + const std::string passphrase); #endif std::string getMountDir(); std::string getFileCacheDir(); diff --git a/src/lib/cloudfuse/child_process_linux.cpp b/src/lib/cloudfuse/child_process_linux.cpp index fee8e9a..5e7d43e 100644 --- a/src/lib/cloudfuse/child_process_linux.cpp +++ b/src/lib/cloudfuse/child_process_linux.cpp @@ -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 } @@ -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; @@ -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(bucketNameEnv.c_str()), const_cast(endpointEnv.c_str()), NULL}; + const std::string bucketSizeEnv = "DISPLAY_CAPACITY=" + std::to_string(bucketSizeMb); + char *const envp[] = {const_cast(bucketNameEnv.c_str()), const_cast(endpointEnv.c_str()), + const_cast(bucketSizeEnv.c_str()), NULL}; return spawnProcess(argv, envp); } diff --git a/src/lib/cloudfuse/child_process_windows.cpp b/src/lib/cloudfuse/child_process_windows.cpp index 77fcf21..d27a86c 100644 --- a/src/lib/cloudfuse/child_process_windows.cpp +++ b/src/lib/cloudfuse/child_process_windows.cpp @@ -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 } @@ -262,7 +263,7 @@ 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; @@ -270,8 +271,9 @@ processReturn CloudfuseMngr::genS3Config(const std::string accessKeyId, const st 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, wchar_t>().from_bytes(argv); const std::wstring wenvp = std::wstring_convert, wchar_t>().from_bytes(envp); diff --git a/src/plugin/settings/engine.cpp b/src/plugin/settings/engine.cpp index 24beccc..ff6ff13 100644 --- a/src/plugin/settings/engine.cpp +++ b/src/plugin/settings/engine.cpp @@ -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; @@ -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]); + } + 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(); @@ -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) { diff --git a/src/plugin/settings/settings_model.h b/src/plugin/settings/settings_model.h index 7366b4e..0c60146 100644 --- a/src/plugin/settings/settings_model.h +++ b/src/plugin/settings/settings_model.h @@ -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", @@ -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";