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

Flag Advanced Settings #53

Merged
merged 9 commits into from
Aug 29, 2024
1 change: 1 addition & 0 deletions src/plugin/settings/device_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <algorithm>

#define NX_PRINT_PREFIX (this->logUtils.printPrefix)
#include <nx/kit/debug.h>
#include <nx/kit/utils.h>
#include <nx/sdk/helpers/active_setting_changed_response.h>
Expand Down
63 changes: 39 additions & 24 deletions src/plugin/settings/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "cloudfuse_helper.h"

// TOOD: get NX_PRINT_PREFIX working with non-member helper functions

Check failure on line 25 in src/plugin/settings/engine.cpp

View workflow job for this annotation

GitHub Actions / Check for spelling errors

TOOD ==> TODO
// #define NX_PRINT_PREFIX (this->logUtils.printPrefix)
jfantinhardesty marked this conversation as resolved.
Show resolved Hide resolved
#include <nx/kit/debug.h>
#include <nx/kit/ini_config.h>
#include <nx/sdk/helpers/active_setting_changed_response.h>
Expand Down Expand Up @@ -200,24 +202,27 @@
{
return true;
}
// endpoint
if (m_prevSettings[kEndpointUrlTextFieldId] != newValues[kEndpointUrlTextFieldId])
if (!credentialsOnly)
{
// if they're different, but both amount to the same thing, then there is no effective change
bool prevIsDefault = m_prevSettings[kEndpointUrlTextFieldId] == kDefaultEndpoint ||
m_prevSettings[kEndpointUrlTextFieldId] == "";
bool newIsDefault =
newValues[kEndpointUrlTextFieldId] == kDefaultEndpoint || newValues[kEndpointUrlTextFieldId] == "";
if (!prevIsDefault || !newIsDefault)
// endpoint
if (m_prevSettings[kEndpointUrlTextFieldId] != newValues[kEndpointUrlTextFieldId])
{
// if they're different, but both amount to the same thing, then there is no effective change
bool prevIsDefault = m_prevSettings[kEndpointUrlTextFieldId] == kDefaultEndpoint ||
m_prevSettings[kEndpointUrlTextFieldId] == "";
bool newIsDefault =
newValues[kEndpointUrlTextFieldId] == kDefaultEndpoint || newValues[kEndpointUrlTextFieldId] == "";
if (!prevIsDefault || !newIsDefault)
{
return true;
}
}
// bucket name
if (m_prevSettings[kBucketNameTextFieldId] != newValues[kBucketNameTextFieldId])
{
return true;
}
}
// bucket name
if (m_prevSettings[kBucketNameTextFieldId] != newValues[kBucketNameTextFieldId])
{
return true;
}
// nothing we care about changed
return false;
}
Expand Down Expand Up @@ -343,10 +348,15 @@
std::map<std::string, std::string> values = currentSettings();
std::string keyId = values[kKeyIdTextFieldId];
std::string secretKey = values[kSecretKeyPasswordFieldId];
std::string endpointUrl = values[kEndpointUrlTextFieldId];
std::string endpointRegion = "us-east-1";
std::string bucketName = values[kBucketNameTextFieldId]; // The default empty string will cause cloudfuse
// to select first available bucket
std::string endpointUrl = kDefaultEndpoint;
std::string bucketName = "";
if (!credentialsOnly)
{
endpointUrl = values[kEndpointUrlTextFieldId];
bucketName = values[kBucketNameTextFieldId]; // The default empty string will cause cloudfuse
// to select first available bucket
}
std::string mountDir = m_cfManager.getMountDir();
std::string fileCacheDir = m_cfManager.getFileCacheDir();
// Unmount before mounting
Expand Down Expand Up @@ -480,9 +490,7 @@
#endif
if (mountRet.errCode != 0)
{
std::string errorMessage = "Unable to launch mount with error: " + mountRet.output;
jfantinhardesty marked this conversation as resolved.
Show resolved Hide resolved
NX_PRINT << errorMessage;
return error(ErrorCode::internalError, errorMessage);
return error(ErrorCode::internalError, "Unable to launch mount with error: " + mountRet.output);
}

// Mount might not show up immediately, so wait for mount to appear
Expand All @@ -497,9 +505,7 @@

if (!m_cfManager.isMounted())
{
std::string errorMessage = "Cloudfuse was not able to successfully mount";
NX_PRINT << errorMessage;
return error(ErrorCode::internalError, errorMessage);
return error(ErrorCode::internalError, "Cloudfuse was not able to successfully mount");
}

return Error(ErrorCode::noError, nullptr);
Expand All @@ -519,15 +525,24 @@
{
NX_PRINT << "cloudfuse Engine::doGetSettingsOnActiveSettingChange";
std::string parseError;
Json::object model = Json::parse(activeSettingChangedAction->settingsModel(), parseError).object_items();
Json model = Json::parse(activeSettingChangedAction->settingsModel(), parseError);
if (parseError != "")
{
std::string errorMessage = "Failed to parse activeSettingChangedAction model JSON. Here's why: " + parseError;
NX_PRINT << errorMessage;
*outResult = error(ErrorCode::internalError, errorMessage);
return;
}

Json::object modelObject = model.object_items();

const std::string settingId(activeSettingChangedAction->activeSettingName());

std::map<std::string, std::string> values = toStdMap(shareToPtr(activeSettingChangedAction->settingsValues()));

const auto settingsResponse = makePtr<SettingsResponse>();
settingsResponse->setValues(makePtr<StringMap>(values));
settingsResponse->setModel(makePtr<String>(Json(model).dump()));
settingsResponse->setModel(makePtr<String>(Json(modelObject).dump()));

const nx::sdk::Ptr<nx::sdk::ActionResponse> actionResponse =
generateActionResponse(settingId, activeSettingChangedAction->params());
Expand Down
94 changes: 54 additions & 40 deletions src/plugin/settings/settings_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,48 +45,22 @@
static const std::string kEnginePluginSideSetting = "testPluginSideSpinBox";
static const std::string kEnginePluginSideSettingValue = "42";
static const std::string kAlternativeSettingsModel = /*suppress newline*/ 1 + (const char *)R"json(")json";
static const std::string kRegularSettingsModelPart1 = /*suppress newline*/ 1 + R"json()json";

