Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import {
RegistryTypeOptions,
ScanIntervalOptions
} from '@sbombastic-image-vulnerability-scanner/types/sbombastic-image-vulnerability-scanner';
export const SCAN_INTERVALS = {
ONE_HOUR: '1h',
THREE_HOURS: '3h',
SIX_HOURS: '6h',
TWELVE_HOURS: '12h',
TWENTY_FOUR_HOURS: '24h',
MANUAL: '0s'
};

export const SCAN_INTERVAL_OPTIONS: { label: string; value: ScanIntervalOptions }[] = [
{ label: 'Every 1 hour', value: '1h' },
{ label: 'Every 3 hours', value: '3h' },
{ label: 'Every 6 hours', value: '6h' },
{ label: 'Every 12 hours', value: '12h' },
{ label: 'Every 24 hours', value: '24h' },
{ label: 'Manual Scan', value: '0s' } // backend disables auto-scan
export const SCAN_INTERVAL_OPTIONS = [
{ label: 'Every 1 hour', value: SCAN_INTERVALS.ONE_HOUR },
{ label: 'Every 3 hours', value: SCAN_INTERVALS.THREE_HOURS },
{ label: 'Every 6 hours', value: SCAN_INTERVALS.SIX_HOURS },
{ label: 'Every 12 hours', value: SCAN_INTERVALS.TWELVE_HOURS },
{ label: 'Every 24 hours', value: SCAN_INTERVALS.TWENTY_FOUR_HOURS },
{ label: 'Manual Scan', value: SCAN_INTERVALS.MANUAL } // backend disables auto-scan
];

export const REGISTRY_TYPE_OPTIONS: {label: string; value: RegistryTypeOptions }[] = [
{ label: 'Docker Hub', value: 'dockerhub'}
export const REGISTRY_TYPE = {
DOCKERHUB: 'dockerhub'
}

export const REGISTRY_DEFAULT_URI = {
DOCKERHUB: "https://registry.hub.docker.com"
};

export const REGISTRY_TYPE_OPTIONS: {label: string; value: string }[] = [
{ label: 'Docker Hub', value: REGISTRY_TYPE.DOCKERHUB }
];
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import LabeledSelect from '@shell/components/form/LabeledSelect';
import Banner from '@components/Banner/Banner.vue';
import { Checkbox } from '@components/Form/Checkbox';
import { MANAGEMENT, NAMESPACE } from '@shell/config/types';
import UnitInput from '@shell/components/form/UnitInput.vue';
import {
REGISTRY_DEFAULT_URI,
REGISTRY_TYPE_OPTIONS,
SCAN_INTERVAL_OPTIONS
SCAN_INTERVAL_OPTIONS, SCAN_INTERVALS
} from "@sbombastic-image-vulnerability-scanner/constants/scan-interval-options";

export default {
Expand All @@ -28,7 +28,6 @@ export default {
SelectOrCreateAuthSecret,
Banner,
Checkbox,
UnitInput,
LabeledSelect
},

Expand All @@ -37,10 +36,7 @@ export default {
data() {
if (!this.value.spec) {
this.value.spec = {
insecure: true,
authSecret: '',
caBundle: '',
type: {},
uri: '',
repositories: [],
};
Expand All @@ -52,8 +48,6 @@ export default {
}

return {
selectedRegistryType: this.value.type || 'ecr',
secretNamespace: this.$store.getters['defaultNamespace'],
inStore: this.$store.getters['currentProduct'].inStore,
errors: null,
};
Expand All @@ -69,7 +63,8 @@ export default {
return this.$store.getters['currentProduct']?.inStore || MANAGEMENT;
},
secretNamespace() {
const tryNames = ['cattle-system', 'default'];
const currentNamespace = this.value.metadata?.namespace? this.value.metadata.namespace: this.$store.getters['defaultNamespace'];
const tryNames = [ currentNamespace, 'default'];

for ( const name of tryNames ) {
if ( this.$store.getters['cluster/byId'](NAMESPACE, name) ) {
Expand All @@ -87,19 +82,19 @@ export default {
REGISTRY_TYPE_OPTIONS: function() {
return REGISTRY_TYPE_OPTIONS;
},

useProxy: {
get() {
return !this.value.spec.insecure;
},
set(val) {
this.value.spec.insecure = !val;
}
}
},
}

// Set default values for creating a new registry configuration
created() {
const spec = this.value.spec;

spec.scanInterval ??= SCAN_INTERVALS.THREE_HOURS;
spec.uri ??= REGISTRY_DEFAULT_URI.DOCKERHUB;
spec.uri = spec.uri || REGISTRY_DEFAULT_URI.DOCKERHUB;
}
}
</script>

<template>
<div class="filled-height">
<Banner color="info">
Expand Down Expand Up @@ -142,63 +137,49 @@ export default {
<LabeledInput
:label="t('imageScanner.registries.configuration.cru.registry.uri.label')"
v-model:value="value.spec.uri"
:placeholderKey="t('imageScanner.registries.configuration.cru.registry.uri.placeholder')"
:placeholder="t('imageScanner.registries.configuration.cru.registry.uri.placeholder')"
/>
</div>
</div>

<Checkbox
v-model:value="useProxy"
class="mt-20 mb-10"
<div class="registry-input-label mt-24 mb-0">
{{ t('imageScanner.registries.configuration.cru.authentication.label') }}
</div>
<SelectOrCreateAuthSecret
v-model:value="value.spec.authSecret"
:mode="mode"
:label="t('imageScanner.registries.configuration.cru.proxy.enable')"
:tooltipKey="t('imageScanner.registries.configuration.cru.proxy.tooltip')"
data-testid="registry-use-proxy"
data-testid="registry-auth-secret"
:register-before-hook="registerBeforeHook"
:namespace="secretNamespace"
:limit-to-namespace="true"
:in-store="inStore"
:allow-ssh=false
generate-name="registry-auth-"
:cache-secrets="true"
/>
<div class="registry-input-label mt-24">
{{ t('imageScanner.registries.configuration.cru.scan.label') }}
</div>

<div v-if="useProxy">
<div class="registry-input-label mb-0">
{{ t('imageScanner.registries.configuration.cru.authLabel') }}
</div>
<SelectOrCreateAuthSecret
:value="value.spec.authSecret"
:mode="mode"
data-testid="registry-auth-secret"
:register-before-hook="registerBeforeHook"
:namespace="secretNamespace"
:limit-to-namespace="true"
:in-store="inStore"
:allow-ssh=false
generate-name="registry-auth-"
:cache-secrets="true"
@input="val => value.spec.authSecret = val"
/>

<div class="registry-input-label mt-24">
{{ t('imageScanner.registries.configuration.cru.scan.label') }}
<div class="row">
<div class="col span-6" >
<LabeledSelect
v-model:value="value.spec.repositories"
:options="value.spec.repositories"
:placeholder="t('imageScanner.registries.configuration.cru.scan.placeholder')"
:label="t('imageScanner.registries.configuration.cru.scan.type')"
/>
</div>

<div class="row">
<div class="col span-6" >
<LabeledSelect
v-model:value="value.spec.repositories"
:label="t('imageScanner.registries.configuration.cru.scan.type')"
>
</LabeledSelect>
</div>
<div class="col span-3">
<LabeledSelect
v-model:value="value.spec.scanInterval"
data-testid="registry-scan-interval-select"
:options = "SCAN_INTERVAL_OPTIONS"
option-key="value"
option-label="label"
value="0s"
:label="t('imageScanner.registries.configuration.cru.scan.schedule.label')"
/>
</div>
<div class="col span-3">
<LabeledSelect
v-model:value="value.spec.scanInterval"
data-testid="registry-scan-interval-select"
:options = "SCAN_INTERVAL_OPTIONS"
option-key="value"
option-label="label"
:label="t('imageScanner.registries.configuration.cru.scan.schedule.label')"
required
/>
</div>

</div>

</CruResource>
Expand Down
4 changes: 3 additions & 1 deletion pkg/sbombastic-image-vulnerability-scanner/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ imageScanner:
proxy:
enable: Use the embedded proxy
tooltip: "When enabled, Rancher routes all registry traffic through its secure proxy instead of direct connections."
authLabel: Authentication
authentication:
label: Authentication
scan:
label: Scanning
type: Repositories to scan
placeholder: Type and press Enter ...
schedule:
label: Scan Interval
scan: Start Scan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ export interface MetadataProperty {
label?: string;
value?: string;
tags?: string[];
}

export type ScanIntervalOptions = "1h" | "3h" | "6h" | "12h" | "24h" | "0s";

export type RegistryTypeOptions = "dockerhub" | "custom";
}