@rancher/shell 3.0.6 → 3.0.8-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/assets/images/pl/dark/rancher-logo.svg +131 -44
  2. package/assets/images/pl/rancher-logo.svg +120 -44
  3. package/assets/images/vendor/githubapp.svg +13 -0
  4. package/assets/styles/base/_basic.scss +2 -2
  5. package/assets/styles/base/_color-classic.scss +51 -0
  6. package/assets/styles/base/_color.scss +3 -3
  7. package/assets/styles/base/_mixins.scss +1 -1
  8. package/assets/styles/base/_typography.scss +1 -1
  9. package/assets/styles/base/_variables-classic.scss +47 -0
  10. package/assets/styles/global/_button.scss +49 -17
  11. package/assets/styles/global/_form.scss +1 -1
  12. package/assets/styles/themes/_dark.scss +4 -0
  13. package/assets/styles/themes/_light.scss +3 -69
  14. package/assets/styles/themes/_modern.scss +194 -50
  15. package/assets/styles/vendor/vue-select.scss +1 -2
  16. package/assets/translations/en-us.yaml +124 -32
  17. package/assets/translations/zh-hans.yaml +0 -4
  18. package/components/ClusterIconMenu.vue +1 -1
  19. package/components/ClusterProviderIcon.vue +1 -1
  20. package/components/CodeMirror.vue +1 -1
  21. package/components/IconOrSvg.vue +40 -29
  22. package/components/Inactivity.vue +222 -106
  23. package/components/InstallHelmCharts.vue +2 -2
  24. package/components/ResourceDetail/index.vue +2 -1
  25. package/components/SortableTable/index.vue +17 -2
  26. package/components/SortableTable/sorting.js +3 -1
  27. package/components/Tabbed/index.vue +5 -5
  28. package/components/fleet/FleetConfigMapSelector.vue +117 -0
  29. package/components/fleet/FleetSecretSelector.vue +127 -0
  30. package/components/fleet/__tests__/FleetConfigMapSelector.test.ts +125 -0
  31. package/components/fleet/__tests__/FleetSecretSelector.test.ts +82 -0
  32. package/components/form/FileImageSelector.vue +13 -4
  33. package/components/form/FileSelector.vue +11 -2
  34. package/components/form/ResourceLabeledSelect.vue +1 -0
  35. package/components/form/ResourceTabs/index.vue +37 -18
  36. package/components/form/SecretSelector.vue +6 -2
  37. package/components/form/__tests__/ResourceLabeledSelect.test.ts +90 -0
  38. package/components/nav/Group.vue +29 -9
  39. package/components/nav/Header.vue +7 -8
  40. package/components/nav/NamespaceFilter.vue +1 -1
  41. package/components/nav/TopLevelMenu.helper.ts +47 -20
  42. package/components/nav/TopLevelMenu.vue +44 -14
  43. package/components/nav/Type.vue +0 -5
  44. package/components/nav/__tests__/TopLevelMenu.test.ts +2 -0
  45. package/config/pagination-table-headers.js +10 -2
  46. package/config/product/auth.js +1 -0
  47. package/config/product/explorer.js +4 -3
  48. package/config/query-params.js +1 -0
  49. package/config/settings.ts +8 -1
  50. package/config/table-headers.js +9 -0
  51. package/config/types.js +2 -0
  52. package/core/plugin.ts +18 -6
  53. package/core/types.ts +8 -0
  54. package/detail/provisioning.cattle.io.cluster.vue +1 -0
  55. package/dialog/AddonConfigConfirmationDialog.vue +45 -1
  56. package/dialog/InstallExtensionDialog.vue +71 -45
  57. package/dialog/UninstallExtensionDialog.vue +2 -1
  58. package/dialog/__tests__/InstallExtensionDialog.test.ts +111 -0
  59. package/edit/__tests__/fleet.cattle.io.helmop.test.ts +52 -11
  60. package/edit/auth/AuthProviderWarningBanners.vue +14 -1
  61. package/edit/auth/github-app-steps.vue +97 -0
  62. package/edit/auth/github-steps.vue +75 -0
  63. package/edit/auth/github.vue +94 -65
  64. package/edit/auth/oidc.vue +86 -16
  65. package/edit/fleet.cattle.io.helmop.vue +51 -2
  66. package/edit/networking.k8s.io.networkpolicy/PolicyRuleTarget.vue +15 -5
  67. package/edit/provisioning.cattle.io.cluster/__tests__/rke2.test.ts +11 -9
  68. package/edit/provisioning.cattle.io.cluster/rke2.vue +56 -9
  69. package/edit/provisioning.cattle.io.cluster/tabs/AddOnConfig.vue +28 -2
  70. package/list/projectsecret.vue +1 -1
  71. package/machine-config/azure.vue +1 -1
  72. package/mixins/__tests__/chart.test.ts +1 -1
  73. package/mixins/chart.js +2 -2
  74. package/models/__tests__/chart.test.ts +17 -9
  75. package/models/__tests__/compliance.cattle.io.clusterscanprofile.spec.js +30 -0
  76. package/models/catalog.cattle.io.app.js +1 -1
  77. package/models/chart.js +3 -1
  78. package/models/compliance.cattle.io.clusterscanprofile.js +1 -1
  79. package/models/event.js +7 -0
  80. package/models/management.cattle.io.authconfig.js +1 -0
  81. package/models/provisioning.cattle.io.cluster.js +9 -0
  82. package/package.json +2 -2
  83. package/pages/auth/login.vue +5 -2
  84. package/pages/auth/verify.vue +1 -1
  85. package/pages/c/_cluster/apps/charts/AppChartCardSubHeader.vue +3 -2
  86. package/pages/c/_cluster/apps/charts/chart.vue +2 -2
  87. package/pages/c/_cluster/explorer/EventsTable.vue +92 -9
  88. package/pages/c/_cluster/explorer/tools/index.vue +3 -3
  89. package/pages/c/_cluster/settings/performance.vue +13 -26
  90. package/pages/c/_cluster/uiplugins/PluginInfoPanel.vue +159 -62
  91. package/pages/c/_cluster/uiplugins/__tests__/PluginInfoPanel.test.ts +102 -0
  92. package/pages/c/_cluster/uiplugins/__tests__/{index.spec.ts → index.test.ts} +121 -55
  93. package/pages/c/_cluster/uiplugins/index.vue +110 -94
  94. package/pages/home.vue +313 -12
  95. package/plugins/__tests__/subscribe.events.test.ts +194 -0
  96. package/plugins/axios.js +2 -1
  97. package/plugins/dashboard-store/actions.js +4 -1
  98. package/plugins/dashboard-store/getters.js +1 -1
  99. package/plugins/dashboard-store/resource-class.js +20 -5
  100. package/plugins/steve/__tests__/subscribe.spec.ts +27 -24
  101. package/plugins/steve/index.js +18 -10
  102. package/plugins/steve/mutations.js +2 -2
  103. package/plugins/steve/resourceWatcher.js +2 -2
  104. package/plugins/steve/steve-pagination-utils.ts +12 -9
  105. package/plugins/steve/subscribe.js +113 -85
  106. package/plugins/subscribe-events.ts +211 -0
  107. package/rancher-components/BadgeState/BadgeState.vue +8 -6
  108. package/rancher-components/Banner/Banner.vue +2 -1
  109. package/rancher-components/Form/Checkbox/Checkbox.vue +3 -3
  110. package/rancher-components/Form/Radio/RadioButton.vue +3 -3
  111. package/scripts/extension/publish +1 -1
  112. package/store/auth.js +8 -3
  113. package/store/aws.js +8 -6
  114. package/store/features.js +1 -0
  115. package/store/index.js +21 -25
  116. package/store/prefs.js +6 -0
  117. package/types/extension-manager.ts +8 -1
  118. package/types/kube/kube-api.ts +2 -1
  119. package/types/rancher/index.d.ts +1 -0
  120. package/types/resources/settings.d.ts +52 -23
  121. package/types/shell/index.d.ts +412 -336
  122. package/types/store/subscribe-events.types.ts +70 -0
  123. package/types/store/subscribe.types.ts +6 -22
  124. package/utils/__tests__/cluster.test.ts +379 -1
  125. package/utils/cluster.js +157 -3
  126. package/utils/dynamic-content/__tests__/config.test.ts +187 -0
  127. package/utils/dynamic-content/__tests__/index.test.ts +390 -0
  128. package/utils/dynamic-content/__tests__/info.test.ts +263 -0
  129. package/utils/dynamic-content/__tests__/new-release.test.ts +216 -0
  130. package/utils/dynamic-content/__tests__/support-notice.test.ts +262 -0
  131. package/utils/dynamic-content/__tests__/util.test.ts +235 -0
  132. package/utils/dynamic-content/config.ts +55 -0
  133. package/utils/dynamic-content/index.ts +273 -0
  134. package/utils/dynamic-content/info.ts +219 -0
  135. package/utils/dynamic-content/new-release.ts +126 -0
  136. package/utils/dynamic-content/support-notice.ts +169 -0
  137. package/utils/dynamic-content/types.d.ts +101 -0
  138. package/utils/dynamic-content/util.ts +122 -0
  139. package/utils/inactivity.ts +104 -0
  140. package/utils/pagination-utils.ts +105 -31
  141. package/utils/pagination-wrapper.ts +6 -8
  142. package/utils/release-notes.ts +1 -1
  143. package/utils/sort.js +5 -0
  144. package/utils/unit-tests/pagination-utils.spec.ts +283 -0
  145. package/utils/validators/formRules/__tests__/index.test.ts +7 -0
  146. package/utils/validators/formRules/index.ts +2 -2
