Skip to content

Commit eeedab0

Browse files
lsongsusexingzhang-suse
authored andcommitted
Fix: Persist the selected authentication secret in authSecret field
1 parent b287150 commit eeedab0

File tree

4 files changed

+78
-87
lines changed

4 files changed

+78
-87
lines changed
Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
import {
2-
RegistryTypeOptions,
3-
ScanIntervalOptions
4-
} from '@sbombastic-image-vulnerability-scanner/types/sbombastic-image-vulnerability-scanner';
1+
export const SCAN_INTERVALS = {
2+
ONE_HOUR: '1h',
3+
THREE_HOURS: '3h',
4+
SIX_HOURS: '6h',
5+
TWELVE_HOURS: '12h',
6+
TWENTY_FOUR_HOURS: '24h',
7+
MANUAL: '0s'
8+
};
59

6-
export const SCAN_INTERVAL_OPTIONS: { label: string; value: ScanIntervalOptions }[] = [
7-
{ label: 'Every 1 hour', value: '1h' },
8-
{ label: 'Every 3 hours', value: '3h' },
9-
{ label: 'Every 6 hours', value: '6h' },
10-
{ label: 'Every 12 hours', value: '12h' },
11-
{ label: 'Every 24 hours', value: '24h' },
12-
{ label: 'Manual Scan', value: '0s' } // backend disables auto-scan
10+
export const SCAN_INTERVAL_OPTIONS = [
11+
{ label: 'Every 1 hour', value: SCAN_INTERVALS.ONE_HOUR },
12+
{ label: 'Every 3 hours', value: SCAN_INTERVALS.THREE_HOURS },
13+
{ label: 'Every 6 hours', value: SCAN_INTERVALS.SIX_HOURS },
14+
{ label: 'Every 12 hours', value: SCAN_INTERVALS.TWELVE_HOURS },
15+
{ label: 'Every 24 hours', value: SCAN_INTERVALS.TWENTY_FOUR_HOURS },
16+
{ label: 'Manual Scan', value: SCAN_INTERVALS.MANUAL } // backend disables auto-scan
1317
];
1418

15-
export const REGISTRY_TYPE_OPTIONS: {label: string; value: RegistryTypeOptions }[] = [
16-
{ label: 'Docker Hub', value: 'dockerhub'}
19+
export const REGISTRY_TYPE = {
20+
DOCKERHUB: 'dockerhub'
21+
}
22+
23+
export const REGISTRY_DEFAULT_URI = {
24+
DOCKERHUB: "https://registry.hub.docker.com"
25+
};
26+
27+
export const REGISTRY_TYPE_OPTIONS: {label: string; value: string }[] = [
28+
{ label: 'Docker Hub', value: REGISTRY_TYPE.DOCKERHUB }
1729
];

pkg/sbombastic-image-vulnerability-scanner/edit/sbombastic.rancher.io.registry.vue

Lines changed: 49 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import LabeledSelect from '@shell/components/form/LabeledSelect';
1010
import Banner from '@components/Banner/Banner.vue';
1111
import { Checkbox } from '@components/Form/Checkbox';
1212
import { MANAGEMENT, NAMESPACE } from '@shell/config/types';
13-
import UnitInput from '@shell/components/form/UnitInput.vue';
1413
import {
14+
REGISTRY_DEFAULT_URI,
1515
REGISTRY_TYPE_OPTIONS,
16-
SCAN_INTERVAL_OPTIONS
16+
SCAN_INTERVAL_OPTIONS, SCAN_INTERVALS
1717
} from "@sbombastic-image-vulnerability-scanner/constants/scan-interval-options";
1818
1919
export default {
@@ -28,7 +28,6 @@ export default {
2828
SelectOrCreateAuthSecret,
2929
Banner,
3030
Checkbox,
31-
UnitInput,
3231
LabeledSelect
3332
},
3433
@@ -37,10 +36,7 @@ export default {
3736
data() {
3837
if (!this.value.spec) {
3938
this.value.spec = {
40-
insecure: true,
4139
authSecret: '',
42-
caBundle: '',
43-
type: {},
4440
uri: '',
4541
repositories: [],
4642
};
@@ -52,8 +48,6 @@ export default {
5248
}
5349
5450
return {
55-
selectedRegistryType: this.value.type || 'ecr',
56-
secretNamespace: this.$store.getters['defaultNamespace'],
5751
inStore: this.$store.getters['currentProduct'].inStore,
5852
errors: null,
5953
};
@@ -69,7 +63,8 @@ export default {
6963
return this.$store.getters['currentProduct']?.inStore || MANAGEMENT;
7064
},
7165
secretNamespace() {
72-
const tryNames = ['cattle-system', 'default'];
66+
const currentNamespace = this.value.metadata?.namespace? this.value.metadata.namespace: this.$store.getters['defaultNamespace'];
67+
const tryNames = [ currentNamespace, 'default'];
7368
7469
for ( const name of tryNames ) {
7570
if ( this.$store.getters['cluster/byId'](NAMESPACE, name) ) {
@@ -87,19 +82,19 @@ export default {
8782
REGISTRY_TYPE_OPTIONS: function() {
8883
return REGISTRY_TYPE_OPTIONS;
8984
},
90-
91-
useProxy: {
92-
get() {
93-
return !this.value.spec.insecure;
94-
},
95-
set(val) {
96-
this.value.spec.insecure = !val;
97-
}
98-
}
9985
},
100-
}
10186
87+
// Set default values for creating a new registry configuration
88+
created() {
89+
const spec = this.value.spec;
90+
91+
spec.scanInterval ??= SCAN_INTERVALS.THREE_HOURS;
92+
spec.uri ??= REGISTRY_DEFAULT_URI.DOCKERHUB;
93+
spec.uri = spec.uri || REGISTRY_DEFAULT_URI.DOCKERHUB;
94+
}
95+
}
10296
</script>
97+
10398
<template>
10499
<div class="filled-height">
105100
<Banner color="info">
@@ -142,63 +137,49 @@ export default {
142137
<LabeledInput
143138
:label="t('imageScanner.registries.configuration.cru.registry.uri.label')"
144139
v-model:value="value.spec.uri"
145-
:placeholderKey="t('imageScanner.registries.configuration.cru.registry.uri.placeholder')"
140+
:placeholder="t('imageScanner.registries.configuration.cru.registry.uri.placeholder')"
146141
/>
147142
</div>
148143
</div>
149-
150-
<Checkbox
151-
v-model:value="useProxy"
152-
class="mt-20 mb-10"
144+
<div class="registry-input-label mt-24 mb-0">
145+
{{ t('imageScanner.registries.configuration.cru.authentication.label') }}
146+
</div>
147+
<SelectOrCreateAuthSecret
148+
v-model:value="value.spec.authSecret"
153149
:mode="mode"
154-
:label="t('imageScanner.registries.configuration.cru.proxy.enable')"
155-
:tooltipKey="t('imageScanner.registries.configuration.cru.proxy.tooltip')"
156-
data-testid="registry-use-proxy"
150+
data-testid="registry-auth-secret"
151+
:register-before-hook="registerBeforeHook"
152+
:namespace="secretNamespace"
153+
:limit-to-namespace="true"
154+
:in-store="inStore"
155+
:allow-ssh=false
156+
generate-name="registry-auth-"
157+
:cache-secrets="true"
157158
/>
159+
<div class="registry-input-label mt-24">
160+
{{ t('imageScanner.registries.configuration.cru.scan.label') }}
161+
</div>
158162
159-
<div v-if="useProxy">
160-
<div class="registry-input-label mb-0">
161-
{{ t('imageScanner.registries.configuration.cru.authLabel') }}
162-
</div>
163-
<SelectOrCreateAuthSecret
164-
:value="value.spec.authSecret"
165-
:mode="mode"
166-
data-testid="registry-auth-secret"
167-
:register-before-hook="registerBeforeHook"
168-
:namespace="secretNamespace"
169-
:limit-to-namespace="true"
170-
:in-store="inStore"
171-
:allow-ssh=false
172-
generate-name="registry-auth-"
173-
:cache-secrets="true"
174-
@input="val => value.spec.authSecret = val"
175-
/>
176-
177-
<div class="registry-input-label mt-24">
178-
{{ t('imageScanner.registries.configuration.cru.scan.label') }}
163+
<div class="row">
164+
<div class="col span-6" >
165+
<LabeledSelect
166+
v-model:value="value.spec.repositories"
167+
:options="value.spec.repositories"
168+
:placeholder="t('imageScanner.registries.configuration.cru.scan.placeholder')"
169+
:label="t('imageScanner.registries.configuration.cru.scan.type')"
170+
/>
179171
</div>
180-
181-
<div class="row">
182-
<div class="col span-6" >
183-
<LabeledSelect
184-
v-model:value="value.spec.repositories"
185-
:label="t('imageScanner.registries.configuration.cru.scan.type')"
186-
>
187-
</LabeledSelect>
188-
</div>
189-
<div class="col span-3">
190-
<LabeledSelect
191-
v-model:value="value.spec.scanInterval"
192-
data-testid="registry-scan-interval-select"
193-
:options = "SCAN_INTERVAL_OPTIONS"
194-
option-key="value"
195-
option-label="label"
196-
value="0s"
197-
:label="t('imageScanner.registries.configuration.cru.scan.schedule.label')"
198-
/>
199-
</div>
172+
<div class="col span-3">
173+
<LabeledSelect
174+
v-model:value="value.spec.scanInterval"
175+
data-testid="registry-scan-interval-select"
176+
:options = "SCAN_INTERVAL_OPTIONS"
177+
option-key="value"
178+
option-label="label"
179+
:label="t('imageScanner.registries.configuration.cru.scan.schedule.label')"
180+
required
181+
/>
200182
</div>
201-
202183
</div>
203184
204185
</CruResource>

pkg/sbombastic-image-vulnerability-scanner/l10n/en-us.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ imageScanner:
3939
proxy:
4040
enable: Use the embedded proxy
4141
tooltip: "When enabled, Rancher routes all registry traffic through its secure proxy instead of direct connections."
42-
authLabel: Authentication
42+
authentication:
43+
label: Authentication
4344
scan:
4445
label: Scanning
4546
type: Repositories to scan
47+
placeholder: Type and press Enter ...
4648
schedule:
4749
label: Scan Interval
4850
scan: Start Scan

pkg/sbombastic-image-vulnerability-scanner/types/sbombastic-image-vulnerability-scanner.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,4 @@ export interface MetadataProperty {
1818
label?: string;
1919
value?: string;
2020
tags?: string[];
21-
}
22-
23-
export type ScanIntervalOptions = "1h" | "3h" | "6h" | "12h" | "24h" | "0s";
24-
25-
export type RegistryTypeOptions = "dockerhub" | "custom";
21+
}

0 commit comments

Comments
 (0)