Skip to content

Commit

Permalink
fix: add CLOUD_OPTIONS_PROVIDER_OVERRIDE constant for schema and prov…
Browse files Browse the repository at this point in the history
…ider-based option overrides

This change introduces the CLOUD_OPTIONS_PROVIDER_OVERRIDE constant, enabling option overrides based on schema and provider. It replaces the need for passing the customization using the example parameters.
  • Loading branch information
andre-code committed Jan 10, 2025
1 parent 625c102 commit de9d4ee
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,11 @@ function PasswordOptionItem({
);
}

const inputName =
option.filteredExamples?.length > 0
? option.filteredExamples[0]?.friendlyName
: option.friendlyName ?? option.name;
const tooltipContainerId = `option-is-secret-${option.name}`;
return (
<>
<label htmlFor={option.name}>
{inputName}{" "}
{option.friendlyName ?? option.name}{" "}
<div id={tooltipContainerId} className="d-inline">
<KeyFill className={cx("bi", "ms-1")} />
<ExclamationTriangleFill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,6 @@ export const CLOUD_OPTIONS_OVERRIDE = {
nextcloud_chunk_size: {
hide: 1,
},
pass: {
examples: [
{
value: "",
help: "For secure access to your Polybox WebDAV shares, we recommend using an application token instead of your account password. To create one, open Polybox, go to Settings > Security, and generate a new Application pass-code.",
provider: "personal",
friendlyName: "Token (or password)",
},
{
value: "",
help: "If there is a password for the folder, enter that in the password field. Otherwise, leave it blank",
provider: "shared",
friendlyName: "Password",
},
],
},
},
switchDrive: {
bearer_token: { friendlyName: "Bearer Token", advanced: true },
Expand All @@ -177,22 +161,6 @@ export const CLOUD_OPTIONS_OVERRIDE = {
nextcloud_chunk_size: {
hide: true,
},
pass: {
examples: [
{
value: "",
help: "For secure access to your SwitchDrive WebDAV shares, we recommend using an application token instead of your account password. To create one, open SwitchDrive, go to Settings > Security, and generate a new Application password",
provider: "personal",
friendlyName: "Token (or password)",
},
{
value: "",
help: "If there is a password for the folder, enter that in the password field. Otherwise, leave it blank",
provider: "shared",
friendlyName: "Password",
},
],
},
},
webdav: {
pass: {
Expand All @@ -206,6 +174,44 @@ export const CLOUD_OPTIONS_OVERRIDE = {
},
} as Record<string, Record<string, Partial<CloudStorageSchemaOptions>>>;

export const CLOUD_OPTIONS_PROVIDER_OVERRIDE = {
polybox: {
personal: {
pass: {
value: "",
friendlyName: "Token (or password)",
help: "For secure access to your SwitchDrive WebDAV shares, we recommend using an application token instead of your account password. To create one, open SwitchDrive, go to Settings > Security, and generate a new Application password",
},
},
shared: {
pass: {
value: "",
help: "If there is a password for the folder, enter that in the password field. Otherwise, leave it blank",
friendlyName: "Password",
},
},
},
switchDrive: {
personal: {
pass: {
value: "",
help: "For secure access to your SwitchDrive WebDAV shares, we recommend using an application token instead of your account password. To create one, open SwitchDrive, go to Settings > Security, and generate a new Application password",
friendlyName: "Token (or password)",
},
},
shared: {
pass: {
value: "",
help: "If there is a password for the folder, enter that in the password field. Otherwise, leave it blank",
friendlyName: "Password",
},
},
},
} as Record<
string,
Record<string, Record<string, Partial<CloudStorageSchemaOptions>>>
>;

export const CLOUD_STORAGE_MOUNT_PATH_HELP = {
s3: {
help:
Expand Down
18 changes: 14 additions & 4 deletions client/src/features/project/utils/projectCloudStorage.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { CloudStorageGetRead } from "../../projectsV2/api/storagesV2.api";
import { SessionCloudStorageV2 } from "../../sessionsV2/sessionsV2.types.ts";
import {
CLOUD_OPTIONS_OVERRIDE,
CLOUD_OPTIONS_PROVIDER_OVERRIDE,
CLOUD_STORAGE_MOUNT_PATH_HELP,
CLOUD_STORAGE_OVERRIDE,
CLOUD_STORAGE_PROVIDERS_SHORTLIST,
Expand Down Expand Up @@ -253,7 +254,7 @@ export function getSchemaOptions(
if (!storage) return;

const optionsOverridden = flags.override
? overrideOptions(storage.options, targetSchema)
? overrideOptions(storage.options, targetSchema, targetProvider)
: storage.options;

const optionsFiltered = optionsOverridden.filter((option) =>
Expand Down Expand Up @@ -365,11 +366,20 @@ export function storageDefinitionFromConfig(

function overrideOptions(
options: CloudStorageSchemaOptions[],
targetSchema: string
targetSchema: string,
targetProvider?: string
): CloudStorageSchemaOptions[] {
return options.map((option) => {
const override = CLOUD_OPTIONS_OVERRIDE[targetSchema]?.[option.name];
return override ? { ...option, ...override } : option;
const schemaOverrides =
CLOUD_OPTIONS_OVERRIDE[targetSchema]?.[option.name] || {};
const providerOverrides =
targetProvider &&
CLOUD_OPTIONS_PROVIDER_OVERRIDE[targetSchema]?.[targetProvider]?.[
option.name
];
return providerOverrides
? { ...option, ...schemaOverrides, ...providerOverrides }
: { ...option, ...schemaOverrides };
});
}

Expand Down

0 comments on commit de9d4ee

Please sign in to comment.