@@ -0,0 +1,273 @@
1
+ /**
2
+ * This is the main dynamic content file that provides the 'fetchAndProcessDynamicContent' function
3
+ *
4
+ * This is the main entry point for reading and processing dynamic content
5
+ */
6
+
7
+ import day from 'dayjs';
8
+ import * as jsyaml from 'js-yaml';
9
+ import semver from 'semver';
10
+ import { isAdminUser } from '@shell/store/type-map';
11
+ import { getVersionData } from '@shell/config/version';
12
+ import { processReleaseVersion } from './new-release';
13
+ import { processSupportNotices } from './support-notice';
14
+ import { Context, DynamicContent, VersionInfo } from './types';
15
+ import { createLogger, LOCAL_STORAGE_CONTENT_DEBUG_LOG } from './util';
16
+ import { getConfig } from './config';
17
+ import { SystemInfoProvider } from './info';
18
+
19
+ const FETCH_DELAY = 3 * 1000; // Short delay to let UI settle before we fetch the updates document
20
+ const FETCH_REQUEST_TIMEOUT = 15000; // Time out the request after 15 seconds
21
+ const FETCH_CONCURRENT_SECONDS = 30; // Time to wait to ignore another in-progress fetch (seconds)
22
+
23
+ export const UPDATE_DATE_FORMAT = 'YYYY-MM-DD'; // Format of the fetch date
24
+
25
+ const LOCAL_STORAGE_UPDATE_FETCH_DATE = 'rancher-updates-fetch-next'; // Local storage setting that holds the date when we should next try and fetch content
26
+ const LOCAL_STORAGE_UPDATE_CONTENT = 'rancher-updates-last-content'; // Local storage setting that holds the last fetched content
27
+ const LOCAL_STORAGE_UPDATE_ERRORS = 'rancher-updates-fetch-errors'; // Local storage setting that holds the count of contiguous errors
28
+ const LOCAL_STORAGE_UPDATE_FETCHING = 'rancher-updates-fetching'; // Local storage setting that holds the date and time of the last fetch that was started
29
+
30
+ const BACKOFFS = [1, 1, 1, 2, 2, 3, 5]; // Backoff in days for the contiguous number of errors (i.e. after 1 errors, we wait 1 day, after 3 errors, we wait 2 days, etc.)
31
+
32
+ const DEFAULT_RELEASE_NOTES_URL = 'https://github.com/rancher/rancher/releases/tag/v$version'; // Default release notes URL
33
+
34
+ /**
35
+ * Fetch dynamic content if needed and process it if it has changed since we last checked
36
+ */
37
+ export async function fetchAndProcessDynamicContent(dispatch: Function, getters: any, axios: any) {
38
+ // Check that the product is Rancher
39
+ // => Check that we are NOT in single product mode (e.g. Harvester)
40
+ const isSingleProduct = getters['isSingleProduct'];
41
+
42
+ if (!!isSingleProduct) {
43
+ return;
44
+ }
45
+
46
+ const config = getConfig(getters);
47
+
48
+ // If not enabled via the configuration, then just return
49
+ if (!config.enabled) {
50
+ console.log('Dynamic content disabled through configuration'); // eslint-disable-line no-console
51
+
52
+ return;
53
+ }
54
+
55
+ const logger = createLogger(config);
56
+
57
+ // Common context to pass through to functions for store access, logging, etc
58
+ const context: Context = {
59
+ dispatch,
60
+ getters,
61
+ axios,
62
+ logger,
63
+ config,
64
+ isAdmin: isAdminUser(getters),
65
+ settings: {
66
+ releaseNotesUrl: DEFAULT_RELEASE_NOTES_URL,
67
+ suseExtensions: [],
68
+ }
69
+ };
70
+
71
+ logger.debug('Read configuration', context.config);
72
+
73
+ try {
74
+ // Fetch the dynamic content if required, otherwise return the cached content or empty object if no content available
75
+ const content = await fetchDynamicContent(context);
76
+
77
+ // Version metadata
78
+ const versionData = getVersionData();
79
+ const version = semver.coerce(versionData.Version);
80
+
81
+ if (!version || !content) {
82
+ return;
83
+ }
84
+
85
+ const versionInfo: VersionInfo = {
86
+ version,
87
+ isPrime: config.prime,
88
+ };
89
+
90
+ // If not logging, then clear out any log data from local storage
91
+ if (!config.log) {
92
+ window.localStorage.removeItem(LOCAL_STORAGE_CONTENT_DEBUG_LOG);
93
+ }
94
+
95
+ if (content?.settings) {
96
+ // Update the settings data from the content, so that it is has the settings with their defaults or values from the dynamic content payload
97
+ context.settings = {
98
+ ...context.settings,
99
+ ...content.settings
100
+ };
101
+ }
102
+
103
+ // If the cached content has a debug version then use that as an override for the current version number
104
+ // This is only for debug and testing purposes
105
+ if (content.settings?.debugVersion) {
106
+ versionInfo.version = semver.coerce(content.settings.debugVersion);
107
+ logger.debug(`Overriding version number to ${ content.settings.debugVersion }`);
108
+ }
109
+
110
+ // We always process the content in case the Rancher version has changed or the date means that an announcement/notification should now be shown
111
+
112
+ // New release notifications and support notifications are shown to ALL community users, but only to admin users when Prime
113
+ if (!config.prime || context.isAdmin) {
114
+ // New release notifications
115
+ processReleaseVersion(context, content.releases, versionInfo);
116
+
117
+ // EOM, EOL notifications
118
+ processSupportNotices(context, content.support, versionInfo);
119
+ }
120
+ } catch (e) {
121
+ logger.error('Error reading or processing dynamic content', e);
122
+ }
123
+ }
124
+
125
+ /**
126
+ * We use a signal to timeout the connection
127
+ * For air-gapped environments, this ensures the request will timeout after FETCH_REQUEST_TIMEOUT
128
+ * This timeout is set relatively low (15s). The default, otherwise, is 2 minutes.
129
+ *
130
+ * @param timeoutMs Time in milliseconds after which the abort signal should signal
131
+ */
132
+ function newRequestAbortSignal(timeoutMs: number) {
133
+ const abortController = new AbortController();
134
+
135
+ setTimeout(() => abortController.abort(), timeoutMs || 0);
136
+
137
+ return abortController.signal;
138
+ }
139
+
140
+ /**
141
+ * Update the local storage data that tracks when to next fetch content and how many consecutive errors we have had
142
+ *
143
+ * @param didError Indicates if we should update to record content retrieved without error or with error
144
+ */
145
+ function updateFetchInfo(didError: boolean) {
146
+ if (!didError) {
147
+ // No error, so check again tomorrow and remove the backoff setting, so it will get its default next time
148
+ const nextFetch = day().add(1, 'day');
149
+ const nextFetchString = nextFetch.format(UPDATE_DATE_FORMAT);
150
+
151
+ window.localStorage.setItem(LOCAL_STORAGE_UPDATE_FETCH_DATE, nextFetchString);
152
+ window.localStorage.removeItem(LOCAL_STORAGE_UPDATE_ERRORS);
153
+ } else {
154
+ // Did error, read the backoff, increase and add to the date
155
+ const contiguousErrorsString = window.localStorage.getItem(LOCAL_STORAGE_UPDATE_ERRORS) || '0';
156
+
157
+ let contiguousErrors = parseInt(contiguousErrorsString, 10);
158
+
159
+ // Increase the number of errors that have happened in a row
160
+ contiguousErrors++;
161
+
162
+ // Once we reach the max backoff, just stick with it
163
+ if (contiguousErrors >= BACKOFFS.length ) {
164
+ contiguousErrors = BACKOFFS.length - 1;
165
+ }
166
+
167
+ // Now find the backoff (days) given the error count and calculate the date of the next fetch
168
+ const daysToAdd = BACKOFFS[contiguousErrors];
169
+ const nextFetch = day().add(daysToAdd, 'day');
170
+ const nextFetchString = nextFetch.format(UPDATE_DATE_FORMAT);
171
+
172
+ window.localStorage.setItem(LOCAL_STORAGE_UPDATE_FETCH_DATE, nextFetchString);
173
+ window.localStorage.setItem(LOCAL_STORAGE_UPDATE_ERRORS, contiguousErrors.toString());
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Fetch dynamic content (if needed)
179
+ */
180
+ export async function fetchDynamicContent(context: Context): Promise<Partial<DynamicContent> | undefined> {
181
+ const { getters, logger, config } = context;
182
+
183
+ // Check if we already have done an update check today
184
+ let content: Partial<DynamicContent> = {};
185
+
186
+ try {
187
+ const today = day();
188
+ const todayString = today.format(UPDATE_DATE_FORMAT);
189
+ const nextFetch = window.localStorage.getItem(LOCAL_STORAGE_UPDATE_FETCH_DATE) || todayString;
190
+
191
+ // Read the cached content from local storage if possible
192
+ content = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_UPDATE_CONTENT) || '{}');
193
+
194
+ const nextFetchDay = day(nextFetch);
195
+
196
+ // Just in case next day gets reset to the past or corrupt, otherwise next fetch needs to not be in the future
197
+ if (!nextFetchDay.isValid() || !nextFetchDay.isAfter(today)) {
198
+ logger.info(`Performing update check on ${ todayString }`);
199
+ logger.debug(`Performing update check on ${ todayString }`);
200
+
201
+ const activeFetch = window.localStorage.getItem(LOCAL_STORAGE_UPDATE_FETCHING);
202
+
203
+ if (activeFetch) {
204
+ const activeFetchDate = day(activeFetch);
205
+
206
+ if (activeFetchDate.isValid() && today.diff(activeFetchDate, 'second') < FETCH_CONCURRENT_SECONDS) {
207
+ logger.debug('Already fetching dynamic content in another tab (or previous tab closed while fetching) - skipping');
208
+
209
+ return content;
210
+ }
211
+ }
212
+
213
+ // Set the local storage key that indicates a tab is fetching the content - prevents other tabs doing so at the same time
214
+ window.localStorage.setItem(LOCAL_STORAGE_UPDATE_FETCHING, today.toString());
215
+
216
+ // Wait a short while before fetching dynamic content
217
+ await new Promise((resolve) => setTimeout(resolve, FETCH_DELAY));
218
+
219
+ const systemData = new SystemInfoProvider(getters, content?.settings || {});
220
+ const qs = systemData.buildQueryString();
221
+ const distribution = config.prime ? 'prime' : 'community';
222
+ const url = `${ config.endpoint.replace('$dist', distribution) }?${ qs }`;
223
+
224
+ logger.debug(`Fetching dynamic content from: ${ url.split('?')[0] }`, url);
225
+
226
+ // We use axios directly so that we can pass in the abort signal to implement the connection timeout
227
+ const res = await context.axios({
228
+ url,
229
+ method: 'get',
230
+ timeout: FETCH_REQUEST_TIMEOUT,
231
+ noApiCsrf: true,
232
+ withCredentials: false,
233
+ signal: newRequestAbortSignal(FETCH_REQUEST_TIMEOUT),
234
+ responseType: 'text' // We always want the raw text back - otherwise YAML gives text and JSON gives object
235
+ });
236
+
237
+ // The data should be YAML (or JSON) in the 'data' attribute
238
+ if (res?.data) {
239
+ try {
240
+ content = jsyaml.load(res.data) as any;
241
+
242
+ window.localStorage.setItem(LOCAL_STORAGE_UPDATE_CONTENT, JSON.stringify(content));
243
+
244
+ // Update the last date now
245
+ updateFetchInfo(false);
246
+ } catch (e) {
247
+ logger.error('Failed to parse YAML/JSON from dynamic content package', e);
248
+ }
249
+ } else {
250
+ logger.error('Error fetching dynamic content package (unexpected data)');
251
+ }
252
+ } else {
253
+ logger.info(`Skipping update check for dynamic content - next check due on ${ nextFetch } (today is ${ todayString })`);
254
+
255
+ // If debug mode, then wait a bit to simulate the delay we would have had if we were fetching
256
+ if (config.debug) {
257
+ await new Promise((resolve) => setTimeout(resolve, FETCH_DELAY));
258
+ }
259
+ }
260
+ } catch (e) {
261
+ logger.error('Error occurred reading dynamic content', e);
262
+
263
+ // We had an error, so update data in local storage so that we try again appropriately next time
264
+ updateFetchInfo(true);
265
+ }
266
+
267
+ logger.debug('End fetchDynamicContent');
268
+
269
+ // Remove the local storage key that indicates a tab is fetching the content
270
+ window.localStorage.removeItem(LOCAL_STORAGE_UPDATE_FETCHING);
271
+
272
+ return content;
273
+ }
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Helper for collecting system information and formatting into to a query string
3
+ */
4
+
5
+ import { sha256 } from '@shell/utils/crypto';
6
+ import {
7
+ COUNT,
8
+ MANAGEMENT,
9
+ } from '@shell/config/types';
10
+ import { SETTING } from '@shell/config/settings';
11
+ import { getVersionData } from '@shell/config/version';
12
+ import { SettingsInfo } from '@shell/utils/dynamic-content/types';
13
+
14
+ const QS_VERSION = 'v1'; // Include a version number in the query string in case we want to version the set of params we are sending
15
+ const UNKNOWN = 'unknown';
16
+
17
+ // List of known UI extensions from SUSE
18
+ const SUSE_EXTENSIONS = [
19
+ 'capi',
20
+ 'elemental',
21
+ 'harvester',
22
+ 'kubewarden',
23
+ 'neuvector-ui-ext',
24
+ 'observability',
25
+ 'supportability-review-app',
26
+ 'virtual-clusters'
27
+ ];
28
+
29
+ /**
30
+ * System information that is collected and which can then be encoded into a query string in the dyanmic content request
31
+ */
32
+ type SystemInfo = {
33
+ systemUUID: string;
34
+ systemHash: string;
35
+ serverVersionType: string;
36
+ userHash: string;
37
+ version: string;
38
+ isDeveloperVersion: boolean;
39
+ isPrime: boolean;
40
+ isLTS: boolean;
41
+ clusterCount: number;
42
+ localCluster: any;
43
+ extensions?: {
44
+ knownInstalled: string[];
45
+ customCount: number;
46
+ };
47
+ browserSize: string;
48
+ screenSize: string;
49
+ language: string;
50
+ };
51
+
52
+ /**
53
+ * Helper that will gather system information and provided the `buildQueryString` method to format as a query string
54
+ */
55
+ export class SystemInfoProvider {
56
+ private info: SystemInfo;
57
+
58
+ constructor(getters: any, settings: Partial<SettingsInfo>) {
59
+ this.info = this.getSystemData(getters, settings);
60
+ }
61
+
62
+ /**
63
+ * Get the data that we need from the system
64
+ * @param getters Store getters to access the store
65
+ * @returns System data
66
+ */
67
+ private getSystemData(getters: any, settingsInfo: Partial<SettingsInfo>): SystemInfo {
68
+ let url;
69
+ let systemUUID = UNKNOWN;
70
+ let serverVersionType = UNKNOWN;
71
+
72
+ const serverUrlSetting = getters['management/byId'](MANAGEMENT.SETTING, SETTING.SERVER_URL);
73
+
74
+ // Server URL
75
+ if (serverUrlSetting) {
76
+ url = serverUrlSetting.value || UNKNOWN;
77
+ }
78
+
79
+ // UUID
80
+ const uuidSetting = getters['management/byId'](MANAGEMENT.SETTING, 'install-uuid');
81
+
82
+ if (uuidSetting) {
83
+ systemUUID = uuidSetting.value || UNKNOWN;
84
+ }
85
+
86
+ // Server Version Type
87
+ const serverVersionTypeSetting = getters['management/byId'](MANAGEMENT.SETTING, 'server-version-type');
88
+
89
+ if (serverVersionTypeSetting) {
90
+ serverVersionType = serverVersionTypeSetting.value || UNKNOWN;
91
+ }
92
+
93
+ // Otherwise, use the window location's host
94
+ url = url || window.location?.host;
95
+
96
+ // System and User hashes
97
+ const systemHash = (sha256(url, 'hex') as string).substring(0, 32);
98
+ const currentPrincipal = getters['auth/principalId'] || UNKNOWN;
99
+ const userHash = (sha256(currentPrincipal, 'hex') as string).substring(0, 32);
100
+
101
+ // Version info
102
+ const versionData = getVersionData();
103
+ const vers = versionData.Version.split('-');
104
+
105
+ // General stats that can help us shape content delivery
106
+
107
+ // High-level information from clusters
108
+ const counts = this.getAll(getters, COUNT)?.[0]?.counts || {};
109
+ const clusterCount = counts[MANAGEMENT.CLUSTER] || {};
110
+ const all = this.getAll(getters, MANAGEMENT.CLUSTER);
111
+ const localCluster = all ? all.find((c: any) => c.isLocal) : undefined;
112
+
113
+ // Stats for installed extensions
114
+ const uiExtensionList = getters['uiplugins/plugins'];
115
+ let extensions;
116
+
117
+ if (uiExtensionList) {
118
+ const suseExtensions = [
119
+ ...SUSE_EXTENSIONS,
120
+ ...settingsInfo?.suseExtensions || []
121
+ ];
122
+ const notBuiltIn = uiExtensionList.filter((e: any) => !e.builtin);
123
+ const suseNames = notBuiltIn.filter((e: any) => suseExtensions.includes(e.name)).map((e: any) => e.name);
124
+ const customCount = notBuiltIn.length - suseNames.length;
125
+
126
+ extensions = {
127
+ knownInstalled: suseNames,
128
+ customCount,
129
+ };
130
+ }
131
+
132
+ const screenSize = `${ window.screen?.width || '?' }x${ window.screen?.height || '?' }`;
133
+ const browserSize = `${ window.innerWidth }x${ window.innerHeight }`;
134
+
135
+ return {
136
+ systemUUID,
137
+ userHash,
138
+ systemHash,
139
+ serverVersionType,
140
+ version: vers[0],
141
+ isDeveloperVersion: vers.length > 1,
142
+ isPrime: versionData.RancherPrime === 'true',
143
+ isLTS: false,
144
+ clusterCount: clusterCount?.summary?.count,
145
+ localCluster,
146
+ extensions,
147
+ screenSize,
148
+ browserSize,
149
+ language: window.navigator?.language,
150
+ };
151
+ }
152
+
153
+ // Helper to get all resources of a type only if they are available
154
+ private getAll(getters: any, typeName: string): any {
155
+ if (getters['management/typeRegistered'](typeName)) {
156
+ return getters['management/all'](typeName);
157
+ }
158
+
159
+ return undefined;
160
+ }
161
+
162
+ /**
163
+ * Build query string of params to send so that we can deliver better content
164
+ */
165
+ public buildQueryString(): string {
166
+ const systemData = this.info;
167
+ const params = [`dcv=${ QS_VERSION }`];
168
+
169
+ // System and User
170
+ params.push(`s=${ systemData.systemHash }`);
171
+ params.push(`u=${ systemData.userHash }`);
172
+
173
+ // Install UUID
174
+ if (systemData.systemUUID !== UNKNOWN) {
175
+ params.push(`uuid=${ systemData.systemUUID }`);
176
+ }
177
+
178
+ // Server Version Type
179
+ if (systemData.serverVersionType !== UNKNOWN) {
180
+ params.push(`svt=${ systemData.serverVersionType }`);
181
+ }
182
+
183
+ // Version info
184
+ params.push(`v=${ systemData.version }`);
185
+ params.push(`dev=${ systemData.isDeveloperVersion }`);
186
+ params.push(`p=${ systemData.isPrime }`);
187
+
188
+ // Remove LTS for now, until we can determine LTS status
189
+ // params.push(`lts=${ systemData.isLTS }`);
190
+
191
+ // Clusters
192
+ params.push(`cc=${ systemData.clusterCount }`);
193
+
194
+ if (systemData.localCluster) {
195
+ params.push(`lkv=${ systemData.localCluster.kubernetesVersionBase || UNKNOWN }`);
196
+ params.push(`lcp=${ systemData.localCluster.provisioner || UNKNOWN }`);
197
+ params.push(`lnc=${ systemData.localCluster.status.nodeCount || 0 }`);
198
+ }
199
+
200
+ // Extensions
201
+ if (systemData.extensions) {
202
+ params.push(`xkn=${ systemData.extensions.knownInstalled.join(',') }`);
203
+ params.push(`xcc=${ systemData.extensions.customCount }`);
204
+ }
205
+
206
+ // Browser Language
207
+ params.push(`bl=${ systemData.language }`);
208
+
209
+ // Browser size
210
+ params.push(`bs=${ systemData.browserSize }`);
211
+
212
+ // Screen size
213
+ if (systemData.screenSize !== '?x?') {
214
+ params.push(`ss=${ systemData.screenSize }`);
215
+ }
216
+
217
+ return params.join('&');
218
+ }
219
+ }
@@ -0,0 +1,126 @@
1
+ /**
2
+ *
3
+ * The code in this file is responsible for adding New Release notifications driven off of the dynamic content metadata
4
+ *
5
+ * We handle two cases:
6
+ *
7
+ * 1. There is a new patch release available for the current Rancher version (e.g. user is in 2.12.0 and we release 2.12.1)
8
+ * 2. There is a new patch release available for the current Rancher version AND there is a newer version for a high minor releases
9
+ * > this often occurs because we release monthly releases in parallel with the new minor releases
10
+ *
11
+ * We show slightly different messages in these 2 cases.
12
+ *
13
+ */
14
+
15
+ import semver from 'semver';
16
+ import { NotificationLevel } from '@shell/types/notifications';
17
+ import { READ_NEW_RELEASE } from '@shell/store/prefs';
18
+ import { Context, ReleaseInfo, VersionInfo } from './types';
19
+ import { removeMatchingNotifications } from './util';
20
+
21
+ export async function processReleaseVersion(context: Context, releaseInfo: ReleaseInfo[] | undefined, versionInfo: VersionInfo) {
22
+ if (!releaseInfo || !versionInfo?.version || !Array.isArray(releaseInfo)) {
23
+ return;
24
+ }
25
+
26
+ const { version } = versionInfo;
27
+ const versions = releaseInfo.map((v: any) => semver.coerce(v.name));
28
+
29
+ // Sort the versions, so that the newest is first in the list
30
+ versions.sort((a: any, b: any) => semver.gt(b, a) ? 1 : -1);
31
+
32
+ // Find first newer version
33
+ const newer = versions.find((v: any) => semver.gt(v, version));
34
+
35
+ // Find newest patch version for the current version (if available)
36
+ const newerPatch = versions.find((v: any) => {
37
+ const newVersion = semver.coerce(v);
38
+
39
+ return newVersion && newVersion.major === version.major && newVersion.minor === version.minor && semver.gt(v, version);
40
+ });
41
+
42
+ if (newer) {
43
+ context.logger.info(`Found a newer release: ${ newer.version }`);
44
+
45
+ if (newerPatch && newer !== newerPatch) {
46
+ context.logger.info(`Also found a newer patch release: ${ newerPatch.version }`);
47
+ // There is a new patch release and a newer release
48
+ await addNewMultipleReleasesNotification(context, newerPatch.version, newer.version);
49
+ } else {
50
+ // There is a new release (but no newer patch release)
51
+ await addNewReleaseNotification(context, newer.version);
52
+ }
53
+ }
54
+ }
55
+
56
+ async function addNewReleaseNotification(context: Context, version: string) {
57
+ const prefix = 'new-release-';
58
+ const releaseNotesUrl = context.settings.releaseNotesUrl.replace('$version', version);
59
+ const { dispatch, getters, logger } = context;
60
+
61
+ // TODO: Get the preference
62
+ const lastReadVersion = getters['prefs/get'](READ_NEW_RELEASE) || '';
63
+ const t = getters['i18n/t'];
64
+
65
+ // Delete notification(s) for old release notes
66
+ // This shouldn't happen normally, as we release less often than notifications should expire
67
+ if (!await removeMatchingNotifications(context, prefix, version) && lastReadVersion !== version) {
68
+ logger.debug(`Adding new release notification for ${ version } because one did not exist`);
69
+
70
+ const notification = {
71
+ id: `${ prefix }${ version }`,
72
+ level: NotificationLevel.Announcement,
73
+ title: t('dynamicContent.newRelease.title', { version }),
74
+ message: t('dynamicContent.newRelease.message', { version }),
75
+ preference: {
76
+ key: READ_NEW_RELEASE,
77
+ value: version
78
+ },
79
+ primaryAction: {
80
+ label: t('dynamicContent.newRelease.moreInfo'),
81
+ target: releaseNotesUrl
82
+ }
83
+ };
84
+
85
+ await dispatch('notifications/add', notification);
86
+ }
87
+ }
88
+
89
+ async function addNewMultipleReleasesNotification(context: Context, version1: string, version2: string) {
90
+ const prefix = 'new-release-';
91
+ const key = `${ version1 }-${ version2 }`;
92
+ const releaseNotesUrl1 = context.settings.releaseNotesUrl.replace('$version', version1);
93
+ const releaseNotesUrl2 = context.settings.releaseNotesUrl.replace('$version', version2);
94
+ const { dispatch, getters, logger } = context;
95
+
96
+ // TODO: Get the preference
97
+ const lastReadVersion = getters['prefs/get'](READ_NEW_RELEASE) || '';
98
+ const t = getters['i18n/t'];
99
+
100
+ // Delete notification(s) for old release notes
101
+ // This shouldn't happen normally, as we release less often than notifications should expire
102
+ if (!await removeMatchingNotifications(context, prefix, key) && lastReadVersion !== key) {
103
+ logger.info(`Adding new multiple release notification for ${ version1 } and ${ version2 }`);
104
+
105
+ const notification = {
106
+ id: `${ prefix }${ key }`,
107
+ level: NotificationLevel.Announcement,
108
+ title: t('dynamicContent.multipleNewReleases.title'),
109
+ message: t('dynamicContent.multipleNewReleases.message', { version1, version2 }),
110
+ preference: {
111
+ key: READ_NEW_RELEASE,
112
+ value: key
113
+ },
114
+ primaryAction: {
115
+ label: t('dynamicContent.multipleNewReleases.moreInfo', { version: version1 }),
116
+ target: releaseNotesUrl1
117
+ },
118
+ secondaryAction: {
119
+ label: t('dynamicContent.multipleNewReleases.moreInfo', { version: version2 }),
120
+ target: releaseNotesUrl2
121
+ }
122
+ };
123
+
124
+ await dispatch('notifications/add', notification);
125
+ }
126
+ }