Skip to content

Commit 3bb83a7

Browse files
lsongsusexingzhang-suse
authored andcommitted
Fix: Add DockerHub authentication support to Registry configuration add/edit page
1 parent fb8f8b2 commit 3bb83a7

File tree

1 file changed

+58
-23
lines changed

1 file changed

+58
-23
lines changed

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

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import NameNsDescription from '@shell/components/form/NameNsDescription';
66
import CruResource from '@shell/components/CruResource';
77
import SelectOrCreateAuthSecret from '@shell/components/form/SelectOrCreateAuthSecret';
88
import LabeledSelect from '@shell/components/form/LabeledSelect';
9-
import { Checkbox } from '@components/Form/Checkbox';
10-
import { MANAGEMENT, NAMESPACE } from '@shell/config/types';
9+
import { MANAGEMENT, SECRET } from '@shell/config/types';
1110
import {
1211
REGISTRY_TYPE_OPTIONS,
1312
SCAN_INTERVAL_OPTIONS, SCAN_INTERVALS
1413
} from "@pkg/constants/scan-interval-options";
1514
import { PRODUCT_NAME, PAGE } from "@pkg/types";
15+
import { SECRET_TYPES } from "@shell/config/secret";
1616
1717
export default {
1818
name: 'CruRegistry',
@@ -23,12 +23,17 @@ export default {
2323
NameNsDescription,
2424
CruResource,
2525
SelectOrCreateAuthSecret,
26-
Checkbox,
2726
LabeledSelect
2827
},
2928
3029
mixins: [CreateEditView],
3130
31+
async fetch() {
32+
this.allSecrets = await this.$store.dispatch(
33+
`${this.inStore}/findAll`,{type: SECRET}
34+
)
35+
},
36+
3237
data() {
3338
if (!this.value.spec) {
3439
this.value.spec = {
@@ -46,6 +51,8 @@ export default {
4651
return {
4752
inStore: this.$store.getters['currentProduct'].inStore,
4853
errors: null,
54+
allSecrets: null,
55+
filteredSecrets: null,
4956
PAGE,
5057
PRODUCT_NAME,
5158
};
@@ -55,17 +62,45 @@ export default {
5562
inStore() {
5663
return this.$store.getters['currentProduct']?.inStore || MANAGEMENT;
5764
},
58-
secretNamespace() {
59-
const currentNamespace = this.value.metadata?.namespace? this.value.metadata.namespace: this.$store.getters['defaultNamespace'];
60-
const tryNames = [ currentNamespace, 'default'];
6165
62-
for ( const name of tryNames ) {
63-
if ( this.$store.getters['cluster/byId'](NAMESPACE, name) ) {
64-
return name;
66+
/**
67+
* Filter secrets given their namespace and required secret type
68+
*
69+
* Convert secrets to list of options and supplement with custom entries
70+
*/
71+
options(){
72+
let filteredSecrets = [];
73+
74+
if(this.allSecrets){
75+
const currentNamespace = this.value.metadata?.namespace? this.value.metadata.namespace: "default";
76+
if(this.allSecrets) {
77+
// Filter secrets given their namespace
78+
filteredSecrets = this.allSecrets
79+
.filter((secret) => secret.metadata.namespace === currentNamespace)
80+
.filter((secret) =>
81+
SECRET_TYPES.DOCKER_JSON === secret._type
82+
);
6583
}
6684
}
6785
68-
return this.$store.getters[`${ this.inStore }/all`](NAMESPACE)[0]?.id;
86+
let out = filteredSecrets.map((x) => {
87+
const {
88+
metadata, id
89+
} = x;
90+
const label = metadata.name;
91+
92+
return {
93+
label,
94+
value: id.includes('/')?id.split('/')[1]:id,
95+
};
96+
});
97+
98+
out.unshift({
99+
label: this.t('generic.none'),
100+
value: "",
101+
});
102+
103+
return out;
69104
},
70105
71106
SCAN_INTERVAL_OPTIONS: function() {
@@ -101,6 +136,8 @@ export default {
101136
});
102137
},
103138
139+
update(){},
140+
104141
doneRoute() {
105142
console.log('doneRoute');
106143
return `c-cluster-${PRODUCT_NAME}-${PAGE.REGISTRIES}`;
@@ -163,21 +200,19 @@ export default {
163200
/>
164201
</div>
165202
</div>
166-
<div class="registry-input-label mt-24 mb-0">
203+
<div class="registry-input-label mt-24">
167204
{{ t('imageScanner.registries.configuration.cru.authentication.label') }}
168205
</div>
169-
<SelectOrCreateAuthSecret
170-
v-model: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="true"
176-
:in-store="inStore"
177-
:allow-ssh=false
178-
generate-name="registry-auth-"
179-
:cache-secrets="true"
180-
/>
206+
<div class="row">
207+
<div class="col span-6">
208+
<LabeledSelect
209+
v-model:value="value.spec.authSecret"
210+
data-testid="auth-secret-select"
211+
:mode="mode"
212+
:options="options"
213+
/>
214+
</div>
215+
</div>
181216
<div class="registry-input-label mt-24">
182217
{{ t('imageScanner.registries.configuration.cru.scan.label') }}
183218
</div>

0 commit comments

Comments
 (0)