Check warning on line 48 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 48 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 48 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 48 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 48 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 48 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 48 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 48 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 48 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 48 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]
static const std::string kEnglishCitiesSettingsModelPart = /*suppress newline*/ 1 + R"json()json";

Check warning on line 49 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 49 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 49 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 49 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 49 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 49 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 49 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 49 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 49 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 49 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]
static const std::string kGermanCitiesSettingsModelPart = /*suppress newline*/ 1 + R"json()json";

Check warning on line 50 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 50 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 50 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 50 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 50 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 50 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 50 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 50 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 50 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 50 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]
static const std::string kRegularSettingsModelPart2 = /*suppress newline*/ 1 + R"json(")json";

Check warning on line 51 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 51 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 51 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 51 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 51 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 51 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 51 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 51 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 51 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 51 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]
// ------------------------------------------------------------------------------------------------

// status
static const std::string kStatusBannerId = "connectionStatus";
static const std::string kStatusSuccess = R"json(
{
"type": "Banner",
"name": ")json" + kStatusBannerId +
R"json(",
"icon": "info",
"text": "Cloud storage connected successfully!"
}
)json";

static const std::string kStatusFailure = R"json(
{
"type": "Banner",
"name": ")json" + kStatusBannerId +
R"json(",
"icon": "warning",
"text": "Cloud storage connection failed!"
}
)json";
// Enable this flag hide all but the credentials section
// NOTE: enabling this will prevent the user from changing the default endpoint (kDefaultEndpoint)
// Only set this flag true if you want to tie your users to a specific cloud storage endpoint
static const bool credentialsOnly = false;

// credentials
static const std::string kKeyIdTextFieldId = "keyId";
static const std::string kSecretKeyPasswordFieldId = "secretKey";
static const std::string kCheckCredentialsButtonId = "checkCredentialsButton";
// advanced
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";
// top-level settings model
static const std::string kEngineSettingsModel = /*suppress newline*/ 1 + R"json(
{
"type": "Settings",
"items":
[
static const std::string kCredentialGroupBox = R"json(
{
"type": "GroupBox",
"caption": "Credentials",
Expand All @@ -95,7 +69,7 @@
{
"type": "TextField",
"name": ")json" + kKeyIdTextFieldId +
R"json(",
R"json(",
"caption": "Access Key ID",
"description": "Cloud bucket access key ID",
"defaultValue": "",
Expand All @@ -105,52 +79,92 @@
{
"type": "PasswordField",
"name": ")json" + kSecretKeyPasswordFieldId +
R"json(",
R"json(",
"caption": "Secret Key",
"description": "Cloud bucket secret key",
"defaultValue": "",
"validationErrorMessage": "Secret key must be 32 or 40 alphanumeric-plus-slash characters",
"validationRegex": "^[A-Za-z0-9\/+=]{32,128}$"
}
]
},
})json";

// advanced
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 kAdvancedGroupBox = R"json(
{
"type": "GroupBox",
"caption": ")json" + kAdvancedSettingsGroupBoxCaption +
R"json(",
R"json(",
"items":
[
{
"type": "TextField",
"name": ")json" + kEndpointUrlTextFieldId +
R"json(",
R"json(",
"caption": "Endpoint URL",
"description": "Set a different endpoint (different region or service)",
"defaultValue": ")json" + kDefaultEndpoint +
R"json(",
R"json(",
"validationErrorMessage": "Endpoint must be a URL (begin with 'http[s]://').",
"validationRegex": "(^$)|(^https?:\/\/.+$)",
"validationRegexFlags": "i"
},
{
"type": "TextField",
"name": ")json" + kBucketNameTextFieldId +
R"json(",
R"json(",
"caption": "Bucket Name",
"description": "Specify a bucket name (leave empty to let the system automatically detect your bucket)",
"defaultValue": "",
"validationErrorMessage": "Bucket name can only contain lowercase letters, numbers, dashes, and dots.",
"validationRegex": "^[-.a-z0-9]*$"
}
]
},
})json";

static const std::string kPluginWebsiteLink = R"json(
{
"type": "Link",
"caption": "Plugin Website",
"url": "https://github.com/Seagate/nx-lyve-cloud-plugin"
}
})json";

// gather settings items together
static const std::string kSettingsItems =
kCredentialGroupBox + (credentialsOnly ? "" : ("," + kAdvancedGroupBox + "," + kPluginWebsiteLink));

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

Check warning on line 140 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 140 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 140 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 140 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 140 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 140 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 140 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 140 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 140 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 140 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]
{
"type": "Settings",
"items":
[)json" + kSettingsItems + R"json(
]
}
)json";

// status
static const std::string kStatusBannerId = "connectionStatus";
static const std::string kStatusSuccess = R"json(
{
"type": "Banner",
"name": ")json" + kStatusBannerId +
R"json(",
"icon": "info",
"text": "Cloud storage connected successfully!"
}
)json";
static const std::string kStatusFailure = R"json(
{
"type": "Banner",
"name": ")json" + kStatusBannerId +
R"json(",
"icon": "warning",
"text": "Cloud storage connection failed!"
}
)json";

} // namespace settings