Skip to content

Commit 31ba4e9

Browse files
lsongsusexingzhang-suse
authored andcommitted
create(edit) registries configuration
1 parent 7a74fd6 commit 31ba4e9

File tree

4 files changed

+523
-1
lines changed

4 files changed

+523
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { IPlugin } from "@shell/core/types";
22
import {
33
PRODUCT_NAME,
44
PAGE,
5+
RESOURCE
56
} from "@sbombastic-image-vulnerability-scanner/types";
67

78
export function init($plugin: IPlugin, store: any) {
@@ -65,9 +66,10 @@ export function init($plugin: IPlugin, store: any) {
6566
});
6667

6768
basicType([
68-
PAGE.REGISTRIES,
6969
PAGE.IMAGE_OVERVIEW,
7070
PAGE.VULNERABILITY_OVERVIEW,
7171
]);
7272

73+
basicType([PAGE.REGISTRIES, RESOURCE.REGISTRY], 'Advanced');
74+
7375
}
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
<script>
2+
import CreateEditView from '@shell/mixins/create-edit-view';
3+
import Footer from '@shell/components/form/Footer';
4+
import { LabeledInput } from '@components/Form/LabeledInput';
5+
import { RadioGroup } from '@components/Form/Radio';
6+
import NameNsDescription from '@shell/components/form/NameNsDescription';
7+
import CruResource from '@shell/components/CruResource';
8+
import SelectOrCreateAuthSecret from '@shell/components/form/SelectOrCreateAuthSecret';
9+
import LabeledSelect from '@shell/components/form/LabeledSelect';
10+
import Banner from '@components/Banner/Banner.vue';
11+
import { Checkbox } from '@components/Form/Checkbox';
12+
import { MANAGEMENT, NAMESPACE, CLUSTER_REPO_TYPES } from '@shell/config/types';
13+
import UnitInput from '@shell/components/form/UnitInput.vue';
14+
import {ref} from "vue";
15+
16+
export default {
17+
name: 'CruRegistry',
18+
19+
components: {
20+
Footer,
21+
RadioGroup,
22+
LabeledInput,
23+
NameNsDescription,
24+
CruResource,
25+
SelectOrCreateAuthSecret,
26+
Banner,
27+
Checkbox,
28+
UnitInput,
29+
LabeledSelect
30+
},
31+
32+
mixins: [CreateEditView],
33+
34+
data() {
35+
36+
if (!this.value.spec) {
37+
this.value.spec = {
38+
insecure: true,
39+
authSecret: '',
40+
caBundle: '',
41+
type: {},
42+
uri: '',
43+
repositories: [],
44+
};
45+
}
46+
if (!this.value.status){
47+
this.value.status = {
48+
conditions: [],
49+
};
50+
}
51+
52+
console.log('this.value after:',this.value);
53+
54+
return {
55+
selectedRegistryType: this.value.type || 'ecr',
56+
secretNamespace: this.$store.getters['defaultNamespace'],
57+
inStore: this.$store.getters['currentProduct'].inStore,
58+
errors: null,
59+
};
60+
},
61+
62+
computed: {
63+
registryTypeOptions(){
64+
return [
65+
{
66+
label: this.t('imageScanner.registries.configuration.cru.registry.type.ecr'),
67+
value: 'ecr',
68+
},
69+
{
70+
label: this.t('imageScanner.registries.configuration.cru.registry.type.azure'),
71+
value: 'azure',
72+
},
73+
];
74+
},
75+
76+
namespace(){
77+
console.log('this.value.spec.type:',this.value.spec.type);
78+
return this.value.spec.type === 'ecr'?"kube-system":""
79+
},
80+
81+
inStore() {
82+
return this.$store.getters['currentProduct']?.inStore || MANAGEMENT;
83+
},
84+
secretNamespace() {
85+
const tryNames = ['cattle-system', 'default'];
86+
87+
for ( const name of tryNames ) {
88+
if ( this.$store.getters['cluster/byId'](NAMESPACE, name) ) {
89+
return name;
90+
}
91+
}
92+
93+
return this.$store.getters[`${ this.inStore }/all`](NAMESPACE)[0]?.id;
94+
},
95+
96+
useProxy: {
97+
get() {
98+
return !this.value.spec.insecure;
99+
},
100+
set(val) {
101+
this.value.spec.insecure = !val;
102+
}
103+
}
104+
},
105+
}
106+
107+
</script>
108+
<template>
109+
<div class="filled-height">
110+
<Banner color="info">
111+
{{t('imageScanner.registries.configuration.cru.description')}}
112+
</Banner>
113+
<CruResource
114+
:done-route="doneRoute"
115+
:mode="mode"
116+
:resource="value"
117+
:subtypes="[]"
118+
:validation-passed="true"
119+
:errors="errors"
120+
@error="(e) => (errors = e)"
121+
@finish="save"
122+
@cancel="done"
123+
>
124+
<NameNsDescription
125+
:value="value"
126+
:mode="mode"
127+
:namespaced="isNamespaced"
128+
@update:value="$emit('input', $event)"
129+
/>
130+
131+
<div class="registry-input-label">
132+
{{ t('imageScanner.registries.configuration.cru.registry.label') }}
133+
</div>
134+
135+
<div class="row">
136+
<div class="col span-6" >
137+
<LabeledSelect
138+
v-model:value="value.spec.type"
139+
data-testid="registry-type-select"
140+
:label="t('imageScanner.registries.configuration.cru.registry.type.label')"
141+
:options="registryTypeOptions"
142+
:placeholder="t('imageScanner.registry.configuration.cru.registry.type.placeholder')"
143+
required
144+
/>
145+
</div>
146+
<div class="col span-3">
147+
<LabeledInput
148+
:label="t('imageScanner.registries.configuration.cru.registry.namespace.label')"
149+
:value="namespace"
150+
:placeholderKey="t('imageScanner.registries.configuration.cru.registry.namespace.placeholder')"
151+
disabled=true
152+
/>
153+
</div>
154+
</div>
155+
156+
<Checkbox
157+
v-model:value="useProxy"
158+
class="mt-20 mb-10"
159+
:mode="mode"
160+
:label="t('imageScanner.registries.configuration.cru.proxy.enable')"
161+
:tooltipKey="t('imageScanner.registries.configuration.cru.proxy.tooltip')"
162+
data-testid="registry-use-proxy"
163+
/>
164+
165+
<div v-if="useProxy">
166+
<div class="registry-input-label mb-0">
167+
{{ t('imageScanner.registries.configuration.cru.authLabel') }}
168+
</div>
169+
<SelectOrCreateAuthSecret
170+
:value="value.spec.authSecret"
171+
:mode="mode"
172+
data-testid="registry-auth-secret"
173+
:register-before-hook="registerBeforeHook"
174+
:namespace="secretNamespace"
175+
:limit-to-namespace="false"
176+
:in-store="inStore"
177+
:allow-ssh=false
178+
generate-name="registry-auth-"
179+
:cache-secrets="true"
180+
@input="val => value.spec.authSecret = val"
181+
/>
182+
183+
<div class="registry-input-label mt-24">
184+
{{ t('imageScanner.registries.configuration.cru.scan.label') }}
185+
</div>
186+
187+
<div class="row">
188+
<div class="col span-6" >
189+
<LabeledSelect
190+
v-model:value="value.spec.repositories"
191+
:label="t('imageScanner.registries.configuration.cru.scan.type')"
192+
>
193+
</LabeledSelect>
194+
</div>
195+
<div class="col span-3">
196+
<UnitInput
197+
v-model:value="unitInput"
198+
:label="t('imageScanner.registries.configuration.cru.scan.schedule.label')"
199+
:mode="mode"
200+
min="0"
201+
:suffix="t('unit.hour', { count: 3 })"
202+
:placeholder="t('imageScanner.registries.configuration.cru.scan.schedule.placeholder', { hours: 3 })"
203+
@update:value="updateRefreshInterval($event)"
204+
/>
205+
</div>
206+
</div>
207+
208+
</div>
209+
210+
</CruResource>
211+
</div>
212+
</template>
213+
214+
<style lang="scss" scoped>
215+
.registry-input-label {
216+
margin-bottom: 16px;
217+
font-size: 16px;
218+
line-height: 20px;
219+
font-weight: 500;
220+
font-family: 'Lato', sans-serif;
221+
color: #141419;
222+
display: block;
223+
}
224+
.mt-24 {
225+
margin-top: 24px;
226+
}
227+
</style>

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
product:
2+
imageScanner: Image Vulnerability Scanner
13
imageScanner:
24
registries:
35
title: Registries configuration
@@ -20,6 +22,29 @@ imageScanner:
2022
progress: Progress
2123
prevScan: Previous scan
2224
configuration:
25+
cru:
26+
description: Start from scratch by using the steps below or go back and clone an existing configuration
27+
registry:
28+
label: Registry
29+
type:
30+
label: Type
31+
ecr: Amazon ECR Registry
32+
azure: Azure Container Registry
33+
custom: Custom Registry
34+
placeholder: Choose a registry type
35+
namespace:
36+
label: Namespace
37+
placeholder: "Choose the registry first"
38+
proxy:
39+
enable: Use the embedded proxy
40+
tooltip: "When enabled, Rancher routes all registry traffic through its secure proxy instead of direct connections."
41+
authLabel: Authentication
42+
scan:
43+
label: Scanning
44+
type: Repositories to scan
45+
schedule:
46+
label: Refresh Interval
47+
placeholder: 'default: {hours}'
2348
scan: Start Scan
2449
meta:
2550
registry: Registry
@@ -77,3 +102,6 @@ imageScanner:
77102
general:
78103
refresh: Refresh data
79104
ago: ago
105+
106+
typeLabel:
107+
sbombastic.rancher.io.registry: Registries configuration

0 commit comments

Comments
 (0)