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

Improvements/update sources #1335

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
26 changes: 26 additions & 0 deletions src/components/models/base/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const OPERATING_SYSTEMS = ['windows', 'linux'] as const;
export const REGISTRY_TYPES = ['docker', 'harbor'] as const;
export const SUBMISSION_PARAM_TYPES = ['str', 'int', 'list', 'bool'] as const;
export const UPDATE_CHANNELS = ['stable', 'rc', 'beta', 'dev'] as const;
export const FETCH_METHODS = ['GET', 'POST', 'GIT'] as const;
export const SIGNATURE_DELIMITERS = {
new_line: '\n',
double_new_line: '\n\n',
Expand All @@ -28,6 +29,7 @@ export type RegistryType = (typeof REGISTRY_TYPES)[number];
export type SubmissionParamType = (typeof SUBMISSION_PARAM_TYPES)[number];
export type UpdateChannel = (typeof UPDATE_CHANNELS)[number];
export type SignatureDelimiter = keyof typeof SIGNATURE_DELIMITERS;
export type FetchMethod = (typeof FETCH_METHODS)[number];

// TODO There is too much invalidation to make the multi_type_param work that should be necessary
/**
Expand Down Expand Up @@ -231,18 +233,33 @@ export type UpdateSource = {
/** CA cert for source */
ca_cert?: string;

/** Processing configuration for source */
configuration?: { [key: string]: any };

/** Default classification used in absence of one defined in files from source */
default_classification: string;

/** Is this source enabled for periodic fetching? */
enabled: boolean;

/** Method of fetching data */
fetch_method: FetchMethod;

/** Branch to checkout from Git repository. */
git_branch?: string;

/** Headers */
headers: EnvironmentVariable[];

//** Ignore caching */
ignore_cache: boolean;

/** Name of source */
name: string;

/** Override signature classification with source */
override_classification: boolean;

/** Password used to authenticate with source */
password?: string;

Expand All @@ -264,6 +281,9 @@ export type UpdateSource = {
/** Synchronize signatures with remote source. Allows system to auto-disable signatures no longer found in source. */
sync: boolean;

/** Interval to update this specific source */
update_interval: number;

/** URI to source */
uri: string;

Expand Down Expand Up @@ -417,16 +437,22 @@ export type ServiceIndexed = Pick<

export const DEFAULT_SOURCE: UpdateSource = {
ca_cert: '',
configuration: {},
default_classification: '',
enabled: true,
fetch_method: 'GET',
headers: [],
ignore_cache: false,
name: '',
override_classification: false,
password: '',
pattern: '',
private_key: '',
proxy: '',
ssl_ignore_errors: false,
uri: '',
username: '',
update_interval: 1,
git_branch: '',
status: {
last_successful_update: '',
Expand Down
37 changes: 3 additions & 34 deletions src/components/routes/admin/service_detail/multi_type_config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import RemoveCircleOutlineOutlinedIcon from '@mui/icons-material/RemoveCircleOut
import { Autocomplete, Grid, IconButton, MenuItem, Select, TextField, Tooltip, useTheme } from '@mui/material';
import FormControl from '@mui/material/FormControl';
import type { Service } from 'components/models/base/service';
import JSONEditor from 'components/visual/JSONEditor';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import ReactJson from 'react-json-view';

type ServiceConfig = {
name: keyof Service['config'];
Expand Down Expand Up @@ -44,25 +44,6 @@ const WrappedMultiTypeConfig = ({
const [tempConfig, setTempConfig] = useState(DEFAULT_CONFIG);
const theme = useTheme();

const jsonTheme = {
base00: 'transparent', // Background
base01: theme.palette.grey[theme.palette.mode === 'dark' ? 800 : 300], // Add key title + Edit value background
base02: theme.palette.grey[theme.palette.mode === 'dark' ? 700 : 400], // Borders and DataType Background
base03: '#444', // Unused
base04: theme.palette.grey[theme.palette.mode === 'dark' ? 700 : 400], // Object size and Add key border
base05: theme.palette.grey[theme.palette.mode === 'dark' ? 400 : 600], // Undefined and Add key background
base06: '#444', // Unused
base07: theme.palette.text.primary, // Brace, Key and Borders
base08: theme.palette.text.secondary, // NaN
base09: theme.palette.mode === 'dark' ? theme.palette.warning.light : theme.palette.warning.dark, // Strings and Icons
base0A: theme.palette.grey[theme.palette.mode === 'dark' ? 300 : 800], // Null, Regex and edit text color
base0B: theme.palette.mode === 'dark' ? theme.palette.error.light : theme.palette.error.dark, // Float
base0C: theme.palette.mode === 'dark' ? theme.palette.secondary.light : theme.palette.secondary.dark, // Array Key
base0D: theme.palette.mode === 'dark' ? theme.palette.info.light : theme.palette.info.dark, // Date, function, expand icon
base0E: theme.palette.mode === 'dark' ? theme.palette.info.light : theme.palette.info.dark, // Boolean
base0F: theme.palette.mode === 'dark' ? theme.palette.error.light : theme.palette.error.dark // Integer
};

const detectConfigType = (cfg: ServiceConfig): ExtendedServiceConfig => {
if (cfg.value === null || cfg.value === undefined) {
return { ...cfg, value: '', type: 'str' };
Expand Down Expand Up @@ -162,14 +143,8 @@ const WrappedMultiTypeConfig = ({
</Select>
</FormControl>
) : parsedConfig.type === 'json' ? (
<ReactJson
name={false}
<JSONEditor
src={parsedConfig.value}
theme={jsonTheme}
enableClipboard={false}
groupArraysAfterLength={10}
displayDataTypes={false}
displayObjectSize={false}
onAdd={handleConfigUpdateJSON}
onDelete={handleConfigUpdateJSON}
onEdit={handleConfigUpdateJSON}
Expand Down Expand Up @@ -265,14 +240,8 @@ const WrappedMultiTypeConfig = ({
</Select>
</FormControl>
) : tempConfig.type === 'json' ? (
<ReactJson
name={false}
<JSONEditor
src={tempConfig.value}
theme={jsonTheme}
enableClipboard={false}
groupArraysAfterLength={10}
displayDataTypes={false}
displayObjectSize={false}
onAdd={handleConfigChangeJSON}
onDelete={handleConfigUpdateJSON}
onEdit={handleConfigChangeJSON}
Expand Down
18 changes: 9 additions & 9 deletions src/components/routes/admin/service_detail/reset_button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button, Tooltip, useTheme } from '@mui/material';
import RefreshIcon from '@mui/icons-material/Refresh';
import { IconButton, Tooltip, useTheme } from '@mui/material';
import type { DockerConfig, Service, UpdateConfig, UpdateSource } from 'components/models/base/service';
import React, { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -7,7 +8,7 @@ type Props = {
service: DockerConfig | Service | UpdateConfig | UpdateSource;
defaults: DockerConfig | Service | UpdateConfig | UpdateSource;
field: string | string[];
reset: () => void;
reset: (field: string) => void;
};

const WrappedResetButton = ({ service, defaults, field, reset }: Props) => {
Expand All @@ -27,21 +28,20 @@ const WrappedResetButton = ({ service, defaults, field, reset }: Props) => {
}
}, [defaults, field, getValue, service]);

return service && defaults && hasChanges() ? (
return service && defaults && hasChanges() && typeof field === 'string' ? (
<Tooltip title={t('reset.tooltip')}>
<Button
<IconButton
color="secondary"
size="small"
style={{ marginLeft: theme.spacing(1), padding: 0, lineHeight: '1rem' }}
variant="outlined"
style={{ marginLeft: theme.spacing(1), padding: 0 }}
onClick={event => {
event.stopPropagation();
event.preventDefault();
reset();
reset(field);
}}
>
{t('reset')}
</Button>
<RefreshIcon />
</IconButton>
</Tooltip>
) : null;
};
Expand Down
Loading