Skip to content

Commit 725b053

Browse files
committed
move long name resolution to partnerStore
1 parent 8450982 commit 725b053

File tree

7 files changed

+103
-92
lines changed

7 files changed

+103
-92
lines changed

src/App.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import PrimaryNavigation from './components/PrimaryNavigation.vue';
1919
import NotificationBannerModule from './components/NotificationBannerModule.vue';
2020
import FooterModule from './components/FooterModule.vue';
2121
import NotFound from './views/NotFound.vue';
22-
import { usePartnerStore } from '@/stores/partners';
2322
import { useSeoMeta } from '@unhead/vue';
2423
2524
export default {
@@ -35,7 +34,6 @@ export default {
3534
}
3635
},
3736
beforeMount() {
38-
usePartnerStore().populatePartnerShortLongNameMap();
3937
useSeoMeta({
4038
title: 'CVE: Common Vulnerabilities and Exposures',
4139
description: 'At cve.org, we provide the authoritative '

src/components/AdpVulnerabilityEnrichment.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<p class="cve-help-text">
3333
This container includes required additional information provided by the CVE Program for this vulnerability.
3434
</p>
35-
</div>
35+
</div>
3636
<div v-if="roleName === 'adp'">
3737
<p class="cve-help-text">SSVC and KEV, plus CVSS and CWE if not provided by the CNA.</p>
3838
</div>
@@ -84,7 +84,7 @@
8484
</ul>
8585
</div>
8686
</div>
87-
</div>
87+
</div>
8888
<div v-if="roleName === 'cna'" id="cve-cna-container-start">
8989
<div id="cve-record-general-info-container" class="content">
9090
<nav id="cve-record-assginer-dates-container" class="level mb-0">
@@ -152,7 +152,7 @@
152152
</div>
153153
<div id="cve-cvsss" v-if="cvsss.length > 0" class="mt-5">
154154
<h4 class="title mb-0">CVSS <span class="tag">{{ cvsss.length }} Total</span></h4>
155-
155+
156156
<div class="cve-learn-more mb-3">
157157
<router-link to="/CVERecord/UserGuide/#cve-cvss" class="cve-learn-more-link">Learn more</router-link>
158158
</div>
@@ -194,23 +194,24 @@
194194
</ul>
195195
</div>
196196

197-
<CveRecordReferences id="cve-references"
197+
<CveRecordReferences id="cve-references"
198198
v-if="cveFieldList.references.length > 0" :references="cveFieldList.references"
199199
>
200200
</CveRecordReferences>
201201
</div>
202202

203-
<CveRecordReferences id="cve-program-references"
203+
<CveRecordReferences id="cve-program-references"
204204
v-if="cveProgramReferences.length > 0" :references="cveProgramReferences"
205205
>
206206
</CveRecordReferences>
207207
</div>
208208
</div>
209209
</div>
210210
</template>
211-
211+
212212
<script>
213213
import { usecveRecordStore } from '@/stores/cveRecord.ts';
214+
import { usePartnerStore } from '@/stores/partners';
214215
import { useGenericGlobalsStore } from '@/stores/genericGlobals';
215216
import ProductStatus from '@/components/ProductStatus.vue';
216217
import CveRecordReferences from './CveRecordReferences.vue';
@@ -258,6 +259,7 @@ export default {
258259
dateUpdated: '',
259260
cveServicesBaseUrl: useGenericGlobalsStore().currentServicesUrl,
260261
usecveRecordStore: usecveRecordStore(),
262+
partnerStore: usePartnerStore(),
261263
}
262264
},
263265
methods: {
@@ -301,7 +303,7 @@ export default {
301303
302304
if (metricObj[cvssVersion]?.version) cvss.version = metricObj[cvssVersion].version;
303305
if (metricObj[cvssVersion]?.vectorString) cvss.vectorString = metricObj[cvssVersion]?.vectorString;
304-
306+
305307
this.cvsss.push(cvss);
306308
}
307309
});
@@ -407,14 +409,14 @@ export default {
407409
}
408410
},
409411
getCveProgramReferences(){
410-
if (this.containerObject.providerMetadata.shortName?.toLowerCase() !== usecveRecordStore().cveProgramShortName) return;
412+
if (this.containerObject.providerMetadata.shortName?.toLowerCase() !== this.partnerStore.cveProgramShortName) return;
411413
this.cveProgramReferences = usecveRecordStore().getReferences(this.containerObject.references);
412414
},
413415
getUpdatedDate() {
414416
if(this.containerObject.providerMetadata?.dateUpdated) {
415417
this.dateUpdated = this.getDate(this.containerObject.providerMetadata?.dateUpdated);
416418
}
417-
419+
418420
},
419421
getDate(dateTime) {
420422
const [date] = dateTime.split('T');
@@ -430,7 +432,7 @@ export default {
430432
</script>
431433
432434
<style lang="scss">
433-
@import '@/assets/style/globals.scss';
435+
@import '@/assets/style/globals.scss';
434436
</style>
435437
436438
<!-- Add "scoped" attribute to limit CSS to this component only -->
@@ -442,7 +444,7 @@ export default {
442444
cursor: pointer;
443445
width: 100%;
444446
}
445-
447+
446448
.cve-container-accordion-panel {
447449
border: 1px solid $theme-color-primary-darker;
448450
}

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { library } from '@fortawesome/fontawesome-svg-core';
1818
import { fab } from '@fortawesome/free-brands-svg-icons';
1919
import {
2020
faAngleDoubleLeft, faAngleDoubleRight, faAngleLeft, faAngleRight, faArrowRight, faBlog, faBook, faCaretDown, faCaretUp, faInfoCircle, faCheckCircle,
21-
faExclamationCircle, faFileCode, faTriangleExclamation, faUpRightFromSquare, faLightbulb, faLink, faMinus, faPassport, faPlus, faPodcast, faIdCard,
21+
faExclamationCircle, faFileCode, faTriangleExclamation, faUpRightFromSquare, faLightbulb, faLink, faMinus, faPassport, faPlus, faPodcast, faIdCard,
2222
faSearch, faHandshake, faUsersCog, faLaptopCode, faPoll, faTimes, faToolbox, faSitemap, faUser, faUserShield, faBullhorn, faWindowMaximize,
2323
} from '@fortawesome/free-solid-svg-icons';
2424
import { faArrowAltCircleRight, faClipboard, faNewspaper } from '@fortawesome/free-regular-svg-icons';
@@ -41,7 +41,7 @@ app.use(pinia);
4141
app.use(head);
4242
app.mixin(VueHeadMixin);
4343

44-
usePartnerStore().populatePartnerCounts();
44+
usePartnerStore().initialize();
4545

4646
app.use(VueGtag, {
4747
config: { id: import.meta.env.VITE_GOOGLE_ANALYTICS_PROPERTY_ID },

src/stores/cveRecord.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import _ from 'lodash';
33

44

55
export const usecveRecordStore = defineStore('cveRecord', {
6-
state: () => {
6+
state: () => {
77
return {
88
cveId: '',
99
cveIdRegex: /^CVE-\d{4}-\d{4,7}$/i,
@@ -27,7 +27,6 @@ export const usecveRecordStore = defineStore('cveRecord', {
2727
submenu: {}
2828
},
2929
orgIdAndLongNameMap: {},
30-
cveProgramShortName: 'cve'
3130
}
3231
},
3332
actions: {

src/stores/partners.js

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ import axios from 'axios';
55
export const usePartnerStore = defineStore('partner', {
66
state: () => {
77
return {
8+
cveProgramShortName: 'cve',
89
partnerCounts: {},
9-
partnerShortLongNameMap: {},
10+
uuid2LongNameMap: {},
1011
selectedPartnerCountry: "",
11-
selectedCountryInternalChange: true, //Used to track if a country was selected from the PartnerMap or the CNAs.vue list
12+
// Used to track if a country was selected from the PartnerMap or the
13+
// CNAs.vue list:
14+
selectedCountryInternalChange: true,
15+
short2FullNameMap: {},
1216
}
1317
},
1418
actions: {
19+
initialize() {
20+
21+
this.populatePartnerCounts();
22+
this.populateUuid2LongNameMap();
23+
this.createShort2FullNameMap();
24+
},
1525
populatePartnerCounts () {
1626
const partnerCounts = {
1727
type: {}, role: {}, totalPartners: 0, countries: {}, countriesCount: 0,
@@ -62,18 +72,79 @@ export const usePartnerStore = defineStore('partner', {
6272

6373
this.partnerCounts = partnerCounts;
6474
},
65-
async populatePartnerShortLongNameMap () {
75+
async populateUuid2LongNameMap () {
6676

6777
const url = `${import.meta.env.VITE_API_BASE_URL}cve-partner-name-map.json`;
6878

6979
try {
7080
const response = await axios.get(url, { timeout: 30000 });
7181

72-
this.partnerShortLongNameMap = response?.data || {};
82+
this.uuid2LongNameMap = response?.data || {};
7383

7484
} catch (error) {
7585
console.log(`Unavailable: ${url}`);
7686
}
77-
}
87+
},
88+
createShort2FullNameMap() {
89+
90+
// This creates a mapping of **lowercased** short names to long names,
91+
// based on the static CNA list data stored locally. At present,
92+
// there is no other way to get a long name given a short name.
93+
94+
const short2FullNameMap = new Map();
95+
96+
PartnerData.forEach((entry) => {
97+
short2FullNameMap.set(entry.shortName.toLowerCase(),
98+
entry.organizationName);
99+
});
100+
101+
this.short2FullNameMap = short2FullNameMap;
102+
},
103+
getOrganizationName(assignerName, assignerUUID, ownerName) {
104+
105+
// Given the assigner name and UUID, as well as the owner name (optional),
106+
// return the appropriate name string to display as the CNA for the
107+
// published record. In almost all cases, this will be the long name
108+
// obtained by using the UUID to get the name from the map. When the
109+
// assigner and owner name are different, the owner's name is displayed
110+
// (it's assumed the ownership has changed and the assigner name does NOT
111+
// reflect the change).
112+
113+
const assignerNameLower = assignerName.toLowerCase();
114+
const ownerNameLower = ownerName?.toLowerCase();
115+
116+
if (ownerName && assignerNameLower !== ownerNameLower) {
117+
118+
// Display the owner name - try to get the full name using the
119+
// static CNA list. Otherwise, the owner's short name is displayed.
120+
121+
return this.short2FullNameMap.get(ownerNameLower)
122+
|| this.short2DisplayName(ownerName);
123+
}
124+
125+
// The displayed name is based on the assigner.
126+
127+
return this.uuid2LongNameMap[assignerUUID]
128+
|| (assignerNameLower === this.cveProgramShortName)
129+
? 'CVE Program' : this.short2FullNameMap.get(assignerNameLower)
130+
|| this.short2DisplayName(assignerName);
131+
},
132+
short2DisplayName(shortName) {
133+
134+
// Modify a given "short name" for display - replace any underscores
135+
// with a space and capitalize each word.
136+
137+
return this.capitalize(shortName.replace('_', ' '));
138+
},
139+
capitalize(str) {
140+
141+
// Capitalize each word in the given string. The 3rd part of the "OR"
142+
// in the regular expression allows for the word starting with various
143+
// "openings", which isn't really needed, but left for possible use
144+
// elsewhere.
145+
146+
return str.replace(/(?:^|\s|["'([{])+\S/g, match => match.toUpperCase());
147+
},
148+
78149
},
79150
});

src/views/CVERecord/PublishedRecord.vue

Lines changed: 9 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ export default {
161161
cnaContainer: {},
162162
cveProgramContainer: {},
163163
adpContainers: {},
164-
orgIdAndLongNameMap: usePartnerStore().partnerShortLongNameMap,
165-
short2FullNameMap: this.createShort2FullNameMap(),
164+
partnerStore: usePartnerStore(),
166165
};
167166
},
168167
methods: {
@@ -192,9 +191,9 @@ export default {
192191
const assignerName = this.cnaContainer.providerMetadata?.shortName;
193192
const assignerUUID = this.cnaContainer.providerMetadata.orgId;
194193
195-
const cnaName = this.getOrganizationName(assignerName,
196-
assignerUUID,
197-
ownerName);
194+
const cnaName = this.partnerStore.getOrganizationName(assignerName,
195+
assignerUUID,
196+
ownerName);
198197
199198
onPageMenu[headingLabel].items['CNA'] = {
200199
label: `CNA: ${cnaName}`,
@@ -205,7 +204,8 @@ export default {
205204
206205
if (Object.keys(this.cveProgramContainer).length > 0) {
207206
onPageMenu[headingLabel].items['CVE Program'] = {
208-
label: this.getOrganizationName(this.cveProgramContainer.providerMetadata?.shortName, this.cveProgramContainer.providerMetadata.orgId),
207+
label: this.partnerStore.getOrganizationName(this.cveProgramContainer.providerMetadata?.shortName,
208+
this.cveProgramContainer.providerMetadata.orgId),
209209
anchorId: `cve-program-${this.cveProgramContainer.providerMetadata.orgId}`
210210
}
211211
this.cveProgramContainer.onPageMenu = onPageMenu[headingLabel].items['CVE Program'];
@@ -215,7 +215,8 @@ export default {
215215
216216
Object.keys(this.adpContainers).forEach( (containerName) => {
217217
adpContainersMenu[`ADP-${this.adpContainers[containerName].providerMetadata.orgId}`] = {
218-
label: this.getOrganizationName(this.adpContainers[containerName].providerMetadata.shortName, this.adpContainers[containerName].providerMetadata.orgId),
218+
label: this.partnerStore.getOrganizationName(this.adpContainers[containerName].providerMetadata.shortName,
219+
this.adpContainers[containerName].providerMetadata.orgId),
219220
anchorId: `adp-${this.adpContainers[containerName].providerMetadata.orgId}`
220221
}
221222
this.adpContainers[containerName].onPageMenu = adpContainersMenu[`ADP-${this.adpContainers[containerName].providerMetadata.orgId}`];
@@ -241,7 +242,7 @@ export default {
241242
242243
if (this.originalRecordData?.containers?.adp) {
243244
this.originalRecordData.containers.adp.forEach((adp) => {
244-
if (adp.providerMetadata.shortName.toLowerCase() === this.cveRecordStore.cveProgramShortName) {
245+
if (adp.providerMetadata.shortName.toLowerCase() === this.partnerStore.cveProgramShortName) {
245246
this.cveProgramContainer = adp;
246247
this.cveRecordStore.accordionState[`cve-program-${adp.providerMetadata.orgId}`] = true;
247248
}
@@ -259,51 +260,6 @@ export default {
259260
this.getContentForField(field);
260261
});
261262
},
262-
getOrganizationName(assignerName, assignerUUID, ownerName) {
263-
264-
// Given the assigner name and UUID, as well as the owner name (optional),
265-
// return the appropriate name string to display as the CNA for the
266-
// published record. In almost all cases, this will be the long name
267-
// obtained by using the UUID to get the name from the map. When the
268-
// assigner and owner name are different, the owner's name is displayed
269-
// (it's assumed the ownership has changed and the assigner name does NOT
270-
// reflect the change).
271-
272-
const assignerNameLower = assignerName.toLowerCase();
273-
const ownerNameLower = ownerName?.toLowerCase();
274-
275-
if (ownerName && assignerNameLower !== ownerNameLower) {
276-
277-
// Display the owner name - try to get the full name using the
278-
// static CNA list. Otherwise, the owner's short name is displayed.
279-
280-
return this.short2FullNameMap.get(ownerNameLower)
281-
|| this.short2DisplayName(ownerName);
282-
}
283-
284-
// The displayed name is based on the assigner.
285-
286-
return this.orgIdAndLongNameMap?.[assignerUUID]
287-
|| (assignerNameLower === this.cveRecordStore.cveProgramShortName)
288-
? 'CVE Program' : this.short2FullNameMap.get(assignerNameLower)
289-
|| this.short2DisplayName(assignerName);
290-
},
291-
short2DisplayName(shortName) {
292-
293-
// Modify a given "short name" for display - replace any underscores
294-
// with a space and capitalize each word.
295-
296-
return this.capitalize(shortName.replace('_', ' '));
297-
},
298-
capitalize(str) {
299-
300-
// Capitalize each word in the given string. The 3rd part of the "OR"
301-
// in the regular expression allows for the word starting with various
302-
// "openings", which isn't really needed, but left for possible use
303-
// elsewhere.
304-
305-
return str.replace(/(?:^|\s|["'([{])+\S/g, match => match.toUpperCase());
306-
},
307263
getCredits() {
308264
// schema: https://github.com/CVEProject/cve-schema/blob/master/schema/v5.0/CVE_JSON_5.0_schema.json#L971-L1015
309265
const value = this.originalRecordData.containers?.cna?.credits;
@@ -622,21 +578,6 @@ export default {
622578
});
623579
return tableWithHeaders;
624580
},
625-
createShort2FullNameMap() {
626-
627-
// This creates a mapping of **lowercased** short names to long names,
628-
// based on the static CNA list data stored locally. At present,
629-
// there is no other way to get a long name given a short name.
630-
631-
const short2FullNameMap = new Map();
632-
633-
CNAData.forEach((entry) => {
634-
short2FullNameMap.set(entry.shortName.toLowerCase(),
635-
entry.organizationName);
636-
});
637-
638-
return short2FullNameMap;
639-
}
640581
},
641582
beforeMount() {
642583

0 commit comments

Comments
 (0)